Skip to content

Commit

Permalink
add hacky support for old chatcolor
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Mar 4, 2024
1 parent ae08ebf commit d80969d
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,53 @@ public LanguageCache(String locale) throws Exception {

public Component getTranslation(String path, String defaultTranslation, boolean upperCase) {
lang.addDefault(path, defaultTranslation);
defaultTranslation = translateChatColor(defaultTranslation);
return MiniMessage.miniMessage().deserialize(upperCase ? lang.getString(path, defaultTranslation).toUpperCase() : lang.getString(path, defaultTranslation));
}

public Component getTranslation(String path, String defaultTranslation, boolean upperCase, String comment) {
lang.addDefault(path, defaultTranslation, comment);
defaultTranslation = translateChatColor(defaultTranslation);
return MiniMessage.miniMessage().deserialize(upperCase ? lang.getString(path, defaultTranslation).toUpperCase() : lang.getString(path, defaultTranslation));
}

public List<Component> getListTranslation(String path, List<String> defaultTranslation, boolean upperCase) {
lang.addDefault(path, defaultTranslation);
return lang.getStringList(path).stream().map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList();
return lang.getStringList(path).stream()
.map(LanguageCache::translateChatColor)
.map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList();
}

public List<Component> getListTranslation(String path, List<String> defaultTranslation, boolean upperCase, String comment) {
lang.addDefault(path, defaultTranslation, comment);
return lang.getStringList(path).stream().map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList();
return lang.getStringList(path).stream()
.map(LanguageCache::translateChatColor)
.map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList();
}

private static String translateChatColor(String string) {
string = string.replace("&0", "<black>");
string = string.replace("&1", "<dark_blue>");
string = string.replace("&2", "<dark_green>");
string = string.replace("&3", "<dark_aqua>");
string = string.replace("&4", "<dark_red>");
string = string.replace("&5", "<dark_purple>");
string = string.replace("&6", "<gold>");
string = string.replace("&7", "<gray>");
string = string.replace("&8", "<dark_gray>");
string = string.replace("&9", "<blue>");
string = string.replace("&a", "<green>");
string = string.replace("&b", "<aqua>");
string = string.replace("&c", "<red>");
string = string.replace("&d", "<light_purple>");
string = string.replace("&e", "<yellow>");
string = string.replace("&f", "<white>");
string = string.replace("&k", "<obfuscated>");
string = string.replace("&l", "<bold>");
string = string.replace("&m", "<strikethrough>");
string = string.replace("&n", "<underlined>");
string = string.replace("&o", "<italic>");
string = string.replace("&r", "<reset>");
return string;
}
}

0 comments on commit d80969d

Please sign in to comment.