diff --git a/src/main/java/me/blackvein/quests/CustomObjective.java b/src/main/java/me/blackvein/quests/CustomObjective.java index cedf78ae6..e7ccd7b5d 100644 --- a/src/main/java/me/blackvein/quests/CustomObjective.java +++ b/src/main/java/me/blackvein/quests/CustomObjective.java @@ -23,8 +23,8 @@ public abstract class CustomObjective implements Listener { private Quests plugin = Quests.getPlugin(Quests.class); private String name = null; private String author = null; - public final Map datamap = new HashMap(); - public final Map descriptions = new HashMap(); + private Map data = new HashMap(); + private Map descriptions = new HashMap(); private String countPrompt = "null"; private String display = "null"; private boolean enableCount = true; @@ -46,9 +46,43 @@ public abstract class CustomObjective implements Listener { public void setAuthor(String author) { this.author = author; } + + public Map getData() { + return data; + } + + /** + * Add a detailed piece of datum to the data map + * @param name + * @param o + */ + public void addDatum(String name, Object o) { + if (o == null) { + data.put(name, o); + } else { + data.put(name, null); + } + } + /** + * Add a blank piece of datum to the data map + * @param name + */ + public void addDatum(String name) { + data.put(name, null); + } + /** + * Add null data for name + * + * @param name + * @deprecated use addDatum() + */ public void addData(String name) { - datamap.put(name, null); + addDatum(name); + } + + public Map getDescriptions() { + return descriptions; } public void addDescription(String data, String description) { @@ -94,7 +128,20 @@ public abstract class CustomObjective implements Listener { public void setEnableCount(boolean enableCount) { this.enableCount = enableCount; } + + public Map getDataForPlayer(Player player, CustomObjective customObj, Quest quest) { + return getDatamap(player, customObj, quest); + } + /** + * Get data for specified player's current stage + * + * @param player The player to get data for + * @param obj The CustomObjective to get data for + * @param quest Quest to get player's current stage. Returns null if player is not on quest + * @return data map if everything matches, otherwise null + * @deprecated use getDataForPlayer() + */ public Map getDatamap(Player player, CustomObjective obj, Quest quest) { Quester quester = plugin.getQuester(player.getUniqueId()); if (quester != null) { @@ -161,13 +208,13 @@ public abstract class CustomObjective implements Listener { if (other.author.equals(name) == false) { return false; } - for (String s : other.datamap.keySet()) { - if (datamap.containsKey(s) == false) { + for (String s : other.getData().keySet()) { + if (getData().containsKey(s) == false) { return false; } } - for (Object val : other.datamap.values()) { - if (datamap.containsValue(val) == false) { + for (Object val : other.getData().values()) { + if (getData().containsValue(val) == false) { return false; } } diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index 948a4179a..1da62d302 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -787,7 +787,7 @@ public class Quester { if (co.getName().equals(entry.getKey())) { String display = co.getDisplay(); Map datamap = getCurrentStage(quest).customObjectiveData.get(index); - for (String key : co.datamap.keySet()) { + for (String key : co.getData().keySet()) { try { display = display.replace("%" + key + "%", ((String) datamap.get(key))); } catch (NullPointerException ne) { @@ -1551,7 +1551,7 @@ public class Quester { } } Map datamap = getCurrentStage(quest).customObjectiveData.get(index); - for (String key : co.datamap.keySet()) { + for (String key : co.getData().keySet()) { message = message.replace("%" + ((String) key) + "%", (String) datamap.get(key)); } if (co.isCountShown() && co.isEnableCount()) { diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 5ab8c72e1..886c1a946 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -922,14 +922,15 @@ 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")); + + rews.setCommands((LinkedList) 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.permissions")) { if (Quests.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) { - rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions")); + rews.setPermissions((LinkedList) config.getStringList("quests." + questKey + ".rewards.permissions")); } else { skipQuestProcess("permissions: Reward in Quest " + quest.getName() + " is not a list of permissions!"); } @@ -953,8 +954,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener skipQuestProcess("" + skill + " in mcmmo-skills: Reward in Quest " + quest.getName() + " is not a valid mcMMO skill name!"); } } - rews.setMcmmoSkills(config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")); - rews.setMcmmoAmounts(config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels")); + rews.setMcmmoSkills((LinkedList) config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")); + rews.setMcmmoAmounts((LinkedList) config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels")); } else { skipQuestProcess("mcmmo-levels: Reward in Quest " + quest.getName() + " is not a list of numbers!"); } @@ -978,8 +979,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener skipQuestProcess("" + heroClass + " in heroes-exp-classes: Reward in Quest " + quest.getName() + " is not a valid Heroes class name!"); } } - rews.setHeroesClasses(config.getStringList("quests." + questKey + ".rewards.heroes-exp-classes")); - rews.setHeroesAmounts(config.getDoubleList("quests." + questKey + ".rewards.heroes-exp-amounts")); + rews.setHeroesClasses((LinkedList) config.getStringList("quests." + questKey + ".rewards.heroes-exp-classes")); + rews.setHeroesAmounts((LinkedList) config.getDoubleList("quests." + questKey + ".rewards.heroes-exp-amounts")); } else { skipQuestProcess("heroes-exp-amounts: Reward in Quest " + quest.getName() + " is not a list of experience amounts (decimal numbers)!"); } @@ -1001,7 +1002,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener skipQuestProcess("" + loot + " in phat-loots: Reward in Quest " + quest.getName() + " is not a valid PhatLoot name!"); } } - rews.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots")); + rews.setPhatLoots((LinkedList) config.getStringList("quests." + questKey + ".rewards.phat-loots")); } else { skipQuestProcess("phat-loots: Reward in Quest " + quest.getName() + " is not a list of PhatLoots!"); } @@ -1877,7 +1878,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener continue; } else { ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); - Map data=populateCustoms(sec2,found.get().datamap); + Map data = populateCustoms(sec2, found.get().getData()); // Added in Github PR #554 oStage.customObjectives.add(found.get()); oStage.customObjectiveCounts.add(count); @@ -2653,7 +2654,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return hero.getHeroClass().getName().equalsIgnoreCase(primaryClass); } - @SuppressWarnings("deprecation") public boolean testSecondaryHeroesClass(String secondaryClass, UUID uuid) { Hero hero = getHero(uuid); return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass); diff --git a/src/main/java/me/blackvein/quests/Rewards.java b/src/main/java/me/blackvein/quests/Rewards.java index fe7bdb5b5..7d9483e12 100644 --- a/src/main/java/me/blackvein/quests/Rewards.java +++ b/src/main/java/me/blackvein/quests/Rewards.java @@ -23,14 +23,14 @@ public class Rewards { private int money = 0; private int questPoints = 0; private int exp = 0; - private List commands = new LinkedList(); - private List permissions = new LinkedList(); + private LinkedList commands = new LinkedList(); + private LinkedList permissions = new LinkedList(); private LinkedList items = new LinkedList(); - private List mcmmoSkills = new LinkedList(); - private List mcmmoAmounts = new LinkedList(); - private List heroesClasses = new LinkedList(); - private List heroesAmounts = new LinkedList(); - private List phatLoots = new LinkedList(); + private LinkedList mcmmoSkills = new LinkedList(); + private LinkedList mcmmoAmounts = new LinkedList(); + private LinkedList heroesClasses = new LinkedList(); + private LinkedList heroesAmounts = new LinkedList(); + private LinkedList phatLoots = new LinkedList(); private Map> customRewards = new HashMap>(); public int getMoney() { @@ -54,13 +54,13 @@ public class Rewards { public List getCommands() { return commands; } - public void setCommands(List commands) { + public void setCommands(LinkedList commands) { this.commands = commands; } public List getPermissions() { return permissions; } - public void setPermissions(List permissions) { + public void setPermissions(LinkedList permissions) { this.permissions = permissions; } public LinkedList getItems() { @@ -72,31 +72,31 @@ public class Rewards { public List getMcmmoSkills() { return mcmmoSkills; } - public void setMcmmoSkills(List mcmmoSkills) { + public void setMcmmoSkills(LinkedList mcmmoSkills) { this.mcmmoSkills = mcmmoSkills; } public List getMcmmoAmounts() { return mcmmoAmounts; } - public void setMcmmoAmounts(List mcmmoAmounts) { + public void setMcmmoAmounts(LinkedList mcmmoAmounts) { this.mcmmoAmounts = mcmmoAmounts; } public List getHeroesClasses() { return heroesClasses; } - public void setHeroesClasses(List heroesClasses) { + public void setHeroesClasses(LinkedList heroesClasses) { this.heroesClasses = heroesClasses; } public List getHeroesAmounts() { return heroesAmounts; } - public void setHeroesAmounts(List heroesAmounts) { + public void setHeroesAmounts(LinkedList heroesAmounts) { this.heroesAmounts = heroesAmounts; } public List getPhatLoots() { return phatLoots; } - public void setPhatLoots(List phatLoots) { + public void setPhatLoots(LinkedList phatLoots) { this.phatLoots = phatLoots; } public Map> getCustomRewards() { diff --git a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java index 2a2efd174..a7d36e445 100644 --- a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java @@ -3869,7 +3869,7 @@ public class CreateStagePrompt extends FixedSetPrompt { LinkedList countList = (LinkedList) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT); if (list.contains(found.getName()) == false) { list.add(found.getName()); - datamapList.add(found.datamap); + datamapList.add(found.getData()); countList.add(-999); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList); @@ -3880,7 +3880,7 @@ public class CreateStagePrompt extends FixedSetPrompt { } else { LinkedList> datamapList = new LinkedList>(); LinkedList countList = new LinkedList(); - datamapList.add(found.datamap); + datamapList.add(found.getData()); countList.add(-999); LinkedList list = new LinkedList(); list.add(found.getName()); @@ -3892,8 +3892,8 @@ public class CreateStagePrompt extends FixedSetPrompt { if (found.isEnableCount()) { return new CustomObjectiveCountPrompt(); } - if (found.datamap.isEmpty() == false) { - context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions); + if (found.getData().isEmpty() == false) { + context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions()); return new ObjectiveCustomDataListPrompt(); } // @@ -3949,8 +3949,8 @@ public class CreateStagePrompt extends FixedSetPrompt { break; } } - if (found != null && found.datamap.isEmpty() == false) { - context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions); + if (found != null && found.getData().isEmpty() == false) { + context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions()); return new ObjectiveCustomDataListPrompt(); } else { return new CreateStagePrompt(plugin, stageNum, questFactory, citizens);