Update sound effects action prompt

This commit is contained in:
PikaMug 2019-11-05 16:42:37 -05:00
parent 072abaf125
commit 08cc98c059
8 changed files with 87 additions and 53 deletions

View File

@ -21,6 +21,7 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.MiscUtil;
public class QuestMob { public class QuestMob {
@ -191,7 +192,7 @@ public class QuestMob {
String[] args = str.split("::"); String[] args = str.split("::");
for (String string : args) { for (String string : args) {
if (string.startsWith("type-")) { if (string.startsWith("type-")) {
entityType = Quests.getMobType(string.substring(5)); entityType = MiscUtil.getProperMobType(string.substring(5));
} else if (string.startsWith("name-")) { } else if (string.startsWith("name-")) {
name = string.substring(5); name = string.substring(5);
} else if (string.startsWith("spawn-")) { } else if (string.startsWith("spawn-")) {

View File

@ -3004,7 +3004,7 @@ public class Quester {
LinkedList<EntityType> mobs = new LinkedList<EntityType>(); LinkedList<EntityType> mobs = new LinkedList<EntityType>();
List<Integer> amounts = questSec.getIntegerList("mobs-killed-amounts"); List<Integer> amounts = questSec.getIntegerList("mobs-killed-amounts");
for (String s : questSec.getStringList("mobs-killed")) { for (String s : questSec.getStringList("mobs-killed")) {
EntityType mob = Quests.getMobType(s); EntityType mob = MiscUtil.getProperMobType(s);
if (mob != null) { if (mob != null) {
mobs.add(mob); mobs.add(mob);
} }

View File

@ -2682,7 +2682,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
List<String> mobNames = config.getStringList("quests." + questKey + ".stages.ordered." + s2 List<String> mobNames = config.getStringList("quests." + questKey + ".stages.ordered." + s2
+ ".mobs-to-kill"); + ".mobs-to-kill");
for (String mob : mobNames) { for (String mob : mobNames) {
EntityType type = getMobType(mob); EntityType type = MiscUtil.getProperMobType(mob);
if (type != null) { if (type != null) {
mobsToKill.add(type); mobsToKill.add(type);
} else { } else {
@ -3438,6 +3438,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return info; 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) { public static EntityType getMobType(String mob) {
return MiscUtil.getProperMobType(mob); return MiscUtil.getProperMobType(mob);
} }

View File

@ -40,6 +40,7 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.timers.ActionTimer; import me.blackvein.quests.timers.ActionTimer;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
public class Action { public class Action {
@ -607,7 +608,7 @@ public class Action {
for (String s : section.getKeys(false)) { for (String s : section.getKeys(false)) {
String mobName = section.getString(s + ".name"); String mobName = section.getString(s + ".name");
Location spawnLocation = Quests.getLocation(section.getString(s + ".spawn-location")); 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"); Integer mobAmount = section.getInt(s + ".spawn-amounts");
if (spawnLocation == null) { if (spawnLocation == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD

View File

@ -1464,23 +1464,17 @@ public class ActionFactory implements ConversationAbandonedListener {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorEffectsTitle") + "\n"; String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorEffectsTitle") + "\n";
effects += ChatColor.DARK_PURPLE + "BLAZE_SHOOT " + ChatColor.GRAY + "- " + Lang.get("effBlazeShoot") Effect[] vals = Effect.values();
+ "\n"; for (int i = 0; i < vals.length; i++) {
effects += ChatColor.DARK_PURPLE + "BOW_FIRE " + ChatColor.GRAY + "- " + Lang.get("effBowFire") + "\n"; Effect eff = vals[i];
effects += ChatColor.DARK_PURPLE + "CLICK1 " + ChatColor.GRAY + "- " + Lang.get("effClick1") + "\n"; if (i < (vals.length - 1)) {
effects += ChatColor.DARK_PURPLE + "CLICK2 " + ChatColor.GRAY + "- " + Lang.get("effClick2") + "\n"; effects += MiscUtil.snakeCaseToUpperCamelCase(eff.name()) + ", ";
effects += ChatColor.DARK_PURPLE + "DOOR_TOGGLE " + ChatColor.GRAY + "- " + Lang.get("effDoorToggle") } else {
+ "\n"; effects += MiscUtil.snakeCaseToUpperCamelCase(eff.name()) + "\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") return effects + ChatColor.YELLOW + Lang.get("effEnterName");
+ "\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");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1488,7 +1482,7 @@ public class ActionFactory implements ConversationAbandonedListener {
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
Player player = (Player) context.getForWhom(); Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
if (Effect.valueOf(input.toUpperCase()) != null) { if (getProperEffect(input) != null) {
LinkedList<String> effects; LinkedList<String> effects;
if (context.getSessionData(CK.E_EFFECTS) != null) { if (context.getSessionData(CK.E_EFFECTS) != null) {
effects = (LinkedList<String>) context.getSessionData(CK.E_EFFECTS); effects = (LinkedList<String>) context.getSessionData(CK.E_EFFECTS);
@ -2028,9 +2022,9 @@ public class ActionFactory implements ConversationAbandonedListener {
continue; continue;
} }
if (i < (mobArr.length - 1)) { if (i < (mobArr.length - 1)) {
mobs += MiscUtil.getProperMobName(mobArr[i]) + ", "; mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", ";
} else { } else {
mobs += MiscUtil.getProperMobName(mobArr[i]) + "\n"; mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + "\n";
} }
} }
return mobs + ChatColor.YELLOW + Lang.get("eventEditorSetMobTypesPrompt"); return mobs + ChatColor.YELLOW + Lang.get("eventEditorSetMobTypesPrompt");
@ -2571,4 +2565,14 @@ public class ActionFactory implements ConversationAbandonedListener {
return new CreateMenuPrompt(); 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;
}
} }

View File

@ -66,7 +66,7 @@ public class MobsPrompt extends FixedSetPrompt {
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) {
for (int i = 0; i < mobs.size(); i++) { for (int i = 0; i < mobs.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA 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"; + ChatColor.DARK_AQUA + amnts.get(i) + "\n";
} }
} else { } else {
@ -79,7 +79,7 @@ public class MobsPrompt extends FixedSetPrompt {
String msg = Lang.get("blocksWithin"); String msg = Lang.get("blocksWithin");
msg = msg.replaceAll("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY); msg = msg.replaceAll("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY);
text += ChatColor.GRAY + " - " + ChatColor.BLUE 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 + ChatColor.DARK_AQUA + amnts.get(i) + ChatColor.GRAY + msg + ChatColor.YELLOW
+ names.get(i) + " (" + locs.get(i) + ")\n"; + names.get(i) + " (" + locs.get(i) + ")\n";
} }
@ -359,9 +359,9 @@ public class MobsPrompt extends FixedSetPrompt {
mobArr.removeAll(toRemove); mobArr.removeAll(toRemove);
for (int i = 0; i < mobArr.size(); i++) { for (int i = 0; i < mobArr.size(); i++) {
if (i < (mobArr.size() - 1)) { if (i < (mobArr.size() - 1)) {
mobs += MiscUtil.getProperMobName(mobArr.get(i)) + ", "; mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()) + ", ";
} else { } else {
mobs += MiscUtil.getProperMobName(mobArr.get(i)) + "\n"; mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()) + "\n";
} }
} }
return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt");
@ -373,7 +373,7 @@ public class MobsPrompt extends FixedSetPrompt {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
LinkedList<String> mobTypes = new LinkedList<String>(); LinkedList<String> mobTypes = new LinkedList<String>();
for (String s : input.split(" ")) { for (String s : input.split(" ")) {
if (Quests.getMobType(s) != null) { if (MiscUtil.getProperMobType(s) != null) {
mobTypes.add(s); mobTypes.add(s);
context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes);
} else { } else {
@ -647,7 +647,7 @@ public class MobsPrompt extends FixedSetPrompt {
if (type.isAlive() == false || Tameable.class.isAssignableFrom(type.getEntityClass()) == false) { if (type.isAlive() == false || Tameable.class.isAssignableFrom(type.getEntityClass()) == false) {
continue; continue;
} }
mobs += MiscUtil.getProperMobName(mobArr[i]) + ", "; mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", ";
} }
mobs = mobs.substring(0, mobs.length() - 2) + "\n"; mobs = mobs.substring(0, mobs.length() - 2) + "\n";
return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt");
@ -659,8 +659,8 @@ public class MobsPrompt extends FixedSetPrompt {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
LinkedList<String> mobTypes = new LinkedList<String>(); LinkedList<String> mobTypes = new LinkedList<String>();
for (String s : input.split(" ")) { for (String s : input.split(" ")) {
if (Quests.getMobType(s) != null) { if (MiscUtil.getProperMobType(s) != null) {
final EntityType type = Quests.getMobType(s); final EntityType type = MiscUtil.getProperMobType(s);
if (type.isAlive() || Tameable.class.isAssignableFrom(type.getEntityClass())) { if (type.isAlive() || Tameable.class.isAssignableFrom(type.getEntityClass())) {
mobTypes.add(MiscUtil.getPrettyMobName(type)); mobTypes.add(MiscUtil.getPrettyMobName(type));
context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes); context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes);

View File

@ -21,6 +21,12 @@ import org.bukkit.entity.EntityType;
public class MiscUtil { public class MiscUtil {
/**
* Capitalize first letter of text and set remainder to lowercase
*
* @param input
* @return
*/
public static String getCapitalized(String input) { public static String getCapitalized(String input) {
if (input.isEmpty()) { if (input.isEmpty()) {
return input; return input;
@ -55,18 +61,43 @@ public class MiscUtil {
return prettyString; 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); name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
for (int i = 0; i < input.chars().filter(num -> num == '_').count(); i++) {
int index = name.indexOf('_'); int index = name.indexOf('_');
if (index != -1) { if (index != -1) {
name = name.substring(0, (index + 1)) + Character.toUpperCase(name.charAt(index + 1)) name = name.substring(0, (index + 1)) + Character.toUpperCase(name.charAt(index + 1))
+ name.substring(index + 2); + name.substring(index + 2);
name = name.replaceFirst("_", ""); name = name.replaceFirst("_", "");
} }
}
return name; 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) { public static EntityType getProperMobType(String properName) {
properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase(); properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase();
for (EntityType et : EntityType.values()) { for (EntityType et : EntityType.values()) {

View File

@ -600,16 +600,6 @@ timeZoneTitle: "- Time Zones -"
enchantmentsTitle: "- Enchantments -" enchantmentsTitle: "- Enchantments -"
questGUITitle: "- GUI Item Display -" questGUITitle: "- GUI Item Display -"
questRegionTitle: "- Quest Region -" 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, <cancel>" effEnterName: "Enter an effect name to add it to the list, <cancel>"
cmdAdd: "add" cmdAdd: "add"
strAdd: "then enter '<command>' to include it" strAdd: "then enter '<command>' to include it"