diff --git a/main/src/main/java/me/blackvein/quests/QuestMob.java b/main/src/main/java/me/blackvein/quests/QuestMob.java index 7df200dd6..19be6ce08 100644 --- a/main/src/main/java/me/blackvein/quests/QuestMob.java +++ b/main/src/main/java/me/blackvein/quests/QuestMob.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.MiscUtil; public class QuestMob { @@ -191,7 +192,7 @@ public class QuestMob { String[] args = str.split("::"); for (String string : args) { if (string.startsWith("type-")) { - entityType = Quests.getMobType(string.substring(5)); + entityType = MiscUtil.getProperMobType(string.substring(5)); } else if (string.startsWith("name-")) { name = string.substring(5); } else if (string.startsWith("spawn-")) { diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 4318c5f53..aec5a80cc 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -3004,7 +3004,7 @@ public class Quester { LinkedList mobs = new LinkedList(); List amounts = questSec.getIntegerList("mobs-killed-amounts"); for (String s : questSec.getStringList("mobs-killed")) { - EntityType mob = Quests.getMobType(s); + EntityType mob = MiscUtil.getProperMobType(s); if (mob != null) { mobs.add(mob); } diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index 2ddcb9cdf..aa41a72e2 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -2682,7 +2682,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener List mobNames = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".mobs-to-kill"); for (String mob : mobNames) { - EntityType type = getMobType(mob); + EntityType type = MiscUtil.getProperMobType(mob); if (type != null) { mobsToKill.add(type); } else { @@ -3437,7 +3437,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener info += " " + loc.getZ(); return info; } - + + /** + * Gets living EntityType from name + * + * @deprecated Use MiscUtil.getProperMobType(EntityType) + * @param mob Name to get type from + * @return EntityType or null if invalid + */ public static EntityType getMobType(String mob) { return MiscUtil.getProperMobType(mob); } diff --git a/main/src/main/java/me/blackvein/quests/actions/Action.java b/main/src/main/java/me/blackvein/quests/actions/Action.java index 122ffabe8..82f50bf7e 100644 --- a/main/src/main/java/me/blackvein/quests/actions/Action.java +++ b/main/src/main/java/me/blackvein/quests/actions/Action.java @@ -40,6 +40,7 @@ import me.blackvein.quests.Quests; import me.blackvein.quests.timers.ActionTimer; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; public class Action { @@ -607,7 +608,7 @@ public class Action { for (String s : section.getKeys(false)) { String mobName = section.getString(s + ".name"); Location spawnLocation = Quests.getLocation(section.getString(s + ".spawn-location")); - EntityType type = Quests.getMobType(section.getString(s + ".mob-type")); + EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type")); Integer mobAmount = section.getInt(s + ".spawn-amounts"); if (spawnLocation == null) { plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD diff --git a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java index 3e11fbc7c..2554293b9 100644 --- a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java +++ b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java @@ -1464,23 +1464,17 @@ public class ActionFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorEffectsTitle") + "\n"; - effects += ChatColor.DARK_PURPLE + "BLAZE_SHOOT " + ChatColor.GRAY + "- " + Lang.get("effBlazeShoot") - + "\n"; - effects += ChatColor.DARK_PURPLE + "BOW_FIRE " + ChatColor.GRAY + "- " + Lang.get("effBowFire") + "\n"; - effects += ChatColor.DARK_PURPLE + "CLICK1 " + ChatColor.GRAY + "- " + Lang.get("effClick1") + "\n"; - effects += ChatColor.DARK_PURPLE + "CLICK2 " + ChatColor.GRAY + "- " + Lang.get("effClick2") + "\n"; - effects += ChatColor.DARK_PURPLE + "DOOR_TOGGLE " + ChatColor.GRAY + "- " + Lang.get("effDoorToggle") - + "\n"; - effects += ChatColor.DARK_PURPLE + "EXTINGUISH " + ChatColor.GRAY + "- " + Lang.get("effExtinguish") + "\n"; - effects += ChatColor.DARK_PURPLE + "GHAST_SHOOT " + ChatColor.GRAY + "- " + Lang.get("effGhastShoot") - + "\n"; - effects += ChatColor.DARK_PURPLE + "GHAST_SHRIEK " + ChatColor.GRAY + "- " + Lang.get("effGhastShriek") - + "\n"; - effects += ChatColor.DARK_PURPLE + "ZOMBIE_CHEW_IRON_DOOR " + ChatColor.GRAY + "- " - + Lang.get("effZombieWood") + "\n"; - effects += ChatColor.DARK_PURPLE + "ZOMBIE_CHEW_WOODEN_DOOR " + ChatColor.GRAY + "- " - + Lang.get("effZombieIron") + "\n"; - return ChatColor.YELLOW + effects + Lang.get("effEnterName"); + Effect[] vals = Effect.values(); + for (int i = 0; i < vals.length; i++) { + Effect eff = vals[i]; + if (i < (vals.length - 1)) { + effects += MiscUtil.snakeCaseToUpperCamelCase(eff.name()) + ", "; + } else { + effects += MiscUtil.snakeCaseToUpperCamelCase(eff.name()) + "\n"; + } + + } + return effects + ChatColor.YELLOW + Lang.get("effEnterName"); } @SuppressWarnings("unchecked") @@ -1488,7 +1482,7 @@ public class ActionFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { Player player = (Player) context.getForWhom(); if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (Effect.valueOf(input.toUpperCase()) != null) { + if (getProperEffect(input) != null) { LinkedList effects; if (context.getSessionData(CK.E_EFFECTS) != null) { effects = (LinkedList) context.getSessionData(CK.E_EFFECTS); @@ -2028,9 +2022,9 @@ public class ActionFactory implements ConversationAbandonedListener { continue; } if (i < (mobArr.length - 1)) { - mobs += MiscUtil.getProperMobName(mobArr[i]) + ", "; + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", "; } else { - mobs += MiscUtil.getProperMobName(mobArr[i]) + "\n"; + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + "\n"; } } return mobs + ChatColor.YELLOW + Lang.get("eventEditorSetMobTypesPrompt"); @@ -2571,4 +2565,14 @@ public class ActionFactory implements ConversationAbandonedListener { return new CreateMenuPrompt(); } } -} + + public Effect getProperEffect(String properName) { + properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase(); + for (Effect eff : Effect.values()) { + if (eff.name().replaceAll("_", "").equalsIgnoreCase(properName)) { + return eff; + } + } + return null; + } +} \ No newline at end of file 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 169dcfa8a..91e61b4f2 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/MobsPrompt.java @@ -66,7 +66,7 @@ public class MobsPrompt extends FixedSetPrompt { if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { for (int i = 0; i < mobs.size(); i++) { text += ChatColor.GRAY + " - " + ChatColor.AQUA - + MiscUtil.getPrettyMobName(Quests.getMobType(mobs.get(i))) + ChatColor.GRAY + " x " + + MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + amnts.get(i) + "\n"; } } else { @@ -79,7 +79,7 @@ public class MobsPrompt extends FixedSetPrompt { String msg = Lang.get("blocksWithin"); msg = msg.replaceAll("", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY); text += ChatColor.GRAY + " - " + ChatColor.BLUE - + MiscUtil.getPrettyMobName(Quests.getMobType(mobs.get(i))) + ChatColor.GRAY + " x " + + MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + amnts.get(i) + ChatColor.GRAY + msg + ChatColor.YELLOW + names.get(i) + " (" + locs.get(i) + ")\n"; } @@ -359,9 +359,9 @@ public class MobsPrompt extends FixedSetPrompt { mobArr.removeAll(toRemove); for (int i = 0; i < mobArr.size(); i++) { if (i < (mobArr.size() - 1)) { - mobs += MiscUtil.getProperMobName(mobArr.get(i)) + ", "; + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()) + ", "; } else { - mobs += MiscUtil.getProperMobName(mobArr.get(i)) + "\n"; + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()) + "\n"; } } return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); @@ -373,7 +373,7 @@ public class MobsPrompt extends FixedSetPrompt { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { LinkedList mobTypes = new LinkedList(); for (String s : input.split(" ")) { - if (Quests.getMobType(s) != null) { + if (MiscUtil.getProperMobType(s) != null) { mobTypes.add(s); context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); } else { @@ -647,7 +647,7 @@ public class MobsPrompt extends FixedSetPrompt { if (type.isAlive() == false || Tameable.class.isAssignableFrom(type.getEntityClass()) == false) { continue; } - mobs += MiscUtil.getProperMobName(mobArr[i]) + ", "; + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", "; } mobs = mobs.substring(0, mobs.length() - 2) + "\n"; return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); @@ -659,8 +659,8 @@ public class MobsPrompt extends FixedSetPrompt { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { LinkedList mobTypes = new LinkedList(); for (String s : input.split(" ")) { - if (Quests.getMobType(s) != null) { - final EntityType type = Quests.getMobType(s); + if (MiscUtil.getProperMobType(s) != null) { + final EntityType type = MiscUtil.getProperMobType(s); if (type.isAlive() || Tameable.class.isAssignableFrom(type.getEntityClass())) { mobTypes.add(MiscUtil.getPrettyMobName(type)); context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes); 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 58e3c30cd..fa16bda3c 100644 --- a/main/src/main/java/me/blackvein/quests/util/MiscUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/MiscUtil.java @@ -20,7 +20,13 @@ import org.bukkit.DyeColor; import org.bukkit.entity.EntityType; public class MiscUtil { - + + /** + * Capitalize first letter of text and set remainder to lowercase + * + * @param input + * @return + */ public static String getCapitalized(String input) { if (input.isEmpty()) { return input; @@ -54,19 +60,44 @@ public class MiscUtil { } return prettyString; } - - public static String getProperMobName(EntityType type) { - String name = type.name().toLowerCase(); + + /** + * Convert text from snake_case to UpperCamelCase + * + * @param type To convert + * @return Converted text + */ + public static String snakeCaseToUpperCamelCase(String input) { + String name = input.toLowerCase(); name = Character.toUpperCase(name.charAt(0)) + name.substring(1); - int index = name.indexOf('_'); - if (index != -1) { - name = name.substring(0, (index + 1)) + Character.toUpperCase(name.charAt(index + 1)) - + name.substring(index + 2); - name = name.replaceFirst("_", ""); + for (int i = 0; i < input.chars().filter(num -> num == '_').count(); i++) { + int index = name.indexOf('_'); + if (index != -1) { + name = name.substring(0, (index + 1)) + Character.toUpperCase(name.charAt(index + 1)) + + name.substring(index + 2); + name = name.replaceFirst("_", ""); + } } return name; } + + /** + * Convert EntityType name from snake_case to UpperCamelCase + * + * @deprecated Use {@link #snakeCaseToUpperCamelCase(String)} + * @param type To convert + * @return Converted text + */ + public static String getProperMobName(EntityType type) { + return snakeCaseToUpperCamelCase(type.name()); + } + /** + * Gets living EntityType from name + * + * @param properName Name to get type from + * @return EntityType or null if invalid + */ public static EntityType getProperMobType(String properName) { properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase(); for (EntityType et : EntityType.values()) { diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 42bf1a833..372c2e209 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -600,16 +600,6 @@ timeZoneTitle: "- Time Zones -" enchantmentsTitle: "- Enchantments -" questGUITitle: "- GUI Item Display -" questRegionTitle: "- Quest Region -" -effBlazeShoot: "Sound of a Blaze firing" -effBowFire: "Sound of a bow firing" -effClick1: "A click sound" -effClick2: "A different click sound" -effDoorToggle: "Sound of a door opening or closing" -effExtinguish: "Sound of fire being extinguished" -effGhastShoot: "Sound of a Ghast firing" -effGhastShriek: "Sound of a Ghast shrieking" -effZombieWood: "Sound of a Zombie chewing an iron door" -effZombieIron: "Sound of a Zombie chewing a wooden door" effEnterName: "Enter an effect name to add it to the list, " cmdAdd: "add" strAdd: "then enter '' to include it"