Skip to content

Commit

Permalink
Changed the json file format to be two arrays instead of two dictiona…
Browse files Browse the repository at this point in the history
…ries; Added all of Hypixel's translations. Closes dubfib#1
  • Loading branch information
OoLunar committed Jan 18, 2023
1 parent 9896c41 commit bc961b0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 34 deletions.
19 changes: 9 additions & 10 deletions src/main/java/com/dubfib/autoutils/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,23 +44,19 @@ 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.
ChatEvent.goodLuckMessages.clear();
ChatEvent.goodLuckMessages.clear();

// Add the translations to the HashMap
for (HashMap<String, String> 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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/dubfib/autoutils/config/Config.java
Original file line number Diff line number Diff line change
@@ -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<String, String>[] translations;
public ArrayList<String> goodLuckTranslations = new ArrayList<String>();
public ArrayList<String> goodGameTranslations = new ArrayList<String>();
};
17 changes: 9 additions & 8 deletions src/main/java/com/dubfib/autoutils/events/ChatEvent.java
Original file line number Diff line number Diff line change
@@ -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<String, String> goodLuckMessages = new HashMap<String, String>();
public static HashMap<String, String> goodGameMessages = new HashMap<String, String>();
// These lists are populated from the languages.json file,
// which is done on startup.
public static ArrayList<String> goodLuckMessages = new ArrayList<String>();
public static ArrayList<String> goodGameMessages = new ArrayList<String>();

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");
}
};
};
62 changes: 48 additions & 14 deletions src/main/resources/assets/autoutils/languages.json
Original file line number Diff line number Diff line change
@@ -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!"
]
}
}

0 comments on commit bc961b0

Please sign in to comment.