From 024e4556984ad65affcf90906092a767d82c2e74 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Tue, 7 Jan 2020 02:18:02 -0500 Subject: [PATCH] Improve translation of enchantments and tameable mob types. Bump version --- dist/pom.xml | 2 +- main/pom.xml | 2 +- .../blackvein/quests/prompts/ItemsPrompt.java | 35 ++++++-------- .../blackvein/quests/prompts/MobsPrompt.java | 6 +-- .../me/blackvein/quests/util/ItemUtil.java | 46 +++++++++++++++---- .../me/blackvein/quests/util/LocaleQuery.java | 4 +- .../me/blackvein/quests/util/MiscUtil.java | 6 ++- main/src/main/resources/strings.yml | 36 +-------------- pom.xml | 4 +- v1_8_R1/pom.xml | 2 +- v1_8_R2/pom.xml | 2 +- v1_8_R3/pom.xml | 2 +- 12 files changed, 68 insertions(+), 79 deletions(-) diff --git a/dist/pom.xml b/dist/pom.xml index a70c09e0b..29d7366e4 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4 quests-dist pom diff --git a/main/pom.xml b/main/pom.xml index 5bf59aae5..d26adb0fd 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -4,7 +4,7 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4 quests-main diff --git a/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java index 75f8d8f8b..b839caf4d 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java @@ -20,6 +20,7 @@ import me.blackvein.quests.Quests; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -387,15 +388,16 @@ public class ItemsPrompt extends FixedSetPrompt { private class EnchantTypesPrompt extends StringPrompt { + @SuppressWarnings("deprecation") @Override public String getPromptText(ConversationContext context) { String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.DARK_PURPLE + Lang.get("stageEditorEnchantments") + ChatColor.LIGHT_PURPLE + " -\n"; for (int i = 0; i < Enchantment.values().length; i++) { if (i == Enchantment.values().length - 1) { - text += ChatColor.GREEN + ItemUtil.getPrettyEnchantmentName(Enchantment.values()[i]) + " "; + text += ChatColor.GREEN + MiscUtil.snakeCaseToUpperCamelCase(Enchantment.values()[i].getName()) + " "; } else { - text += ChatColor.GREEN + ItemUtil.getPrettyEnchantmentName(Enchantment.values()[i]) + ", "; + text += ChatColor.GREEN + MiscUtil.snakeCaseToUpperCamelCase(Enchantment.values()[i].getName()) + ", "; } } text = text.substring(0, text.length() - 1); @@ -405,31 +407,22 @@ public class ItemsPrompt extends FixedSetPrompt { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - String[] args = input.split(Lang.get("charSemi")); - LinkedList enchs = new LinkedList(); - boolean valid; - for (String s : args) { - s = s.trim(); - valid = false; - for (Enchantment e : Enchantment.values()) { - if (ItemUtil.getPrettyEnchantmentName(e).equalsIgnoreCase(s)) { - if (enchs.contains(s) == false) { - enchs.add(ItemUtil.getPrettyEnchantmentName(e)); - valid = true; - break; - } else { - context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate")); - return new EnchantTypesPrompt(); - } + LinkedList enchTypes = new LinkedList(); + for (String s : input.split(" ")) { + if (ItemUtil.getEnchantmentFromProperName(s) != null) { + if (enchTypes.contains(s) == false) { + enchTypes.add(s); + } else { + context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate")); + return new EnchantTypesPrompt(); } - } - if (valid == false) { + } else { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " " + Lang.get("stageEditorInvalidEnchantment")); return new EnchantTypesPrompt(); } } - context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchs); + context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchTypes); } return new EnchantmentListPrompt(); } diff --git a/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java index e7f512f22..1a5c51d07 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java @@ -376,13 +376,13 @@ public class MobsPrompt extends FixedSetPrompt { for (String s : input.split(" ")) { if (MiscUtil.getProperMobType(s) != null) { mobTypes.add(s); - context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorInvalidMob")); return new MobTypesPrompt(); } } + context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); } return new MobListPrompt(); } @@ -556,7 +556,7 @@ public class MobsPrompt extends FixedSetPrompt { if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) { text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("stageEditorSetMobTypes") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " + Lang.get("stageEditorSetTameAmounts") + " (" + Lang.get("noneSet") + ")\n"; text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("clear") + "\n"; @@ -663,7 +663,7 @@ public class MobsPrompt extends FixedSetPrompt { if (MiscUtil.getProperMobType(s) != null) { final EntityType type = MiscUtil.getProperMobType(s); if (type.isAlive() || Tameable.class.isAssignableFrom(type.getEntityClass())) { - mobTypes.add(MiscUtil.getPrettyMobName(type)); + mobTypes.add(s); context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes); } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED diff --git a/main/src/main/java/me/blackvein/quests/util/ItemUtil.java b/main/src/main/java/me/blackvein/quests/util/ItemUtil.java index b35ea73dd..82fe1162d 100644 --- a/main/src/main/java/me/blackvein/quests/util/ItemUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/ItemUtil.java @@ -601,8 +601,17 @@ public class ItemUtil { * @return pretty localized name */ public static String getPrettyEnchantmentName(Enchantment e) { - String prettyString = getEnchantmentName(e); - prettyString = MiscUtil.capitalsToSpaces(prettyString); + String baseString = e.getName(); + String[] substrings = baseString.split("_"); + String prettyString = ""; + int size = 1; + for (String s : substrings) { + prettyString = prettyString.concat(MiscUtil.getCapitalized(s)); + if (size < substrings.length) { + prettyString = prettyString.concat(" "); + } + size++; + } return prettyString; } @@ -612,7 +621,7 @@ public class ItemUtil { * @param e Enchantment to get localized name of * @return localized name */ - private static String getEnchantmentName(Enchantment e) { + /*private static String getEnchantmentName(Enchantment e) { try { return (Lang.get("ENCHANTMENT_" + e.getName())); } catch (NullPointerException ne) { @@ -620,15 +629,34 @@ public class ItemUtil { + "update the file or simply add an entry for the enchantment"); return e.getName().toLowerCase().replace("_", " "); } - } + }*/ - public static Enchantment getEnchantmentFromProperName(String enchant) { - String ench = Lang.getKey(enchant.replace(" ", "")); - ench = ench.replace("ENCHANTMENT_", ""); - Enchantment e = Enchantment.getByName(ench); - return e != null ? e : getEnchantmentFromProperLegacyName(ench.replace(" ", "")); + /** + * Gets enchantment from name + * + * @param properName Name to get enchantment from + * @return Enchantment or null if invalid + */ + public static Enchantment getEnchantmentFromProperName(String properName) { + properName = properName.replace(" ", "").toUpperCase(); + for (Enchantment e : Enchantment.values()) { + if (e.getName().replace("_", "").equalsIgnoreCase(properName.replace("_", ""))) { + return e; + } + if (getEnchantmentFromProperLegacyName(properName) != null) { + return e; + } + } + return null; } + /** + * Gets Enchantment from name as it appears in lang file + * + * @deprecated Use {@link #getProperEnchantmentType(String)} + * @param enchant Name to match lang value to + * @return Enchantment or null if invalid + */ public static Enchantment getEnchantmentFromProperLegacyName(String enchant) { if (enchant.equalsIgnoreCase(Lang.get("ENCHANTMENT_ARROW_DAMAGE"))) { return Enchantment.ARROW_DAMAGE; diff --git a/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java b/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java index 729172fcc..1035c94a8 100644 --- a/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java +++ b/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java @@ -154,7 +154,7 @@ public class LocaleQuery { if (enchantments != null && !enchantments.isEmpty()) { int count = 0; for (Enchantment e : enchantments.keySet()) { - enchKeys[count] = "enchantment.minecraft." + e.toString().toLowerCase(); + enchKeys[count] = "enchantment." + e.getKey().toString().toLowerCase().replace(":", "."); count++; } } @@ -162,7 +162,7 @@ public class LocaleQuery { String msg = message.replace("", "\",{\"translate\":\"" + matKey + "\"},\""); if (enchKeys != null && enchKeys.length > 0) { for (String ek : enchKeys) { - msg.replaceFirst("", "\",{\"translate\":\"" + ek + "\"},\""); + msg = msg.replace("", "\",{\"translate\":\"" + ek + "\"},\""); } } Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + player.getName() + " [\"" + msg + "\"]"); diff --git a/main/src/main/java/me/blackvein/quests/util/MiscUtil.java b/main/src/main/java/me/blackvein/quests/util/MiscUtil.java index c85ff9437..e5808c671 100644 --- a/main/src/main/java/me/blackvein/quests/util/MiscUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/MiscUtil.java @@ -148,9 +148,9 @@ public class MiscUtil { * @return EntityType or null if invalid */ public static EntityType getProperMobType(String properName) { - properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase(); + properName = properName.replace("_", "").replace(" ", "").toUpperCase(); for (EntityType et : EntityType.values()) { - if (et.isAlive() && et.name().replaceAll("_", "").equalsIgnoreCase(properName)) { + if (et.isAlive() && et.name().replace("_", "").equalsIgnoreCase(properName)) { return et; } } @@ -260,6 +260,8 @@ public class MiscUtil { /** * Adds a single space in front of all capital letters * + * Unused internally. Left for external use + * * @param s string to process * @return processed string */ diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 2268a9be5..a32c1bb21 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -194,7 +194,7 @@ stageEditorEnterBlockAmounts: "Enter block amounts, , " stageEditorEnterBlockDurability: "Enter block durabilities (numbers), , " stageEditorCatchFishPrompt: "Enter number of fish to catch, , " stageEditorKillPlayerPrompt: "Enter number of players to kill, , " -stageEditorEnchantTypePrompt: "Enter enchantment names, , " +stageEditorEnchantTypePrompt: "Enter enchantment names, , " stageEditorEnchantAmountsPrompt: "Enter enchant amounts (numbers), , " stageEditorItemNamesPrompt: "Enter item names, , " stageEditorNPCPrompt: "Enter NPC IDs, , " @@ -701,40 +701,6 @@ journalAlreadyHave: "You already have your Quest Journal out." journalNoRoom: "You have no room in your inventory for your Quest Journal!" journalNoQuests: "You have no accepted quests!" journalDenied: "You cannot do that with your Quest Journal." -ENCHANTMENT_ARROW_DAMAGE: "Power" -ENCHANTMENT_ARROW_FIRE: "Flame" -ENCHANTMENT_ARROW_INFINITE: "Infinity" -ENCHANTMENT_ARROW_KNOCKBACK: "Punch" -ENCHANTMENT_BINDING_CURSE: "BindingCurse" -ENCHANTMENT_CHANNELING: "Channeling" -ENCHANTMENT_DAMAGE_ALL: "Sharpness" -ENCHANTMENT_DAMAGE_ARTHROPODS: "BaneOfArthropods" -ENCHANTMENT_DEPTH_STRIDER: "DepthStrider" -ENCHANTMENT_DAMAGE_UNDEAD: "Smite" -ENCHANTMENT_DIG_SPEED: "Efficiency" -ENCHANTMENT_DURABILITY: "Unbreaking" -ENCHANTMENT_FIRE_ASPECT: "FireAspect" -ENCHANTMENT_FROST_WALKER: "FrostWalker" -ENCHANTMENT_IMPALING: "Impaling" -ENCHANTMENT_KNOCKBACK: "Knockback" -ENCHANTMENT_LOOT_BONUS_BLOCKS: "Fortune" -ENCHANTMENT_LOOT_BONUS_MOBS: "Looting" -ENCHANTMENT_LOYALTY: "Loyalty" -ENCHANTMENT_LUCK: "LuckOfTheSea" -ENCHANTMENT_LURE: "Lure" -ENCHANTMENT_MENDING: "Mending" -ENCHANTMENT_OXYGEN: "Respiration" -ENCHANTMENT_PROTECTION_ENVIRONMENTAL: "Protection" -ENCHANTMENT_PROTECTION_EXPLOSIONS: "BlastProtection" -ENCHANTMENT_PROTECTION_FALL: "FeatherFalling" -ENCHANTMENT_PROTECTION_FIRE: "FireProtection" -ENCHANTMENT_PROTECTION_PROJECTILE: "ProjectileProtection" -ENCHANTMENT_RIPTIDE: "Riptide" -ENCHANTMENT_SILK_TOUCH: "SilkTouch" -ENCHANTMENT_SWEEPING_EDGE: "SweepingEdge" -ENCHANTMENT_THORNS: "Thorns" -ENCHANTMENT_VANISHING_CURSE: "VanishingCurse" -ENCHANTMENT_WATER_WORKER: "AquaAffinity" COLOR_BLACK: "Black" COLOR_BLUE: "Blue" COLOR_BROWN: "Brown" diff --git a/pom.xml b/pom.xml index 67a754ec7..b3ed32b02 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4 quests https://github.com/PikaMug/Quests/ - 3.8.3 + 3.8.4 UTF-8 1.8 1.8 diff --git a/v1_8_R1/pom.xml b/v1_8_R1/pom.xml index 170ed7c39..d9e7ff0e6 100644 --- a/v1_8_R1/pom.xml +++ b/v1_8_R1/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4 diff --git a/v1_8_R2/pom.xml b/v1_8_R2/pom.xml index 35f090021..42a743f2a 100644 --- a/v1_8_R2/pom.xml +++ b/v1_8_R2/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4 diff --git a/v1_8_R3/pom.xml b/v1_8_R3/pom.xml index 3dc094f00..40344148a 100644 --- a/v1_8_R3/pom.xml +++ b/v1_8_R3/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 3.8.3 + 3.8.4