mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2025-05-09 07:34:02 +02:00
Fix missing 'final' modifiers
This commit is contained in:
parent
834a3dd4e5
commit
c5085bc460
Fabric/src/main/java/chylex/customwindowtitle
Forge/src/main/java/chylex/customwindowtitle
@ -10,21 +10,21 @@ public final class TitleParser{
|
||||
private static final Pattern tokenRegex = Pattern.compile("\\{([a-z]+)(?::([^}]+))?}");
|
||||
private static final Logger logger = LogManager.getLogger("CustomWindowTitle");
|
||||
|
||||
public static String parse(String input){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Matcher matcher = tokenRegex.matcher(input);
|
||||
public static String parse(final String input){
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final Matcher matcher = tokenRegex.matcher(input);
|
||||
|
||||
while(matcher.find()){
|
||||
String token = matcher.group(1);
|
||||
String[] args = StringUtils.split(matcher.group(2), ',');
|
||||
final String token = matcher.group(1);
|
||||
final String[] args = StringUtils.split(matcher.group(2), ',');
|
||||
|
||||
String result = null;
|
||||
|
||||
try{
|
||||
result = TitleTokens.getTokenFunction(token).apply(args == null ? ArrayUtils.EMPTY_STRING_ARRAY : args);
|
||||
}catch(TokenException e){
|
||||
}catch(final TokenException e){
|
||||
logger.warn("Error processing token '" + token + "': " + e.getMessage());
|
||||
}catch(Throwable t){
|
||||
}catch(final Throwable t){
|
||||
logger.warn("Error processing token '" + token + "': " + t.getMessage(), t);
|
||||
}
|
||||
|
||||
|
@ -11,29 +11,29 @@ public final class TitleTokens{
|
||||
|
||||
private static final Map<String, Function<String[], String>> tokenMap = new HashMap<>();
|
||||
|
||||
public static void registerToken(String token, Function<String[], String> processor){
|
||||
public static void registerToken(final String token, final Function<String[], String> processor){
|
||||
tokenMap.putIfAbsent(token, processor);
|
||||
}
|
||||
|
||||
public static Function<String[], String> getTokenFunction(String token){
|
||||
public static Function<String[], String> getTokenFunction(final String token){
|
||||
return tokenMap.getOrDefault(token, args -> null);
|
||||
}
|
||||
|
||||
// Arguments
|
||||
|
||||
public static Function<String[], String> noArgs(Supplier<String> func){
|
||||
public static Function<String[], String> noArgs(final Supplier<String> func){
|
||||
return args -> args.length > 0 ? fail("expected no arguments, got " + args.length) : func.get();
|
||||
}
|
||||
|
||||
public static Function<String[], String> oneArg(UnaryOperator<String> func){
|
||||
public static Function<String[], String> oneArg(final UnaryOperator<String> func){
|
||||
return args -> args.length != 1 ? fail("expected 1 argument, got " + args.length) : func.apply(args[0]);
|
||||
}
|
||||
|
||||
public static Function<String[], String> rangeArgs(int min, int max, Function<String[], String> func){
|
||||
public static Function<String[], String> rangeArgs(final int min, final int max, final Function<String[], String> func){
|
||||
return args -> args.length < min || args.length > max ? fail("expected between " + min + " and " + max + " arguments, got " + args.length) : func.apply(args);
|
||||
}
|
||||
|
||||
private static String fail(String message){
|
||||
private static String fail(final String message){
|
||||
throw new TokenException(message);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package chylex.customwindowtitle;
|
||||
|
||||
public class TokenException extends RuntimeException{
|
||||
public TokenException(String message){
|
||||
public TokenException(final String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ public class CustomWindowTitle implements ClientModInitializer{
|
||||
|
||||
@Override
|
||||
public void onInitializeClient(){
|
||||
Path configFile = Paths.get(FabricLoader.getInstance().getConfigDirectory().getAbsolutePath(), "customwindowtitle-client.toml");
|
||||
final Path configFile = Paths.get(FabricLoader.getInstance().getConfigDirectory().getAbsolutePath(), "customwindowtitle-client.toml");
|
||||
|
||||
try{
|
||||
String prefix = "title = ";
|
||||
final String prefix = "title = ";
|
||||
|
||||
if (!Files.exists(configFile)){
|
||||
Files.write(configFile, Collections.singletonList(prefix + '"' + defaultTitle + '"'), StandardCharsets.UTF_8);
|
||||
@ -35,7 +35,7 @@ public class CustomWindowTitle implements ClientModInitializer{
|
||||
.findFirst()
|
||||
.orElse(defaultTitle);
|
||||
}
|
||||
}catch(IOException e){
|
||||
}catch(final IOException e){
|
||||
throw new RuntimeException("CustomWindowTitle configuration error", e);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ final class TokenData{
|
||||
return SharedConstants.getGameVersion().getName();
|
||||
}
|
||||
|
||||
static String getModVersion(String modId){
|
||||
static String getModVersion(final String modId){
|
||||
return FabricLoader.getInstance().getModContainer(modId).orElseThrow(() -> new TokenException("mod info for '" + modId + "' not found")).getMetadata().getVersion().getFriendlyString();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(MinecraftClient.class)
|
||||
public final class DisableVanillaTitle{
|
||||
@Inject(method = "updateWindowTitle()V", at = @At("HEAD"), cancellable = true)
|
||||
private void updateTitle(CallbackInfo info){
|
||||
private void updateTitle(final CallbackInfo info){
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,21 @@ public final class TitleParser{
|
||||
private static final Pattern tokenRegex = Pattern.compile("\\{([a-z]+)(?::([^}]+))?}");
|
||||
private static final Logger logger = LogManager.getLogger("CustomWindowTitle");
|
||||
|
||||
public static String parse(String input){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Matcher matcher = tokenRegex.matcher(input);
|
||||
public static String parse(final String input){
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final Matcher matcher = tokenRegex.matcher(input);
|
||||
|
||||
while(matcher.find()){
|
||||
String token = matcher.group(1);
|
||||
String[] args = StringUtils.split(matcher.group(2), ',');
|
||||
final String token = matcher.group(1);
|
||||
final String[] args = StringUtils.split(matcher.group(2), ',');
|
||||
|
||||
String result = null;
|
||||
|
||||
try{
|
||||
result = TitleTokens.getTokenFunction(token).apply(args == null ? ArrayUtils.EMPTY_STRING_ARRAY : args);
|
||||
}catch(TokenException e){
|
||||
}catch(final TokenException e){
|
||||
logger.warn("Error processing token '" + token + "': " + e.getMessage());
|
||||
}catch(Throwable t){
|
||||
}catch(final Throwable t){
|
||||
logger.warn("Error processing token '" + token + "': " + t.getMessage(), t);
|
||||
}
|
||||
|
||||
|
@ -11,29 +11,29 @@ public final class TitleTokens{
|
||||
|
||||
private static final Map<String, Function<String[], String>> tokenMap = new HashMap<>();
|
||||
|
||||
public static void registerToken(String token, Function<String[], String> processor){
|
||||
public static void registerToken(final String token, final Function<String[], String> processor){
|
||||
tokenMap.putIfAbsent(token, processor);
|
||||
}
|
||||
|
||||
public static Function<String[], String> getTokenFunction(String token){
|
||||
public static Function<String[], String> getTokenFunction(final String token){
|
||||
return tokenMap.getOrDefault(token, args -> null);
|
||||
}
|
||||
|
||||
// Arguments
|
||||
|
||||
public static Function<String[], String> noArgs(Supplier<String> func){
|
||||
public static Function<String[], String> noArgs(final Supplier<String> func){
|
||||
return args -> args.length > 0 ? fail("expected no arguments, got " + args.length) : func.get();
|
||||
}
|
||||
|
||||
public static Function<String[], String> oneArg(UnaryOperator<String> func){
|
||||
public static Function<String[], String> oneArg(final UnaryOperator<String> func){
|
||||
return args -> args.length != 1 ? fail("expected 1 argument, got " + args.length) : func.apply(args[0]);
|
||||
}
|
||||
|
||||
public static Function<String[], String> rangeArgs(int min, int max, Function<String[], String> func){
|
||||
public static Function<String[], String> rangeArgs(final int min, final int max, final Function<String[], String> func){
|
||||
return args -> args.length < min || args.length > max ? fail("expected between " + min + " and " + max + " arguments, got " + args.length) : func.apply(args);
|
||||
}
|
||||
|
||||
private static String fail(String message){
|
||||
private static String fail(final String message){
|
||||
throw new TokenException(message);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package chylex.customwindowtitle;
|
||||
|
||||
public class TokenException extends RuntimeException{
|
||||
public TokenException(String message){
|
||||
public TokenException(final String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class CustomWindowTitle{
|
||||
private final ConfigValue<String> configTitle;
|
||||
|
||||
public CustomWindowTitle(){
|
||||
ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder();
|
||||
final ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder();
|
||||
|
||||
configTitle = configBuilder.define("title", "Minecraft {mcversion}");
|
||||
|
||||
@ -26,7 +26,7 @@ public class CustomWindowTitle{
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientSetup(FMLClientSetupEvent e){
|
||||
public void onClientSetup(final FMLClientSetupEvent e){
|
||||
e.getMinecraftSupplier().get().execute(this::updateTitle);
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ final class TokenData{
|
||||
return SharedConstants.getVersion().getName();
|
||||
}
|
||||
|
||||
static String getModVersion(String modId){
|
||||
ModFileInfo file = ModList.get().getModFileById(modId);
|
||||
static String getModVersion(final String modId){
|
||||
final ModFileInfo file = ModList.get().getModFileById(modId);
|
||||
|
||||
if (file == null){
|
||||
throw new TokenException("mod file for '" + modId + "' not found");
|
||||
}
|
||||
|
||||
for(IModInfo info : file.getMods()){
|
||||
for(final IModInfo info : file.getMods()){
|
||||
if (info.getModId().equals(modId)){
|
||||
return info.getVersion().toString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user