From b84f507644ca2b405a86261f93942a1101e72b45 Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Fri, 10 Jul 2020 21:24:20 +0200 Subject: [PATCH] Clean up code --- .../translater/CachingTransformer.java | 3 +- .../io/gitlab/jfronny/translater/ModInit.java | 43 ++++++++++--------- .../jfronny/translater/YnTransformer.java | 16 +++---- .../translater/mixin/MixinLanguage.java | 2 - 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/main/java/io/gitlab/jfronny/translater/CachingTransformer.java b/src/main/java/io/gitlab/jfronny/translater/CachingTransformer.java index c0e4690..af79974 100644 --- a/src/main/java/io/gitlab/jfronny/translater/CachingTransformer.java +++ b/src/main/java/io/gitlab/jfronny/translater/CachingTransformer.java @@ -6,8 +6,9 @@ import java.io.*; import java.util.Properties; public abstract class CachingTransformer implements StringTransformer { - Properties cache = null; private static final File cacheFile = new File(FabricLoader.getInstance().getConfigDirectory(), "Translater.cache"); + Properties cache = null; + @Override public String transform(String str) { if (cache == null) { diff --git a/src/main/java/io/gitlab/jfronny/translater/ModInit.java b/src/main/java/io/gitlab/jfronny/translater/ModInit.java index 8e5854b..d36c8db 100644 --- a/src/main/java/io/gitlab/jfronny/translater/ModInit.java +++ b/src/main/java/io/gitlab/jfronny/translater/ModInit.java @@ -8,30 +8,31 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class ModInit implements ModInitializer { - public static final String MOD_NAME = "translater"; - public static final String MOD_ID = "translater"; - public static Cfg cfg; - public ModInit() { - AutoConfig.register(Cfg.class, JanksonConfigSerializer::new); - cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig(); - } + public static final String MOD_NAME = "translater"; + public static final String MOD_ID = "translater"; + private static final Logger logger = LogManager.getFormatterLogger(MOD_ID); + public static Cfg cfg; - private static final Logger logger = LogManager.getFormatterLogger(MOD_ID); - @Override - public void onInitialize() { - Log("Loaded translater"); - } + public ModInit() { + AutoConfig.register(Cfg.class, JanksonConfigSerializer::new); + cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig(); + } - public static void Log(String msg) { - logger.log(Level.INFO, "[" + MOD_NAME + "]" + msg); - } + public static void Log(String msg) { + logger.log(Level.INFO, "[" + MOD_NAME + "]" + msg); + } - public static void Warn(String msg) { - logger.log(Level.WARN, "[" + MOD_NAME + "]" + msg); - } + public static void Warn(String msg) { + logger.log(Level.WARN, "[" + MOD_NAME + "]" + msg); + } - public static void LogDebug(String msg) { - logger.log(Level.DEBUG, "[" + MOD_NAME + "]" + msg); - } + public static void LogDebug(String msg) { + logger.log(Level.DEBUG, "[" + MOD_NAME + "]" + msg); + } + + @Override + public void onInitialize() { + Log("Loaded translater"); + } } diff --git a/src/main/java/io/gitlab/jfronny/translater/YnTransformer.java b/src/main/java/io/gitlab/jfronny/translater/YnTransformer.java index a5fac48..f3dfeb0 100644 --- a/src/main/java/io/gitlab/jfronny/translater/YnTransformer.java +++ b/src/main/java/io/gitlab/jfronny/translater/YnTransformer.java @@ -2,18 +2,17 @@ package io.gitlab.jfronny.translater; import com.github.vbauer.yta.model.Direction; import com.github.vbauer.yta.model.Language; -import com.github.vbauer.yta.model.Languages; import com.github.vbauer.yta.service.YTranslateApiImpl; -import com.sun.org.apache.xpath.internal.operations.Mod; import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.Random; +import java.util.Set; public class YnTransformer extends CachingTransformer { + private static final Random rnd = new Random(); private static YTranslateApiImpl api = null; private static Set languages = null; - private static final Random rnd = new Random(); @Override public String getTransformed(String str) { @@ -35,8 +34,7 @@ public class YnTransformer extends CachingTransformer { f = false; } return res.toString(); - } - else if (str.contains("$")) { + } else if (str.contains("$")) { StringBuilder res = new StringBuilder(); boolean f = true; for (String s : str.split("\\$")) { @@ -47,8 +45,7 @@ public class YnTransformer extends CachingTransformer { f = false; } return res.toString(); - } - else if (str.contains("§")) { + } else if (str.contains("§")) { StringBuilder res = new StringBuilder(); boolean f = true; for (String s : str.split("§")) { @@ -59,8 +56,7 @@ public class YnTransformer extends CachingTransformer { f = false; } return res.toString(); - } - else { + } else { return Break(str); } } catch (Exception e) { diff --git a/src/main/java/io/gitlab/jfronny/translater/mixin/MixinLanguage.java b/src/main/java/io/gitlab/jfronny/translater/mixin/MixinLanguage.java index 580eca7..b3ba297 100644 --- a/src/main/java/io/gitlab/jfronny/translater/mixin/MixinLanguage.java +++ b/src/main/java/io/gitlab/jfronny/translater/mixin/MixinLanguage.java @@ -8,8 +8,6 @@ import net.fabricmc.loader.api.MappingResolver; import net.minecraft.client.resource.language.TranslationStorage; import net.minecraft.util.Language; import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject;