diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 2f8b45d6..e88bfcbb 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -89,8 +89,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { onLatestVersion = checker.isUsingLatestVersion(); // File setup saveDefaultConfig(); - //saveResource("translations.yml", false); if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false); + if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false); if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false); if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false); @@ -104,11 +104,15 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { // Configuration Sync final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile(); final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile(); + final File translationFile = Path.of(getInstance().getDataFolder().getPath(), "translations.yml").toFile(); try { CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"), "database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location"); CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml")); - } catch (Exception e) {} + CommentedConfiguration.loadConfiguration(translationFile).syncWithConfig(translationFile, getInstance().getResource("translations.yml")); + } catch (Exception e) { + e.printStackTrace(); + } // Setup setup(); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java index db37c550..fd75edf5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java @@ -69,9 +69,9 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1)); if (cosmetic == null) return "INVALID_COSMETIC"; Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot()); - if (currentCosmetic == null) return "false"; - if (currentCosmetic.getId() == cosmetic.getId()) return "true"; - return "false"; + if (currentCosmetic == null) return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false)); // I hate this way of handling translations + if (currentCosmetic.getId() == cosmetic.getId()) return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(true)); + return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false)); } case "current": if (placeholderArgs == null) { @@ -82,26 +82,29 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { if (slot == null) return null; if (user.getCosmetic(slot) == null) return null; if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId(); + + String output; switch (placeholderArgs.get(2).toLowerCase()) { case "material" -> { - return getMaterialName(user.getCosmetic(slot)); + output = getMaterialName(user.getCosmetic(slot)); } case "custommodeldata" -> { - return getModelData(user.getCosmetic(slot)); + output = getModelData(user.getCosmetic(slot)); } case "name" -> { - return getItemName(user.getCosmetic(slot)); + output = getItemName(user.getCosmetic(slot)); } case "lore" -> { - return getItemLore(user.getCosmetic(slot)); + output = getItemLore(user.getCosmetic(slot)); } case "permission" -> { - return user.getCosmetic(slot).getPermission(); + output = user.getCosmetic(slot).getPermission(); } default -> { - return user.getCosmetic(slot).getId(); + output = user.getCosmetic(slot).getId(); } } + return TranslationUtil.getTranslation("current-cosmetic", String.valueOf(output)); } case "unlocked": if (placeholderArgs == null) { @@ -121,7 +124,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { return "INVALID_COSMETIC"; } } - return TranslationUtil.getTranslation("unlockedCosmetic", String.valueOf(user.canEquipCosmetic(cosmetic))); + return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic))); } case "equipped": if (placeholderArgs == null) { @@ -131,11 +134,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { String args1 = placeholderArgs.get(1); if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) { - if (user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null) { - return "true"; - } else { - return "false"; - } + return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null)); } MessagesUtil.sendDebugMessages(args1); @@ -154,14 +153,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { } } if (user.getCosmetic(cosmetic.getSlot()) == null) return "false"; - if (cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId()) { - return "true"; - } else { - return "false"; - } + return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId())); } case "wardrobe-enabled": - return String.valueOf(user.isInWardrobe()); + return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe())); } return null; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationPair.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationPair.java new file mode 100644 index 00000000..a5e4f34f --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationPair.java @@ -0,0 +1,20 @@ +package com.hibiscusmc.hmccosmetics.util; + +public class TranslationPair { + + private String key; + private String value; + + public TranslationPair(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public String getValue() { + return value; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationUtil.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationUtil.java index dcfe377a..3af2654c 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationUtil.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/TranslationUtil.java @@ -2,38 +2,37 @@ package com.hibiscusmc.hmccosmetics.util; import org.spongepowered.configurate.ConfigurationNode; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; public class TranslationUtil { - private static HashMap keys = new HashMap<>(); + // unlocked-cosmetic -> true -> True + private static HashMap> keys = new HashMap<>(); public static void setup(ConfigurationNode config) { - // TODO: Finish this - /* for (ConfigurationNode node : config.childrenMap().values()) { - HashMap translableMessages = new HashMap<>(); + ArrayList pairs = new ArrayList<>(); for (ConfigurationNode translatableMessage : node.childrenMap().values()) { - translableMessages.put( new Pair<>(translatableMessage.key().toString(), translatableMessage.getString())) + String key = translatableMessage.key().toString(); + key.replaceAll("'", ""); // Autoupdater adds ' to it? Removes it from the key + TranslationPair pair = new TranslationPair(key, translatableMessage.getString()); + pairs.add(pair); MessagesUtil.sendDebugMessages("setupTranslation key:" + node.key().toString() + " | " + node); + MessagesUtil.sendDebugMessages("Overall Key " + node.key().toString()); + MessagesUtil.sendDebugMessages("Key '" + pair.getKey() + "' Value '" + pair.getValue() + "'"); } - keys.put(node.key().toString().toLowerCase(), HashMap); + keys.put(node.key().toString().toLowerCase(), pairs); } - */ } public static String getTranslation(String key, String message) { - // TODO: Finish this - return message; - /* - key = key.toLowerCase(); - MessagesUtil.sendDebugMessages("getTranslation key:" + key + " | " + message); - if (!keys.containsKey(key)) return message; - List config = keys.get(key); - if (config.getFirst() == message) { - return config.getSecond().toString(); + List pairs = keys.get(key); + for (TranslationPair pair : pairs) { + if (pair.getKey() == message) return pair.getValue(); } + return message; - */ } } diff --git a/common/src/main/resources/translations.yml b/common/src/main/resources/translations.yml index 0ee32b3a..acb0ef40 100644 --- a/common/src/main/resources/translations.yml +++ b/common/src/main/resources/translations.yml @@ -1,3 +1,15 @@ -unlockedCosmetic: - true: "True" - false: "false" \ No newline at end of file +unlocked-cosmetic: + true: "true" + false: "false" +equipped-cosmetic: + true: "true" + false: "false" +in-wardrobe: + true: "true" + false: "false" +using-cosmetic: + true: "true" + false: "false" +current-cosmetic: + true: "true" + false: "false"