diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index 3bc2b2272..e63e514ad 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -619,8 +619,14 @@ public class Quest { none = null; } if (rews.getCommands().isEmpty() == false) { + int index = 0; for (String s : rews.getCommands()) { - player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getCommands().get(rews.getCommands().indexOf(s))); + if (rews.getCommandsOverrideDisplay().isEmpty() == false && rews.getCommandsOverrideDisplay().size() >= index) { + player.sendMessage("- " + ChatColor.DARK_GREEN + rews.getCommandsOverrideDisplay().get(index)); + } else { + player.sendMessage("- " + ChatColor.DARK_GREEN + s); + } + index++; } none = null; } diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index 5158f635a..dce178247 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -799,6 +799,7 @@ public class QuestFactory implements ConversationAbandonedListener { List RPGItemAmounts = null; Integer expRew = null; List commandRews = null; + List commandDisplayOverrideRews = null; List permRews = null; List mcMMOSkillRews = null; List mcMMOSkillAmounts = null; @@ -894,6 +895,10 @@ public class QuestFactory implements ConversationAbandonedListener { commandRews = new LinkedList(); commandRews.addAll((List)cc.getSessionData(CK.REW_COMMAND)); } + if (cc.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY) != null) { + commandDisplayOverrideRews = new LinkedList(); + commandDisplayOverrideRews.addAll((List)cc.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY)); + } if (cc.getSessionData(CK.REW_PERMISSION) != null) { permRews = new LinkedList(); permRews.addAll((List) cc.getSessionData(CK.REW_PERMISSION)); @@ -1363,7 +1368,11 @@ public class QuestFactory implements ConversationAbandonedListener { stage.set("start-message", startMessage == null ? startMessage : startMessage.replace("\\n", "\n")); stage.set("complete-message", completeMessage == null ? completeMessage : completeMessage.replace("\\n", "\n")); } - if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null || RPGItemRews != null || heroesClassRews != null && heroesClassRews.isEmpty() == false || phatLootRews != null && phatLootRews.isEmpty() == false || customRews != null && customRews.isEmpty() == false) { + if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false + || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false + || commandDisplayOverrideRews != null && commandDisplayOverrideRews.isEmpty() == false || mcMMOSkillRews != null + || RPGItemRews != null || heroesClassRews != null && heroesClassRews.isEmpty() == false + || phatLootRews != null && phatLootRews.isEmpty() == false || customRews != null && customRews.isEmpty() == false) { ConfigurationSection rews = cs.createSection("rewards"); rews.set("items", (itemRews != null && itemRews.isEmpty() == false) ? itemRews : null); rews.set("money", moneyRew); @@ -1371,6 +1380,7 @@ public class QuestFactory implements ConversationAbandonedListener { rews.set("exp", expRew); rews.set("permissions", permRews); rews.set("commands", commandRews); + rews.set("commands-override-display", commandDisplayOverrideRews); rews.set("mcmmo-skills", mcMMOSkillRews); rews.set("mcmmo-levels", mcMMOSkillAmounts); rews.set("rpgitem-names", RPGItemRews); @@ -1492,6 +1502,9 @@ public class QuestFactory implements ConversationAbandonedListener { if (rews.getCommands().isEmpty() == false) { cc.setSessionData(CK.REW_COMMAND, rews.getCommands()); } + if (rews.getCommandsOverrideDisplay().isEmpty() == false) { + cc.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, rews.getCommandsOverrideDisplay()); + } if (rews.getPermissions().isEmpty() == false) { cc.setSessionData(CK.REW_PERMISSION, rews.getPermissions()); } diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index 6b8c7c0d5..5c7727d7a 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -1565,12 +1565,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } if (config.contains("quests." + questKey + ".rewards.commands")) { if (Quests.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) { - rews.setCommands(config.getStringList("quests." + questKey + ".rewards.commands")); } else { skipQuestProcess("commands: Reward in Quest " + quest.getName() + " is not a list of commands!"); } } + if (config.contains("quests." + questKey + ".rewards.commands-override-display")) { + if (Quests.checkList(config.getList("quests." + questKey + ".rewards.commands-override-display"), String.class)) { + rews.setCommandsOverrideDisplay(config.getStringList("quests." + questKey + ".rewards.commands-override-display")); + } else { + skipQuestProcess("commands-override-display: Reward in Quest " + quest.getName() + " is not a list of strings!"); + } + } if (config.contains("quests." + questKey + ".rewards.permissions")) { if (Quests.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) { rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions")); diff --git a/main/src/main/java/me/blackvein/quests/Rewards.java b/main/src/main/java/me/blackvein/quests/Rewards.java index d1479b4ba..ee9ce0b50 100644 --- a/main/src/main/java/me/blackvein/quests/Rewards.java +++ b/main/src/main/java/me/blackvein/quests/Rewards.java @@ -24,6 +24,7 @@ public class Rewards { private int questPoints = 0; private int exp = 0; private List commands = new LinkedList(); + private List commandsOverrideDisplay = new LinkedList(); private List permissions = new LinkedList(); private List items = new LinkedList(); private List mcmmoSkills = new LinkedList(); @@ -57,6 +58,12 @@ public class Rewards { public void setCommands(List commands) { this.commands = commands; } + public List getCommandsOverrideDisplay() { + return commandsOverrideDisplay; + } + public void setCommandsOverrideDisplay(List commandsOverrideDisplay) { + this.commandsOverrideDisplay = commandsOverrideDisplay; + } public List getPermissions() { return permissions; } diff --git a/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java index 7d6f5814e..999b92e28 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java @@ -133,7 +133,10 @@ public class RequirementsPrompt extends FixedSetPrompt { text += ChatColor.RESET + "" + ChatColor.DARK_PURPLE + " - " + ChatColor.LIGHT_PURPLE + s + "\n"; } } - if (context.getSessionData(CK.REQ_MONEY) == null && context.getSessionData(CK.REQ_QUEST_POINTS) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_ITEMS) == null && context.getSessionData(CK.REQ_PERMISSION) == null && context.getSessionData(CK.REQ_QUEST) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_MCMMO_SKILLS) == null && context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null && context.getSessionData(CK.REQ_CUSTOM) == null) { + if (context.getSessionData(CK.REQ_MONEY) == null && context.getSessionData(CK.REQ_QUEST_POINTS) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null + && context.getSessionData(CK.REQ_ITEMS) == null && context.getSessionData(CK.REQ_PERMISSION) == null && context.getSessionData(CK.REQ_QUEST) == null + && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_MCMMO_SKILLS) == null && context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null + && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null && context.getSessionData(CK.REQ_CUSTOM) == null) { text += ChatColor.GRAY + "" + ChatColor.BOLD + "10 - " + ChatColor.RESET + ChatColor.GRAY + Lang.get("reqSetFail") + " (" + Lang.get("reqNone") + ")\n"; } else if (context.getSessionData(CK.Q_FAIL_MESSAGE) == null) { text += ChatColor.RED + "" + ChatColor.BOLD + "10 - " + ChatColor.RESET + ChatColor.RED + Lang.get("reqSetFail") + " (" + Lang.get("questRequiredNoneSet") + ")\n"; diff --git a/main/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java index dbeff0023..8f8b79d9e 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java @@ -78,8 +78,11 @@ public class RewardsPrompt extends FixedSetPrompt { } else { text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("rewSetCommands") + "\n"; List commands = (List) context.getSessionData(CK.REW_COMMAND); + List overrides = (List) context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY); + int index = 0; for (String cmd : commands) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + cmd + "\n"; + text += ChatColor.GRAY + " - " + ChatColor.AQUA + cmd + (overrides != null ? ChatColor.GRAY + " (\"" + ChatColor.AQUA + overrides.get(index) + ChatColor.GRAY + "\")" : "") + "\n"; + index++; } } if (context.getSessionData(CK.REW_PERMISSION) == null) { @@ -156,7 +159,7 @@ public class RewardsPrompt extends FixedSetPrompt { } else if (input.equalsIgnoreCase("4")) { return new ExperiencePrompt(); } else if (input.equalsIgnoreCase("5")) { - return new CommandsPrompt(); + return new CommandsListPrompt(); } else if (input.equalsIgnoreCase("6")) { return new PermissionsPrompt(); } else if (input.equalsIgnoreCase("7")) { @@ -340,6 +343,72 @@ public class RewardsPrompt extends FixedSetPrompt { } } + private class CommandsListPrompt extends FixedSetPrompt { + + public CommandsListPrompt() { + super("1", "2", "3", "4"); + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("rewCommands") + " -\n"; + if (context.getSessionData(CK.REW_COMMAND) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("rewSetCommands") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " + Lang.get("rewSetCommandsOverrides") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done"); + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("rewSetCommands") + "\n"; + for (String s : getCommand(context)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + if (context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("rewSetCommandsOverrides") + " (" + Lang.get("stageEditorOptional") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("rewSetCommandsOverrides") + "\n"; + for (String s : getCommandOverrideDisplay(context)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + } + text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done"); + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new CommandsPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.REW_COMMAND) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("rewNoCommands")); + return new CommandsListPrompt(); + } else { + return new CommandsOverrideDisplayPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCommandsCleared")); + context.setSessionData(CK.REW_COMMAND, null); + context.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, null); + return new CommandsListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + return new RewardsPrompt(plugin, factory); + } + return null; + } + + @SuppressWarnings("unchecked") + private List getCommand(ConversationContext context) { + return (List) context.getSessionData(CK.REW_COMMAND); + } + + @SuppressWarnings("unchecked") + private List getCommandOverrideDisplay(ConversationContext context) { + return (List) context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY); + } + } + private class CommandsPrompt extends StringPrompt { @Override @@ -365,7 +434,35 @@ public class RewardsPrompt extends FixedSetPrompt { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(CK.REW_COMMAND, null); } - return new RewardsPrompt(plugin, factory); + return new CommandsListPrompt(); + } + } + + private class CommandsOverrideDisplayPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.YELLOW + Lang.get("rewCommandsOverridePrompt") + "\n"; + text += ChatColor.ITALIC + "" + ChatColor.GOLD + Lang.get("rewCommandsOverrideHint"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + String[] args = input.split(Lang.get("charSemi")); + List overrides = new LinkedList(); + for (String s : args) { + if (s.startsWith("/")) { + s = s.substring(1); + } + overrides.add(s); + } + context.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, overrides); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, null); + } + return new CommandsListPrompt(); } } diff --git a/main/src/main/java/me/blackvein/quests/util/CK.java b/main/src/main/java/me/blackvein/quests/util/CK.java index beb43652f..983cb955b 100644 --- a/main/src/main/java/me/blackvein/quests/util/CK.java +++ b/main/src/main/java/me/blackvein/quests/util/CK.java @@ -114,6 +114,7 @@ public class CK { public static final String REW_ITEMS = "itemRews"; public static final String REW_EXP = "expRew"; public static final String REW_COMMAND = "commandRews"; + public static final String REW_COMMAND_OVERRIDE_DISPLAY = "commandOverrideDisplay"; public static final String REW_PERMISSION = "permissionRews"; public static final String REW_MCMMO_SKILLS = "mcMMOSkillRews"; public static final String REW_MCMMO_AMOUNTS = "mcMMOSkillAmounts"; diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 0ce514fa9..11416741f 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -495,6 +495,12 @@ rewSetQuestPoints: "Set Quest Points reward" rewSetItems: "Set item rewards" rewSetExperience: "Set experience reward" rewSetCommands: "Set command rewards" +rewCommands: "Command rewards" +rewSetCommandsOverrides: "Set command display overrides" +rewCommandsCleared: "Command rewards cleared." +rewCommandsOverridePrompt: "Enter command display override, , " +rewCommandsOverrideHint: "(This override will display your own text as the reward)" +rewNoCommands: "You must set commands first!" rewSetPermission: "Set permission rewards" rewSetMcMMO: "Set mcMMO skill rewards" rewSetHeroes: "Set Heroes experience rewards"