diff --git a/src/main/java/com/dubfib/autoutils/Main.java b/src/main/java/com/dubfib/autoutils/Main.java index 5d5de98..d058af8 100644 --- a/src/main/java/com/dubfib/autoutils/Main.java +++ b/src/main/java/com/dubfib/autoutils/Main.java @@ -3,10 +3,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; + import com.dubfib.autoutils.config.Config; import com.dubfib.autoutils.events.ChatEvent; import com.google.gson.Gson; @@ -43,8 +44,7 @@ public void init(FMLInitializationEvent event) { } // Parse the JSON using Gson - Gson gson = new Gson(); - Config config = gson.fromJson(new InputStreamReader(stream), Config.class); + Config config = new Gson().fromJson(new InputStreamReader(stream), Config.class); // Ensure that the HashMaps are empty, if this method is ever (somehow) // called more than once. @@ -52,14 +52,11 @@ public void init(FMLInitializationEvent event) { ChatEvent.goodLuckMessages.clear(); // Add the translations to the HashMap - for (HashMap translation : config.translations) { - Object[] keyCollection = translation.keySet().toArray(); - ChatEvent.goodLuckMessages.put((String) keyCollection[0], translation.get(keyCollection[0])); - System.out.println("Added " + keyCollection[0] + " to the good luck messages"); + ChatEvent.goodLuckMessages.addAll(config.goodLuckTranslations); + ChatEvent.goodGameMessages.addAll(config.goodGameTranslations); - ChatEvent.goodLuckMessages.put((String) keyCollection[1], translation.get(keyCollection[1])); - System.out.println("Added " + keyCollection[1] + " to the good game messages"); - } + LogManager.getLogger(Config.NAME).info("Loaded " + ChatEvent.goodLuckMessages.size() + + " good luck messages and " + ChatEvent.goodGameMessages.size() + " good game messages"); FMLCommonHandler.instance().bus().register(this); MinecraftForge.EVENT_BUS.register(this); @@ -71,6 +68,8 @@ public void onChat(ClientChatReceivedEvent event) { ChatEvent.AutoGG(getPlainText(event.message)); }; + // Use Regex to remove all of the text formatting codes, + // leaving only the plaintext. private String getPlainText(IChatComponent message) { String baseString = message.getUnformattedText(); Matcher m = textFormattingPattern.matcher(baseString); diff --git a/src/main/java/com/dubfib/autoutils/config/Config.java b/src/main/java/com/dubfib/autoutils/config/Config.java index 03230cb..ce9667b 100644 --- a/src/main/java/com/dubfib/autoutils/config/Config.java +++ b/src/main/java/com/dubfib/autoutils/config/Config.java @@ -1,10 +1,11 @@ package com.dubfib.autoutils.config; -import java.util.HashMap; +import java.util.ArrayList; public class Config { public static final String NAME = "AutoUtilities"; public static final String ID = "autoutils"; public static final String VERSION = "1.1"; - public HashMap[] translations; + public ArrayList goodLuckTranslations = new ArrayList(); + public ArrayList goodGameTranslations = new ArrayList(); }; \ No newline at end of file diff --git a/src/main/java/com/dubfib/autoutils/events/ChatEvent.java b/src/main/java/com/dubfib/autoutils/events/ChatEvent.java index efa0d2f..3d395a8 100644 --- a/src/main/java/com/dubfib/autoutils/events/ChatEvent.java +++ b/src/main/java/com/dubfib/autoutils/events/ChatEvent.java @@ -1,23 +1,24 @@ package com.dubfib.autoutils.events; -import java.util.HashMap; +import java.util.ArrayList; import net.minecraft.client.Minecraft; public class ChatEvent { - // These hashmaps are populated on startup by the init() method in Main.java - public static HashMap goodLuckMessages = new HashMap(); - public static HashMap goodGameMessages = new HashMap(); + // These lists are populated from the languages.json file, + // which is done on startup. + public static ArrayList goodLuckMessages = new ArrayList(); + public static ArrayList goodGameMessages = new ArrayList(); public static void AutoGL(String message) { - if (goodLuckMessages.containsKey(message.trim())) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac " + goodLuckMessages.get(message)); + if (goodLuckMessages.contains(message)) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac glhf"); } }; public static void AutoGG(String message) { - if (goodGameMessages.containsKey(message.trim())) { - Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac " + goodGameMessages.get(message)); + if (goodGameMessages.contains(message)) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac gg"); } }; }; \ No newline at end of file diff --git a/src/main/resources/assets/autoutils/languages.json b/src/main/resources/assets/autoutils/languages.json index 1095950..375b834 100644 --- a/src/main/resources/assets/autoutils/languages.json +++ b/src/main/resources/assets/autoutils/languages.json @@ -1,16 +1,50 @@ { - "translations": [ - { - "The game starts in 2 seconds!": "glhf", - "This game has been recorded. Click here to watch the Replay!": "gg" - }, - { - "Th' voyage begins in 2 seconds!": "glhf", - "Treasure Summary": "gg" - }, - { - "Oyun 2 saniye içinde başlıyor!": "glhf", - "Bu oyun kayıt edildi. Replay'i izlemek için tıkla!": "gg" - } + "goodLuckTranslations": [ + "The game starts in 2 seconds!", + "游戏将在2秒后开始!", + "遊戲將在 2 秒後開始!", + "Hra začíná za 2 s!", + "Spillet starter om 2 sekunder!", + "Het spel begint over 2 seconden!", + "Pelin alkuun 2 sekuntia!", + "La partie débute dans 2 secondes!", + "Das Spiel beginnt in 2 Sekunden!", + "Το παιχνίδι αρχίζει σε 2 δευτερόλεπτα!", + "La partita inizia tra 2 secondi!", + "あと 2 秒でゲームが開始します!", + "게임이 2초 후에 시작합니다!", + "Spillet starter om 2 sekunder!", + "Th' voyage begins in 2 seconds!", + "Gra rozpocznie się za 2 sek.!", + "O jogo começa em 2 segundos!", + "Jocul începe în 2 secunde!", + "Игра начнётся через 2 секунд(ы)!", + "¡El juego comienza en 2 segundos!", + "Spelet startar om 2 sekunder!", + "Oyun 2 saniye içinde başlıyor!", + "Гра почнеться через 3 секунд!" + ], + "goodGameTranslations": [ + "This game has been recorded. Click here to watch the Replay!", + "已自动排队!点击红色小床图标回到大厅!", + "已開始排隊!使用床來取消排隊!", + "Dit potje is opgenomen. Bekijk hier de replay!", + "Tämä peli on nauhoitettu. Klikkaa tästä nähdäksesi uusinnan!", + "Cette partie a été enregistrée. Cliquez ici pour regarder le Replay!", + "Αυτό το παιχνίδι καταγράφηκε. Κάνε κλικ εδώ για να δεις το Replay!", + "Questa partita è stata registrata. Clicca qui per guardare il Replay!", + "このゲームは録画されました。ここをクリックして Replay を視聴!", + "게임이 저장되었습니다. 다시 보기를 시청하려면 클릭하세요!", + "Denne runden har blitt filmet. Klikk her for å se replay!", + "'Tis game be recorded matey. Click here t' watch th' Replay!", + "Ta gra została nagrana. Kliknij tutaj, aby obejrzeć powtórkę!", + "Este jogo foi gravado. Clica aqui para veres a repetição!", + "Esta partida foi gravada. Clique aqui para assistir o replay!", + "Acest joc a fost înregistrat. Apasă aici pentru a vedea Replay-ul!", + "Эта игра была записана. Нажмите здесь, чтобы просмотреть Replay!", + "Esta partida se ha grabado. ¡Haz clic aquí para ver el Replay!", + "Detta spel har spelats in. Klicka här för att se replayn!", + "Bu oyun kayıt edildi. Replay'i izlemek için tıkla!", + "Цю гру записано. Натисніть тут, щоб переглянути Replay!" ] -} +} \ No newline at end of file