diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index fd7a109cf..88bb37d0f 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -27,7 +27,6 @@ import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; @@ -38,33 +37,20 @@ import org.bukkit.conversations.ConversationAbandonedListener; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationFactory; import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import com.sk89q.worldguard.protection.managers.RegionManager; - -import me.blackvein.quests.Quests.ReloadCallback; -import me.blackvein.quests.actions.Action; -import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; -import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; -import me.blackvein.quests.convo.quests.prompts.GUIDisplayPrompt; -import me.blackvein.quests.convo.quests.prompts.OptionsPrompt; -import me.blackvein.quests.convo.quests.prompts.PlannerPrompt; -import me.blackvein.quests.convo.quests.prompts.RequirementsPrompt; -import me.blackvein.quests.convo.quests.prompts.RewardsPrompt; -import me.blackvein.quests.convo.quests.prompts.StageMenuPrompt; -import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; -import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; -import me.blackvein.quests.reflect.worldguard.WorldGuardAPI; +import me.blackvein.quests.convo.quests.main.QuestMainPrompt; +import me.blackvein.quests.convo.quests.menu.QuestMenuPrompt; +import me.blackvein.quests.convo.quests.stages.StageMenuPrompt; +import me.blackvein.quests.interfaces.ReloadCallback; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; -import net.citizensnpcs.api.CitizensAPI; public class QuestFactory implements ConversationAbandonedListener { @@ -154,470 +140,29 @@ public class QuestFactory implements ConversationAbandonedListener { selectedReachLocations.remove(player.getUniqueId()); } - public class QuestMenuPrompt extends QuestsEditorNumericPrompt { - public QuestMenuPrompt(ConversationContext context) { - super(context); - } - - private final int size = 4; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return Lang.get("questEditorTitle"); - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - case 2: - case 3: - return ChatColor.BLUE; - case 4: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.YELLOW + Lang.get("questEditorCreate"); - case 2: - return ChatColor.YELLOW + Lang.get("questEditorEdit"); - case 3: - return ChatColor.YELLOW + Lang.get("questEditorDelete"); - case 4: - return ChatColor.RED + Lang.get("exit"); - default: - return null; - } - } - - public String getAdditionalText(ConversationContext context, int number) { - return null; - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - String text = ChatColor.GOLD + getTitle(context) + "\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; - } - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - final Player player = (Player) context.getForWhom(); - switch (input.intValue()) { - case 1: - if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.create")) { - return new QuestSelectCreatePrompt(plugin, context); - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new QuestMenuPrompt(context); - } - case 2: - if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.edit")) { - return new QuestSelectEditPrompt(); - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new QuestMenuPrompt(context); - } - case 3: - if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.delete")) { - return new QuestSelectDeletePrompt(); - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new QuestMenuPrompt(context); - } - case 4: - context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("exited")); - return Prompt.END_OF_CONVERSATION; - default: - return new QuestMenuPrompt(context); - } - } - } - public Prompt returnToMenu(ConversationContext context) { return new QuestMainPrompt(context); } - - public class QuestMainPrompt extends QuestsEditorNumericPrompt { - public QuestMainPrompt(ConversationContext context) { - super(context); - } - - private final int size = 15; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return Lang.get("quest") + ": " + context.getSessionData(CK.Q_NAME) + "" + ChatColor.GRAY - + (context.getSessionData(CK.Q_ID) != null ? " (" + Lang.get("id") + ":" - + context.getSessionData(CK.Q_ID) + ")": ""); - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - case 2: - case 3: - case 4: - case 5: - return ChatColor.BLUE; - case 6: - if (plugin.getDependencies().getWorldGuardApi() != null) { - return ChatColor.BLUE; - } else { - return ChatColor.GRAY; - } - case 7: - return ChatColor.BLUE; - case 8: - if (plugin.getDependencies().getCitizens() != null) { - return ChatColor.BLUE; - } else { - return ChatColor.GRAY; - } - case 9: - case 10: - case 11: - case 12: - case 13: - return ChatColor.BLUE; - case 14: - return ChatColor.GREEN; - case 15: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.YELLOW + Lang.get("questEditorName"); - case 2: - if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { - return ChatColor.RED + Lang.get("questEditorAskMessage"); - } else { - return ChatColor.YELLOW + Lang.get("questEditorAskMessage"); - } - case 3: - if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { - return ChatColor.RED + Lang.get("questEditorFinishMessage"); - } else { - return ChatColor.YELLOW + Lang.get("questEditorFinishMessage"); - } - case 4: - if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() - != null) { - return ChatColor.YELLOW + Lang.get("questEditorNPCStart"); - } else if (plugin.getDependencies().getCitizens() != null) { - return ChatColor.YELLOW + Lang.get("questEditorNPCStart"); - } else { - return ChatColor.GRAY + Lang.get("questEditorNPCStart"); - } - case 5: - return ChatColor.YELLOW + Lang.get("questEditorBlockStart"); - case 6: - if (plugin.getDependencies().getWorldGuardApi() != null) { - if (context.getSessionData(CK.Q_REGION) == null) { - return ChatColor.YELLOW + Lang.get("questWGSetRegion"); - } else { - return ChatColor.YELLOW + Lang.get("questWGSetRegion"); - } - } else { - return ChatColor.GRAY + Lang.get("questWGSetRegion"); - } - case 7: - return ChatColor.YELLOW + Lang.get("questEditorInitialEvent"); - case 8: - if (plugin.getDependencies().getCitizens() != null) { - if (context.getSessionData(CK.Q_GUIDISPLAY) == null) { - return ChatColor.YELLOW + Lang.get("questEditorSetGUI"); - } else { - return ChatColor.YELLOW + Lang.get("questEditorSetGUI"); - } - } else { - return ChatColor.GRAY + Lang.get("questEditorSetGUI"); - } - case 9: - return ChatColor.DARK_AQUA + Lang.get("questEditorReqs"); - case 10: - return ChatColor.AQUA + Lang.get("questEditorPln"); - case 11: - return ChatColor.LIGHT_PURPLE + Lang.get("questEditorStages"); - case 12: - return ChatColor.DARK_PURPLE + Lang.get("questEditorRews"); - case 13: - return ChatColor.DARK_GREEN + Lang.get("questEditorOpts"); - case 14: - return ChatColor.GREEN + Lang.get("save"); - case 15: - return ChatColor.RED + Lang.get("exit"); - default: - return null; - } - } - - public String getAdditionalText(ConversationContext context, int number) { - switch (number) { - case 1: - return ""; - case 2: - if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { - return ChatColor.DARK_RED + "(" + Lang.get("questRequiredNoneSet") + ")"; - } else { - return ChatColor.YELLOW + "(" + context.getSessionData(CK.Q_ASK_MESSAGE) + ChatColor.RESET - + ChatColor.YELLOW + ")"; - } - case 3: - if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { - return ChatColor.DARK_RED + "(" + Lang.get("questRequiredNoneSet") + ")"; - } else { - return ChatColor.YELLOW + "(" + context.getSessionData(CK.Q_FINISH_MESSAGE) + ChatColor.RESET - + ChatColor.YELLOW + ")"; - } - case 4: - if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() - != null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else if (plugin.getDependencies().getCitizens() != null) { - return ChatColor.YELLOW + "(" + CitizensAPI.getNPCRegistry().getById((Integer) context - .getSessionData(CK.Q_START_NPC)).getName() + ChatColor.RESET + ChatColor.YELLOW + ")"; - } else { - return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; - } - case 5: - if (context.getSessionData(CK.Q_START_BLOCK) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); - return ChatColor.YELLOW + "(" + l.getWorld().getName() + ", " + l.getBlockX() + ", " - + l.getBlockY() + ", " + l.getBlockZ() + ")"; - } - case 6: - if (plugin.getDependencies().getWorldGuardApi() != null) { - if (context.getSessionData(CK.Q_REGION) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - return ChatColor.YELLOW + "(" + ChatColor.GREEN - + (String) context.getSessionData(CK.Q_REGION) + ChatColor.YELLOW + ")"; - } - } else { - return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; - } - case 7: - if (context.getSessionData(CK.Q_INITIAL_EVENT) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - return ChatColor.YELLOW + "(" + (String) context.getSessionData(CK.Q_INITIAL_EVENT) + ")"; - } - case 8: - if (plugin.getDependencies().getCitizens() != null) { - if (context.getSessionData(CK.Q_GUIDISPLAY) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - return ChatColor.YELLOW + "(" + ItemUtil.getDisplayString((ItemStack) context - .getSessionData(CK.Q_GUIDISPLAY)) + ChatColor.RESET + ChatColor.YELLOW + ")"; - } - } else { - return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; - } - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - return ""; - default: - return null; - } - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = ChatColor.GOLD + "- " + getTitle(context).replaceFirst(": ", ": " + ChatColor.AQUA) - + ChatColor.GOLD + " -\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; - } - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - switch (input.intValue()) { - case 1: - return new QuestSetNamePrompt(); - case 2: - return new AskMessagePrompt(); - case 3: - return new FinishMessagePrompt(); - case 4: - if (plugin.getDependencies().getCitizens() != null) { - return new NPCStartPrompt(); - } else { - return new QuestMainPrompt(context); - } - case 5: - selectedBlockStarts.put(((Player) context.getForWhom()).getUniqueId(), null); - return new BlockStartPrompt(); - case 6: - if (plugin.getDependencies().getWorldGuardApi() != null) { - return new RegionPrompt(); - } else { - return new QuestMainPrompt(context); - } - case 7: - return new InitialActionPrompt(); - case 8: - if (plugin.getDependencies().getCitizens() != null) { - return new GUIDisplayPrompt(context); - } else { - return new QuestMainPrompt(context); - } - case 9: - return new RequirementsPrompt(context); - case 10: - return new PlannerPrompt(context); - case 11: - return new StageMenuPrompt(context); - case 12: - return new RewardsPrompt(context); - case 13: - return new OptionsPrompt(context); - case 14: - return new SavePrompt(context); - case 15: - return new ExitPrompt(context); - default: - return new QuestMainPrompt(context); - } - } - } - - public class QuestSelectCreatePrompt extends QuestsEditorStringPrompt { - public QuestSelectCreatePrompt(Quests plugin, ConversationContext context) { - super(context); - } - - public String getTitle(ConversationContext context) { - return Lang.get("questCreateTitle"); - } - - public String getQueryText(ConversationContext context) { - return Lang.get("questEditorEnterQuestName"); - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = ChatColor.GOLD + getTitle(context)+ "\n" + ChatColor.YELLOW + getQueryText(context); - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); - return new QuestSelectCreatePrompt(plugin, context); - } - input = input.trim(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Quest q : plugin.getQuests()) { - if (q.getName().equalsIgnoreCase(input)) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNameExists")); - return new QuestSelectCreatePrompt(plugin, context); - } - } - if (editingQuestNames.contains(input)) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); - return new QuestSelectCreatePrompt(plugin, context); - } - if (input.contains(".") || input.contains(",")) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); - return new QuestSelectCreatePrompt(plugin, context); - } - if (input.equals("")) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); - return new QuestSelectCreatePrompt(plugin, context); - } - context.setSessionData(CK.Q_NAME, input); - editingQuestNames.add(input); - return new QuestMainPrompt(context); - } else { - return new QuestMenuPrompt(context); - } - } - } - - private class QuestSelectEditPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String s = ChatColor.GOLD + Lang.get("questEditTitle") + "\n"; - for (Quest q : plugin.getQuests()) { - s += ChatColor.GRAY + "- " + ChatColor.AQUA + q.getName() + "\n"; - } - return s + ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - Quest q = plugin.getQuest(input); - if (q != null) { - loadQuest(context, q); - return new QuestMainPrompt(context); - } - return new QuestSelectEditPrompt(); - } else { - return new QuestMenuPrompt(context); - } - } - } @SuppressWarnings("deprecation") - public static void loadQuest(ConversationContext context, Quest q) { + public void loadQuest(ConversationContext context, Quest q) { context.setSessionData(CK.ED_QUEST_EDIT, q.getName()); context.setSessionData(CK.Q_ID, q.getId()); context.setSessionData(CK.Q_NAME, q.getName()); - if (q.npcStart != null) { - context.setSessionData(CK.Q_START_NPC, q.npcStart.getId()); + if (q.getNpcStart() != null) { + context.setSessionData(CK.Q_START_NPC, q.getNpcStart().getId()); } - context.setSessionData(CK.Q_START_BLOCK, q.blockStart); - context.setSessionData(CK.Q_ASK_MESSAGE, q.description); - context.setSessionData(CK.Q_FINISH_MESSAGE, q.finished); - if (q.initialAction != null) { - context.setSessionData(CK.Q_INITIAL_EVENT, q.initialAction.getName()); + context.setSessionData(CK.Q_START_BLOCK, q.getBlockStart()); + context.setSessionData(CK.Q_ASK_MESSAGE, q.getDescription()); + context.setSessionData(CK.Q_FINISH_MESSAGE, q.getFinished()); + if (q.getInitialAction() != null) { + context.setSessionData(CK.Q_INITIAL_EVENT, q.getInitialAction().getName()); } - if (q.regionStart != null) { - context.setSessionData(CK.Q_REGION, q.regionStart); + if (q.getRegionStart() != null) { + context.setSessionData(CK.Q_REGION, q.getRegionStart()); } - if (q.guiDisplay != null) { - context.setSessionData(CK.Q_GUIDISPLAY, q.guiDisplay); + if (q.getGUIDisplay() != null) { + context.setSessionData(CK.Q_GUIDISPLAY, q.getGUIDisplay()); } Requirements reqs = q.getRequirements(); if (reqs.getMoney() != 0) { @@ -735,7 +280,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList names = new LinkedList(); LinkedList amnts = new LinkedList(); LinkedList durab = new LinkedList(); - for (ItemStack e : stage.blocksToBreak) { + for (ItemStack e : stage.getBlocksToBreak()) { names.add(e.getType().name()); amnts.add(e.getAmount()); durab.add(e.getDurability()); @@ -748,7 +293,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList names = new LinkedList(); LinkedList amnts = new LinkedList(); LinkedList durab = new LinkedList(); - for (ItemStack e : stage.blocksToDamage) { + for (ItemStack e : stage.getBlocksToDamage()) { names.add(e.getType().name()); amnts.add(e.getAmount()); durab.add(e.getDurability()); @@ -761,7 +306,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList names = new LinkedList(); LinkedList amnts = new LinkedList(); LinkedList durab = new LinkedList(); - for (ItemStack e : stage.blocksToPlace) { + for (ItemStack e : stage.getBlocksToPlace()) { names.add(e.getType().name()); amnts.add(e.getAmount()); durab.add(e.getDurability()); @@ -774,7 +319,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList names = new LinkedList(); LinkedList amnts = new LinkedList(); LinkedList durab = new LinkedList(); - for (ItemStack e : stage.blocksToUse) { + for (ItemStack e : stage.getBlocksToUse()) { names.add(e.getType().name()); amnts.add(e.getAmount()); durab.add(e.getDurability()); @@ -787,7 +332,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList names = new LinkedList(); LinkedList amnts = new LinkedList(); LinkedList durab = new LinkedList(); - for (ItemStack e : stage.blocksToCut) { + for (ItemStack e : stage.getBlocksToCut()) { names.add(e.getType().name()); amnts.add(e.getAmount()); durab.add(e.getDurability()); @@ -814,7 +359,7 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList enchants = new LinkedList(); LinkedList names = new LinkedList(); LinkedList amounts = new LinkedList(); - for (Entry, Integer> e : stage.itemsToEnchant.entrySet()) { + for (Entry, Integer> e : stage.getItemsToEnchant().entrySet()) { amounts.add(e.getValue()); for (Entry e2 : e.getKey().entrySet()) { names.add(e2.getValue().name()); @@ -832,16 +377,16 @@ public class QuestFactory implements ConversationAbandonedListener { } context.setSessionData(pref + CK.S_BREW_ITEMS, items); } - if (stage.cowsToMilk != null) { - context.setSessionData(pref + CK.S_COW_MILK, stage.cowsToMilk); + if (stage.getCowsToMilk() != null) { + context.setSessionData(pref + CK.S_COW_MILK, stage.getCowsToMilk()); } - if (stage.fishToCatch != null) { - context.setSessionData(pref + CK.S_FISH, stage.fishToCatch); + if (stage.getFishToCatch() != null) { + context.setSessionData(pref + CK.S_FISH, stage.getFishToCatch()); } - if (stage.playersToKill != null) { - context.setSessionData(pref + CK.S_PLAYER_KILL, stage.playersToKill); + if (stage.getPlayersToKill() != null) { + context.setSessionData(pref + CK.S_PLAYER_KILL, stage.getPlayersToKill()); } - if (stage.getItemsToDeliver().isEmpty() == false) { + if (!stage.getItemsToDeliver().isEmpty()) { LinkedList items = new LinkedList(); LinkedList npcs = new LinkedList(); for (ItemStack is : stage.getItemsToDeliver()) { @@ -852,104 +397,104 @@ public class QuestFactory implements ConversationAbandonedListener { } context.setSessionData(pref + CK.S_DELIVERY_ITEMS, items); context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); - context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.deliverMessages); + context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.getDeliverMessages()); } - if (stage.citizensToInteract.isEmpty() == false) { + if (!stage.getCitizensToInteract().isEmpty()) { LinkedList npcs = new LinkedList(); - for (Integer n : stage.citizensToInteract) { + for (Integer n : stage.getCitizensToInteract()) { npcs.add(n); } context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); } - if (stage.citizensToKill.isEmpty() == false) { + if (!stage.getCitizensToKill().isEmpty()) { LinkedList npcs = new LinkedList(); - for (Integer n : stage.citizensToKill) { + for (Integer n : stage.getCitizensToKill()) { npcs.add(n); } context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); - context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.citizenNumToKill); + context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.getCitizenNumToKill()); } - if (stage.mobsToKill.isEmpty() == false) { + if (!stage.getMobsToKill().isEmpty()) { LinkedList mobs = new LinkedList(); - for (EntityType et : stage.mobsToKill) { + for (EntityType et : stage.getMobsToKill()) { mobs.add(MiscUtil.getPrettyMobName(et)); } context.setSessionData(pref + CK.S_MOB_TYPES, mobs); - context.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.mobNumToKill); - if (stage.locationsToKillWithin.isEmpty() == false) { + context.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.getMobNumToKill()); + if (!stage.getLocationsToKillWithin().isEmpty()) { LinkedList locs = new LinkedList(); - for (Location l : stage.locationsToKillWithin) { + for (Location l : stage.getLocationsToKillWithin()) { locs.add(ConfigUtil.getLocationInfo(l)); } context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locs); - context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.radiiToKillWithin); - context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.killNames); + context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.getRadiiToKillWithin()); + context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.getKillNames()); } } - if (stage.locationsToReach.isEmpty() == false) { + if (!stage.getLocationsToReach().isEmpty()) { LinkedList locs = new LinkedList(); - for (Location l : stage.locationsToReach) { + for (Location l : stage.getLocationsToReach()) { locs.add(ConfigUtil.getLocationInfo(l)); } context.setSessionData(pref + CK.S_REACH_LOCATIONS, locs); - context.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.radiiToReachWithin); - context.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.locationNames); + context.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.getRadiiToReachWithin()); + context.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.getLocationNames()); } - if (stage.mobsToTame.isEmpty() == false) { + if (!stage.getMobsToTame().isEmpty()) { LinkedList mobs = new LinkedList(); LinkedList amnts = new LinkedList(); - for (Entry e : stage.mobsToTame.entrySet()) { + for (Entry e : stage.getMobsToTame().entrySet()) { mobs.add(MiscUtil.getPrettyMobName(e.getKey())); amnts.add(e.getValue()); } context.setSessionData(pref + CK.S_TAME_TYPES, mobs); context.setSessionData(pref + CK.S_TAME_AMOUNTS, amnts); } - if (stage.sheepToShear.isEmpty() == false) { + if (!stage.getSheepToShear().isEmpty()) { LinkedList colors = new LinkedList(); LinkedList amnts = new LinkedList(); - for (Entry e : stage.sheepToShear.entrySet()) { + for (Entry e : stage.getSheepToShear().entrySet()) { colors.add(MiscUtil.getPrettyDyeColorName(e.getKey())); amnts.add(e.getValue()); } context.setSessionData(pref + CK.S_SHEAR_COLORS, colors); context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amnts); } - if (stage.passwordDisplays.isEmpty() == false) { - context.setSessionData(pref + CK.S_PASSWORD_DISPLAYS, stage.passwordDisplays); - context.setSessionData(pref + CK.S_PASSWORD_PHRASES, stage.passwordPhrases); + if (!stage.getPasswordDisplays().isEmpty()) { + context.setSessionData(pref + CK.S_PASSWORD_DISPLAYS, stage.getPasswordDisplays()); + context.setSessionData(pref + CK.S_PASSWORD_PHRASES, stage.getPasswordPhrases()); } - if (stage.customObjectives.isEmpty() == false) { + if (!stage.getCustomObjectives().isEmpty()) { LinkedList list = new LinkedList(); LinkedList countList = new LinkedList(); LinkedList> datamapList = new LinkedList>(); - for (int i = 0; i < stage.customObjectives.size(); i++) { - list.add(stage.customObjectives.get(i).getName()); - countList.add(stage.customObjectiveCounts.get(i)); + for (int i = 0; i < stage.getCustomObjectives().size(); i++) { + list.add(stage.getCustomObjectives().get(i).getName()); + countList.add(stage.getCustomObjectiveCounts().get(i)); } - datamapList.addAll(stage.customObjectiveData); + datamapList.addAll(stage.getCustomObjectiveData()); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList); } - if (stage.startAction != null) { - context.setSessionData(pref + CK.S_START_EVENT, stage.startAction.getName()); + if (stage.getStartAction() != null) { + context.setSessionData(pref + CK.S_START_EVENT, stage.getStartAction().getName()); } - if (stage.finishAction != null) { - context.setSessionData(pref + CK.S_FINISH_EVENT, stage.finishAction.getName()); + if (stage.getFinishAction() != null) { + context.setSessionData(pref + CK.S_FINISH_EVENT, stage.getFinishAction().getName()); } - if (stage.deathAction != null) { - context.setSessionData(pref + CK.S_DEATH_EVENT, stage.deathAction.getName()); + if (stage.getDeathAction() != null) { + context.setSessionData(pref + CK.S_DEATH_EVENT, stage.getDeathAction().getName()); } - if (stage.disconnectAction != null) { - context.setSessionData(pref + CK.S_DISCONNECT_EVENT, stage.disconnectAction.getName()); + if (stage.getDisconnectAction() != null) { + context.setSessionData(pref + CK.S_DISCONNECT_EVENT, stage.getDisconnectAction().getName()); } if (!stage.getChatActions().isEmpty()) { LinkedList chatEvents = new LinkedList(); LinkedList chatEventTriggers = new LinkedList(); - for (String s : stage.chatActions.keySet()) { + for (String s : stage.getChatActions().keySet()) { chatEventTriggers.add(s); - chatEvents.add(stage.chatActions.get(s).getName()); + chatEvents.add(stage.getChatActions().get(s).getName()); } context.setSessionData(pref + CK.S_CHAT_EVENTS, chatEvents); context.setSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers); @@ -957,109 +502,35 @@ public class QuestFactory implements ConversationAbandonedListener { if (!stage.getCommandActions().isEmpty()) { LinkedList commandEvents = new LinkedList(); LinkedList commandEventTriggers = new LinkedList(); - for (String s : stage.commandActions.keySet()) { + for (String s : stage.getCommandActions().keySet()) { commandEventTriggers.add(s); - commandEvents.add(stage.commandActions.get(s).getName()); + commandEvents.add(stage.getCommandActions().get(s).getName()); } context.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents); context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers); } - if (stage.delay != -1) { - context.setSessionData(pref + CK.S_DELAY, stage.delay); - if (stage.delayMessage != null) { - context.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.delayMessage); + if (stage.getDelay() != -1) { + context.setSessionData(pref + CK.S_DELAY, stage.getDelay()); + if (stage.getDelayMessage() != null) { + context.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.getDelayMessage()); } } - if (stage.script != null) { - context.setSessionData(pref + CK.S_DENIZEN, stage.script); + if (stage.getScript() != null) { + context.setSessionData(pref + CK.S_DENIZEN, stage.getScript()); } - if (stage.completeMessage != null) { - context.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.completeMessage); + if (stage.getCompleteMessage() != null) { + context.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.getCompleteMessage()); } - if (stage.startMessage != null) { - context.setSessionData(pref + CK.S_START_MESSAGE, stage.startMessage); + if (stage.getStartMessage() != null) { + context.setSessionData(pref + CK.S_START_MESSAGE, stage.getStartMessage()); } - if (stage.objectiveOverrides.isEmpty() == false) { - context.setSessionData(pref + CK.S_OVERRIDE_DISPLAY, stage.objectiveOverrides); + if (!stage.getObjectiveOverrides().isEmpty()) { + context.setSessionData(pref + CK.S_OVERRIDE_DISPLAY, stage.getObjectiveOverrides()); } } } - private class QuestSelectDeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + Lang.get("questDeleteTitle") + "\n"; - for (Quest quest : plugin.getQuests()) { - text += ChatColor.AQUA + quest.getName() + ChatColor.GRAY + ","; - } - text = text.substring(0, text.length() - 1) + "\n"; - text += ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - LinkedList used = new LinkedList(); - Quest found = plugin.getQuest(input); - if (found != null) { - for (Quest q : plugin.getQuests()) { - if (q.getRequirements().getNeededQuests().contains(q.getName()) - || q.getRequirements().getBlockQuests().contains(q.getName())) { - used.add(q.getName()); - } - } - if (used.isEmpty()) { - context.setSessionData(CK.ED_QUEST_DELETE, found.getName()); - return new QuestConfirmDeletePrompt(); - } else { - ((Player) context.getForWhom()).sendMessage(ChatColor.RED - + Lang.get("questEditorQuestAsRequirement1") + " \"" + ChatColor.DARK_PURPLE - + context.getSessionData(CK.ED_QUEST_DELETE) + ChatColor.RED + "\" " - + Lang.get("questEditorQuestAsRequirement2")); - for (String s : used) { - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "- " + ChatColor.DARK_RED + s); - } - ((Player) context.getForWhom()).sendMessage(ChatColor.RED - + Lang.get("questEditorQuestAsRequirement3")); - return new QuestSelectDeletePrompt(); - } - } - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("questEditorQuestNotFound")); - return new QuestSelectDeletePrompt(); - } else { - return new QuestMenuPrompt(context); - } - } - } - - private class QuestConfirmDeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + "" + ChatColor.GREEN + " - " - + Lang.get("yesWord") + "\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + "" + ChatColor.RED + " - " - + Lang.get("noWord"); - return ChatColor.RED + Lang.get("confirmDelete") + " (" + ChatColor.YELLOW - + (String) context.getSessionData(CK.ED_QUEST_DELETE) + ChatColor.RED + ")\n" + text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - deleteQuest(context); - return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new QuestMenuPrompt(context); - } else { - return new QuestConfirmDeletePrompt(); - } - } - } - - private void deleteQuest(ConversationContext context) { + public void deleteQuest(ConversationContext context) { FileConfiguration data = new YamlConfiguration(); File questsFile = new File(plugin.getDataFolder(), "quests.yml"); try { @@ -1100,439 +571,6 @@ public class QuestFactory implements ConversationAbandonedListener { context.getForWhom().sendRawMessage(ChatColor.GREEN + Lang.get("questDeleted")); } - private class QuestSetNamePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Quest q : plugin.getQuests()) { - if (q.getName().equalsIgnoreCase(input)) { - String s = null; - if (context.getSessionData(CK.ED_QUEST_EDIT) != null) { - s = (String) context.getSessionData(CK.ED_QUEST_EDIT); - } - if (s != null && s.equalsIgnoreCase(input) == false) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNameExists")); - return new QuestSetNamePrompt(); - } - } - } - if (editingQuestNames.contains(input)) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); - return new QuestSetNamePrompt(); - } - if (input.contains(",")) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); - return new QuestSelectCreatePrompt(plugin, context); - } - editingQuestNames.remove((String) context.getSessionData(CK.Q_NAME)); - context.setSessionData(CK.Q_NAME, input); - editingQuestNames.add(input); - } - return new QuestMainPrompt(context); - } - } - - private class AskMessagePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorEnterAskMessage"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (input.startsWith("++")) { - if (context.getSessionData(CK.Q_ASK_MESSAGE) != null) { - context.setSessionData(CK.Q_ASK_MESSAGE, context.getSessionData(CK.Q_ASK_MESSAGE) + " " - + input.substring(2)); - return new QuestMainPrompt(context); - } - } - context.setSessionData(CK.Q_ASK_MESSAGE, input); - } - return new QuestMainPrompt(context); - } - } - - private class FinishMessagePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorEnterFinishMessage"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (input.startsWith("++")) { - if (context.getSessionData(CK.Q_FINISH_MESSAGE) != null) { - context.setSessionData(CK.Q_FINISH_MESSAGE, context.getSessionData(CK.Q_FINISH_MESSAGE) + " " - + input.substring(2)); - return new QuestMainPrompt(context); - } - } - context.setSessionData(CK.Q_FINISH_MESSAGE, input); - } - return new QuestMainPrompt(context); - } - } - - private class NPCStartPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); - return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n" - + ChatColor.GOLD + Lang.get("npcHint"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { - try { - int i = Integer.parseInt(input); - if (i > -1) { - if (CitizensAPI.getNPCRegistry().getById(i) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC")); - return new NPCStartPrompt(); - } - context.setSessionData(CK.Q_START_NPC, i); - selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); - return new QuestMainPrompt(context); - } - } catch (NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.RED - + Lang.get("reqNotANumber").replace("", input)); - return new NPCStartPrompt(); - } - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { - context.setSessionData(CK.Q_START_NPC, null); - } - selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); - return new QuestMainPrompt(context); - } - } - - private class BlockStartPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorEnterBlockStart"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdDone")) || input.equalsIgnoreCase(Lang.get("cmdCancel"))) { - if (input.equalsIgnoreCase(Lang.get("cmdDone"))) { - Block block = selectedBlockStarts.get(player.getUniqueId()); - if (block != null) { - Location loc = block.getLocation(); - context.setSessionData(CK.Q_START_BLOCK, loc); - selectedBlockStarts.remove(player.getUniqueId()); - } else { - player.sendMessage(ChatColor.RED + Lang.get("questEditorNoStartBlockSelected")); - return new BlockStartPrompt(); - } - } else { - selectedBlockStarts.remove(player.getUniqueId()); - } - return new QuestMainPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { - selectedBlockStarts.remove(player.getUniqueId()); - context.setSessionData(CK.Q_START_BLOCK, null); - return new QuestMainPrompt(context); - } - return new BlockStartPrompt(); - } - } - - private class RegionPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.AQUA + Lang.get("questRegionTitle") + "\n"; - boolean any = false; - for (World world : plugin.getServer().getWorlds()) { - WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi(); - RegionManager rm = api.getRegionManager(world); - for (String region : rm.getRegions().keySet()) { - any = true; - text += ChatColor.GREEN + region + ", "; - } - } - if (any) { - text = text.substring(0, text.length() - 2); - text += "\n\n"; - } else { - text += ChatColor.GRAY + "(" + Lang.get("none") + ")\n\n"; - } - return text + ChatColor.YELLOW + Lang.get("questWGPrompt"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { - String found = null; - boolean done = false; - for (World world : plugin.getServer().getWorlds()) { - WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi(); - RegionManager rm = api.getRegionManager(world); - for (String region : rm.getRegions().keySet()) { - if (region.equalsIgnoreCase(input)) { - found = region; - done = true; - break; - } - } - if (done) { - break; - } - } - if (found == null) { - String error = Lang.get("questWGInvalidRegion"); - error = error.replace("", ChatColor.RED + input + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + error); - return new RegionPrompt(); - } else { - context.setSessionData(CK.Q_REGION, found); - return new QuestMainPrompt(context); - } - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { - context.setSessionData(CK.Q_REGION, null); - player.sendMessage(ChatColor.YELLOW + Lang.get("questWGRegionCleared")); - return new QuestMainPrompt(context); - } else { - return new QuestMainPrompt(context); - } - } - } - - private class InitialActionPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.AQUA + Lang.get("eventTitle") + "\n"; - if (plugin.getActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); - } else { - for (Action e : plugin.getActions()) { - text += ChatColor.GREEN + "- " + e.getName() + "\n"; - } - } - return text + ChatColor.YELLOW + Lang.get("questEditorEnterInitialEvent"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { - Action a = plugin.getAction(input); - if (a != null) { - context.setSessionData(CK.Q_INITIAL_EVENT, a.getName()); - return new QuestMainPrompt(context); - } - player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " " - + Lang.get("questEditorInvalidEventName")); - return new InitialActionPrompt(); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { - context.setSessionData(CK.Q_INITIAL_EVENT, null); - player.sendMessage(ChatColor.YELLOW + Lang.get("questEditorEventCleared")); - return new QuestMainPrompt(context); - } else { - return new QuestMainPrompt(context); - } - } - } - - public class SavePrompt extends QuestsEditorStringPrompt { - public SavePrompt(ConversationContext context) { - super(context); - } - - private final int size = 2; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return null; - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.GREEN; - case 2: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.GREEN + Lang.get("yesWord"); - case 2: - return ChatColor.RED + Lang.get("noWord"); - default: - return null; - } - } - - public String getQueryText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA - + context.getSessionData(CK.Q_NAME) + ChatColor.YELLOW + "\"?"; - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = getQueryText(context) + "\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; - } - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedAskMessage")); - return new QuestMainPrompt(context); - } else if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedFinishMessage")); - return new QuestMainPrompt(context); - } else if (new StageMenuPrompt(context).getStages(context) == 0) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedStages")); - return new QuestMainPrompt(context); - } - FileConfiguration data = new YamlConfiguration(); - try { - data.load(new File(plugin.getDataFolder(), "quests.yml")); - ConfigurationSection questSection = data.getConfigurationSection("quests"); - if (questSection == null) { - questSection = data.createSection("quests"); - } - ConfigurationSection newSection; - if (context.getSessionData(CK.Q_ID) == null) { - // Creating - int customNum = 1; - while (true) { - if (questSection.contains("custom" + customNum)) { - customNum++; - } else { - break; - } - } - newSection = questSection.createSection("custom" + customNum); - } else { - // Editing - newSection = questSection.createSection((String)context.getSessionData(CK.Q_ID)); - } - saveQuest(context, newSection); - data.save(new File(plugin.getDataFolder(), "quests.yml")); - context.getForWhom().sendRawMessage(ChatColor.GREEN - + Lang.get("questEditorSaved").replace("", "/questadmin " - + Lang.get("COMMAND_QUESTADMIN_RELOAD"))); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new QuestMainPrompt(context); - } else { - return new SavePrompt(context); - } - } - } - - public class ExitPrompt extends QuestsEditorStringPrompt { - public ExitPrompt(ConversationContext context) { - super(context); - } - - private final int size = 2; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return null; - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.GREEN; - case 2: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.GREEN + Lang.get("yesWord"); - case 2: - return ChatColor.RED + Lang.get("noWord"); - default: - return null; - } - } - - public String getQueryText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("confirmDelete"); - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = getQueryText(context) + "\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; - } - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - context.getForWhom().sendRawMessage(ChatColor.BOLD + "" + ChatColor.YELLOW + Lang.get("exited")); - return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new QuestMainPrompt(context); - } else { - return new ExitPrompt(context); - } - } - } - public void saveQuest(ConversationContext context, ConfigurationSection section) { String edit = null; if (context.getSessionData(CK.ED_QUEST_EDIT) != null) { diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index c722af077..4e2ce18e4 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -1,3558 +1,3555 @@ -/******************************************************************************************************* - * Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN - * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *******************************************************************************************************/ - -package me.blackvein.quests; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.lang.reflect.Constructor; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.AbstractMap; -import java.util.Arrays; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.logging.Level; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.command.CommandExecutor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.conversations.ConversationAbandonedEvent; -import org.bukkit.conversations.ConversationAbandonedListener; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.ConversationFactory; -import org.bukkit.conversations.ConversationPrefix; -import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Tameable; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import com.codisimus.plugins.phatloots.PhatLootsAPI; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.herocraftonline.heroes.characters.classes.HeroClass; - -import me.blackvein.quests.actions.Action; -import me.blackvein.quests.actions.ActionFactory; -import me.blackvein.quests.convo.quests.prompts.QuestOfferPrompt; -import me.blackvein.quests.exceptions.ActionFormatException; -import me.blackvein.quests.exceptions.QuestFormatException; -import me.blackvein.quests.exceptions.StageFormatException; -import me.blackvein.quests.listeners.CmdExecutor; -import me.blackvein.quests.listeners.DungeonsListener; -import me.blackvein.quests.listeners.NpcListener; -import me.blackvein.quests.listeners.PartiesListener; -import me.blackvein.quests.listeners.PlayerListener; -import me.blackvein.quests.tasks.NpcEffectThread; -import me.blackvein.quests.tasks.PlayerMoveThread; -import me.blackvein.quests.util.ConfigUtil; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import me.blackvein.quests.util.LocaleQuery; -import me.blackvein.quests.util.MiscUtil; -import me.clip.placeholderapi.PlaceholderAPI; - -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.npc.NPC; - -public class Quests extends JavaPlugin implements ConversationAbandonedListener { - - private boolean loading = true; - private String bukkitVersion = "0"; - private Dependencies depends; - private Settings settings; - private final List customRequirements = new LinkedList(); - private final List customRewards = new LinkedList(); - private final List customObjectives = new LinkedList(); - private LinkedList questers = new LinkedList(); - private LinkedList quests = new LinkedList(); - private LinkedList actions = new LinkedList(); - private LinkedList questNpcs = new LinkedList(); - private CommandExecutor cmdExecutor; - private ConversationFactory conversationFactory; - private ConversationFactory npcConversationFactory; - private QuestFactory questFactory; - private ActionFactory eventFactory; - private PlayerListener playerListener; - private NpcListener npcListener; - private NpcEffectThread effThread; - private PlayerMoveThread moveThread; - private DungeonsListener dungeonsListener; - private PartiesListener partiesListener; - private DenizenTrigger trigger; - private LocaleQuery localeQuery; - - @Override - public void onEnable() { - /****** WARNING: ORDER OF STEPS MATTERS ******/ - - // 1 - Initialize variables - bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; - settings = new Settings(this); - localeQuery = new LocaleQuery(this); - localeQuery.setBukkitVersion(bukkitVersion); - playerListener = new PlayerListener(this); - effThread = new NpcEffectThread(this); - moveThread = new PlayerMoveThread(this); - npcListener = new NpcListener(this); - dungeonsListener = new DungeonsListener(); - partiesListener = new PartiesListener(); - questFactory = new QuestFactory(this); - eventFactory = new ActionFactory(this); - depends = new Dependencies(this); - trigger = new DenizenTrigger(this); - - // 2 - Load main config - settings.init(); - - // 3 - Setup language files - try { - setupLang(); - } catch (IOException e) { - e.printStackTrace(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - - // 4 - Load command executor - cmdExecutor = new CmdExecutor(this); - - // 5 - Load soft-depends - depends.init(); - - // 6 - Save resources from jar - saveResourceAs("quests.yml", "quests.yml", false); - saveResourceAs("actions.yml", "actions.yml", false); - - // 7 - Save config with any new options - getConfig().options().copyDefaults(true); - saveConfig(); - - // 8 - Setup commands - getCommand("quests").setExecutor(cmdExecutor); - getCommand("questadmin").setExecutor(cmdExecutor); - getCommand("quest").setExecutor(cmdExecutor); - - // 9 - Build conversation factories - this.conversationFactory = new ConversationFactory(this).withModality(false) - .withPrefix(new ConversationPrefix() { - @Override - public String getPrefix(ConversationContext context) { - return ChatColor.GRAY.toString(); - } - }) - .withFirstPrompt(new QuestAcceptPrompt()).withTimeout(settings.getAcceptTimeout()) - .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!") - .addConversationAbandonedListener(this); - this.npcConversationFactory = new ConversationFactory(this).withModality(false) - .withFirstPrompt(new QuestOfferPrompt(this)).withTimeout(settings.getAcceptTimeout()) - .withLocalEcho(false).addConversationAbandonedListener(this); - - // 10 - Register listeners - getServer().getPluginManager().registerEvents(playerListener, this); - if (depends.getCitizens() != null) { - getServer().getPluginManager().registerEvents(npcListener, this); - if (settings.canNpcEffects()) { - getServer().getScheduler().scheduleSyncRepeatingTask(this, effThread, 20, 20); - } - } - if (settings.getStrictPlayerMovement() > 0) { - long ticks = settings.getStrictPlayerMovement() * 20; - getServer().getScheduler().scheduleSyncRepeatingTask(this, moveThread, ticks, ticks); - } - if (depends.getDungeonsApi() != null) { - getServer().getPluginManager().registerEvents(dungeonsListener, this); - } - if (depends.getPartiesApi() != null) { - getServer().getPluginManager().registerEvents(partiesListener, this); - } - - // 11 - Delay loading of Quests, Actions and modules - delayLoadQuestInfo(5L); - } - - @Override - public void onDisable() { - getLogger().info("Saving Quester data..."); - for (Player p : getServer().getOnlinePlayers()) { - Quester quester = getQuester(p.getUniqueId()); - quester.saveData(); - } - } - - public boolean isLoading() { - return loading; - } - - public String getDetectedBukkitVersion() { - return bukkitVersion; - } - - public Dependencies getDependencies() { - return depends; - } - - public Settings getSettings() { - return settings; - } - - public List getCustomRequirements() { - return customRequirements; - } - - public Optional getCustomRequirement(String className) { - for (int i = 0; i < customRequirements.size(); i++) { - CustomRequirement cr = customRequirements.get(i); - if (cr.getClass().getName().equals(className)) { - return Optional.of(cr); - } - } - return Optional.empty(); - } - - public List getCustomRewards() { - return customRewards; - } - - public Optional getCustomReward(String className) { - for (int i = 0; i < customRewards.size(); i++) { - CustomReward cr = customRewards.get(i); - if (cr.getClass().getName().equals(className)) { - return Optional.of(cr); - } - } - return Optional.empty(); - } - - public List getCustomObjectives() { - return customObjectives; - } - - public Optional getCustomObjective(String className) { - for (int i = 0; i < customObjectives.size(); i++) { - CustomObjective co = customObjectives.get(i); - if (co.getClass().getName().equals(className)) { - return Optional.of(co); - } - } - return Optional.empty(); - } - - public LinkedList getQuests() { - return quests; - } - - public LinkedList getActions() { - return actions; - } - - public void setActions(LinkedList actions) { - this.actions = actions; - } - - public LinkedList getQuesters() { - return questers; - } - - public void setQuesters(LinkedList questers) { - this.questers = questers; - } - - public LinkedList getQuestNpcs() { - return questNpcs; - } - - public void setQuestNpcs(LinkedList questNpcs) { - this.questNpcs = questNpcs; - } - - public ConversationFactory getConversationFactory() { - return conversationFactory; - } - - public ConversationFactory getNpcConversationFactory() { - return npcConversationFactory; - } - - public QuestFactory getQuestFactory() { - return questFactory; - } - - public ActionFactory getActionFactory() { - return eventFactory; - } - - @Deprecated - public ActionFactory getEventFactory() { - return eventFactory; - } - - public PlayerListener getPlayerListener() { - return playerListener; - } - - public DenizenTrigger getDenizenTrigger() { - return trigger; - } - - public LocaleQuery getLocaleQuery() { - return localeQuery; - } - - @Override - public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { - if (abandonedEvent.gracefulExit() == false) { - if (abandonedEvent.getContext().getForWhom() != null) { - try { - abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW - + Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout")); - } catch (Exception e) { - // Do nothing - } - } - } - } - - private class QuestAcceptPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get((Player) context.getForWhom(), "acceptQuest") + " " + ChatColor.GREEN - + Lang.get("yesWord") + " / " + Lang.get("noWord"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String s) { - Player player = (Player) context.getForWhom(); - if (s.equalsIgnoreCase(Lang.get(player, "yesWord"))) { - String questToTake = getQuester(player.getUniqueId()).questToTake; - try { - if (getQuest(questToTake) == null) { - getLogger().info(player.getName() + " attempted to take quest \"" + questToTake - + "\" but something went wrong"); - player.sendMessage(ChatColor.RED - + "Something went wrong! Please report issue to an administrator."); - } else { - getQuester(player.getUniqueId()).takeQuest(getQuest(questToTake), false); - } - } catch (Exception e) { - e.printStackTrace(); - } - return Prompt.END_OF_CONVERSATION; - } else if (s.equalsIgnoreCase(Lang.get("noWord"))) { - player.sendMessage(ChatColor.YELLOW + Lang.get("cancelled")); - return Prompt.END_OF_CONVERSATION; - } else { - String msg = Lang.get(player, "questInvalidChoice") - .replace("", Lang.get(player, "yesWord")) - .replace("", Lang.get(player, "noWord")); - player.sendMessage(ChatColor.RED + msg); - return new QuestAcceptPrompt(); - } - } - } - - /** - * Transfer language files from jar to disk - */ - private void setupLang() throws IOException, URISyntaxException { - final String path = "lang"; - final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); - if(jarFile.isFile()) { - final JarFile jar = new JarFile(jarFile); - final Enumeration entries = jar.entries(); - Set results = new HashSet(); - while(entries.hasMoreElements()) { - final String name = entries.nextElement().getName(); - if (name.startsWith(path + "/") && name.contains("strings.yml")) { - results.add(name); - } - } - for (String resourcePath : results) { - saveResourceAs(resourcePath, resourcePath, false); - saveResourceAs(resourcePath, resourcePath.replace(".yml", "_new.yml"), true); - } - jar.close(); - } - try { - Lang.init(this); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - } - - /** - * Save a Quests plugin resource to a specific path in the filesystem - * - * @param resourcePath jar file location starting from resource folder, i.e. "lang/el-GR/strings.yml" - * @param outputPath file destination starting from Quests folder, i.e. "lang/el-GR/strings.yml" - * @param replace whether or not to replace the destination file - */ - public void saveResourceAs(String resourcePath, String outputPath, boolean replace) { - if (resourcePath == null || resourcePath.equals("")) { - throw new IllegalArgumentException("ResourcePath cannot be null or empty"); - } - - resourcePath = resourcePath.replace('\\', '/'); - InputStream in = getResource(resourcePath); - if (in == null) { - throw new IllegalArgumentException("The embedded resource '" + resourcePath - + "' cannot be found in Quests jar"); - } - - String outPath = outputPath.replace('/', File.separatorChar).replace('\\', File.separatorChar); - File outFile = new File(getDataFolder(), outPath); - File outDir = new File(outFile.getPath().replace(outFile.getName(), "")); - - if (!outDir.exists()) { - if (!outDir.mkdirs()) { - getLogger().log(Level.SEVERE, "Failed to make directories for " + outFile.getName() + " (canWrite= " - + outDir.canWrite() + ")"); - } - } - - try { - if (!outFile.exists() || replace) { - OutputStream out = new FileOutputStream(outFile); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.close(); - in.close(); - if (!outFile.exists()) { - getLogger().severe("Unable to copy " + outFile.getName() + " (canWrite= " + outFile.canWrite() - + ")"); - } - } - } catch (IOException ex) { - getLogger().log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex); - } - } - - /** - * Load quests, actions, and modules after specified delay

- * - * At startup, this lets soft-depends (namely Citizens) fully load first - */ - private void delayLoadQuestInfo(long ticks) { - getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - - @Override - public void run() { - loadQuests(); - loadActions(); - getLogger().log(Level.INFO, "Loaded " + quests.size() + " Quest(s)" - + ", " + actions.size() + " Action(s)" - + ", " + Lang.size() + " Phrase(s)"); - for (Player p : getServer().getOnlinePlayers()) { - Quester quester = new Quester(Quests.this); - quester.setUUID(p.getUniqueId()); - if (quester.loadData() == false) { - quester.saveData(); - } - // Workaround for issues with the compass on fast join - quester.findCompassTarget(); - questers.add(quester); - } - if (depends.getCitizens() != null) { - if (depends.getCitizens().getNPCRegistry() == null) { - getLogger().log(Level.SEVERE, - "Citizens was enabled but NPCRegistry was null. Disabling linkage."); - depends.disableCitizens(); - } - } - loadModules(); - loading = false; - } - }, ticks); - } - - /** - * Load modules from file - */ - public void loadModules() { - File f = new File(this.getDataFolder(), "modules"); - if (f.exists() && f.isDirectory()) { - File[] modules = f.listFiles(); - if (modules != null) { - for (File module : modules) { - if (module.isDirectory() == false && module.getName().endsWith(".jar")) { - loadModule(module); - } - } - } - } else { - f.mkdir(); - } - boolean failedToLoad; - FileConfiguration config = null; - File file = new File(this.getDataFolder(), "quests.yml"); - try { - config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), "UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } - if (config != null) { - ConfigurationSection questsSection; - if (config.contains("quests")) { - questsSection = config.getConfigurationSection("quests"); - for (String questKey : questsSection.getKeys(false)) { - try { - failedToLoad = false; - if (config.contains("quests." + questKey)) { - loadCustomSections(getQuestById(questKey), config, questKey); - } else { - throw new QuestFormatException("Quest block is missing", questKey); - } - if (failedToLoad) { - getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping."); - } - } catch (QuestFormatException ex) { - continue; - } catch (StageFormatException ex) { - continue; - } - } - } - } else { - getLogger().severe("Unable to load module data from quests.yml"); - } - } - - /** - * Load the specified jar as a module - * - * @param jar A custom reward/requirement/objective jar - */ - public void loadModule(File jar) { - try { - @SuppressWarnings("resource") - JarFile jarFile = new JarFile(jar); - Enumeration e = jarFile.entries(); - URL[] urls = { new URL("jar:file:" + jar.getPath() + "!/") }; - ClassLoader cl = URLClassLoader.newInstance(urls, getClassLoader()); - int count = 0; - while (e.hasMoreElements()) { - JarEntry je = (JarEntry) e.nextElement(); - if (je.isDirectory() || !je.getName().endsWith(".class")) { - continue; - } - String className = je.getName().substring(0, je.getName().length() - 6); - className = className.replace('/', '.'); - Class c = Class.forName(className, true, cl); - if (CustomRequirement.class.isAssignableFrom(c)) { - Class requirementClass = c.asSubclass(CustomRequirement.class); - Constructor cstrctr = requirementClass.getConstructor(); - CustomRequirement requirement = cstrctr.newInstance(); - Optionaloo=getCustomRequirement(requirement.getClass().getName()); - if (oo.isPresent()) customRequirements.remove(oo.get()); - customRequirements.add(requirement); - String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName(); - String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor(); - count++; - getLogger().info("Loaded Module: " + name + " by " + author); - } else if (CustomReward.class.isAssignableFrom(c)) { - Class rewardClass = c.asSubclass(CustomReward.class); - Constructor cstrctr = rewardClass.getConstructor(); - CustomReward reward = cstrctr.newInstance(); - Optionaloo=getCustomReward(reward.getClass().getName()); - if (oo.isPresent()) customRewards.remove(oo.get()); - customRewards.add(reward); - String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName(); - String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor(); - count++; - getLogger().info("Loaded Module: " + name + " by " + author); - } else if (CustomObjective.class.isAssignableFrom(c)) { - Class objectiveClass = c.asSubclass(CustomObjective.class); - Constructor cstrctr = objectiveClass.getConstructor(); - CustomObjective objective = cstrctr.newInstance(); - Optionaloo=getCustomObjective(objective.getClass().getName()); - if (oo.isPresent()) { - HandlerList.unregisterAll(oo.get()); - customObjectives.remove(oo.get()); - } - customObjectives.add(objective); - String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName(); - String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor(); - count++; - getLogger().info("Loaded Module: " + name + " by " + author); - try { - getServer().getPluginManager().registerEvents(objective, this); - getLogger().info("Registered events for custom objective \"" + name + "\""); - } catch (Exception ex) { - getLogger().warning("Failed to register events for custom objective \"" + name - + "\". Does the objective class listen for events?"); - ex.printStackTrace(); - } - } - } - if (count == 0) { - getLogger().severe("Unable to load module from file: " + jar.getName() - + ", jar file is not a valid module!"); - } - } catch (Exception e) { - getLogger().severe("Unable to load module from file: " + jar.getName()); - e.printStackTrace(); - } - } - - /** - * Show all of a player's objectives for the current stage of a quest.

- * - * Respects PlaceholderAPI and translations, when enabled. - * - * @param quest The quest to get current stage objectives of - * @param quester The player to show current stage objectives to - * @param ignoreOverrides Whether to ignore objective-overrides - */ - @SuppressWarnings("deprecation") - public void showObjectives(Quest quest, Quester quester, boolean ignoreOverrides) { - if (quester.getQuestData(quest) == null) { - getLogger().warning("Quest data was null when showing objectives for " + quest.getName()); - return; - } - if (quester.getCurrentStage(quest) == null) { - getLogger().warning("Current stage was null when showing objectives for " + quest.getName()); - return; - } - if (!ignoreOverrides && !quester.getCurrentStage(quest).objectiveOverrides.isEmpty()) { - for (String s: quester.getCurrentStage(quest).objectiveOverrides) { - String message = ChatColor.GREEN + ConfigUtil.parseString( - ChatColor.translateAlternateColorCodes('&', s), quest, quester.getPlayer()); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - return; - } - QuestData data = quester.getQuestData(quest); - Stage stage = quester.getCurrentStage(quest); - for (ItemStack e : stage.blocksToBreak) { - for (ItemStack e2 : data.blocksBroken) { - if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { - ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "break") + " " - + color + ": " + e2.getAmount() + "/" + e.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); - } - } - } - } - for (ItemStack e : stage.blocksToDamage) { - for (ItemStack e2 : data.blocksDamaged) { - if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { - ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "damage") + " " - + color + ": " + e2.getAmount() + "/" + e.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); - } - } - } - } - for (ItemStack e : stage.blocksToPlace) { - for (ItemStack e2 : data.blocksPlaced) { - if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { - ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "place") + " " - + color + ": " + e2.getAmount() + "/" + e.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); - } - } - } - } - for (ItemStack e : stage.blocksToUse) { - for (ItemStack e2 : data.blocksUsed) { - if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { - ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "use") + " " - + color + ": " + e2.getAmount() + "/" + e.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); - } - } - } - } - for (ItemStack e : stage.blocksToCut) { - for (ItemStack e2 : data.blocksCut) { - if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { - ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "cut") + " " - + color + ": " + e2.getAmount() + "/" + e.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); - } - } - } - } - for (ItemStack is : stage.itemsToCraft) { - int crafted = 0; - if (data.itemsCrafted.containsKey(is)) { - crafted = data.itemsCrafted.get(is); - } - int amt = is.getAmount(); - ChatColor color = crafted < amt ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "craft") + " " - + color + ": " + crafted + "/" + is.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), - is.getEnchantments()); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); - } - } - for (ItemStack is : stage.itemsToSmelt) { - int smelted = 0; - if (data.itemsSmelted.containsKey(is)) { - smelted = data.itemsSmelted.get(is); - } - int amt = is.getAmount(); - ChatColor color = smelted < amt ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "smelt") + " " - + color + ": " + smelted + "/" + is.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), - is.getEnchantments()); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); - } - } - Map set; - Map set2; - Set enchantSet; - Set enchantSet2; - Collection matSet; - Enchantment enchantment = null; - Enchantment enchantment2 = null; - Material mat = null; - int num1; - int num2; - for (Entry, Integer> e : stage.itemsToEnchant.entrySet()) { - for (Entry, Integer> e2 : data.itemsEnchanted.entrySet()) { - set = e2.getKey(); - set2 = e.getKey(); - enchantSet = set.keySet(); - enchantSet2 = set2.keySet(); - for (Object o : enchantSet.toArray()) { - enchantment = (Enchantment) o; - } - for (Object o : enchantSet2.toArray()) { - enchantment2 = (Enchantment) o; - } - num1 = e2.getValue(); - num2 = e.getValue(); - matSet = set.values(); - for (Object o : matSet.toArray()) { - mat = (Material) o; - } - if (enchantment2 == enchantment) { - ChatColor color = num1 < num2 ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "enchantItem") - + color + ": " + num1 + "/" + num2; - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - Map enchs = new HashMap(); - enchs.put(enchantment, 1); - if (getSettings().canTranslateNames()) { - localeQuery.sendMessage(quester.getPlayer(), message, mat, (short) 0, enchs); - } else { - quester.getPlayer().sendMessage(message - .replace("", ItemUtil.getName(new ItemStack(mat))) - .replace("", enchantment.getName())); - } - } - } - } - for (ItemStack is : stage.itemsToBrew) { - int brewed = 0; - if (data.itemsBrewed.containsKey(is)) { - brewed = data.itemsBrewed.get(is); - } - int amt = is.getAmount(); - ChatColor color = brewed < amt ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "brew") + " " - + color + ": " + brewed + "/" + is.getAmount(); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames()) { - if (is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { - // Bukkit version is 1.9+ - localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), - is.getEnchantments(), is.getItemMeta()); - } else if (Material.getMaterial("LINGERING_POTION") == null && !is.hasItemMeta() ) { - // Bukkit version is below 1.9 - localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), - is.getEnchantments()); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); - } - } - } - if (stage.cowsToMilk != null) { - ChatColor color = data.getCowsMilked() < stage.cowsToMilk ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "milkCow") - + color + ": " + data.getCowsMilked() + "/" + stage.cowsToMilk; - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - if (stage.fishToCatch != null) { - ChatColor color = data.getFishCaught() < stage.fishToCatch ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "catchFish") - + color + ": " + data.getFishCaught() + "/" + stage.fishToCatch; - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - for (EntityType e : stage.mobsToKill) { - for (EntityType e2 : data.mobsKilled) { - if (e == e2) { - if (data.mobNumKilled.size() > data.mobsKilled.indexOf(e2) - && stage.mobNumToKill.size() > stage.mobsToKill.indexOf(e)) { - ChatColor color = data.mobNumKilled.get(data.mobsKilled.indexOf(e2)) - < stage.mobNumToKill.get(stage.mobsToKill.indexOf(e)) - ? ChatColor.GREEN : ChatColor.GRAY; - String message = ""; - if (stage.locationsToKillWithin.isEmpty()) { - message = color + Lang.get(quester.getPlayer(), "kill") + " " - + ChatColor.AQUA + "" + color + ": " - + (data.mobNumKilled.get(data.mobsKilled.indexOf(e2))) - + "/" + (stage.mobNumToKill.get(stage.mobsToKill.indexOf(e))); - } else { - message = color + Lang.get(quester.getPlayer(), "killAtLocation") + color + ": " - + (data.mobNumKilled.get(data.mobsKilled.indexOf(e2))) + "/" - + (stage.mobNumToKill.get(stage.mobsToKill.indexOf(e))); - message = message.replace("", - stage.killNames.get(stage.mobsToKill.indexOf(e))); - } - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames()) { - localeQuery.sendMessage(quester.getPlayer(), message, e, null); - } else { - quester.getPlayer().sendMessage(message.replace("", MiscUtil.getProperMobName(e))); - } - } - } - } - } - if (stage.playersToKill != null) { - ChatColor color = data.getPlayersKilled() < stage.playersToKill ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "killPlayer") - + color + ": " + data.getPlayersKilled() + "/" + stage.playersToKill; - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - int index = 0; - for (ItemStack is : stage.itemsToDeliver) { - int delivered = 0; - if (data.itemsDelivered.size() > index) { - delivered = data.itemsDelivered.get(index).getAmount(); - } - int toDeliver = is.getAmount(); - Integer npc = stage.itemDeliveryTargets.get(index); - index++; - ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "deliver") - + color + ": " + delivered + "/" + toDeliver; - message = message.replace("", depends.getNPCName(npc)); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { - localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), - is.getEnchantments()); - } else { - quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); - } - } - for (Integer n : stage.citizensToInteract) { - for (Entry e : data.citizensInteracted.entrySet()) { - if (e.getKey().equals(n)) { - ChatColor color = e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "talkTo"); - message = message.replace("", depends.getNPCName(n)); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - } - } - for (Integer n : stage.citizensToKill) { - for (Integer n2 : data.citizensKilled) { - if (n.equals(n2)) { - if (data.citizenNumKilled.size() > data.citizensKilled.indexOf(n2) - && stage.citizenNumToKill.size() > stage.citizensToKill.indexOf(n)) { - ChatColor color = data.citizenNumKilled.get(data.citizensKilled.indexOf(n2)) - < stage.citizenNumToKill.get(stage.citizensToKill.indexOf(n)) == false - ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "kill") + " " + depends.getNPCName(n) - + color + " " + data.citizenNumKilled.get(stage.citizensToKill.indexOf(n)) + "/" - + stage.citizenNumToKill.get(stage.citizensToKill.indexOf(n)); - if (depends.getPlaceholderApi() != null) { - message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); - } - quester.getPlayer().sendMessage(message); - } - } - } - } - for (Entry e : stage.mobsToTame.entrySet()) { - for (Entry e2 : data.mobsTamed.entrySet()) { - if (e.getKey().equals(e2.getKey())) { - ChatColor color = e2.getValue() < e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "tame") + " " + "" - + color + ": " + e2.getValue() + "/" + e.getValue(); - if (getSettings().canTranslateNames()) { - localeQuery.sendMessage(quester.getPlayer(), message, e.getKey(), null); - } else { - quester.getPlayer().sendMessage(message.replace("", - MiscUtil.getProperMobName(e.getKey()))); - } - } - } - } - for (Entry e : stage.sheepToShear.entrySet()) { - for (Entry e2 : data.sheepSheared.entrySet()) { - if (e.getKey().equals(e2.getKey())) { - ChatColor color = e2.getValue() < e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "shearSheep") - + color + ": " + e2.getValue() + "/" + e.getValue(); - message = message.replace("", e.getKey().name().toLowerCase()); - quester.getPlayer().sendMessage(message); - } - } - } - for (Location l : stage.locationsToReach) { - for (Location l2 : data.locationsReached) { - if (l.equals(l2)) { - if (!data.hasReached.isEmpty()) { - ChatColor color = data.hasReached.get(data.locationsReached.indexOf(l2)) == false - ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + Lang.get(quester.getPlayer(), "goTo"); - message = message.replace("", - stage.locationNames.get(stage.locationsToReach.indexOf(l))); - quester.getPlayer().sendMessage(message); - } - } - } - } - for (String s : stage.passwordDisplays) { - if (data.passwordsSaid.containsKey(s)) { - Boolean b = data.passwordsSaid.get(s); - ChatColor color = b != null && !b == false ? ChatColor.GREEN : ChatColor.GRAY; - String message = color + s; - quester.getPlayer().sendMessage(message); - } - } - for (CustomObjective co : stage.customObjectives) { - int countsIndex = 0; - String display = co.getDisplay(); - List unfinished = new LinkedList(); - List finished = new LinkedList(); - for (Entry entry : data.customObjectiveCounts.entrySet()) { - if (co.getName().equals(entry.getKey())) { - for (Entry prompt : co.getData()) { - String replacement = "%" + prompt.getKey() + "%"; - try { - for (Entry e : stage.customObjectiveData) { - if (e.getKey().equals(prompt.getKey())) { - if (display.contains(replacement)) { - display = display.replace(replacement, ((String) e.getValue())); - } - } - } - } catch (NullPointerException ne) { - getLogger().severe("Unable to fetch display for " + co.getName() + " on " - + quest.getName()); - ne.printStackTrace(); - } - } - if (entry.getValue() < stage.customObjectiveCounts.get(countsIndex)) { - if (co.canShowCount()) { - display = display.replace("%count%", entry.getValue() + "/" - + stage.customObjectiveCounts.get(countsIndex)); - } - unfinished.add(display); - } else { - if (co.canShowCount()) { - display = display.replace("%count%", stage.customObjectiveCounts.get(countsIndex) - + "/" + stage.customObjectiveCounts.get(countsIndex)); - } - finished.add(display); - } - } - countsIndex++; - } - for (String s : unfinished) { - quester.getPlayer().sendMessage(ChatColor.GREEN + s); - } - for (String s : finished) { - quester.getPlayer().sendMessage(ChatColor.GRAY + s); - } - } - } - - /** - * Show the player a list of their quests - * - * @param quester Quester to show the list - * @param page Page to display, with 7 quests per page - */ - public void listQuests(Quester quester, int page) { - // Although we could copy the quests list to a new object, we instead opt to - // duplicate code to improve efficiency if ignore-locked-quests is set to 'false' - int rows = 7; - Player player = quester.getPlayer(); - if (getSettings().canIgnoreLockedQuests()) { - LinkedList available = new LinkedList(); - for (Quest q : quests) { - if (quester.getCompletedQuests().contains(q.getName()) == false) { - if (q.testRequirements(player)) { - available.add(q); - } - } else if (q.getPlanner().hasCooldown() && quester.getCooldownDifference(q) < 0) { - if (q.testRequirements(player)) { - available.add(q); - } - } - } - if ((available.size() + rows) <= (page * rows) || available.size() == 0) { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); - } else { - player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); - int fromOrder = (page - 1) * rows; - List subQuests; - if (available.size() >= (fromOrder + rows)) { - subQuests = available.subList((fromOrder), (fromOrder + rows)); - } else { - subQuests = available.subList((fromOrder), available.size()); - } - fromOrder++; - for (Quest q : subQuests) { - player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); - fromOrder++; - } - int numPages = (int) Math.ceil(((double) available.size()) / ((double) rows)); - String msg = Lang.get(player, "pageFooter"); - msg = msg.replace("", String.valueOf(page)); - msg = msg.replace("", String.valueOf(numPages)); - player.sendMessage(ChatColor.GOLD + msg); - } - } else { - if ((quests.size() + rows) <= (page * rows) || quests.size() == 0) { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); - } else { - player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); - int fromOrder = (page - 1) * rows; - List subQuests; - if (quests.size() >= (fromOrder + rows)) { - subQuests = quests.subList((fromOrder), (fromOrder + rows)); - } else { - subQuests = quests.subList((fromOrder), quests.size()); - } - fromOrder++; - for (Quest q : subQuests) { - player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); - fromOrder++; - } - int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows)); - String msg = Lang.get(player, "pageFooter"); - msg = msg.replace("", String.valueOf(page)); - msg = msg.replace("", String.valueOf(numPages)); - player.sendMessage(ChatColor.GOLD + msg); - } - } - } - - public interface ReloadCallback { - public void execute(T response); - } - - /** - * @deprecated Use {@link #reload(ReloadCallback)} - */ - public void reloadQuests() { - reload(null); - } - - /** - * Reload quests, actions, config settings, lang and modules, and player data - */ - public void reload(final ReloadCallback callback) { - reloadConfig(); - Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { - - @Override - public void run() { - loading = true; - try { - for (Quester quester : questers) { - quester.saveData(); - } - quests.clear(); - actions.clear(); - Lang.clear(); - settings.init(); - Lang.init(Quests.this); - loadQuests(); - loadActions(); - for (Quester quester : questers) { - quester.loadData(); - for (Quest q : quester.currentQuests.keySet()) { - quester.checkQuest(q); - } - } - loadModules(); - - if (callback != null) { - Bukkit.getScheduler().runTask(Quests.this, new Runnable() { - - @Override - public void run() { - callback.execute(true); - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - if (callback != null) { - Bukkit.getScheduler().runTask(Quests.this, new Runnable() { - - @Override - public void run() { - callback.execute(false); - } - }); - } - } - loading = false; - } - }); - } - - /** - * Get Quester from player UUID - * - * @param id Player UUID - * @return Quester, or null if not found - */ - public Quester getQuester(UUID id) { - Quester quester = null; - for (Quester q: questers) { - if (q.getUUID().equals(id)) { - quester = q; - } - } - if (quester == null) { - quester = new Quester(this); - quester.setUUID(id); - if (depends.getCitizens() != null) { - if (depends.getCitizens().getNPCRegistry().getByUniqueId(id) != null) { - return quester; - } - } - questers.add(quester); - if (!quester.loadData()) { - questers.remove(quester); - } - } - return quester; - } - - /** - * Get a list of all online Questers - * - * @deprecated Use {@link Bukkit#getOnlinePlayers()} and then {@link #getQuester(UUID)} - * @return list of online Questers - */ - public LinkedList getOnlineQuesters() { - LinkedList qs = new LinkedList(); - for (Player p : getServer().getOnlinePlayers()) { - Quester quester = new Quester(this); - quester.setUUID(p.getUniqueId()); - if (quester.loadData() == false) { - quester.saveData(); - } - qs.add(quester); - // Workaround for issues with the compass on fast join - quester.findCompassTarget(); - } - return qs; - } - - /** - * Load quests from file - */ - public void loadQuests() { - boolean failedToLoad; - boolean needsSaving = false; - FileConfiguration config = null; - File file = new File(this.getDataFolder(), "quests.yml"); - try { - config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), "UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } - if (config != null) { - ConfigurationSection questsSection; - if (config.contains("quests")) { - questsSection = config.getConfigurationSection("quests"); - } else { - questsSection = config.createSection("quests"); - needsSaving = true; - } - if (questsSection == null) { - getLogger().severe("Missing \'quests\' section marker within quests.yml, canceled loading"); - return; - } - for (String questKey : questsSection.getKeys(false)) { - try { - Quest quest = new Quest(); - failedToLoad = false; - quest.id = questKey; - if (config.contains("quests." + questKey + ".name")) { - quest.setName(ConfigUtil.parseString(config.getString("quests." + questKey + ".name"), quest)); - } else { - throw new QuestFormatException("Quest block is missing", questKey); - } - if (depends.getCitizens() != null && config.contains("quests." + questKey + ".npc-giver-id")) { - if (CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey + ".npc-giver-id")) - != null) { - quest.npcStart = CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey - + ".npc-giver-id")); - questNpcs.add(CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey - + ".npc-giver-id"))); - } else { - throw new QuestFormatException("npc-giver-id has invalid NPC ID", questKey); - } - } - if (config.contains("quests." + questKey + ".block-start")) { - Location location = ConfigUtil.getLocation(config.getString("quests." + questKey - + ".block-start")); - if (location != null) { - quest.blockStart = location; - } else { - throw new QuestFormatException("block-start has invalid location format", questKey); - } - } - if (config.contains("quests." + questKey + ".region") - && getDependencies().getWorldGuardApi() != null) { - String region = config.getString("quests." + questKey + ".region"); - boolean exists = false; - for (World world : getServer().getWorlds()) { - if (getDependencies().getWorldGuardApi().getRegionManager(world) != null) { - if (getDependencies().getWorldGuardApi().getRegionManager(world).hasRegion(region)) { - quest.regionStart = region; - exists = true; - break; - } - } - } - if (!exists) { - throw new QuestFormatException("region has invalid WorldGuard region name", questKey); - } - } - if (config.contains("quests." + questKey + ".gui-display")) { - ItemStack stack = config.getItemStack("quests." + questKey + ".gui-display"); - if (stack == null) { - // Legacy - String item = config.getString("quests." + questKey + ".gui-display"); - try { - stack = ItemUtil.readItemStack(item); - } catch (Exception e) { - throw new QuestFormatException("items has invalid formatting for " + item, questKey); - } - } - if (stack != null) { - quest.guiDisplay = stack; - } else { - throw new QuestFormatException("gui-display has invalid item format", questKey); - } - } - if (config.contains("quests." + questKey + ".redo-delay")) { - // Legacy - if (config.getInt("quests." + questKey + ".redo-delay", -999) != -999) { - quest.getPlanner().setCooldown(config.getInt("quests." + questKey + ".redo-delay") * 1000); - } else { - throw new QuestFormatException("redo-delay is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".finish-message")) { - quest.finished = ConfigUtil.parseString(config.getString("quests." + questKey - + ".finish-message"), quest); - } else { - throw new QuestFormatException("finish-message is missing", questKey); - } - if (config.contains("quests." + questKey + ".ask-message")) { - quest.description = ConfigUtil.parseString(config.getString("quests." + questKey - + ".ask-message"), quest); - } else { - throw new QuestFormatException("ask-message is missing", questKey); - } - if (config.contains("quests." + questKey + ".action")) { - Action act = loadAction(config.getString("quests." + questKey + ".action")); - if (act != null) { - quest.initialAction = act; - } else { - throw new QuestFormatException("action failed to load", questKey); - } - } else if (config.contains("quests." + questKey + ".event")) { - Action action = null; - - action = loadAction(config.getString("quests." + questKey + ".event")); - if (action != null) { - quest.initialAction = action; - } else { - throw new QuestFormatException("action failed to load", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements")) { - loadQuestRequirements(config, questsSection, quest, questKey); - } - if (config.contains("quests." + questKey + ".planner")) { - loadQuestPlanner(config, questsSection, quest, questKey); - } - if (config.contains("quests." + questKey + ".options")) { - loadQuestOptions(config, questsSection, quest, questKey); - } - quest.plugin = this; - loadQuestStages(quest, config, questKey); - loadQuestRewards(config, quest, questKey); - quests.add(quest); - if (needsSaving) { - try { - config.save(file); - } catch (IOException e) { - getLogger().log(Level.SEVERE, "Failed to save Quest \"" + questKey + "\""); - e.printStackTrace(); - } - } - if (failedToLoad == true) { - getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping."); - } - } catch (QuestFormatException e) { - e.printStackTrace(); - continue; - } catch (StageFormatException e) { - e.printStackTrace(); - continue; - } catch (ActionFormatException e) { - e.printStackTrace(); - continue; - } - } - } else { - getLogger().severe("Unable to load quests.yml"); - } - } - - @SuppressWarnings("unchecked") - private void loadQuestRewards(FileConfiguration config, Quest quest, String questKey) throws QuestFormatException { - Rewards rews = quest.getRewards(); - if (config.contains("quests." + questKey + ".rewards.items")) { - LinkedList temp = new LinkedList(); - List stackList = (List) config.get("quests." + questKey + ".rewards.items"); - if (ConfigUtil.checkList(stackList, ItemStack.class)) { - for (ItemStack stack : stackList) { - if (stack != null) { - temp.add(stack); - } - } - } else { - // Legacy - if (ConfigUtil.checkList(stackList, String.class)) { - List items = config.getStringList("quests." + questKey + ".rewards.items"); - for (String item : items) { - try { - ItemStack stack = ItemUtil.readItemStack(item); - if (stack != null) { - temp.add(stack); - } - } catch (Exception e) { - throw new QuestFormatException("Reward items has invalid formatting for " + item, questKey); - } - } - } else { - throw new QuestFormatException("Reward items has invalid formatting", questKey); - } - } - rews.setItems(temp); - } - if (config.contains("quests." + questKey + ".rewards.money")) { - if (config.getInt("quests." + questKey + ".rewards.money", -999) != -999) { - rews.setMoney(config.getInt("quests." + questKey + ".rewards.money")); - } else { - throw new QuestFormatException("Reward money is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.exp")) { - if (config.getInt("quests." + questKey + ".rewards.exp", -999) != -999) { - rews.setExp(config.getInt("quests." + questKey + ".rewards.exp")); - } else { - throw new QuestFormatException("Reward exp is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.commands")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) { - rews.setCommands(config.getStringList("quests." + questKey + ".rewards.commands")); - } else { - throw new QuestFormatException("Reward commands is not a list of commands", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.commands-override-display")) { - // Legacy - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands-override-display"), - String.class)) { - rews.setCommandsOverrideDisplay(config.getStringList("quests." + questKey - + ".rewards.commands-override-display")); - } else { - throw new QuestFormatException("Reward commands-override-display is not a list of strings", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.permissions")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) { - rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions")); - } else { - throw new QuestFormatException("Reward permissions is not a list of permissions", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.permission-worlds")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey - + ".rewards.permission-worlds"), String.class)) { - rews.setPermissionWorlds(config.getStringList("quests." + questKey + ".rewards.permission-worlds")); - } else { - throw new QuestFormatException("Reward permissions is not a list of worlds", questKey); - } - } - if (config.contains("quests." + questKey + ".rewards.quest-points")) { - if (config.getInt("quests." + questKey + ".rewards.quest-points", -999) != -999) { - rews.setQuestPoints(config.getInt("quests." + questKey + ".rewards.quest-points")); - } else { - throw new QuestFormatException("Reward quest-points is not a number", questKey); - } - } - if (depends.isPluginAvailable("mcMMO")) { - if (config.contains("quests." + questKey + ".rewards.mcmmo-skills")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.mcmmo-skills"), - String.class)) { - if (config.contains("quests." + questKey + ".rewards.mcmmo-levels")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.mcmmo-levels"), - Integer.class)) { - for (String skill : config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")) { - if (depends.getMcmmoClassic() == null) { - throw new QuestFormatException("Reward mcMMO not found for mcmmo-skills", questKey); - } else if (Quests.getMcMMOSkill(skill) == null) { - throw new QuestFormatException("Reward mcmmo-skills has invalid skill name " + skill, questKey); - } - } - rews.setMcmmoSkills(config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")); - rews.setMcmmoAmounts(config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels")); - } else { - throw new QuestFormatException("Reward mcmmo-levels is not a list of numbers", questKey); - } - } else { - throw new QuestFormatException("Reward mcmmo-levels is missing!", questKey); - } - } else { - throw new QuestFormatException("Reward mcmmo-skills is not a list of mcMMO skill names", questKey); - } - } - } - if (depends.isPluginAvailable("Heroes")) { - if (config.contains("quests." + questKey + ".rewards.heroes-exp-classes")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.heroes-exp-classes"), - String.class)) { - if (config.contains("quests." + questKey + ".rewards.heroes-exp-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.heroes-exp-amounts"), - Double.class)) { - for (String heroClass : config.getStringList("quests." + questKey - + ".rewards.heroes-exp-classes")) { - if (depends.getHeroes() == null) { - throw new QuestFormatException("Heroes not found for heroes-exp-classes", questKey); - } else if (depends.getHeroes().getClassManager().getClass(heroClass) == null) { - throw new QuestFormatException("Reward heroes-exp-classes has invalid class name " - + heroClass, questKey); - } - } - rews.setHeroesClasses(config.getStringList("quests." + questKey - + ".rewards.heroes-exp-classes")); - rews.setHeroesAmounts(config.getDoubleList("quests." + questKey - + ".rewards.heroes-exp-amounts")); - } else { - throw new QuestFormatException("Reward heroes-exp-amounts is not a list of decimal numbers", questKey); - } - } else { - throw new QuestFormatException("Reward heroes-exp-amounts is missing", questKey); - } - } else { - throw new QuestFormatException("Reward heroes-exp-classes is not a list of Heroes classes", questKey); - } - } - } - if (depends.isPluginAvailable("PhatLoots")) { - if (config.contains("quests." + questKey + ".rewards.phat-loots")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.phat-loots"), String.class)) { - for (String loot : config.getStringList("quests." + questKey + ".rewards.phat-loots")) { - if (depends.getPhatLoots() == null) { - throw new QuestFormatException("PhatLoots not found for phat-loots", questKey); - } else if (PhatLootsAPI.getPhatLoot(loot) == null) { - throw new QuestFormatException("Reward phat-loots has invalid PhatLoot name " + loot, questKey); - } - } - rews.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots")); - } else { - throw new QuestFormatException("Reward phat-loots is not a list of PhatLoots", questKey); - } - } - } - if (config.contains("quests." + questKey + ".rewards.details-override")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey - + ".rewards.details-override"), String.class)) { - rews.setDetailsOverride(config.getStringList("quests." + questKey + ".rewards.details-override")); - } else { - throw new QuestFormatException("Reward details-override is not a list of strings", questKey); - } - } - } - - @SuppressWarnings("unchecked") - private void loadQuestRequirements(FileConfiguration config, ConfigurationSection questsSection, Quest quest, - String questKey) throws QuestFormatException { - Requirements reqs = quest.getRequirements(); - if (config.contains("quests." + questKey + ".requirements.fail-requirement-message")) { - Object o = config.get("quests." + questKey + ".requirements.fail-requirement-message"); - if (o instanceof List) { - reqs.setDetailsOverride(config.getStringList("quests." + questKey - + ".requirements.fail-requirement-message")); - } else { - // Legacy - List override = new LinkedList(); - override.add((String) o); - reqs.setDetailsOverride(override); - } - } - if (config.contains("quests." + questKey + ".requirements.items")) { - List temp = new LinkedList(); - List stackList = (List) config.get("quests." + questKey + ".requirements.items"); - if (ConfigUtil.checkList(stackList, ItemStack.class)) { - for (ItemStack stack : stackList) { - if (stack != null) { - temp.add(stack); - } - } - } else { - // Legacy - List items = config.getStringList("quests." + questKey + ".requirements.items"); - if (ConfigUtil.checkList(items, String.class)) { - for (String item : items) { - try { - ItemStack stack = ItemUtil.readItemStack(item); - if (stack != null) { - temp.add(stack); - } - } catch (Exception e) { - throw new QuestFormatException("Requirement items has invalid formatting for " + item, questKey); - } - } - } else { - throw new QuestFormatException("Requirement items has invalid formatting", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.remove-items")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.remove-items"), - Boolean.class)) { - reqs.setRemoveItems(config.getBooleanList("quests." + questKey + ".requirements.remove-items")); - } else { - throw new QuestFormatException("Requirement remove-items is not a list of true/false values", questKey); - } - } else { - throw new QuestFormatException("Requirement remove-items is missing", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.money")) { - if (config.getInt("quests." + questKey + ".requirements.money", -999) != -999) { - reqs.setMoney(config.getInt("quests." + questKey + ".requirements.money")); - } else { - throw new QuestFormatException("Requirement money is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.quest-points")) { - if (config.getInt("quests." + questKey + ".requirements.quest-points", -999) != -999) { - reqs.setQuestPoints(config.getInt("quests." + questKey + ".requirements.quest-points")); - } else { - throw new QuestFormatException("Requirement quest-points is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.quest-blocks")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quest-blocks"), - String.class)) { - List names = config.getStringList("quests." + questKey + ".requirements.quest-blocks"); - boolean failed = false; - String failedQuest = "NULL"; - List temp = new LinkedList(); - for (String name : names) { - boolean done = false; - for (String id : questsSection.getKeys(false)) { - String name2 = config.getString("quests." + id + ".name"); - if (name2.equalsIgnoreCase(name) - || ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name))) { - temp.add(name); - done = true; - break; - } - } - if (!done) { - failed = true; - failedQuest = name; - break; - } - } - reqs.setNeededQuests(temp); - if (failed) { - throw new QuestFormatException("Requirement quest-blocks has invalid quest name " + failedQuest, questKey); - } - } else { - throw new QuestFormatException("Requirement quest-blocks is not a list of quest names", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.quests")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quests"), String.class)) { - List names = config.getStringList("quests." + questKey + ".requirements.quests"); - boolean failed = false; - String failedQuest = "NULL"; - List temp = new LinkedList(); - for (String name : names) { - boolean done = false; - for (String id : questsSection.getKeys(false)) { - String name2 = config.getString("quests." + id + ".name"); - if (name2.equalsIgnoreCase(name) - || ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name))) { - temp.add(name); - done = true; - break; - } - } - if (!done) { - failed = true; - failedQuest = name; - break; - } - } - reqs.setNeededQuests(temp); - if (failed) { - throw new QuestFormatException("Requirement quests has invalid quest name " + failedQuest, questKey); - } - } else { - throw new QuestFormatException("Requirement quests is not a list of quest names", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.permissions")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.permissions"), - String.class)) { - reqs.setPermissions(config.getStringList("quests." + questKey + ".requirements.permissions")); - } else { - throw new QuestFormatException("Requirement permissions is not a list of permissions", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.mcmmo-skills")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.mcmmo-skills"), - String.class)) { - if (config.contains("quests." + questKey + ".requirements.mcmmo-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.mcmmo-amounts"), - Integer.class)) { - List skills = config.getStringList("quests." + questKey + ".requirements.mcmmo-skills"); - List amounts = config.getIntegerList("quests." + questKey - + ".requirements.mcmmo-amounts"); - if (skills.size() != amounts.size()) { - throw new QuestFormatException("Requirement mcmmo-skills: and mcmmo-amounts are not the same size", - questKey); - } - reqs.setMcmmoSkills(skills); - reqs.setMcmmoAmounts(amounts); - } else { - throw new QuestFormatException("Requirement mcmmo-amounts is not a list of numbers", questKey); - } - } else { - throw new QuestFormatException("Requirement mcmmo-amounts is missing", questKey); - } - } else { - throw new QuestFormatException("Requirement mcmmo-skills is not a list of skills", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.heroes-primary-class")) { - String className = config.getString("quests." + questKey + ".requirements.heroes-primary-class"); - HeroClass hc = depends.getHeroes().getClassManager().getClass(className); - if (hc != null && hc.isPrimary()) { - reqs.setHeroesPrimaryClass(hc.getName()); - } else if (hc != null) { - throw new QuestFormatException("Requirement heroes-primary-class is not a primary Heroes class", questKey); - } else { - throw new QuestFormatException("Requirement heroes-primary-class has invalid Heroes class", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.heroes-secondary-class")) { - String className = config.getString("quests." + questKey + ".requirements.heroes-secondary-class"); - HeroClass hc = depends.getHeroes().getClassManager().getClass(className); - if (hc != null && hc.isSecondary()) { - reqs.setHeroesSecondaryClass(hc.getName()); - } else if (hc != null) { - throw new QuestFormatException("Requirement heroes-secondary-class is not a secondary Heroes class", questKey); - } else { - throw new QuestFormatException("Requirement heroes-secondary-class has invalid Heroes class", questKey); - } - } - if (config.contains("quests." + questKey + ".requirements.details-override")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey - + ".requirements.details-override"), String.class)) { - reqs.setDetailsOverride(config.getStringList("quests." + questKey + ".requirements.details-override")); - } else { - throw new QuestFormatException("Requirement details-override is not a list of strings", questKey); - } - } - } - - private void loadQuestPlanner(FileConfiguration config, ConfigurationSection questsSection, Quest quest, - String questKey) throws QuestFormatException { - Planner pln = quest.getPlanner(); - if (config.contains("quests." + questKey + ".planner.start")) { - pln.setStart(config.getString("quests." + questKey + ".planner.start")); - } - if (config.contains("quests." + questKey + ".planner.end")) { - pln.setEnd(config.getString("quests." + questKey + ".planner.end")); - } - if (config.contains("quests." + questKey + ".planner.repeat")) { - if (config.getInt("quests." + questKey + ".planner.repeat", -999) != -999) { - pln.setRepeat(config.getInt("quests." + questKey + ".planner.repeat") * 1000); - } else { - throw new QuestFormatException("Requirement repeat is not a number", questKey); - } - } - if (config.contains("quests." + questKey + ".planner.cooldown")) { - if (config.getInt("quests." + questKey + ".planner.cooldown", -999) != -999) { - pln.setCooldown(config.getInt("quests." + questKey + ".planner.cooldown") * 1000); - } else { - throw new QuestFormatException("Requirement cooldown is not a number", questKey); - } - } - } - - private void loadQuestOptions(FileConfiguration config, ConfigurationSection questsSection, Quest quest, - String questKey) throws QuestFormatException { - Options opts = quest.getOptions(); - if (config.contains("quests." + questKey + ".options.allow-commands")) { - opts.setAllowCommands(config.getBoolean("quests." + questKey + ".options.allow-commands")); - } - if (config.contains("quests." + questKey + ".options.allow-quitting")) { - opts.setAllowQuitting(config.getBoolean("quests." + questKey + ".options.allow-quitting")); - } else if (getConfig().contains("allow-quitting")) { - // Legacy - opts.setAllowQuitting(getConfig().getBoolean("allow-quitting")); - } - if (config.contains("quests." + questKey + ".options.use-dungeonsxl-plugin")) { - opts.setUseDungeonsXLPlugin(config.getBoolean("quests." + questKey + ".options.use-dungeonsxl-plugin")); - } - if (config.contains("quests." + questKey + ".options.use-parties-plugin")) { - opts.setUsePartiesPlugin(config.getBoolean("quests." + questKey + ".options.use-parties-plugin")); - } - if (config.contains("quests." + questKey + ".options.share-progress-level")) { - opts.setShareProgressLevel(config.getInt("quests." + questKey + ".options.share-progress-level")); - } - if (config.contains("quests." + questKey + ".options.require-same-quest")) { - opts.setRequireSameQuest(config.getBoolean("quests." + questKey + ".options.require-same-quest")); - } - } - - @SuppressWarnings({ "unchecked", "unused" }) - private void loadQuestStages(Quest quest, FileConfiguration config, String questKey) - throws StageFormatException, ActionFormatException { - ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered"); - for (String stage : questStages.getKeys(false)) { - int stageNum = 0; - try { - stageNum = Integer.valueOf(stage); - } catch (NumberFormatException e) { - getLogger().severe("Stage key " + stage + "must be a number!"); - continue; - } - Stage oStage = new Stage(); - List breakNames = new LinkedList(); - List breakAmounts = new LinkedList(); - List breakDurability = new LinkedList(); - List damageNames = new LinkedList(); - List damageAmounts = new LinkedList(); - List damageDurability = new LinkedList(); - List placeNames = new LinkedList(); - List placeAmounts = new LinkedList(); - List placeDurability = new LinkedList(); - List useNames = new LinkedList(); - List useAmounts = new LinkedList(); - List useDurability = new LinkedList(); - List cutNames = new LinkedList(); - List cutAmounts = new LinkedList(); - List cutDurability = new LinkedList(); - List mobsToKill = new LinkedList(); - List mobNumToKill = new LinkedList(); - List locationsToKillWithin = new LinkedList(); - List radiiToKillWithin = new LinkedList(); - List areaNames = new LinkedList(); - List itemsToCraft = new LinkedList(); - List itemsToSmelt = new LinkedList(); - List enchantments = new LinkedList(); - List itemsToEnchant = new LinkedList(); - List amountsToEnchant = new LinkedList(); - List itemsToBrew = new LinkedList(); - List npcIdsToTalkTo = new LinkedList(); - List itemsToDeliver= new LinkedList(); - List itemDeliveryTargetIds = new LinkedList(); - List deliveryMessages = new LinkedList(); - List npcIdsToKill = new LinkedList(); - List npcAmountsToKill = new LinkedList(); - // Legacy Denizen script load - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".script-to-run")) { - if (getDependencies().getDenizenAPI().containsScript(config.getString("quests." + questKey - + ".stages.ordered." + stageNum + ".script-to-run"))) { - oStage.script = config.getString("quests." + questKey + ".stages.ordered." + stageNum + ".script-to-run"); - } else { - throw new StageFormatException("script-to-run is not a valid Denizen script", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-names"), String.class)) { - breakNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-names"); - } else { - throw new StageFormatException("break-block-names is not a list of strings", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-amounts"), Integer.class)) { - breakAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-amounts"); - } else { - throw new StageFormatException("break-block-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("break-block-amounts is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-durability")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-durability"), Integer.class)) { - breakDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum - + ".break-block-durability"); - } else { - throw new StageFormatException("break-block-durability is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("break-block-durability is missing", quest, stageNum); - } - } - int breakIndex = 0; - for (String s : breakNames) { - ItemStack is; - if (breakDurability.get(breakIndex) != -1) { - is = ItemUtil.processItemStack(s, breakAmounts.get(breakIndex), breakDurability.get(breakIndex)); - } else { - // Legacy - is = ItemUtil.processItemStack(s, breakAmounts.get(breakIndex), (short) 0); - } - if (Material.matchMaterial(s) != null) { - oStage.blocksToBreak.add(is); - } else { - throw new StageFormatException("break-block-names has invalid item name " + s, quest, stageNum); - } - breakIndex++; - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-names"), String.class)) { - damageNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-names"); - } else { - throw new StageFormatException("damage-block-names is not a list of strings", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-amounts"), Integer.class)) { - damageAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-amounts"); - } else { - throw new StageFormatException("damage-block-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("damage-block-amounts is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-durability")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-durability"), Integer.class)) { - damageDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum - + ".damage-block-durability"); - } else { - throw new StageFormatException("damage-block-durability is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("damage-block-durability is missing", quest, stageNum); - } - } - int damageIndex = 0; - for (String s : damageNames) { - ItemStack is; - if (damageDurability.get(damageIndex) != -1) { - is = ItemUtil.processItemStack(s, damageAmounts.get(damageIndex), - damageDurability.get(damageIndex)); - } else { - // Legacy - is = ItemUtil.processItemStack(s, damageAmounts.get(damageIndex), (short) 0); - } - if (Material.matchMaterial(s) != null) { - oStage.blocksToDamage.add(is); - } else { - throw new StageFormatException("damage-block-names has invalid item name " + s, quest, stageNum); - } - damageIndex++; - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-names"), String.class)) { - placeNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-names"); - } else { - throw new StageFormatException("place-block-names is not a list of strings", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-amounts"), Integer.class)) { - placeAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-amounts"); - } else { - throw new StageFormatException("place-block-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("place-block-amounts is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-durability")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-durability"), Integer.class)) { - placeDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum - + ".place-block-durability"); - } else { - throw new StageFormatException("place-block-durability is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("place-block-durability is missing", quest, stageNum); - } - } - int placeIndex = 0; - for (String s : placeNames) { - ItemStack is; - if (placeDurability.get(placeIndex) != -1) { - is = ItemUtil.processItemStack(s, placeAmounts.get(placeIndex), placeDurability.get(placeIndex)); - } else { - // Legacy - is = ItemUtil.processItemStack(s, placeAmounts.get(placeIndex), (short) 0); - } - if (Material.matchMaterial(s) != null) { - oStage.blocksToPlace.add(is); - } else { - throw new StageFormatException("place-block-names has invalid item name " + s, quest, stageNum); - } - placeIndex++; - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-names"), String.class)) { - useNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-names"); - } else { - throw new StageFormatException("use-block-names is not a list of strings", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-amounts"),Integer.class)) { - useAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-amounts"); - } else { - throw new StageFormatException("use-block-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("use-block-amounts is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-durability")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-durability"), Integer.class)) { - useDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum - + ".use-block-durability"); - } else { - throw new StageFormatException("use-block-durability is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("use-block-durability is missing", quest, stageNum); - } - } - int useIndex = 0; - for (String s : useNames) { - ItemStack is; - if (useDurability.get(useIndex) != -1) { - is = ItemUtil.processItemStack(s, useAmounts.get(useIndex), useDurability.get(useIndex)); - } else { - // Legacy - is = ItemUtil.processItemStack(s, useAmounts.get(useIndex), (short) 0); - } - if (Material.matchMaterial(s) != null) { - oStage.blocksToUse.add(is); - } else { - throw new StageFormatException("use-block-names has invalid item name " + s, quest, stageNum); - } - useIndex++; - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-names"), String.class)) { - cutNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-names"); - } else { - throw new StageFormatException("cut-block-names is not a list of strings", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-amounts"), Integer.class)) { - cutAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-amounts"); - } else { - throw new StageFormatException("cut-block-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("cut-block-amounts is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-durability")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-durability"), Integer.class)) { - cutDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum - + ".cut-block-durability"); - } else { - throw new StageFormatException("cut-block-durability is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("cut-block-durability is missing", quest, stageNum); - } - } - int cutIndex = 0; - for (String s : cutNames) { - ItemStack is; - if (cutDurability.get(cutIndex) != -1) { - is = ItemUtil.processItemStack(s, cutAmounts.get(cutIndex), cutDurability.get(cutIndex)); - } else { - // Legacy - is = ItemUtil.processItemStack(s, cutAmounts.get(cutIndex), (short) 0); - } - if (Material.matchMaterial(s) != null) { - oStage.blocksToCut.add(is); - } else { - throw new StageFormatException("cut-block-names has invalid item name " + s, quest, stageNum); - } - cutIndex++; - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-craft")) { - itemsToCraft = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-craft"); - if (ConfigUtil.checkList(itemsToCraft, ItemStack.class)) { - for (ItemStack stack : itemsToCraft) { - if (stack != null) { - oStage.itemsToCraft.add(stack); - } else { - throw new StageFormatException("items-to-craft has invalid formatting " + stack, quest, stageNum); - } - } - } else { - // Legacy - List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-craft"); - if (ConfigUtil.checkList(items, String.class)) { - for (String item : items) { - ItemStack is = ItemUtil.readItemStack("" + item); - if (is != null) { - oStage.itemsToCraft.add(is); - } else { - throw new StageFormatException("Legacy items-to-craft has invalid formatting " + item, quest, stageNum); - } - } - } else { - throw new StageFormatException("items-to-craft is not formatted properly", quest, stageNum); - } - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-smelt")) { - itemsToSmelt = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-smelt"); - if (ConfigUtil.checkList(itemsToSmelt, ItemStack.class)) { - for (ItemStack stack : itemsToSmelt) { - if (stack != null) { - oStage.itemsToSmelt.add(stack); - } else { - throw new StageFormatException("items-to-smelt has invalid formatting " + stack, quest, stageNum); - } - } - } else { - // Legacy - List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-smelt"); - if (ConfigUtil.checkList(items, String.class)) { - for (String item : items) { - ItemStack is = ItemUtil.readItemStack("" + item); - if (is != null) { - oStage.itemsToSmelt.add(is); - } else { - throw new StageFormatException("Legacy items-to-smelt has invalid formatting " + item, quest, stageNum); - } - } - } else { - throw new StageFormatException("items-to-smelt is not formatted properly", quest, stageNum); - } - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantments")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantments"), String.class)) { - for (String enchant : config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantments")) { - Enchantment e = ItemUtil.getEnchantmentFromProperName(enchant); - if (e != null) { - enchantments.add(e); - } else { - throw new StageFormatException("enchantments has invalid enchantment " + enchant, quest, stageNum); - } - } - } else { - throw new StageFormatException("enchantments is not a list of enchantment names", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantment-item-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantment-item-names"), String.class)) { - for (String item : config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantment-item-names")) { - if (Material.matchMaterial(item) != null) { - itemsToEnchant.add(Material.matchMaterial(item)); - } else { - throw new StageFormatException("enchantment-item-names has invalid item name " + item, quest, stageNum); - } - } - } else { - throw new StageFormatException("enchantment-item-names has invalid item name", quest, stageNum); - } - } else { - throw new StageFormatException("enchantment-item-names is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantment-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantment-amounts"), Integer.class)) { - amountsToEnchant = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".enchantment-amounts"); - } else { - throw new StageFormatException("enchantment-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("enchantment-amounts is missing", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-brew")) { - itemsToBrew = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-brew"); - if (ConfigUtil.checkList(itemsToBrew, ItemStack.class)) { - for (ItemStack stack : itemsToBrew) { - if (stack != null) { - oStage.itemsToBrew.add(stack); - } else { - throw new StageFormatException("items-to-brew has invalid formatting " + stack, quest, stageNum); - } - } - } else { - // Legacy - List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".items-to-brew"); - if (ConfigUtil.checkList(items, String.class)) { - for (String item : items) { - ItemStack is = ItemUtil.readItemStack("" + item); - if (is != null) { - oStage.itemsToBrew.add(is); - } else { - throw new StageFormatException("Legacy items-to-brew has invalid formatting " + item, quest, stageNum); - } - } - } else { - throw new StageFormatException("items-to-brew has invalid formatting", quest, stageNum); - } - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk")) { - if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk", -999) != -999) { - oStage.cowsToMilk = config.getInt("quests." + questKey + ".stages.ordered." + stageNum - + ".cows-to-milk"); - } else { - throw new StageFormatException("cows-to-milk is not a number", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch")) { - if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch", -999) != -999) { - oStage.fishToCatch = config.getInt("quests." + questKey + ".stages.ordered." + stageNum - + ".fish-to-catch"); - } else { - throw new StageFormatException("fish-to-catch is not a number", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".players-to-kill")) { - if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".players-to-kill", -999) != -999) { - oStage.playersToKill = config.getInt("quests." + questKey + ".stages.ordered." + stageNum - + ".players-to-kill"); - } else { - throw new StageFormatException("players-to-kill is not a number", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-talk-to"), Integer.class)) { - npcIdsToTalkTo = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-talk-to"); - for (int i : npcIdsToTalkTo) { - if (getDependencies().getCitizens() != null) { - if (CitizensAPI.getNPCRegistry().getById(i) != null) { - questNpcs.add(CitizensAPI.getNPCRegistry().getById(i)); - } else { - throw new StageFormatException("npc-ids-to-talk-to has invalid NPC ID of " + i, quest, stageNum); - } - } else { - throw new StageFormatException("Citizens not found for npc-ids-to-talk-to", quest, stageNum); - } - - } - } else { - throw new StageFormatException("npc-ids-to-talk-to is not a list of numbers", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-deliver")) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-delivery-ids")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-delivery-ids"), Integer.class)) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delivery-messages")) { - itemsToDeliver = (List) config.get("quests." + questKey + ".stages.ordered." - + stageNum + ".items-to-deliver"); - itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." - + stageNum + ".npc-delivery-ids"); - deliveryMessages.addAll(config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".delivery-messages")); - int index = 0; - if (ConfigUtil.checkList(itemsToDeliver, ItemStack.class)) { - for (ItemStack stack : itemsToDeliver) { - if (stack != null) { - int npcId = itemDeliveryTargetIds.get(index); - index++; - if (stack != null) { - if (getDependencies().getCitizens() != null) { - NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); - if (npc != null) { - oStage.itemsToDeliver.add(stack); - oStage.itemDeliveryTargets.add(npcId); - oStage.deliverMessages.addAll(deliveryMessages); - } else { - throw new StageFormatException("Citizens not found for npc-delivery-ids", quest, stageNum); - } - } else { - throw new StageFormatException("npc-delivery-ids has invalid NPC ID of " + npcId, quest, stageNum); - } - } else { - throw new StageFormatException("items-to-deliver has invalid formatting " + stack, quest, stageNum); - } - } - } - } else { - List items = config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".items-to-deliver"); - if (ConfigUtil.checkList(items, String.class)) { - // Legacy - for (String item : items) { - ItemStack is = ItemUtil.readItemStack("" + item); - int npcId = itemDeliveryTargetIds.get(index); - index++; - if (is != null) { - if (getDependencies().getCitizens() != null) { - NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); - if (npc != null) { - oStage.itemsToDeliver.add(is); - oStage.itemDeliveryTargets.add(npcId); - oStage.deliverMessages.addAll(deliveryMessages); - } else { - throw new StageFormatException("npc-delivery-ids has invalid NPC ID of " + npcId, quest, stageNum); - } - } else { - throw new StageFormatException("Citizens was not found installed for npc-delivery-ids", quest, stageNum); - } - } else { - throw new StageFormatException("items-to-deliver has invalid formatting " + item, quest, stageNum); - } - } - } else { - throw new StageFormatException("items-to-deliver has invalid formatting", quest, stageNum); - } - } - } - } else { - throw new StageFormatException("npc-delivery-ids is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("npc-delivery-id is missing", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-kill")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-kill"), Integer.class)) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-kill-amounts"), Integer.class)) { - npcIdsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-kill"); - npcAmountsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-kill-amounts"); - for (int i : npcIdsToKill) { - if (CitizensAPI.getNPCRegistry().getById(i) != null) { - if (npcAmountsToKill.get(npcIdsToKill.indexOf(i)) > 0) { - oStage.citizensToKill.add(i); - oStage.citizenNumToKill.add(npcAmountsToKill.get(npcIdsToKill.indexOf(i))); - questNpcs.add(CitizensAPI.getNPCRegistry().getById(i)); - } else { - throw new StageFormatException("npc-kill-amounts is not a positive number", quest, stageNum); - } - } else { - throw new StageFormatException("npc-ids-to-kill has invalid NPC ID of " + i, quest, stageNum); - } - } - } else { - throw new StageFormatException("npc-kill-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("npc-kill-amounts is missing", quest, stageNum); - } - } else { - throw new StageFormatException("npc-ids-to-kill is not a list of numbers", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mobs-to-kill")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".mobs-to-kill"), String.class)) { - List mobNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".mobs-to-kill"); - for (String mob : mobNames) { - EntityType type = MiscUtil.getProperMobType(mob); - if (type != null) { - mobsToKill.add(type); - } else { - throw new StageFormatException("mobs-to-kill has invalid mob name " + mob, quest, stageNum); - } - } - } else { - throw new StageFormatException("mobs-to-kill is not a list of mob names", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mob-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".mob-amounts"), Integer.class)) { - for (int i : config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".mob-amounts")) { - mobNumToKill.add(i); - } - } else { - throw new StageFormatException("mob-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("mob-amounts is missing", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".locations-to-kill")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".locations-to-kill"), String.class)) { - List locations = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".locations-to-kill"); - for (String loc : locations) { - if (ConfigUtil.getLocation(loc) != null) { - locationsToKillWithin.add(ConfigUtil.getLocation(loc)); - } else { - throw new StageFormatException("locations-to-kill has invalid formatting " + loc, quest, stageNum); - } - } - } else { - throw new StageFormatException("locations-to-kill is not a list of locations", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".kill-location-radii")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".kill-location-radii"), Integer.class)) { - List radii = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".kill-location-radii"); - for (int i : radii) { - radiiToKillWithin.add(i); - } - } else { - throw new StageFormatException("kill-location-radii is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("kill-location-radii is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".kill-location-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".kill-location-names"), String.class)) { - List locationNames = config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".kill-location-names"); - for (String name : locationNames) { - areaNames.add(name); - } - } else { - throw new StageFormatException("kill-location-names is not a list of names", quest, stageNum); - } - } else { - throw new StageFormatException("kill-location-names is missing", quest, stageNum); - } - } - oStage.mobsToKill.addAll(mobsToKill); - oStage.mobNumToKill.addAll(mobNumToKill); - oStage.locationsToKillWithin.addAll(locationsToKillWithin); - oStage.radiiToKillWithin.addAll(radiiToKillWithin); - oStage.killNames.addAll(areaNames); - Map, Integer> enchants = new HashMap, Integer>(); - for (Enchantment e : enchantments) { - Map map = new HashMap(); - map.put(e, itemsToEnchant.get(enchantments.indexOf(e))); - enchants.put(map, amountsToEnchant.get(enchantments.indexOf(e))); - } - oStage.itemsToEnchant = enchants; - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".locations-to-reach")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".locations-to-reach"), String.class)) { - List locations = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".locations-to-reach"); - for (String loc : locations) { - if (ConfigUtil.getLocation(loc) != null) { - oStage.locationsToReach.add(ConfigUtil.getLocation(loc)); - } else { - throw new StageFormatException("locations-to-reach has invalid formatting" + loc, quest, stageNum); - } - } - } else { - throw new StageFormatException("locations-to-reach is not a list of locations", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".reach-location-radii")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".reach-location-radii"), Integer.class)) { - List radii = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".reach-location-radii"); - for (int i : radii) { - oStage.radiiToReachWithin.add(i); - } - } else { - throw new StageFormatException("reach-location-radii is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("reach-location-radii is missing", quest, stageNum); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".reach-location-names")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".reach-location-names"), String.class)) { - List locationNames = config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".reach-location-names"); - for (String name : locationNames) { - oStage.locationNames.add(name); - } - } else { - throw new StageFormatException("reach-location-names is not a list of names", quest, stageNum); - } - } else { - throw new StageFormatException("reach-location-names is missing", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mobs-to-tame")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".mobs-to-tame"), String.class)) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mob-tame-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".mob-tame-amounts"), Integer.class)) { - List mobs = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".mobs-to-tame"); - List mobAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." - + stageNum + ".mob-tame-amounts"); - for (String mob : mobs) { - if (Tameable.class.isAssignableFrom(EntityType.valueOf(mob.toUpperCase()) - .getEntityClass())) { - oStage.mobsToTame.put(EntityType.valueOf(mob.toUpperCase()), - mobAmounts.get(mobs.indexOf(mob))); - } else { - throw new StageFormatException("mobs-to-tame has invalid tameable mob " + mob, quest, stageNum); - } - } - } else { - throw new StageFormatException("mob-tame-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("mob-tame-amounts is missing", quest, stageNum); - } - } else { - throw new StageFormatException("mobs-to-tame is not a list of mob names", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".sheep-to-shear")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".sheep-to-shear"), String.class)) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".sheep-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".sheep-amounts"), Integer.class)) { - List sheep = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".sheep-to-shear"); - List shearAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." - + stageNum + ".sheep-amounts"); - for (String color : sheep) { - DyeColor dc = MiscUtil.getProperDyeColor(color); - try { - if (dc == null) { - dc = DyeColor.valueOf(color.toUpperCase()); - } - } catch (IllegalArgumentException e) { - // Fail silently - } - if (dc != null) { - oStage.sheepToShear.put(dc, shearAmounts.get(sheep.indexOf(color))); - // Legacy start --> - } else if (color.equalsIgnoreCase(Lang.get("COLOR_BLACK"))) { - oStage.sheepToShear.put(DyeColor.BLACK, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_BLUE"))) { - oStage.sheepToShear.put(DyeColor.BLUE, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_BROWN"))) { - oStage.sheepToShear.put(DyeColor.BROWN, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_CYAN"))) { - oStage.sheepToShear.put(DyeColor.CYAN, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_GRAY"))) { - oStage.sheepToShear.put(DyeColor.GRAY, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_GREEN"))) { - oStage.sheepToShear.put(DyeColor.GREEN, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_LIGHT_BLUE"))) { - oStage.sheepToShear.put(DyeColor.LIGHT_BLUE, - shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_LIME"))) { - oStage.sheepToShear.put(DyeColor.LIME, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_MAGENTA"))) { - oStage.sheepToShear.put(DyeColor.MAGENTA, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_ORANGE"))) { - oStage.sheepToShear.put(DyeColor.ORANGE, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_PINK"))) { - oStage.sheepToShear.put(DyeColor.PINK, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_PURPLE"))) { - oStage.sheepToShear.put(DyeColor.PURPLE, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_RED"))) { - oStage.sheepToShear.put(DyeColor.RED, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_SILVER"))) { - // 1.13 changed DyeColor.SILVER -> DyeColor.LIGHT_GRAY - oStage.sheepToShear.put(DyeColor.getByColor(Color.SILVER), - shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_WHITE"))) { - oStage.sheepToShear.put(DyeColor.WHITE, shearAmounts.get(sheep.indexOf(color))); - } else if (color.equalsIgnoreCase(Lang.get("COLOR_YELLOW"))) { - oStage.sheepToShear.put(DyeColor.YELLOW, shearAmounts.get(sheep.indexOf(color))); - // <-- Legacy end - } else { - throw new StageFormatException("sheep-to-shear has invalid color " + color, quest, stageNum); - } - } - } else { - throw new StageFormatException("sheep-amounts is not a list of numbers", quest, stageNum); - } - } else { - throw new StageFormatException("sheep-amounts is missing", quest, stageNum); - } - } else { - throw new StageFormatException("sheep-to-shear is not a list of colors", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".password-displays")) { - List displays = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".password-displays"); - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".password-phrases")) { - List phrases = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum - + ".password-phrases"); - if (displays.size() == phrases.size()) { - for (int passIndex = 0; passIndex < displays.size(); passIndex++) { - oStage.passwordDisplays.add(displays.get(passIndex)); - LinkedList answers = new LinkedList(); - answers.addAll(Arrays.asList(phrases.get(passIndex).split("\\|"))); - oStage.passwordPhrases.add(answers); - } - } else { - throw new StageFormatException("password-displays and password-phrases are not the same size", quest, - stageNum); - } - } else { - throw new StageFormatException("password-phrases is missing", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".objective-override")) { - Object o = config.get("quests." + questKey + ".stages.ordered." + stageNum - + ".objective-override"); - if (o instanceof List) { - oStage.objectiveOverrides.addAll(config.getStringList("quests." + questKey - + ".stages.ordered." + stageNum + ".objective-override")); - } else { - // Legacy - String s = config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".objective-override"); - oStage.objectiveOverrides.add(s); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".start-event")) { - Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".start-event")); - if (action != null) { - oStage.startAction = action; - } else { - throw new StageFormatException("start-event failed to load", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".finish-event")) { - Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".finish-event")); - if (action != null) { - oStage.finishAction = action; - } else { - throw new StageFormatException("finish-event failed to load", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".death-event")) { - Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".death-event")); - if (action != null) { - oStage.deathAction = action; - } else { - throw new StageFormatException("death-event failed to load", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".disconnect-event")) { - Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".disconnect-event")); - if (action != null) { - oStage.disconnectAction = action; - } else { - throw new StageFormatException("disconnect-event failed to load", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".chat-events")) { - if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".chat-events")) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".chat-event-triggers")) { - if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".chat-event-triggers")) { - List chatEvents = config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".chat-events"); - List chatEventTriggers = config.getStringList("quests." + questKey - + ".stages.ordered." + stageNum + ".chat-event-triggers"); - boolean loadEventFailed = false; - for (int i = 0; i < chatEvents.size(); i++) { - Action action = loadAction(chatEvents.get(i)); - if (action != null) { - oStage.chatActions.put(chatEventTriggers.get(i), action); - } else { - loadEventFailed = true; - throw new StageFormatException("chat-events failed to load " + chatEvents.get(i), quest, stageNum); - } - } - if (loadEventFailed) { - break; - } - } else { - throw new StageFormatException("chat-event-triggers is not in list format", quest, stageNum); - } - } else { - throw new StageFormatException("chat-event-triggers is missing", quest, stageNum); - } - } else { - throw new StageFormatException("chat-events is not in list format", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".command-events")) { - if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".command-events")) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".command-event-triggers")) { - if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".command-event-triggers")) { - List commandEvents = config.getStringList("quests." + questKey + ".stages.ordered." - + stageNum + ".command-events"); - List commandEventTriggers = config.getStringList("quests." + questKey - + ".stages.ordered." + stageNum + ".command-event-triggers"); - boolean loadEventFailed = false; - for (int i = 0; i < commandEvents.size(); i++) { - Action action = loadAction(commandEvents.get(i)); - if (action != null) { - oStage.commandActions.put(commandEventTriggers.get(i), action); - } else { - loadEventFailed = true; - throw new StageFormatException("command-events failed to load " + commandEvents.get(i), quest, stageNum); - } - } - if (loadEventFailed) { - break; - } - } else { - throw new StageFormatException("command-event-triggers is not in list format", quest, stageNum); - } - } else { - throw new StageFormatException("command-event-triggers is missing", quest, stageNum); - } - } else { - throw new StageFormatException("command-events is not in list format", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delay")) { - if (config.getLong("quests." + questKey + ".stages.ordered." + stageNum + ".delay", -999) != -999) { - oStage.delay = config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".delay") * 1000; - } else { - throw new StageFormatException("delay is not a number", quest, stageNum); - } - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delay-message")) { - oStage.delayMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".delay-message"); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".start-message")) { - oStage.startMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".start-message"); - } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".complete-message")) { - oStage.completeMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum - + ".complete-message"); - } - LinkedList ids = new LinkedList(); - if (npcIdsToTalkTo != null) { - ids.addAll(npcIdsToTalkTo); - } - oStage.citizensToInteract = ids; - quest.getStages().add(oStage); - } - } - - protected Action loadAction(String name) throws ActionFormatException { - if (name == null) { - return null; - } - File legacy = new File(getDataFolder(), "events.yml"); - File actions = new File(getDataFolder(), "actions.yml"); - FileConfiguration data = new YamlConfiguration(); - try { - if (actions.isFile()) { - data.load(actions); - } else { - data.load(legacy); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - String legacyName = "events." + name; - String actionKey = "actions." + name + "."; - if (data.contains(legacyName)) { - actionKey = legacyName + "."; - } - Action action = new Action(this); - action.setName(name); - if (data.contains(actionKey + "message")) { - action.setMessage(ConfigUtil.parseString(data.getString(actionKey + "message"))); - } - if (data.contains(actionKey + "open-book")) { - action.setBook(data.getString(actionKey + "open-book")); - } - if (data.contains(actionKey + "clear-inventory")) { - if (data.isBoolean(actionKey + "clear-inventory")) { - action.setClearInv(data.getBoolean(actionKey + "clear-inventory")); - } else { - throw new ActionFormatException("clear-inventory is not a true/false value", actionKey); - } - } - if (data.contains(actionKey + "fail-quest")) { - if (data.isBoolean(actionKey + "fail-quest")) { - action.setFailQuest(data.getBoolean(actionKey + "fail-quest")); - } else { - throw new ActionFormatException("fail-quest is not a true/false value", actionKey); - } - } - if (data.contains(actionKey + "explosions")) { - if (ConfigUtil.checkList(data.getList(actionKey + "explosions"), String.class)) { - LinkedList explosions = new LinkedList(); - for (String s : data.getStringList(actionKey + "explosions")) { - Location loc = ConfigUtil.getLocation(s); - if (loc == null) { - throw new ActionFormatException("explosions is not in proper \"WorldName x y z\" format", actionKey); - } - explosions.add(loc); - } - action.setExplosions(explosions); - } else { - throw new ActionFormatException("explosions is not a list of locations", actionKey); - } - } - if (data.contains(actionKey + "effects")) { - if (ConfigUtil.checkList(data.getList(actionKey + "effects"), String.class)) { - if (data.contains(actionKey + "effect-locations")) { - if (ConfigUtil.checkList(data.getList(actionKey + "effect-locations"), String.class)) { - List effectList = data.getStringList(actionKey + "effects"); - List effectLocs = data.getStringList(actionKey + "effect-locations"); - Map effects = new HashMap(); - for (String s : effectList) { - Effect effect = null; - try { - effect = Effect.valueOf(s.toUpperCase()); - } catch (IllegalArgumentException e) { - throw new ActionFormatException("effect-locations is not a valid effect name", - actionKey); - } - Location l = ConfigUtil.getLocation(effectLocs.get(effectList.indexOf(s))); - if (l == null) { - throw new ActionFormatException("effect-locations is not in proper \"WorldName x y z\"" - + "format", actionKey); - } - effects.put(l, effect); - } - action.setEffects(effects); - } else { - throw new ActionFormatException("effect-locations is not a list of locations", actionKey); - } - } else { - throw new ActionFormatException("effect-locations is missing", actionKey); - } - } else { - throw new ActionFormatException("effects is not a list of effects", actionKey); - } - } - if (data.contains(actionKey + "items")) { - LinkedList temp = new LinkedList(); - @SuppressWarnings("unchecked") - List stackList = (List) data.get(actionKey + "items"); - if (ConfigUtil.checkList(stackList, ItemStack.class)) { - for (ItemStack stack : stackList) { - if (stack != null) { - temp.add(stack); - } - } - } else { - // Legacy - if (ConfigUtil.checkList(stackList, String.class)) { - List items = data.getStringList(actionKey + "items"); - for (String item : items) { - try { - ItemStack stack = ItemUtil.readItemStack(item); - if (stack != null) { - temp.add(stack); - } - } catch (Exception e) { - throw new ActionFormatException("items is not formatted properly", actionKey); - } - } - } else { - throw new ActionFormatException("items is not a list of items", actionKey); - } - } - action.setItems(temp); - } - if (data.contains(actionKey + "storm-world")) { - World stormWorld = getServer().getWorld(data.getString(actionKey + "storm-world")); - if (stormWorld == null) { - throw new ActionFormatException("storm-world is not a valid world name", actionKey); - } - if (data.contains(actionKey + "storm-duration")) { - if (data.getInt(actionKey + "storm-duration", -999) != -999) { - action.setStormDuration(data.getInt(actionKey + "storm-duration") * 1000); - } else { - throw new ActionFormatException("storm-duration is not a number", actionKey); - } - action.setStormWorld(stormWorld); - } else { - throw new ActionFormatException("storm-duration is missing", actionKey); - } - } - if (data.contains(actionKey + "thunder-world")) { - World thunderWorld = getServer().getWorld(data.getString(actionKey + "thunder-world")); - if (thunderWorld == null) { - throw new ActionFormatException("thunder-world is not a valid world name", actionKey); - } - if (data.contains(actionKey + "thunder-duration")) { - if (data.getInt(actionKey + "thunder-duration", -999) != -999) { - action.setThunderDuration(data.getInt(actionKey + "thunder-duration")); - } else { - throw new ActionFormatException("thunder-duration is not a number", actionKey); - } - action.setThunderWorld(thunderWorld); - } else { - throw new ActionFormatException("thunder-duration is missing", actionKey); - } - } - if (data.contains(actionKey + "mob-spawns")) { - ConfigurationSection section = data.getConfigurationSection(actionKey + "mob-spawns"); - LinkedList mobSpawns = new LinkedList(); - for (String s : section.getKeys(false)) { - String mobName = section.getString(s + ".name"); - Location spawnLocation = ConfigUtil.getLocation(section.getString(s + ".spawn-location")); - EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type")); - Integer mobAmount = section.getInt(s + ".spawn-amounts"); - if (spawnLocation == null) { - throw new ActionFormatException("mob-spawn-locations is not in proper \"WorldName x y z\" format", - actionKey); - } - if (type == null) { - throw new ActionFormatException("mob-spawn-types is not a list of mob types", actionKey); - } - ItemStack[] inventory = new ItemStack[5]; - Float[] dropChances = new Float[5]; - inventory[0] = ItemUtil.readItemStack(section.getString(s + ".held-item")); - dropChances[0] = (float) section.getDouble(s + ".held-item-drop-chance"); - inventory[1] = ItemUtil.readItemStack(section.getString(s + ".boots")); - dropChances[1] = (float) section.getDouble(s + ".boots-drop-chance"); - inventory[2] = ItemUtil.readItemStack(section.getString(s + ".leggings")); - dropChances[2] = (float) section.getDouble(s + ".leggings-drop-chance"); - inventory[3] = ItemUtil.readItemStack(section.getString(s + ".chest-plate")); - dropChances[3] = (float) section.getDouble(s + ".chest-plate-drop-chance"); - inventory[4] = ItemUtil.readItemStack(section.getString(s + ".helmet")); - dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance"); - QuestMob questMob = new QuestMob(type, spawnLocation, mobAmount); - questMob.setInventory(inventory); - questMob.setDropChances(dropChances); - questMob.setName(mobName); - mobSpawns.add(questMob); - } - action.setMobSpawns(mobSpawns); - } - if (data.contains(actionKey + "lightning-strikes")) { - if (ConfigUtil.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) { - LinkedList lightningStrikes = new LinkedList(); - for (String s : data.getStringList(actionKey + "lightning-strikes")) { - Location loc = ConfigUtil.getLocation(s); - if (loc == null) { - throw new ActionFormatException("lightning-strikes is not in proper \"WorldName x y z\" format", - actionKey); - } - lightningStrikes.add(loc); - } - action.setLightningStrikes(lightningStrikes); - } else { - throw new ActionFormatException("lightning-strikes is not a list of locations", actionKey); - } - } - if (data.contains(actionKey + "commands")) { - if (ConfigUtil.checkList(data.getList(actionKey + "commands"), String.class)) { - LinkedList commands = new LinkedList(); - for (String s : data.getStringList(actionKey + "commands")) { - if (s.startsWith("/")) { - s = s.replaceFirst("/", ""); - } - commands.add(s); - } - action.setCommands(commands); - } else { - throw new ActionFormatException("commands is not a list of commands", actionKey); - } - } - if (data.contains(actionKey + "potion-effect-types")) { - if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) { - if (data.contains(actionKey + "potion-effect-durations")) { - if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) { - if (data.contains(actionKey + "potion-effect-amplifiers")) { - if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-amplifiers"), - Integer.class)) { - List types = data.getStringList(actionKey + "potion-effect-types"); - List durations = data.getIntegerList(actionKey + "potion-effect-durations"); - List amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers"); - LinkedList potionEffects = new LinkedList(); - for (String s : types) { - PotionEffectType type = PotionEffectType.getByName(s); - if (type == null) { - throw new ActionFormatException("potion-effect-types is not a list of potion " - + "effect types", actionKey); - } - PotionEffect effect = new PotionEffect(type, durations - .get(types.indexOf(s)), amplifiers.get(types.indexOf(s))); - potionEffects.add(effect); - } - action.setPotionEffects(potionEffects); - } else { - throw new ActionFormatException("potion-effect-amplifiers is not a list of numbers", - actionKey); - } - } else { - throw new ActionFormatException("potion-effect-amplifiers is missing", actionKey); - } - } else { - throw new ActionFormatException("potion-effect-durations is not a list of numbers", actionKey); - } - } else { - throw new ActionFormatException("potion-effect-durations is missing", actionKey); - } - } else { - throw new ActionFormatException("potion-effect-types is not a list of potion effects", actionKey); - } - } - if (data.contains(actionKey + "hunger")) { - if (data.getInt(actionKey + "hunger", -999) != -999) { - action.setHunger(data.getInt(actionKey + "hunger")); - } else { - throw new ActionFormatException("hunger is not a number", actionKey); - } - } - if (data.contains(actionKey + "saturation")) { - if (data.getInt(actionKey + "saturation", -999) != -999) { - action.setSaturation(data.getInt(actionKey + "saturation")); - } else { - throw new ActionFormatException("saturation is not a number", actionKey); - } - } - if (data.contains(actionKey + "health")) { - if (data.getInt(actionKey + "health", -999) != -999) { - action.setHealth(data.getInt(actionKey + "health")); - } else { - throw new ActionFormatException("health is not a number", actionKey); - } - } - if (data.contains(actionKey + "teleport-location")) { - if (data.isString(actionKey + "teleport-location")) { - Location teleport = ConfigUtil.getLocation(data.getString(actionKey + "teleport-location")); - if (teleport == null) { - throw new ActionFormatException("teleport-location is not in proper \"WorldName x y z\" format", - actionKey); - } - action.setTeleport(teleport); - } else { - throw new ActionFormatException("teleport-location is not a location", actionKey); - } - } - if (data.contains(actionKey + "timer")) { - if (data.isInt(actionKey + "timer")) { - action.setTimer(data.getInt(actionKey + "timer")); - } else { - throw new ActionFormatException("timer is not a number", actionKey); - } - } - if (data.contains(actionKey + "cancel-timer")) { - if (data.isBoolean(actionKey + "cancel-timer")) { - action.setCancelTimer(data.getBoolean(actionKey + "cancel-timer")); - } else { - throw new ActionFormatException("cancel-timer is not a true/false value", actionKey); - } - } - if (data.contains(actionKey + "denizen-script")) { - action.setDenizenScript(data.getString(actionKey + "denizen-script")); - } - return action; - } - - private void loadCustomSections(Quest quest, FileConfiguration config, String questKey) - throws StageFormatException, QuestFormatException { - ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered"); - for (String stageNum : questStages.getKeys(false)) { - if (quest == null) { - getLogger().severe("Unable to load custom objectives because quest for " + questKey + " was null"); - return; - } - if (quest.getStage(Integer.valueOf(stageNum) - 1) == null) { - getLogger().severe("Unable to load custom objectives because stage" + (Integer.valueOf(stageNum) - 1) - + " for " + quest.getName() + " was null"); - return; - } - Stage oStage = quest.getStage(Integer.valueOf(stageNum) - 1); - oStage.customObjectives = new LinkedList<>(); - oStage.customObjectiveCounts = new LinkedList<>(); - oStage.customObjectiveData = new LinkedList<>(); - oStage.customObjectiveDisplays = new LinkedList<>(); - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".custom-objectives")) { - ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".stages.ordered." - + stageNum + ".custom-objectives"); - for (String path : sec.getKeys(false)) { - String name = sec.getString(path + ".name"); - int count = sec.getInt(path + ".count"); - Optional found = Optional.empty(); - for (CustomObjective cr : customObjectives) { - if (cr.getName().equalsIgnoreCase(name)) { - found = Optional.of(cr); - break; - } - } - if (!found.isPresent()) { - getLogger().warning("Custom objective \"" + name + "\" for Stage " + stageNum + " of Quest \"" - + quest.getName() + "\" could not be found!"); - continue; - } else { - ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); - oStage.customObjectives.add(found.get()); - if (count <= 0) { - oStage.customObjectiveCounts.add(0); - } else { - oStage.customObjectiveCounts.add(count); - } - for (Entry prompt : found.get().getData()) { - Entry data = populateCustoms(sec2, prompt); - oStage.customObjectiveData.add(data); - } - } - } - } - } - Rewards rews = quest.getRewards(); - if (config.contains("quests." + questKey + ".rewards.custom-rewards")) { - ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".rewards.custom-rewards"); - Map> temp = new HashMap>(); - for (String path : sec.getKeys(false)) { - String name = sec.getString(path + ".name"); - Optionalfound = Optional.empty(); - for (CustomReward cr : customRewards) { - if (cr.getName().equalsIgnoreCase(name)) { - found=Optional.of(cr); - break; - } - } - if (!found.isPresent()) { - getLogger().warning("Custom reward \"" + name + "\" for Quest \"" + quest.getName() - + "\" could not be found!"); - continue; - } else { - ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); - Map data = populateCustoms(sec2, found.get().getData()); - temp.put(name, data); - } - } - rews.setCustomRewards(temp); - } - Requirements reqs = quest.getRequirements(); - if (config.contains("quests." + questKey + ".requirements.custom-requirements")) { - ConfigurationSection sec = config.getConfigurationSection("quests." + questKey - + ".requirements.custom-requirements"); - Map> temp = new HashMap>(); - for (String path : sec.getKeys(false)) { - String name = sec.getString(path + ".name"); - Optionalfound=Optional.empty(); - for (CustomRequirement cr : customRequirements) { - if (cr.getName().equalsIgnoreCase(name)) { - found=Optional.of(cr); - break; - } - } - if (!found.isPresent()) { - throw new QuestFormatException(name + " custom requirement not found", questKey); - } else { - ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); - Map data = populateCustoms(sec2,found.get().getData()); - temp.put(name, data); - } - } - reqs.setCustomRequirements(temp); - } - } - - /** - * Permits use of fallbacks for customs maps

- * - * Avoid null objects in datamap by initializing the entry value with empty string if no fallback present. - * - * @param section The section of configuration to check - * @param datamap The map to process - * @return Populated map - */ - private static Map populateCustoms(ConfigurationSection section, Map datamap) { - Map data = new HashMap(); - if (section != null) { - for (String key : datamap.keySet()) { - data.put(key, section.contains(key) ? section.get(key) : datamap.get(key) != null - ? datamap.get(key) : new String()); - } - } - return data; - } - - /** - * Permits use of fallbacks for customs entries

- * - * Avoid null objects in datamap by initializing the entry value with empty string if no fallback present. - * - * @param section The section of configuration to check - * @param datamap The entry to process - * @return Populated entry - */ - private static Entry populateCustoms(ConfigurationSection section, Entry datamap) { - String key = null;; - Object value = null;; - if (section != null) { - key = datamap.getKey(); - value = datamap.getValue(); - } - return new AbstractMap.SimpleEntry(key, section.contains(key) ? section.get(key) : value != null - ? value : new String()); - } - - /** - * Load actions from file - */ - public void loadActions() { - YamlConfiguration config = new YamlConfiguration(); - File legacyFile = new File(this.getDataFolder(), "events.yml"); - File actionsFile = new File(this.getDataFolder(), "actions.yml"); - // Using isFile() because exists() and renameTo() can return false positives - if (legacyFile.isFile()) { - getLogger().log(Level.INFO, "Renaming legacy events.yml to actions.yml ..."); - try { - legacyFile.renameTo(actionsFile); - if (actionsFile.isFile()) { - getLogger().log(Level.INFO, "Success! Deleting legacy events.yml ..."); - legacyFile.delete(); - getLogger().log(Level.INFO, "Done!"); - } - } catch (Exception e) { - getLogger().log(Level.WARNING, "Unable to rename events.yml to actions.yml"); - e.printStackTrace(); - } - } - if (actionsFile.length() != 0) { - try { - if (actionsFile.isFile()) { - config.load(actionsFile); - } else { - config.load(legacyFile); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - ConfigurationSection sec = config.getConfigurationSection("actions"); - if (sec == null) { - getLogger().log(Level.INFO, - "Could not find section \"actions\" from actions.yml. Trying legacy \"events\"..."); - sec = config.getConfigurationSection("events"); - } - if (sec != null) { - for (String s : sec.getKeys(false)) { - Action action = null; - try { - action= loadAction(s); - } catch (ActionFormatException e) { - e.printStackTrace(); - } - if (action != null) { - actions.add(action); - } else { - getLogger().log(Level.SEVERE, "Failed to load Action \"" + s + "\". Skipping."); - } - } - } else { - getLogger().log(Level.SEVERE, "Could not find beginning section from actions.yml. Skipping."); - } - } else { - getLogger().log(Level.WARNING, "Empty file actions.yml was not loaded."); - } - } - - public static SkillType getMcMMOSkill(String s) { - return SkillType.getSkill(s); - } - - /** - * @deprecated Use InventoryUtil.removeItem(Inventory, ItemStack) - */ - public static boolean removeItem(Inventory inventory, ItemStack is) { - int amount = is.getAmount(); - HashMap allItems = inventory.all(is.getType()); - HashMap removeFrom = new HashMap(); - int foundAmount = 0; - for (Map.Entry item : allItems.entrySet()) { - if (ItemUtil.compareItems(is, item.getValue(), true) == 0) { - if (item.getValue().getAmount() >= amount - foundAmount) { - removeFrom.put(item.getKey(), amount - foundAmount); - foundAmount = amount; - } else { - foundAmount += item.getValue().getAmount(); - removeFrom.put(item.getKey(), item.getValue().getAmount()); - } - if (foundAmount >= amount) { - break; - } - } - } - if (foundAmount == amount) { - for (Map.Entry toRemove : removeFrom.entrySet()) { - ItemStack item = inventory.getItem(toRemove.getKey()); - if (item.getAmount() - toRemove.getValue() <= 0) { - inventory.clear(toRemove.getKey()); - } else { - item.setAmount(item.getAmount() - toRemove.getValue()); - inventory.setItem(toRemove.getKey(), item); - } - } - return true; - } - return false; - } - - /** - * Checks if player can use Quests - * - * @param uuid the entity UUID to be checked - * @return {@code true} if entity is a Player that has permission - */ - public boolean canUseQuests(UUID uuid) { - return !checkQuester(uuid); - } - - /** - * Checks if player CANNOT use Quests - * - * @param uuid the entity UUID to be checked - * @return {@code true} if entity has no permission or is not a player - * @deprecated Use {@link #canUseQuests(UUID)} - */ - public boolean checkQuester(UUID uuid) { - if (!(Bukkit.getPlayer(uuid) instanceof Player)) { - return true; - } - Player p = Bukkit.getPlayer(uuid); - if (p.isOp()) { - return false; - } - try { - for (PermissionAttachmentInfo pm : p.getEffectivePermissions()) { - if (pm.getPermission().startsWith("quests") - || pm.getPermission().equals("*") - || pm.getPermission().equals("*.*")) { - return false; - } - } - } catch (NullPointerException ne) { - // User has no permissions - } catch (ConcurrentModificationException cme) { - // Bummer. Not much we can do about it - } - return true; - } - - /** - * Get a Quest by ID - * - * @param id ID of the quest - * @return Exact match or null if not found - * @since 3.8.6 - */ - public Quest getQuestById(String id) { - if (id == null) { - return null; - } - for (Quest q : quests) { - if (q.getId().equals(id)) { - return q; - } - } - return null; - } - - /** - * Get a Quest by name - * - * @param name Name of the quest - * @return Closest match or null if not found - */ - public Quest getQuest(String name) { - if (name == null) { - return null; - } - for (Quest q : quests) { - if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { - return q; - } - } - for (Quest q : quests) { - if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { - return q; - } - } - for (Quest q : quests) { - if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { - return q; - } - } - return null; - } - - /** - * Get an Action by name - * - * @param name Name of the action - * @return Closest match or null if not found - */ - public Action getAction(String name) { - if (name == null) { - return null; - } - for (Action a : actions) { - if (a.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { - return a; - } - } - for (Action a : actions) { - if (a.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { - return a; - } - } - for (Action a : actions) { - if (a.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { - return a; - } - } - return null; - } - - /** - * Checks whether a NPC has a quest that the player may accept - * - * @param npc The giver NPC to check - * @param quester The player to check - * @return true if at least one available quest has not yet been completed - */ - public boolean hasQuest(NPC npc, Quester quester) { - for (Quest q : quests) { - if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == false) { - if (q.npcStart.getId() == npc.getId()) { - boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); - if (ignoreLockedQuests == false || ignoreLockedQuests == true - && q.testRequirements(quester) == true) { - return true; - } - } - } - } - return false; - } - - // Unused internally, left for external use - /** - * Checks whether a NPC has a quest that the player has already completed - * - * @param npc The giver NPC to check - * @param quester The player to check - * @return true if at least one available quest has been completed - */ - public boolean hasCompletedQuest(NPC npc, Quester quester) { - for (Quest q : quests) { - if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == true) { - if (q.npcStart.getId() == npc.getId()) { - boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); - if (ignoreLockedQuests == false || ignoreLockedQuests == true - && q.testRequirements(quester) == true) { - return true; - } - } - } - } - return false; - } - - /** - * Checks whether a NPC has a repeatable quest that the player has already completed - * - * @param npc The giver NPC to check - * @param quester The player to check - * @return true if at least one available, redoable quest has been completed - */ - public boolean hasCompletedRedoableQuest(NPC npc, Quester quester) { - for (Quest q : quests) { - if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == true - && q.getPlanner().getCooldown() > -1) { - if (q.npcStart.getId() == npc.getId()) { - boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); - if (ignoreLockedQuests == false || ignoreLockedQuests == true - && q.testRequirements(quester) == true) { - return true; - } - } - } - } - return false; - } -} +/******************************************************************************************************* + * Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *******************************************************************************************************/ + +package me.blackvein.quests; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.lang.reflect.Constructor; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.DyeColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.CommandExecutor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.ConversationAbandonedEvent; +import org.bukkit.conversations.ConversationAbandonedListener; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.ConversationFactory; +import org.bukkit.conversations.ConversationPrefix; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.codisimus.plugins.phatloots.PhatLootsAPI; +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.herocraftonline.heroes.characters.classes.HeroClass; + +import me.blackvein.quests.actions.Action; +import me.blackvein.quests.actions.ActionFactory; +import me.blackvein.quests.convo.npcs.NpcOfferQuestPrompt; +import me.blackvein.quests.exceptions.ActionFormatException; +import me.blackvein.quests.exceptions.QuestFormatException; +import me.blackvein.quests.exceptions.StageFormatException; +import me.blackvein.quests.interfaces.ReloadCallback; +import me.blackvein.quests.listeners.CmdExecutor; +import me.blackvein.quests.listeners.DungeonsListener; +import me.blackvein.quests.listeners.NpcListener; +import me.blackvein.quests.listeners.PartiesListener; +import me.blackvein.quests.listeners.PlayerListener; +import me.blackvein.quests.tasks.NpcEffectThread; +import me.blackvein.quests.tasks.PlayerMoveThread; +import me.blackvein.quests.util.ConfigUtil; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.LocaleQuery; +import me.blackvein.quests.util.MiscUtil; +import me.clip.placeholderapi.PlaceholderAPI; + +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.npc.NPC; + +public class Quests extends JavaPlugin implements ConversationAbandonedListener { + + private boolean loading = true; + private String bukkitVersion = "0"; + private Dependencies depends; + private Settings settings; + private final List customRequirements = new LinkedList(); + private final List customRewards = new LinkedList(); + private final List customObjectives = new LinkedList(); + private LinkedList questers = new LinkedList(); + private LinkedList quests = new LinkedList(); + private LinkedList actions = new LinkedList(); + private LinkedList questNpcs = new LinkedList(); + private CommandExecutor cmdExecutor; + private ConversationFactory conversationFactory; + private ConversationFactory npcConversationFactory; + private QuestFactory questFactory; + private ActionFactory eventFactory; + private PlayerListener playerListener; + private NpcListener npcListener; + private NpcEffectThread effThread; + private PlayerMoveThread moveThread; + private DungeonsListener dungeonsListener; + private PartiesListener partiesListener; + private DenizenTrigger trigger; + private LocaleQuery localeQuery; + + @Override + public void onEnable() { + /****** WARNING: ORDER OF STEPS MATTERS ******/ + + // 1 - Initialize variables + bukkitVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; + settings = new Settings(this); + localeQuery = new LocaleQuery(this); + localeQuery.setBukkitVersion(bukkitVersion); + playerListener = new PlayerListener(this); + effThread = new NpcEffectThread(this); + moveThread = new PlayerMoveThread(this); + npcListener = new NpcListener(this); + dungeonsListener = new DungeonsListener(); + partiesListener = new PartiesListener(); + questFactory = new QuestFactory(this); + eventFactory = new ActionFactory(this); + depends = new Dependencies(this); + trigger = new DenizenTrigger(this); + + // 2 - Load main config + settings.init(); + + // 3 - Setup language files + try { + setupLang(); + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + // 4 - Load command executor + cmdExecutor = new CmdExecutor(this); + + // 5 - Load soft-depends + depends.init(); + + // 6 - Save resources from jar + saveResourceAs("quests.yml", "quests.yml", false); + saveResourceAs("actions.yml", "actions.yml", false); + + // 7 - Save config with any new options + getConfig().options().copyDefaults(true); + saveConfig(); + + // 8 - Setup commands + getCommand("quests").setExecutor(cmdExecutor); + getCommand("questadmin").setExecutor(cmdExecutor); + getCommand("quest").setExecutor(cmdExecutor); + + // 9 - Build conversation factories + this.conversationFactory = new ConversationFactory(this).withModality(false) + .withPrefix(new ConversationPrefix() { + @Override + public String getPrefix(ConversationContext context) { + return ChatColor.GRAY.toString(); + } + }) + .withFirstPrompt(new QuestAcceptPrompt()).withTimeout(settings.getAcceptTimeout()) + .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!") + .addConversationAbandonedListener(this); + this.npcConversationFactory = new ConversationFactory(this).withModality(false) + .withFirstPrompt(new NpcOfferQuestPrompt(this)).withTimeout(settings.getAcceptTimeout()) + .withLocalEcho(false).addConversationAbandonedListener(this); + + // 10 - Register listeners + getServer().getPluginManager().registerEvents(playerListener, this); + if (depends.getCitizens() != null) { + getServer().getPluginManager().registerEvents(npcListener, this); + if (settings.canNpcEffects()) { + getServer().getScheduler().scheduleSyncRepeatingTask(this, effThread, 20, 20); + } + } + if (settings.getStrictPlayerMovement() > 0) { + long ticks = settings.getStrictPlayerMovement() * 20; + getServer().getScheduler().scheduleSyncRepeatingTask(this, moveThread, ticks, ticks); + } + if (depends.getDungeonsApi() != null) { + getServer().getPluginManager().registerEvents(dungeonsListener, this); + } + if (depends.getPartiesApi() != null) { + getServer().getPluginManager().registerEvents(partiesListener, this); + } + + // 11 - Delay loading of Quests, Actions and modules + delayLoadQuestInfo(5L); + } + + @Override + public void onDisable() { + getLogger().info("Saving Quester data..."); + for (Player p : getServer().getOnlinePlayers()) { + Quester quester = getQuester(p.getUniqueId()); + quester.saveData(); + } + } + + public boolean isLoading() { + return loading; + } + + public String getDetectedBukkitVersion() { + return bukkitVersion; + } + + public Dependencies getDependencies() { + return depends; + } + + public Settings getSettings() { + return settings; + } + + public List getCustomRequirements() { + return customRequirements; + } + + public Optional getCustomRequirement(String className) { + for (int i = 0; i < customRequirements.size(); i++) { + CustomRequirement cr = customRequirements.get(i); + if (cr.getClass().getName().equals(className)) { + return Optional.of(cr); + } + } + return Optional.empty(); + } + + public List getCustomRewards() { + return customRewards; + } + + public Optional getCustomReward(String className) { + for (int i = 0; i < customRewards.size(); i++) { + CustomReward cr = customRewards.get(i); + if (cr.getClass().getName().equals(className)) { + return Optional.of(cr); + } + } + return Optional.empty(); + } + + public List getCustomObjectives() { + return customObjectives; + } + + public Optional getCustomObjective(String className) { + for (int i = 0; i < customObjectives.size(); i++) { + CustomObjective co = customObjectives.get(i); + if (co.getClass().getName().equals(className)) { + return Optional.of(co); + } + } + return Optional.empty(); + } + + public LinkedList getQuests() { + return quests; + } + + public LinkedList getActions() { + return actions; + } + + public void setActions(LinkedList actions) { + this.actions = actions; + } + + public LinkedList getQuesters() { + return questers; + } + + public void setQuesters(LinkedList questers) { + this.questers = questers; + } + + public LinkedList getQuestNpcs() { + return questNpcs; + } + + public void setQuestNpcs(LinkedList questNpcs) { + this.questNpcs = questNpcs; + } + + public ConversationFactory getConversationFactory() { + return conversationFactory; + } + + public ConversationFactory getNpcConversationFactory() { + return npcConversationFactory; + } + + public QuestFactory getQuestFactory() { + return questFactory; + } + + public ActionFactory getActionFactory() { + return eventFactory; + } + + @Deprecated + public ActionFactory getEventFactory() { + return eventFactory; + } + + public PlayerListener getPlayerListener() { + return playerListener; + } + + public DenizenTrigger getDenizenTrigger() { + return trigger; + } + + public LocaleQuery getLocaleQuery() { + return localeQuery; + } + + @Override + public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { + if (abandonedEvent.gracefulExit() == false) { + if (abandonedEvent.getContext().getForWhom() != null) { + try { + abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW + + Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout")); + } catch (Exception e) { + // Do nothing + } + } + } + } + + private class QuestAcceptPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get((Player) context.getForWhom(), "acceptQuest") + " " + ChatColor.GREEN + + Lang.get("yesWord") + " / " + Lang.get("noWord"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String s) { + Player player = (Player) context.getForWhom(); + if (s.equalsIgnoreCase(Lang.get(player, "yesWord"))) { + String questToTake = getQuester(player.getUniqueId()).questToTake; + try { + if (getQuest(questToTake) == null) { + getLogger().info(player.getName() + " attempted to take quest \"" + questToTake + + "\" but something went wrong"); + player.sendMessage(ChatColor.RED + + "Something went wrong! Please report issue to an administrator."); + } else { + getQuester(player.getUniqueId()).takeQuest(getQuest(questToTake), false); + } + } catch (Exception e) { + e.printStackTrace(); + } + return Prompt.END_OF_CONVERSATION; + } else if (s.equalsIgnoreCase(Lang.get("noWord"))) { + player.sendMessage(ChatColor.YELLOW + Lang.get("cancelled")); + return Prompt.END_OF_CONVERSATION; + } else { + String msg = Lang.get(player, "questInvalidChoice") + .replace("", Lang.get(player, "yesWord")) + .replace("", Lang.get(player, "noWord")); + player.sendMessage(ChatColor.RED + msg); + return new QuestAcceptPrompt(); + } + } + } + + /** + * Transfer language files from jar to disk + */ + private void setupLang() throws IOException, URISyntaxException { + final String path = "lang"; + final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); + if(jarFile.isFile()) { + final JarFile jar = new JarFile(jarFile); + final Enumeration entries = jar.entries(); + Set results = new HashSet(); + while(entries.hasMoreElements()) { + final String name = entries.nextElement().getName(); + if (name.startsWith(path + "/") && name.contains("strings.yml")) { + results.add(name); + } + } + for (String resourcePath : results) { + saveResourceAs(resourcePath, resourcePath, false); + saveResourceAs(resourcePath, resourcePath.replace(".yml", "_new.yml"), true); + } + jar.close(); + } + try { + Lang.init(this); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + } + + /** + * Save a Quests plugin resource to a specific path in the filesystem + * + * @param resourcePath jar file location starting from resource folder, i.e. "lang/el-GR/strings.yml" + * @param outputPath file destination starting from Quests folder, i.e. "lang/el-GR/strings.yml" + * @param replace whether or not to replace the destination file + */ + public void saveResourceAs(String resourcePath, String outputPath, boolean replace) { + if (resourcePath == null || resourcePath.equals("")) { + throw new IllegalArgumentException("ResourcePath cannot be null or empty"); + } + + resourcePath = resourcePath.replace('\\', '/'); + InputStream in = getResource(resourcePath); + if (in == null) { + throw new IllegalArgumentException("The embedded resource '" + resourcePath + + "' cannot be found in Quests jar"); + } + + String outPath = outputPath.replace('/', File.separatorChar).replace('\\', File.separatorChar); + File outFile = new File(getDataFolder(), outPath); + File outDir = new File(outFile.getPath().replace(outFile.getName(), "")); + + if (!outDir.exists()) { + if (!outDir.mkdirs()) { + getLogger().log(Level.SEVERE, "Failed to make directories for " + outFile.getName() + " (canWrite= " + + outDir.canWrite() + ")"); + } + } + + try { + if (!outFile.exists() || replace) { + OutputStream out = new FileOutputStream(outFile); + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + out.close(); + in.close(); + if (!outFile.exists()) { + getLogger().severe("Unable to copy " + outFile.getName() + " (canWrite= " + outFile.canWrite() + + ")"); + } + } + } catch (IOException ex) { + getLogger().log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex); + } + } + + /** + * Load quests, actions, and modules after specified delay

+ * + * At startup, this lets soft-depends (namely Citizens) fully load first + */ + private void delayLoadQuestInfo(long ticks) { + getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + + @Override + public void run() { + loadQuests(); + loadActions(); + getLogger().log(Level.INFO, "Loaded " + quests.size() + " Quest(s)" + + ", " + actions.size() + " Action(s)" + + ", " + Lang.size() + " Phrase(s)"); + for (Player p : getServer().getOnlinePlayers()) { + Quester quester = new Quester(Quests.this); + quester.setUUID(p.getUniqueId()); + if (quester.loadData() == false) { + quester.saveData(); + } + // Workaround for issues with the compass on fast join + quester.findCompassTarget(); + questers.add(quester); + } + if (depends.getCitizens() != null) { + if (depends.getCitizens().getNPCRegistry() == null) { + getLogger().log(Level.SEVERE, + "Citizens was enabled but NPCRegistry was null. Disabling linkage."); + depends.disableCitizens(); + } + } + loadModules(); + loading = false; + } + }, ticks); + } + + /** + * Load modules from file + */ + public void loadModules() { + File f = new File(this.getDataFolder(), "modules"); + if (f.exists() && f.isDirectory()) { + File[] modules = f.listFiles(); + if (modules != null) { + for (File module : modules) { + if (module.isDirectory() == false && module.getName().endsWith(".jar")) { + loadModule(module); + } + } + } + } else { + f.mkdir(); + } + boolean failedToLoad; + FileConfiguration config = null; + File file = new File(this.getDataFolder(), "quests.yml"); + try { + config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), "UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + } + if (config != null) { + ConfigurationSection questsSection; + if (config.contains("quests")) { + questsSection = config.getConfigurationSection("quests"); + for (String questKey : questsSection.getKeys(false)) { + try { + failedToLoad = false; + if (config.contains("quests." + questKey)) { + loadCustomSections(getQuestById(questKey), config, questKey); + } else { + throw new QuestFormatException("Quest block is missing", questKey); + } + if (failedToLoad) { + getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping."); + } + } catch (QuestFormatException ex) { + continue; + } catch (StageFormatException ex) { + continue; + } + } + } + } else { + getLogger().severe("Unable to load module data from quests.yml"); + } + } + + /** + * Load the specified jar as a module + * + * @param jar A custom reward/requirement/objective jar + */ + public void loadModule(File jar) { + try { + @SuppressWarnings("resource") + JarFile jarFile = new JarFile(jar); + Enumeration e = jarFile.entries(); + URL[] urls = { new URL("jar:file:" + jar.getPath() + "!/") }; + ClassLoader cl = URLClassLoader.newInstance(urls, getClassLoader()); + int count = 0; + while (e.hasMoreElements()) { + JarEntry je = (JarEntry) e.nextElement(); + if (je.isDirectory() || !je.getName().endsWith(".class")) { + continue; + } + String className = je.getName().substring(0, je.getName().length() - 6); + className = className.replace('/', '.'); + Class c = Class.forName(className, true, cl); + if (CustomRequirement.class.isAssignableFrom(c)) { + Class requirementClass = c.asSubclass(CustomRequirement.class); + Constructor cstrctr = requirementClass.getConstructor(); + CustomRequirement requirement = cstrctr.newInstance(); + Optionaloo=getCustomRequirement(requirement.getClass().getName()); + if (oo.isPresent()) customRequirements.remove(oo.get()); + customRequirements.add(requirement); + String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName(); + String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor(); + count++; + getLogger().info("Loaded Module: " + name + " by " + author); + } else if (CustomReward.class.isAssignableFrom(c)) { + Class rewardClass = c.asSubclass(CustomReward.class); + Constructor cstrctr = rewardClass.getConstructor(); + CustomReward reward = cstrctr.newInstance(); + Optionaloo=getCustomReward(reward.getClass().getName()); + if (oo.isPresent()) customRewards.remove(oo.get()); + customRewards.add(reward); + String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName(); + String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor(); + count++; + getLogger().info("Loaded Module: " + name + " by " + author); + } else if (CustomObjective.class.isAssignableFrom(c)) { + Class objectiveClass = c.asSubclass(CustomObjective.class); + Constructor cstrctr = objectiveClass.getConstructor(); + CustomObjective objective = cstrctr.newInstance(); + Optionaloo=getCustomObjective(objective.getClass().getName()); + if (oo.isPresent()) { + HandlerList.unregisterAll(oo.get()); + customObjectives.remove(oo.get()); + } + customObjectives.add(objective); + String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName(); + String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor(); + count++; + getLogger().info("Loaded Module: " + name + " by " + author); + try { + getServer().getPluginManager().registerEvents(objective, this); + getLogger().info("Registered events for custom objective \"" + name + "\""); + } catch (Exception ex) { + getLogger().warning("Failed to register events for custom objective \"" + name + + "\". Does the objective class listen for events?"); + ex.printStackTrace(); + } + } + } + if (count == 0) { + getLogger().severe("Unable to load module from file: " + jar.getName() + + ", jar file is not a valid module!"); + } + } catch (Exception e) { + getLogger().severe("Unable to load module from file: " + jar.getName()); + e.printStackTrace(); + } + } + + /** + * Show all of a player's objectives for the current stage of a quest.

+ * + * Respects PlaceholderAPI and translations, when enabled. + * + * @param quest The quest to get current stage objectives of + * @param quester The player to show current stage objectives to + * @param ignoreOverrides Whether to ignore objective-overrides + */ + @SuppressWarnings("deprecation") + public void showObjectives(Quest quest, Quester quester, boolean ignoreOverrides) { + if (quester.getQuestData(quest) == null) { + getLogger().warning("Quest data was null when showing objectives for " + quest.getName()); + return; + } + if (quester.getCurrentStage(quest) == null) { + getLogger().warning("Current stage was null when showing objectives for " + quest.getName()); + return; + } + if (!ignoreOverrides && !quester.getCurrentStage(quest).objectiveOverrides.isEmpty()) { + for (String s: quester.getCurrentStage(quest).objectiveOverrides) { + String message = ChatColor.GREEN + ConfigUtil.parseString( + ChatColor.translateAlternateColorCodes('&', s), quest, quester.getPlayer()); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + return; + } + QuestData data = quester.getQuestData(quest); + Stage stage = quester.getCurrentStage(quest); + for (ItemStack e : stage.blocksToBreak) { + for (ItemStack e2 : data.blocksBroken) { + if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { + ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "break") + " " + + color + ": " + e2.getAmount() + "/" + e.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); + } + } + } + } + for (ItemStack e : stage.blocksToDamage) { + for (ItemStack e2 : data.blocksDamaged) { + if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { + ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "damage") + " " + + color + ": " + e2.getAmount() + "/" + e.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); + } + } + } + } + for (ItemStack e : stage.blocksToPlace) { + for (ItemStack e2 : data.blocksPlaced) { + if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { + ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "place") + " " + + color + ": " + e2.getAmount() + "/" + e.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); + } + } + } + } + for (ItemStack e : stage.blocksToUse) { + for (ItemStack e2 : data.blocksUsed) { + if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { + ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "use") + " " + + color + ": " + e2.getAmount() + "/" + e.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); + } + } + } + } + for (ItemStack e : stage.blocksToCut) { + for (ItemStack e2 : data.blocksCut) { + if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { + ChatColor color = e2.getAmount() < e.getAmount() ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "cut") + " " + + color + ": " + e2.getAmount() + "/" + e.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !e.hasItemMeta() && !e.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getType(), e.getDurability(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(e))); + } + } + } + } + for (ItemStack is : stage.itemsToCraft) { + int crafted = 0; + if (data.itemsCrafted.containsKey(is)) { + crafted = data.itemsCrafted.get(is); + } + int amt = is.getAmount(); + ChatColor color = crafted < amt ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "craft") + " " + + color + ": " + crafted + "/" + is.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), + is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + for (ItemStack is : stage.itemsToSmelt) { + int smelted = 0; + if (data.itemsSmelted.containsKey(is)) { + smelted = data.itemsSmelted.get(is); + } + int amt = is.getAmount(); + ChatColor color = smelted < amt ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "smelt") + " " + + color + ": " + smelted + "/" + is.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), + is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + Map set; + Map set2; + Set enchantSet; + Set enchantSet2; + Collection matSet; + Enchantment enchantment = null; + Enchantment enchantment2 = null; + Material mat = null; + int num1; + int num2; + for (Entry, Integer> e : stage.itemsToEnchant.entrySet()) { + for (Entry, Integer> e2 : data.itemsEnchanted.entrySet()) { + set = e2.getKey(); + set2 = e.getKey(); + enchantSet = set.keySet(); + enchantSet2 = set2.keySet(); + for (Object o : enchantSet.toArray()) { + enchantment = (Enchantment) o; + } + for (Object o : enchantSet2.toArray()) { + enchantment2 = (Enchantment) o; + } + num1 = e2.getValue(); + num2 = e.getValue(); + matSet = set.values(); + for (Object o : matSet.toArray()) { + mat = (Material) o; + } + if (enchantment2 == enchantment) { + ChatColor color = num1 < num2 ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "enchantItem") + + color + ": " + num1 + "/" + num2; + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + Map enchs = new HashMap(); + enchs.put(enchantment, 1); + if (getSettings().canTranslateNames()) { + localeQuery.sendMessage(quester.getPlayer(), message, mat, (short) 0, enchs); + } else { + quester.getPlayer().sendMessage(message + .replace("", ItemUtil.getName(new ItemStack(mat))) + .replace("", enchantment.getName())); + } + } + } + } + for (ItemStack is : stage.itemsToBrew) { + int brewed = 0; + if (data.itemsBrewed.containsKey(is)) { + brewed = data.itemsBrewed.get(is); + } + int amt = is.getAmount(); + ChatColor color = brewed < amt ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "brew") + " " + + color + ": " + brewed + "/" + is.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames()) { + if (is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + // Bukkit version is 1.9+ + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), + is.getEnchantments(), is.getItemMeta()); + } else if (Material.getMaterial("LINGERING_POTION") == null && !is.hasItemMeta() ) { + // Bukkit version is below 1.9 + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), + is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + } + if (stage.cowsToMilk != null) { + ChatColor color = data.getCowsMilked() < stage.cowsToMilk ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "milkCow") + + color + ": " + data.getCowsMilked() + "/" + stage.cowsToMilk; + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + if (stage.fishToCatch != null) { + ChatColor color = data.getFishCaught() < stage.fishToCatch ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "catchFish") + + color + ": " + data.getFishCaught() + "/" + stage.fishToCatch; + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + for (EntityType e : stage.mobsToKill) { + for (EntityType e2 : data.mobsKilled) { + if (e == e2) { + if (data.mobNumKilled.size() > data.mobsKilled.indexOf(e2) + && stage.mobNumToKill.size() > stage.mobsToKill.indexOf(e)) { + ChatColor color = data.mobNumKilled.get(data.mobsKilled.indexOf(e2)) + < stage.mobNumToKill.get(stage.mobsToKill.indexOf(e)) + ? ChatColor.GREEN : ChatColor.GRAY; + String message = ""; + if (stage.locationsToKillWithin.isEmpty()) { + message = color + Lang.get(quester.getPlayer(), "kill") + " " + + ChatColor.AQUA + "" + color + ": " + + (data.mobNumKilled.get(data.mobsKilled.indexOf(e2))) + + "/" + (stage.mobNumToKill.get(stage.mobsToKill.indexOf(e))); + } else { + message = color + Lang.get(quester.getPlayer(), "killAtLocation") + color + ": " + + (data.mobNumKilled.get(data.mobsKilled.indexOf(e2))) + "/" + + (stage.mobNumToKill.get(stage.mobsToKill.indexOf(e))); + message = message.replace("", + stage.killNames.get(stage.mobsToKill.indexOf(e))); + } + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames()) { + localeQuery.sendMessage(quester.getPlayer(), message, e, null); + } else { + quester.getPlayer().sendMessage(message.replace("", MiscUtil.getProperMobName(e))); + } + } + } + } + } + if (stage.playersToKill != null) { + ChatColor color = data.getPlayersKilled() < stage.playersToKill ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "killPlayer") + + color + ": " + data.getPlayersKilled() + "/" + stage.playersToKill; + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + int index = 0; + for (ItemStack is : stage.itemsToDeliver) { + int delivered = 0; + if (data.itemsDelivered.size() > index) { + delivered = data.itemsDelivered.get(index).getAmount(); + } + int toDeliver = is.getAmount(); + Integer npc = stage.itemDeliveryTargets.get(index); + index++; + ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "deliver") + + color + ": " + delivered + "/" + toDeliver; + message = message.replace("", depends.getNPCName(npc)); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateNames() && !is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), + is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + for (Integer n : stage.citizensToInteract) { + for (Entry e : data.citizensInteracted.entrySet()) { + if (e.getKey().equals(n)) { + ChatColor color = e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "talkTo"); + message = message.replace("", depends.getNPCName(n)); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + } + } + for (Integer n : stage.citizensToKill) { + for (Integer n2 : data.citizensKilled) { + if (n.equals(n2)) { + if (data.citizenNumKilled.size() > data.citizensKilled.indexOf(n2) + && stage.citizenNumToKill.size() > stage.citizensToKill.indexOf(n)) { + ChatColor color = data.citizenNumKilled.get(data.citizensKilled.indexOf(n2)) + < stage.citizenNumToKill.get(stage.citizensToKill.indexOf(n)) == false + ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "kill") + " " + depends.getNPCName(n) + + color + " " + data.citizenNumKilled.get(stage.citizensToKill.indexOf(n)) + "/" + + stage.citizenNumToKill.get(stage.citizensToKill.indexOf(n)); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + quester.getPlayer().sendMessage(message); + } + } + } + } + for (Entry e : stage.mobsToTame.entrySet()) { + for (Entry e2 : data.mobsTamed.entrySet()) { + if (e.getKey().equals(e2.getKey())) { + ChatColor color = e2.getValue() < e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "tame") + " " + "" + + color + ": " + e2.getValue() + "/" + e.getValue(); + if (getSettings().canTranslateNames()) { + localeQuery.sendMessage(quester.getPlayer(), message, e.getKey(), null); + } else { + quester.getPlayer().sendMessage(message.replace("", + MiscUtil.getProperMobName(e.getKey()))); + } + } + } + } + for (Entry e : stage.sheepToShear.entrySet()) { + for (Entry e2 : data.sheepSheared.entrySet()) { + if (e.getKey().equals(e2.getKey())) { + ChatColor color = e2.getValue() < e.getValue() == false ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "shearSheep") + + color + ": " + e2.getValue() + "/" + e.getValue(); + message = message.replace("", e.getKey().name().toLowerCase()); + quester.getPlayer().sendMessage(message); + } + } + } + for (Location l : stage.locationsToReach) { + for (Location l2 : data.locationsReached) { + if (l.equals(l2)) { + if (!data.hasReached.isEmpty()) { + ChatColor color = data.hasReached.get(data.locationsReached.indexOf(l2)) == false + ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + Lang.get(quester.getPlayer(), "goTo"); + message = message.replace("", + stage.locationNames.get(stage.locationsToReach.indexOf(l))); + quester.getPlayer().sendMessage(message); + } + } + } + } + for (String s : stage.passwordDisplays) { + if (data.passwordsSaid.containsKey(s)) { + Boolean b = data.passwordsSaid.get(s); + ChatColor color = b != null && !b == false ? ChatColor.GREEN : ChatColor.GRAY; + String message = color + s; + quester.getPlayer().sendMessage(message); + } + } + for (CustomObjective co : stage.customObjectives) { + int countsIndex = 0; + String display = co.getDisplay(); + List unfinished = new LinkedList(); + List finished = new LinkedList(); + for (Entry entry : data.customObjectiveCounts.entrySet()) { + if (co.getName().equals(entry.getKey())) { + for (Entry prompt : co.getData()) { + String replacement = "%" + prompt.getKey() + "%"; + try { + for (Entry e : stage.customObjectiveData) { + if (e.getKey().equals(prompt.getKey())) { + if (display.contains(replacement)) { + display = display.replace(replacement, ((String) e.getValue())); + } + } + } + } catch (NullPointerException ne) { + getLogger().severe("Unable to fetch display for " + co.getName() + " on " + + quest.getName()); + ne.printStackTrace(); + } + } + if (entry.getValue() < stage.customObjectiveCounts.get(countsIndex)) { + if (co.canShowCount()) { + display = display.replace("%count%", entry.getValue() + "/" + + stage.customObjectiveCounts.get(countsIndex)); + } + unfinished.add(display); + } else { + if (co.canShowCount()) { + display = display.replace("%count%", stage.customObjectiveCounts.get(countsIndex) + + "/" + stage.customObjectiveCounts.get(countsIndex)); + } + finished.add(display); + } + } + countsIndex++; + } + for (String s : unfinished) { + quester.getPlayer().sendMessage(ChatColor.GREEN + s); + } + for (String s : finished) { + quester.getPlayer().sendMessage(ChatColor.GRAY + s); + } + } + } + + /** + * Show the player a list of their quests + * + * @param quester Quester to show the list + * @param page Page to display, with 7 quests per page + */ + public void listQuests(Quester quester, int page) { + // Although we could copy the quests list to a new object, we instead opt to + // duplicate code to improve efficiency if ignore-locked-quests is set to 'false' + int rows = 7; + Player player = quester.getPlayer(); + if (getSettings().canIgnoreLockedQuests()) { + LinkedList available = new LinkedList(); + for (Quest q : quests) { + if (quester.getCompletedQuests().contains(q.getName()) == false) { + if (q.testRequirements(player)) { + available.add(q); + } + } else if (q.getPlanner().hasCooldown() && quester.getCooldownDifference(q) < 0) { + if (q.testRequirements(player)) { + available.add(q); + } + } + } + if ((available.size() + rows) <= (page * rows) || available.size() == 0) { + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); + } else { + player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); + int fromOrder = (page - 1) * rows; + List subQuests; + if (available.size() >= (fromOrder + rows)) { + subQuests = available.subList((fromOrder), (fromOrder + rows)); + } else { + subQuests = available.subList((fromOrder), available.size()); + } + fromOrder++; + for (Quest q : subQuests) { + player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); + fromOrder++; + } + int numPages = (int) Math.ceil(((double) available.size()) / ((double) rows)); + String msg = Lang.get(player, "pageFooter"); + msg = msg.replace("", String.valueOf(page)); + msg = msg.replace("", String.valueOf(numPages)); + player.sendMessage(ChatColor.GOLD + msg); + } + } else { + if ((quests.size() + rows) <= (page * rows) || quests.size() == 0) { + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "pageNotExist")); + } else { + player.sendMessage(ChatColor.GOLD + Lang.get(player, "questListTitle")); + int fromOrder = (page - 1) * rows; + List subQuests; + if (quests.size() >= (fromOrder + rows)) { + subQuests = quests.subList((fromOrder), (fromOrder + rows)); + } else { + subQuests = quests.subList((fromOrder), quests.size()); + } + fromOrder++; + for (Quest q : subQuests) { + player.sendMessage(ChatColor.YELLOW + Integer.toString(fromOrder) + ". " + q.getName()); + fromOrder++; + } + int numPages = (int) Math.ceil(((double) quests.size()) / ((double) rows)); + String msg = Lang.get(player, "pageFooter"); + msg = msg.replace("", String.valueOf(page)); + msg = msg.replace("", String.valueOf(numPages)); + player.sendMessage(ChatColor.GOLD + msg); + } + } + } + + /** + * @deprecated Use {@link #reload(ReloadCallback)} + */ + public void reloadQuests() { + reload(null); + } + + /** + * Reload quests, actions, config settings, lang and modules, and player data + */ + public void reload(final ReloadCallback callback) { + reloadConfig(); + Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { + + @Override + public void run() { + loading = true; + try { + for (Quester quester : questers) { + quester.saveData(); + } + quests.clear(); + actions.clear(); + Lang.clear(); + settings.init(); + Lang.init(Quests.this); + loadQuests(); + loadActions(); + for (Quester quester : questers) { + quester.loadData(); + for (Quest q : quester.currentQuests.keySet()) { + quester.checkQuest(q); + } + } + loadModules(); + + if (callback != null) { + Bukkit.getScheduler().runTask(Quests.this, new Runnable() { + + @Override + public void run() { + callback.execute(true); + } + }); + } + } catch (Exception e) { + e.printStackTrace(); + if (callback != null) { + Bukkit.getScheduler().runTask(Quests.this, new Runnable() { + + @Override + public void run() { + callback.execute(false); + } + }); + } + } + loading = false; + } + }); + } + + /** + * Get Quester from player UUID + * + * @param id Player UUID + * @return Quester, or null if not found + */ + public Quester getQuester(UUID id) { + Quester quester = null; + for (Quester q: questers) { + if (q.getUUID().equals(id)) { + quester = q; + } + } + if (quester == null) { + quester = new Quester(this); + quester.setUUID(id); + if (depends.getCitizens() != null) { + if (depends.getCitizens().getNPCRegistry().getByUniqueId(id) != null) { + return quester; + } + } + questers.add(quester); + if (!quester.loadData()) { + questers.remove(quester); + } + } + return quester; + } + + /** + * Get a list of all online Questers + * + * @deprecated Use {@link Bukkit#getOnlinePlayers()} and then {@link #getQuester(UUID)} + * @return list of online Questers + */ + public LinkedList getOnlineQuesters() { + LinkedList qs = new LinkedList(); + for (Player p : getServer().getOnlinePlayers()) { + Quester quester = new Quester(this); + quester.setUUID(p.getUniqueId()); + if (quester.loadData() == false) { + quester.saveData(); + } + qs.add(quester); + // Workaround for issues with the compass on fast join + quester.findCompassTarget(); + } + return qs; + } + + /** + * Load quests from file + */ + public void loadQuests() { + boolean failedToLoad; + boolean needsSaving = false; + FileConfiguration config = null; + File file = new File(this.getDataFolder(), "quests.yml"); + try { + config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), "UTF-8")); + } catch (IOException e) { + e.printStackTrace(); + } + if (config != null) { + ConfigurationSection questsSection; + if (config.contains("quests")) { + questsSection = config.getConfigurationSection("quests"); + } else { + questsSection = config.createSection("quests"); + needsSaving = true; + } + if (questsSection == null) { + getLogger().severe("Missing \'quests\' section marker within quests.yml, canceled loading"); + return; + } + for (String questKey : questsSection.getKeys(false)) { + try { + Quest quest = new Quest(); + failedToLoad = false; + quest.id = questKey; + if (config.contains("quests." + questKey + ".name")) { + quest.setName(ConfigUtil.parseString(config.getString("quests." + questKey + ".name"), quest)); + } else { + throw new QuestFormatException("Quest block is missing", questKey); + } + if (depends.getCitizens() != null && config.contains("quests." + questKey + ".npc-giver-id")) { + if (CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey + ".npc-giver-id")) + != null) { + quest.npcStart = CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey + + ".npc-giver-id")); + questNpcs.add(CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questKey + + ".npc-giver-id"))); + } else { + throw new QuestFormatException("npc-giver-id has invalid NPC ID", questKey); + } + } + if (config.contains("quests." + questKey + ".block-start")) { + Location location = ConfigUtil.getLocation(config.getString("quests." + questKey + + ".block-start")); + if (location != null) { + quest.blockStart = location; + } else { + throw new QuestFormatException("block-start has invalid location format", questKey); + } + } + if (config.contains("quests." + questKey + ".region") + && getDependencies().getWorldGuardApi() != null) { + String region = config.getString("quests." + questKey + ".region"); + boolean exists = false; + for (World world : getServer().getWorlds()) { + if (getDependencies().getWorldGuardApi().getRegionManager(world) != null) { + if (getDependencies().getWorldGuardApi().getRegionManager(world).hasRegion(region)) { + quest.regionStart = region; + exists = true; + break; + } + } + } + if (!exists) { + throw new QuestFormatException("region has invalid WorldGuard region name", questKey); + } + } + if (config.contains("quests." + questKey + ".gui-display")) { + ItemStack stack = config.getItemStack("quests." + questKey + ".gui-display"); + if (stack == null) { + // Legacy + String item = config.getString("quests." + questKey + ".gui-display"); + try { + stack = ItemUtil.readItemStack(item); + } catch (Exception e) { + throw new QuestFormatException("items has invalid formatting for " + item, questKey); + } + } + if (stack != null) { + quest.guiDisplay = stack; + } else { + throw new QuestFormatException("gui-display has invalid item format", questKey); + } + } + if (config.contains("quests." + questKey + ".redo-delay")) { + // Legacy + if (config.getInt("quests." + questKey + ".redo-delay", -999) != -999) { + quest.getPlanner().setCooldown(config.getInt("quests." + questKey + ".redo-delay") * 1000); + } else { + throw new QuestFormatException("redo-delay is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".finish-message")) { + quest.finished = ConfigUtil.parseString(config.getString("quests." + questKey + + ".finish-message"), quest); + } else { + throw new QuestFormatException("finish-message is missing", questKey); + } + if (config.contains("quests." + questKey + ".ask-message")) { + quest.description = ConfigUtil.parseString(config.getString("quests." + questKey + + ".ask-message"), quest); + } else { + throw new QuestFormatException("ask-message is missing", questKey); + } + if (config.contains("quests." + questKey + ".action")) { + Action act = loadAction(config.getString("quests." + questKey + ".action")); + if (act != null) { + quest.initialAction = act; + } else { + throw new QuestFormatException("action failed to load", questKey); + } + } else if (config.contains("quests." + questKey + ".event")) { + Action action = null; + + action = loadAction(config.getString("quests." + questKey + ".event")); + if (action != null) { + quest.initialAction = action; + } else { + throw new QuestFormatException("action failed to load", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements")) { + loadQuestRequirements(config, questsSection, quest, questKey); + } + if (config.contains("quests." + questKey + ".planner")) { + loadQuestPlanner(config, questsSection, quest, questKey); + } + if (config.contains("quests." + questKey + ".options")) { + loadQuestOptions(config, questsSection, quest, questKey); + } + quest.plugin = this; + loadQuestStages(quest, config, questKey); + loadQuestRewards(config, quest, questKey); + quests.add(quest); + if (needsSaving) { + try { + config.save(file); + } catch (IOException e) { + getLogger().log(Level.SEVERE, "Failed to save Quest \"" + questKey + "\""); + e.printStackTrace(); + } + } + if (failedToLoad == true) { + getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping."); + } + } catch (QuestFormatException e) { + e.printStackTrace(); + continue; + } catch (StageFormatException e) { + e.printStackTrace(); + continue; + } catch (ActionFormatException e) { + e.printStackTrace(); + continue; + } + } + } else { + getLogger().severe("Unable to load quests.yml"); + } + } + + @SuppressWarnings("unchecked") + private void loadQuestRewards(FileConfiguration config, Quest quest, String questKey) throws QuestFormatException { + Rewards rews = quest.getRewards(); + if (config.contains("quests." + questKey + ".rewards.items")) { + LinkedList temp = new LinkedList(); + List stackList = (List) config.get("quests." + questKey + ".rewards.items"); + if (ConfigUtil.checkList(stackList, ItemStack.class)) { + for (ItemStack stack : stackList) { + if (stack != null) { + temp.add(stack); + } + } + } else { + // Legacy + if (ConfigUtil.checkList(stackList, String.class)) { + List items = config.getStringList("quests." + questKey + ".rewards.items"); + for (String item : items) { + try { + ItemStack stack = ItemUtil.readItemStack(item); + if (stack != null) { + temp.add(stack); + } + } catch (Exception e) { + throw new QuestFormatException("Reward items has invalid formatting for " + item, questKey); + } + } + } else { + throw new QuestFormatException("Reward items has invalid formatting", questKey); + } + } + rews.setItems(temp); + } + if (config.contains("quests." + questKey + ".rewards.money")) { + if (config.getInt("quests." + questKey + ".rewards.money", -999) != -999) { + rews.setMoney(config.getInt("quests." + questKey + ".rewards.money")); + } else { + throw new QuestFormatException("Reward money is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.exp")) { + if (config.getInt("quests." + questKey + ".rewards.exp", -999) != -999) { + rews.setExp(config.getInt("quests." + questKey + ".rewards.exp")); + } else { + throw new QuestFormatException("Reward exp is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.commands")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) { + rews.setCommands(config.getStringList("quests." + questKey + ".rewards.commands")); + } else { + throw new QuestFormatException("Reward commands is not a list of commands", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.commands-override-display")) { + // Legacy + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.commands-override-display"), + String.class)) { + rews.setCommandsOverrideDisplay(config.getStringList("quests." + questKey + + ".rewards.commands-override-display")); + } else { + throw new QuestFormatException("Reward commands-override-display is not a list of strings", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.permissions")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) { + rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions")); + } else { + throw new QuestFormatException("Reward permissions is not a list of permissions", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.permission-worlds")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + + ".rewards.permission-worlds"), String.class)) { + rews.setPermissionWorlds(config.getStringList("quests." + questKey + ".rewards.permission-worlds")); + } else { + throw new QuestFormatException("Reward permissions is not a list of worlds", questKey); + } + } + if (config.contains("quests." + questKey + ".rewards.quest-points")) { + if (config.getInt("quests." + questKey + ".rewards.quest-points", -999) != -999) { + rews.setQuestPoints(config.getInt("quests." + questKey + ".rewards.quest-points")); + } else { + throw new QuestFormatException("Reward quest-points is not a number", questKey); + } + } + if (depends.isPluginAvailable("mcMMO")) { + if (config.contains("quests." + questKey + ".rewards.mcmmo-skills")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.mcmmo-skills"), + String.class)) { + if (config.contains("quests." + questKey + ".rewards.mcmmo-levels")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.mcmmo-levels"), + Integer.class)) { + for (String skill : config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")) { + if (depends.getMcmmoClassic() == null) { + throw new QuestFormatException("Reward mcMMO not found for mcmmo-skills", questKey); + } else if (Quests.getMcMMOSkill(skill) == null) { + throw new QuestFormatException("Reward mcmmo-skills has invalid skill name " + skill, questKey); + } + } + rews.setMcmmoSkills(config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")); + rews.setMcmmoAmounts(config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels")); + } else { + throw new QuestFormatException("Reward mcmmo-levels is not a list of numbers", questKey); + } + } else { + throw new QuestFormatException("Reward mcmmo-levels is missing!", questKey); + } + } else { + throw new QuestFormatException("Reward mcmmo-skills is not a list of mcMMO skill names", questKey); + } + } + } + if (depends.isPluginAvailable("Heroes")) { + if (config.contains("quests." + questKey + ".rewards.heroes-exp-classes")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.heroes-exp-classes"), + String.class)) { + if (config.contains("quests." + questKey + ".rewards.heroes-exp-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.heroes-exp-amounts"), + Double.class)) { + for (String heroClass : config.getStringList("quests." + questKey + + ".rewards.heroes-exp-classes")) { + if (depends.getHeroes() == null) { + throw new QuestFormatException("Heroes not found for heroes-exp-classes", questKey); + } else if (depends.getHeroes().getClassManager().getClass(heroClass) == null) { + throw new QuestFormatException("Reward heroes-exp-classes has invalid class name " + + heroClass, questKey); + } + } + rews.setHeroesClasses(config.getStringList("quests." + questKey + + ".rewards.heroes-exp-classes")); + rews.setHeroesAmounts(config.getDoubleList("quests." + questKey + + ".rewards.heroes-exp-amounts")); + } else { + throw new QuestFormatException("Reward heroes-exp-amounts is not a list of decimal numbers", questKey); + } + } else { + throw new QuestFormatException("Reward heroes-exp-amounts is missing", questKey); + } + } else { + throw new QuestFormatException("Reward heroes-exp-classes is not a list of Heroes classes", questKey); + } + } + } + if (depends.isPluginAvailable("PhatLoots")) { + if (config.contains("quests." + questKey + ".rewards.phat-loots")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".rewards.phat-loots"), String.class)) { + for (String loot : config.getStringList("quests." + questKey + ".rewards.phat-loots")) { + if (depends.getPhatLoots() == null) { + throw new QuestFormatException("PhatLoots not found for phat-loots", questKey); + } else if (PhatLootsAPI.getPhatLoot(loot) == null) { + throw new QuestFormatException("Reward phat-loots has invalid PhatLoot name " + loot, questKey); + } + } + rews.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots")); + } else { + throw new QuestFormatException("Reward phat-loots is not a list of PhatLoots", questKey); + } + } + } + if (config.contains("quests." + questKey + ".rewards.details-override")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + + ".rewards.details-override"), String.class)) { + rews.setDetailsOverride(config.getStringList("quests." + questKey + ".rewards.details-override")); + } else { + throw new QuestFormatException("Reward details-override is not a list of strings", questKey); + } + } + } + + @SuppressWarnings("unchecked") + private void loadQuestRequirements(FileConfiguration config, ConfigurationSection questsSection, Quest quest, + String questKey) throws QuestFormatException { + Requirements reqs = quest.getRequirements(); + if (config.contains("quests." + questKey + ".requirements.fail-requirement-message")) { + Object o = config.get("quests." + questKey + ".requirements.fail-requirement-message"); + if (o instanceof List) { + reqs.setDetailsOverride(config.getStringList("quests." + questKey + + ".requirements.fail-requirement-message")); + } else { + // Legacy + List override = new LinkedList(); + override.add((String) o); + reqs.setDetailsOverride(override); + } + } + if (config.contains("quests." + questKey + ".requirements.items")) { + List temp = new LinkedList(); + List stackList = (List) config.get("quests." + questKey + ".requirements.items"); + if (ConfigUtil.checkList(stackList, ItemStack.class)) { + for (ItemStack stack : stackList) { + if (stack != null) { + temp.add(stack); + } + } + } else { + // Legacy + List items = config.getStringList("quests." + questKey + ".requirements.items"); + if (ConfigUtil.checkList(items, String.class)) { + for (String item : items) { + try { + ItemStack stack = ItemUtil.readItemStack(item); + if (stack != null) { + temp.add(stack); + } + } catch (Exception e) { + throw new QuestFormatException("Requirement items has invalid formatting for " + item, questKey); + } + } + } else { + throw new QuestFormatException("Requirement items has invalid formatting", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.remove-items")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.remove-items"), + Boolean.class)) { + reqs.setRemoveItems(config.getBooleanList("quests." + questKey + ".requirements.remove-items")); + } else { + throw new QuestFormatException("Requirement remove-items is not a list of true/false values", questKey); + } + } else { + throw new QuestFormatException("Requirement remove-items is missing", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.money")) { + if (config.getInt("quests." + questKey + ".requirements.money", -999) != -999) { + reqs.setMoney(config.getInt("quests." + questKey + ".requirements.money")); + } else { + throw new QuestFormatException("Requirement money is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.quest-points")) { + if (config.getInt("quests." + questKey + ".requirements.quest-points", -999) != -999) { + reqs.setQuestPoints(config.getInt("quests." + questKey + ".requirements.quest-points")); + } else { + throw new QuestFormatException("Requirement quest-points is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.quest-blocks")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quest-blocks"), + String.class)) { + List names = config.getStringList("quests." + questKey + ".requirements.quest-blocks"); + boolean failed = false; + String failedQuest = "NULL"; + List temp = new LinkedList(); + for (String name : names) { + boolean done = false; + for (String id : questsSection.getKeys(false)) { + String name2 = config.getString("quests." + id + ".name"); + if (name2.equalsIgnoreCase(name) + || ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name))) { + temp.add(name); + done = true; + break; + } + } + if (!done) { + failed = true; + failedQuest = name; + break; + } + } + reqs.setNeededQuests(temp); + if (failed) { + throw new QuestFormatException("Requirement quest-blocks has invalid quest name " + failedQuest, questKey); + } + } else { + throw new QuestFormatException("Requirement quest-blocks is not a list of quest names", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.quests")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.quests"), String.class)) { + List names = config.getStringList("quests." + questKey + ".requirements.quests"); + boolean failed = false; + String failedQuest = "NULL"; + List temp = new LinkedList(); + for (String name : names) { + boolean done = false; + for (String id : questsSection.getKeys(false)) { + String name2 = config.getString("quests." + id + ".name"); + if (name2.equalsIgnoreCase(name) + || ChatColor.stripColor(name2).equalsIgnoreCase(ChatColor.stripColor(name))) { + temp.add(name); + done = true; + break; + } + } + if (!done) { + failed = true; + failedQuest = name; + break; + } + } + reqs.setNeededQuests(temp); + if (failed) { + throw new QuestFormatException("Requirement quests has invalid quest name " + failedQuest, questKey); + } + } else { + throw new QuestFormatException("Requirement quests is not a list of quest names", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.permissions")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.permissions"), + String.class)) { + reqs.setPermissions(config.getStringList("quests." + questKey + ".requirements.permissions")); + } else { + throw new QuestFormatException("Requirement permissions is not a list of permissions", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.mcmmo-skills")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.mcmmo-skills"), + String.class)) { + if (config.contains("quests." + questKey + ".requirements.mcmmo-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".requirements.mcmmo-amounts"), + Integer.class)) { + List skills = config.getStringList("quests." + questKey + ".requirements.mcmmo-skills"); + List amounts = config.getIntegerList("quests." + questKey + + ".requirements.mcmmo-amounts"); + if (skills.size() != amounts.size()) { + throw new QuestFormatException("Requirement mcmmo-skills: and mcmmo-amounts are not the same size", + questKey); + } + reqs.setMcmmoSkills(skills); + reqs.setMcmmoAmounts(amounts); + } else { + throw new QuestFormatException("Requirement mcmmo-amounts is not a list of numbers", questKey); + } + } else { + throw new QuestFormatException("Requirement mcmmo-amounts is missing", questKey); + } + } else { + throw new QuestFormatException("Requirement mcmmo-skills is not a list of skills", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.heroes-primary-class")) { + String className = config.getString("quests." + questKey + ".requirements.heroes-primary-class"); + HeroClass hc = depends.getHeroes().getClassManager().getClass(className); + if (hc != null && hc.isPrimary()) { + reqs.setHeroesPrimaryClass(hc.getName()); + } else if (hc != null) { + throw new QuestFormatException("Requirement heroes-primary-class is not a primary Heroes class", questKey); + } else { + throw new QuestFormatException("Requirement heroes-primary-class has invalid Heroes class", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.heroes-secondary-class")) { + String className = config.getString("quests." + questKey + ".requirements.heroes-secondary-class"); + HeroClass hc = depends.getHeroes().getClassManager().getClass(className); + if (hc != null && hc.isSecondary()) { + reqs.setHeroesSecondaryClass(hc.getName()); + } else if (hc != null) { + throw new QuestFormatException("Requirement heroes-secondary-class is not a secondary Heroes class", questKey); + } else { + throw new QuestFormatException("Requirement heroes-secondary-class has invalid Heroes class", questKey); + } + } + if (config.contains("quests." + questKey + ".requirements.details-override")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + + ".requirements.details-override"), String.class)) { + reqs.setDetailsOverride(config.getStringList("quests." + questKey + ".requirements.details-override")); + } else { + throw new QuestFormatException("Requirement details-override is not a list of strings", questKey); + } + } + } + + private void loadQuestPlanner(FileConfiguration config, ConfigurationSection questsSection, Quest quest, + String questKey) throws QuestFormatException { + Planner pln = quest.getPlanner(); + if (config.contains("quests." + questKey + ".planner.start")) { + pln.setStart(config.getString("quests." + questKey + ".planner.start")); + } + if (config.contains("quests." + questKey + ".planner.end")) { + pln.setEnd(config.getString("quests." + questKey + ".planner.end")); + } + if (config.contains("quests." + questKey + ".planner.repeat")) { + if (config.getInt("quests." + questKey + ".planner.repeat", -999) != -999) { + pln.setRepeat(config.getInt("quests." + questKey + ".planner.repeat") * 1000); + } else { + throw new QuestFormatException("Requirement repeat is not a number", questKey); + } + } + if (config.contains("quests." + questKey + ".planner.cooldown")) { + if (config.getInt("quests." + questKey + ".planner.cooldown", -999) != -999) { + pln.setCooldown(config.getInt("quests." + questKey + ".planner.cooldown") * 1000); + } else { + throw new QuestFormatException("Requirement cooldown is not a number", questKey); + } + } + } + + private void loadQuestOptions(FileConfiguration config, ConfigurationSection questsSection, Quest quest, + String questKey) throws QuestFormatException { + Options opts = quest.getOptions(); + if (config.contains("quests." + questKey + ".options.allow-commands")) { + opts.setAllowCommands(config.getBoolean("quests." + questKey + ".options.allow-commands")); + } + if (config.contains("quests." + questKey + ".options.allow-quitting")) { + opts.setAllowQuitting(config.getBoolean("quests." + questKey + ".options.allow-quitting")); + } else if (getConfig().contains("allow-quitting")) { + // Legacy + opts.setAllowQuitting(getConfig().getBoolean("allow-quitting")); + } + if (config.contains("quests." + questKey + ".options.use-dungeonsxl-plugin")) { + opts.setUseDungeonsXLPlugin(config.getBoolean("quests." + questKey + ".options.use-dungeonsxl-plugin")); + } + if (config.contains("quests." + questKey + ".options.use-parties-plugin")) { + opts.setUsePartiesPlugin(config.getBoolean("quests." + questKey + ".options.use-parties-plugin")); + } + if (config.contains("quests." + questKey + ".options.share-progress-level")) { + opts.setShareProgressLevel(config.getInt("quests." + questKey + ".options.share-progress-level")); + } + if (config.contains("quests." + questKey + ".options.require-same-quest")) { + opts.setRequireSameQuest(config.getBoolean("quests." + questKey + ".options.require-same-quest")); + } + } + + @SuppressWarnings({ "unchecked", "unused" }) + private void loadQuestStages(Quest quest, FileConfiguration config, String questKey) + throws StageFormatException, ActionFormatException { + ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered"); + for (String stage : questStages.getKeys(false)) { + int stageNum = 0; + try { + stageNum = Integer.valueOf(stage); + } catch (NumberFormatException e) { + getLogger().severe("Stage key " + stage + "must be a number!"); + continue; + } + Stage oStage = new Stage(); + List breakNames = new LinkedList(); + List breakAmounts = new LinkedList(); + List breakDurability = new LinkedList(); + List damageNames = new LinkedList(); + List damageAmounts = new LinkedList(); + List damageDurability = new LinkedList(); + List placeNames = new LinkedList(); + List placeAmounts = new LinkedList(); + List placeDurability = new LinkedList(); + List useNames = new LinkedList(); + List useAmounts = new LinkedList(); + List useDurability = new LinkedList(); + List cutNames = new LinkedList(); + List cutAmounts = new LinkedList(); + List cutDurability = new LinkedList(); + List mobsToKill = new LinkedList(); + List mobNumToKill = new LinkedList(); + List locationsToKillWithin = new LinkedList(); + List radiiToKillWithin = new LinkedList(); + List areaNames = new LinkedList(); + List itemsToCraft = new LinkedList(); + List itemsToSmelt = new LinkedList(); + List enchantments = new LinkedList(); + List itemsToEnchant = new LinkedList(); + List amountsToEnchant = new LinkedList(); + List itemsToBrew = new LinkedList(); + List npcIdsToTalkTo = new LinkedList(); + List itemsToDeliver= new LinkedList(); + List itemDeliveryTargetIds = new LinkedList(); + List deliveryMessages = new LinkedList(); + List npcIdsToKill = new LinkedList(); + List npcAmountsToKill = new LinkedList(); + // Legacy Denizen script load + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".script-to-run")) { + if (getDependencies().getDenizenAPI().containsScript(config.getString("quests." + questKey + + ".stages.ordered." + stageNum + ".script-to-run"))) { + oStage.script = config.getString("quests." + questKey + ".stages.ordered." + stageNum + ".script-to-run"); + } else { + throw new StageFormatException("script-to-run is not a valid Denizen script", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-names"), String.class)) { + breakNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-names"); + } else { + throw new StageFormatException("break-block-names is not a list of strings", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-amounts"), Integer.class)) { + breakAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-amounts"); + } else { + throw new StageFormatException("break-block-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("break-block-amounts is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".break-block-durability")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-durability"), Integer.class)) { + breakDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum + + ".break-block-durability"); + } else { + throw new StageFormatException("break-block-durability is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("break-block-durability is missing", quest, stageNum); + } + } + int breakIndex = 0; + for (String s : breakNames) { + ItemStack is; + if (breakDurability.get(breakIndex) != -1) { + is = ItemUtil.processItemStack(s, breakAmounts.get(breakIndex), breakDurability.get(breakIndex)); + } else { + // Legacy + is = ItemUtil.processItemStack(s, breakAmounts.get(breakIndex), (short) 0); + } + if (Material.matchMaterial(s) != null) { + oStage.blocksToBreak.add(is); + } else { + throw new StageFormatException("break-block-names has invalid item name " + s, quest, stageNum); + } + breakIndex++; + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-names"), String.class)) { + damageNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-names"); + } else { + throw new StageFormatException("damage-block-names is not a list of strings", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-amounts"), Integer.class)) { + damageAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-amounts"); + } else { + throw new StageFormatException("damage-block-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("damage-block-amounts is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".damage-block-durability")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-durability"), Integer.class)) { + damageDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum + + ".damage-block-durability"); + } else { + throw new StageFormatException("damage-block-durability is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("damage-block-durability is missing", quest, stageNum); + } + } + int damageIndex = 0; + for (String s : damageNames) { + ItemStack is; + if (damageDurability.get(damageIndex) != -1) { + is = ItemUtil.processItemStack(s, damageAmounts.get(damageIndex), + damageDurability.get(damageIndex)); + } else { + // Legacy + is = ItemUtil.processItemStack(s, damageAmounts.get(damageIndex), (short) 0); + } + if (Material.matchMaterial(s) != null) { + oStage.blocksToDamage.add(is); + } else { + throw new StageFormatException("damage-block-names has invalid item name " + s, quest, stageNum); + } + damageIndex++; + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-names"), String.class)) { + placeNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-names"); + } else { + throw new StageFormatException("place-block-names is not a list of strings", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-amounts"), Integer.class)) { + placeAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-amounts"); + } else { + throw new StageFormatException("place-block-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("place-block-amounts is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".place-block-durability")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-durability"), Integer.class)) { + placeDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum + + ".place-block-durability"); + } else { + throw new StageFormatException("place-block-durability is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("place-block-durability is missing", quest, stageNum); + } + } + int placeIndex = 0; + for (String s : placeNames) { + ItemStack is; + if (placeDurability.get(placeIndex) != -1) { + is = ItemUtil.processItemStack(s, placeAmounts.get(placeIndex), placeDurability.get(placeIndex)); + } else { + // Legacy + is = ItemUtil.processItemStack(s, placeAmounts.get(placeIndex), (short) 0); + } + if (Material.matchMaterial(s) != null) { + oStage.blocksToPlace.add(is); + } else { + throw new StageFormatException("place-block-names has invalid item name " + s, quest, stageNum); + } + placeIndex++; + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-names"), String.class)) { + useNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-names"); + } else { + throw new StageFormatException("use-block-names is not a list of strings", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-amounts"),Integer.class)) { + useAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-amounts"); + } else { + throw new StageFormatException("use-block-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("use-block-amounts is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".use-block-durability")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-durability"), Integer.class)) { + useDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum + + ".use-block-durability"); + } else { + throw new StageFormatException("use-block-durability is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("use-block-durability is missing", quest, stageNum); + } + } + int useIndex = 0; + for (String s : useNames) { + ItemStack is; + if (useDurability.get(useIndex) != -1) { + is = ItemUtil.processItemStack(s, useAmounts.get(useIndex), useDurability.get(useIndex)); + } else { + // Legacy + is = ItemUtil.processItemStack(s, useAmounts.get(useIndex), (short) 0); + } + if (Material.matchMaterial(s) != null) { + oStage.blocksToUse.add(is); + } else { + throw new StageFormatException("use-block-names has invalid item name " + s, quest, stageNum); + } + useIndex++; + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-names"), String.class)) { + cutNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-names"); + } else { + throw new StageFormatException("cut-block-names is not a list of strings", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-amounts"), Integer.class)) { + cutAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-amounts"); + } else { + throw new StageFormatException("cut-block-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("cut-block-amounts is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cut-block-durability")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-durability"), Integer.class)) { + cutDurability = config.getShortList("quests." + questKey + ".stages.ordered." + stageNum + + ".cut-block-durability"); + } else { + throw new StageFormatException("cut-block-durability is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("cut-block-durability is missing", quest, stageNum); + } + } + int cutIndex = 0; + for (String s : cutNames) { + ItemStack is; + if (cutDurability.get(cutIndex) != -1) { + is = ItemUtil.processItemStack(s, cutAmounts.get(cutIndex), cutDurability.get(cutIndex)); + } else { + // Legacy + is = ItemUtil.processItemStack(s, cutAmounts.get(cutIndex), (short) 0); + } + if (Material.matchMaterial(s) != null) { + oStage.blocksToCut.add(is); + } else { + throw new StageFormatException("cut-block-names has invalid item name " + s, quest, stageNum); + } + cutIndex++; + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-craft")) { + itemsToCraft = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-craft"); + if (ConfigUtil.checkList(itemsToCraft, ItemStack.class)) { + for (ItemStack stack : itemsToCraft) { + if (stack != null) { + oStage.itemsToCraft.add(stack); + } else { + throw new StageFormatException("items-to-craft has invalid formatting " + stack, quest, stageNum); + } + } + } else { + // Legacy + List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-craft"); + if (ConfigUtil.checkList(items, String.class)) { + for (String item : items) { + ItemStack is = ItemUtil.readItemStack("" + item); + if (is != null) { + oStage.itemsToCraft.add(is); + } else { + throw new StageFormatException("Legacy items-to-craft has invalid formatting " + item, quest, stageNum); + } + } + } else { + throw new StageFormatException("items-to-craft is not formatted properly", quest, stageNum); + } + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-smelt")) { + itemsToSmelt = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-smelt"); + if (ConfigUtil.checkList(itemsToSmelt, ItemStack.class)) { + for (ItemStack stack : itemsToSmelt) { + if (stack != null) { + oStage.itemsToSmelt.add(stack); + } else { + throw new StageFormatException("items-to-smelt has invalid formatting " + stack, quest, stageNum); + } + } + } else { + // Legacy + List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-smelt"); + if (ConfigUtil.checkList(items, String.class)) { + for (String item : items) { + ItemStack is = ItemUtil.readItemStack("" + item); + if (is != null) { + oStage.itemsToSmelt.add(is); + } else { + throw new StageFormatException("Legacy items-to-smelt has invalid formatting " + item, quest, stageNum); + } + } + } else { + throw new StageFormatException("items-to-smelt is not formatted properly", quest, stageNum); + } + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantments")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantments"), String.class)) { + for (String enchant : config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantments")) { + Enchantment e = ItemUtil.getEnchantmentFromProperName(enchant); + if (e != null) { + enchantments.add(e); + } else { + throw new StageFormatException("enchantments has invalid enchantment " + enchant, quest, stageNum); + } + } + } else { + throw new StageFormatException("enchantments is not a list of enchantment names", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantment-item-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantment-item-names"), String.class)) { + for (String item : config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantment-item-names")) { + if (Material.matchMaterial(item) != null) { + itemsToEnchant.add(Material.matchMaterial(item)); + } else { + throw new StageFormatException("enchantment-item-names has invalid item name " + item, quest, stageNum); + } + } + } else { + throw new StageFormatException("enchantment-item-names has invalid item name", quest, stageNum); + } + } else { + throw new StageFormatException("enchantment-item-names is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantment-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantment-amounts"), Integer.class)) { + amountsToEnchant = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".enchantment-amounts"); + } else { + throw new StageFormatException("enchantment-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("enchantment-amounts is missing", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-brew")) { + itemsToBrew = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-brew"); + if (ConfigUtil.checkList(itemsToBrew, ItemStack.class)) { + for (ItemStack stack : itemsToBrew) { + if (stack != null) { + oStage.itemsToBrew.add(stack); + } else { + throw new StageFormatException("items-to-brew has invalid formatting " + stack, quest, stageNum); + } + } + } else { + // Legacy + List items = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".items-to-brew"); + if (ConfigUtil.checkList(items, String.class)) { + for (String item : items) { + ItemStack is = ItemUtil.readItemStack("" + item); + if (is != null) { + oStage.itemsToBrew.add(is); + } else { + throw new StageFormatException("Legacy items-to-brew has invalid formatting " + item, quest, stageNum); + } + } + } else { + throw new StageFormatException("items-to-brew has invalid formatting", quest, stageNum); + } + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk")) { + if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".cows-to-milk", -999) != -999) { + oStage.cowsToMilk = config.getInt("quests." + questKey + ".stages.ordered." + stageNum + + ".cows-to-milk"); + } else { + throw new StageFormatException("cows-to-milk is not a number", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch")) { + if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".fish-to-catch", -999) != -999) { + oStage.fishToCatch = config.getInt("quests." + questKey + ".stages.ordered." + stageNum + + ".fish-to-catch"); + } else { + throw new StageFormatException("fish-to-catch is not a number", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".players-to-kill")) { + if (config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".players-to-kill", -999) != -999) { + oStage.playersToKill = config.getInt("quests." + questKey + ".stages.ordered." + stageNum + + ".players-to-kill"); + } else { + throw new StageFormatException("players-to-kill is not a number", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-talk-to"), Integer.class)) { + npcIdsToTalkTo = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-talk-to"); + for (int i : npcIdsToTalkTo) { + if (getDependencies().getCitizens() != null) { + if (CitizensAPI.getNPCRegistry().getById(i) != null) { + questNpcs.add(CitizensAPI.getNPCRegistry().getById(i)); + } else { + throw new StageFormatException("npc-ids-to-talk-to has invalid NPC ID of " + i, quest, stageNum); + } + } else { + throw new StageFormatException("Citizens not found for npc-ids-to-talk-to", quest, stageNum); + } + + } + } else { + throw new StageFormatException("npc-ids-to-talk-to is not a list of numbers", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-deliver")) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-delivery-ids")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-delivery-ids"), Integer.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delivery-messages")) { + itemsToDeliver = (List) config.get("quests." + questKey + ".stages.ordered." + + stageNum + ".items-to-deliver"); + itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." + + stageNum + ".npc-delivery-ids"); + deliveryMessages.addAll(config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".delivery-messages")); + int index = 0; + if (ConfigUtil.checkList(itemsToDeliver, ItemStack.class)) { + for (ItemStack stack : itemsToDeliver) { + if (stack != null) { + int npcId = itemDeliveryTargetIds.get(index); + index++; + if (stack != null) { + if (getDependencies().getCitizens() != null) { + NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); + if (npc != null) { + oStage.itemsToDeliver.add(stack); + oStage.itemDeliveryTargets.add(npcId); + oStage.deliverMessages.addAll(deliveryMessages); + } else { + throw new StageFormatException("Citizens not found for npc-delivery-ids", quest, stageNum); + } + } else { + throw new StageFormatException("npc-delivery-ids has invalid NPC ID of " + npcId, quest, stageNum); + } + } else { + throw new StageFormatException("items-to-deliver has invalid formatting " + stack, quest, stageNum); + } + } + } + } else { + List items = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".items-to-deliver"); + if (ConfigUtil.checkList(items, String.class)) { + // Legacy + for (String item : items) { + ItemStack is = ItemUtil.readItemStack("" + item); + int npcId = itemDeliveryTargetIds.get(index); + index++; + if (is != null) { + if (getDependencies().getCitizens() != null) { + NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); + if (npc != null) { + oStage.itemsToDeliver.add(is); + oStage.itemDeliveryTargets.add(npcId); + oStage.deliverMessages.addAll(deliveryMessages); + } else { + throw new StageFormatException("npc-delivery-ids has invalid NPC ID of " + npcId, quest, stageNum); + } + } else { + throw new StageFormatException("Citizens was not found installed for npc-delivery-ids", quest, stageNum); + } + } else { + throw new StageFormatException("items-to-deliver has invalid formatting " + item, quest, stageNum); + } + } + } else { + throw new StageFormatException("items-to-deliver has invalid formatting", quest, stageNum); + } + } + } + } else { + throw new StageFormatException("npc-delivery-ids is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("npc-delivery-id is missing", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-kill")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-kill"), Integer.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-kill-amounts"), Integer.class)) { + npcIdsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-kill"); + npcAmountsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-kill-amounts"); + for (int i : npcIdsToKill) { + if (CitizensAPI.getNPCRegistry().getById(i) != null) { + if (npcAmountsToKill.get(npcIdsToKill.indexOf(i)) > 0) { + oStage.citizensToKill.add(i); + oStage.citizenNumToKill.add(npcAmountsToKill.get(npcIdsToKill.indexOf(i))); + questNpcs.add(CitizensAPI.getNPCRegistry().getById(i)); + } else { + throw new StageFormatException("npc-kill-amounts is not a positive number", quest, stageNum); + } + } else { + throw new StageFormatException("npc-ids-to-kill has invalid NPC ID of " + i, quest, stageNum); + } + } + } else { + throw new StageFormatException("npc-kill-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("npc-kill-amounts is missing", quest, stageNum); + } + } else { + throw new StageFormatException("npc-ids-to-kill is not a list of numbers", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mobs-to-kill")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".mobs-to-kill"), String.class)) { + List mobNames = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".mobs-to-kill"); + for (String mob : mobNames) { + EntityType type = MiscUtil.getProperMobType(mob); + if (type != null) { + mobsToKill.add(type); + } else { + throw new StageFormatException("mobs-to-kill has invalid mob name " + mob, quest, stageNum); + } + } + } else { + throw new StageFormatException("mobs-to-kill is not a list of mob names", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mob-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".mob-amounts"), Integer.class)) { + for (int i : config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".mob-amounts")) { + mobNumToKill.add(i); + } + } else { + throw new StageFormatException("mob-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("mob-amounts is missing", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".locations-to-kill")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".locations-to-kill"), String.class)) { + List locations = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".locations-to-kill"); + for (String loc : locations) { + if (ConfigUtil.getLocation(loc) != null) { + locationsToKillWithin.add(ConfigUtil.getLocation(loc)); + } else { + throw new StageFormatException("locations-to-kill has invalid formatting " + loc, quest, stageNum); + } + } + } else { + throw new StageFormatException("locations-to-kill is not a list of locations", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".kill-location-radii")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".kill-location-radii"), Integer.class)) { + List radii = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".kill-location-radii"); + for (int i : radii) { + radiiToKillWithin.add(i); + } + } else { + throw new StageFormatException("kill-location-radii is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("kill-location-radii is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".kill-location-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".kill-location-names"), String.class)) { + List locationNames = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".kill-location-names"); + for (String name : locationNames) { + areaNames.add(name); + } + } else { + throw new StageFormatException("kill-location-names is not a list of names", quest, stageNum); + } + } else { + throw new StageFormatException("kill-location-names is missing", quest, stageNum); + } + } + oStage.mobsToKill.addAll(mobsToKill); + oStage.mobNumToKill.addAll(mobNumToKill); + oStage.locationsToKillWithin.addAll(locationsToKillWithin); + oStage.radiiToKillWithin.addAll(radiiToKillWithin); + oStage.killNames.addAll(areaNames); + Map, Integer> enchants = new HashMap, Integer>(); + for (Enchantment e : enchantments) { + Map map = new HashMap(); + map.put(e, itemsToEnchant.get(enchantments.indexOf(e))); + enchants.put(map, amountsToEnchant.get(enchantments.indexOf(e))); + } + oStage.itemsToEnchant = enchants; + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".locations-to-reach")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".locations-to-reach"), String.class)) { + List locations = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".locations-to-reach"); + for (String loc : locations) { + if (ConfigUtil.getLocation(loc) != null) { + oStage.locationsToReach.add(ConfigUtil.getLocation(loc)); + } else { + throw new StageFormatException("locations-to-reach has invalid formatting" + loc, quest, stageNum); + } + } + } else { + throw new StageFormatException("locations-to-reach is not a list of locations", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".reach-location-radii")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".reach-location-radii"), Integer.class)) { + List radii = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".reach-location-radii"); + for (int i : radii) { + oStage.radiiToReachWithin.add(i); + } + } else { + throw new StageFormatException("reach-location-radii is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("reach-location-radii is missing", quest, stageNum); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".reach-location-names")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".reach-location-names"), String.class)) { + List locationNames = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".reach-location-names"); + for (String name : locationNames) { + oStage.locationNames.add(name); + } + } else { + throw new StageFormatException("reach-location-names is not a list of names", quest, stageNum); + } + } else { + throw new StageFormatException("reach-location-names is missing", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mobs-to-tame")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".mobs-to-tame"), String.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mob-tame-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".mob-tame-amounts"), Integer.class)) { + List mobs = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".mobs-to-tame"); + List mobAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + + stageNum + ".mob-tame-amounts"); + for (String mob : mobs) { + if (Tameable.class.isAssignableFrom(EntityType.valueOf(mob.toUpperCase()) + .getEntityClass())) { + oStage.mobsToTame.put(EntityType.valueOf(mob.toUpperCase()), + mobAmounts.get(mobs.indexOf(mob))); + } else { + throw new StageFormatException("mobs-to-tame has invalid tameable mob " + mob, quest, stageNum); + } + } + } else { + throw new StageFormatException("mob-tame-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("mob-tame-amounts is missing", quest, stageNum); + } + } else { + throw new StageFormatException("mobs-to-tame is not a list of mob names", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".sheep-to-shear")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".sheep-to-shear"), String.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".sheep-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".sheep-amounts"), Integer.class)) { + List sheep = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".sheep-to-shear"); + List shearAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." + + stageNum + ".sheep-amounts"); + for (String color : sheep) { + DyeColor dc = MiscUtil.getProperDyeColor(color); + try { + if (dc == null) { + dc = DyeColor.valueOf(color.toUpperCase()); + } + } catch (IllegalArgumentException e) { + // Fail silently + } + if (dc != null) { + oStage.sheepToShear.put(dc, shearAmounts.get(sheep.indexOf(color))); + // Legacy start --> + } else if (color.equalsIgnoreCase(Lang.get("COLOR_BLACK"))) { + oStage.sheepToShear.put(DyeColor.BLACK, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_BLUE"))) { + oStage.sheepToShear.put(DyeColor.BLUE, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_BROWN"))) { + oStage.sheepToShear.put(DyeColor.BROWN, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_CYAN"))) { + oStage.sheepToShear.put(DyeColor.CYAN, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_GRAY"))) { + oStage.sheepToShear.put(DyeColor.GRAY, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_GREEN"))) { + oStage.sheepToShear.put(DyeColor.GREEN, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_LIGHT_BLUE"))) { + oStage.sheepToShear.put(DyeColor.LIGHT_BLUE, + shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_LIME"))) { + oStage.sheepToShear.put(DyeColor.LIME, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_MAGENTA"))) { + oStage.sheepToShear.put(DyeColor.MAGENTA, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_ORANGE"))) { + oStage.sheepToShear.put(DyeColor.ORANGE, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_PINK"))) { + oStage.sheepToShear.put(DyeColor.PINK, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_PURPLE"))) { + oStage.sheepToShear.put(DyeColor.PURPLE, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_RED"))) { + oStage.sheepToShear.put(DyeColor.RED, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_SILVER"))) { + // 1.13 changed DyeColor.SILVER -> DyeColor.LIGHT_GRAY + oStage.sheepToShear.put(DyeColor.getByColor(Color.SILVER), + shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_WHITE"))) { + oStage.sheepToShear.put(DyeColor.WHITE, shearAmounts.get(sheep.indexOf(color))); + } else if (color.equalsIgnoreCase(Lang.get("COLOR_YELLOW"))) { + oStage.sheepToShear.put(DyeColor.YELLOW, shearAmounts.get(sheep.indexOf(color))); + // <-- Legacy end + } else { + throw new StageFormatException("sheep-to-shear has invalid color " + color, quest, stageNum); + } + } + } else { + throw new StageFormatException("sheep-amounts is not a list of numbers", quest, stageNum); + } + } else { + throw new StageFormatException("sheep-amounts is missing", quest, stageNum); + } + } else { + throw new StageFormatException("sheep-to-shear is not a list of colors", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".password-displays")) { + List displays = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".password-displays"); + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".password-phrases")) { + List phrases = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".password-phrases"); + if (displays.size() == phrases.size()) { + for (int passIndex = 0; passIndex < displays.size(); passIndex++) { + oStage.passwordDisplays.add(displays.get(passIndex)); + LinkedList answers = new LinkedList(); + answers.addAll(Arrays.asList(phrases.get(passIndex).split("\\|"))); + oStage.passwordPhrases.add(answers); + } + } else { + throw new StageFormatException("password-displays and password-phrases are not the same size", quest, + stageNum); + } + } else { + throw new StageFormatException("password-phrases is missing", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".objective-override")) { + Object o = config.get("quests." + questKey + ".stages.ordered." + stageNum + + ".objective-override"); + if (o instanceof List) { + oStage.objectiveOverrides.addAll(config.getStringList("quests." + questKey + + ".stages.ordered." + stageNum + ".objective-override")); + } else { + // Legacy + String s = config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".objective-override"); + oStage.objectiveOverrides.add(s); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".start-event")) { + Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".start-event")); + if (action != null) { + oStage.startAction = action; + } else { + throw new StageFormatException("start-event failed to load", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".finish-event")) { + Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".finish-event")); + if (action != null) { + oStage.finishAction = action; + } else { + throw new StageFormatException("finish-event failed to load", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".death-event")) { + Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".death-event")); + if (action != null) { + oStage.deathAction = action; + } else { + throw new StageFormatException("death-event failed to load", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".disconnect-event")) { + Action action = loadAction(config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".disconnect-event")); + if (action != null) { + oStage.disconnectAction = action; + } else { + throw new StageFormatException("disconnect-event failed to load", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".chat-events")) { + if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".chat-events")) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".chat-event-triggers")) { + if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".chat-event-triggers")) { + List chatEvents = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".chat-events"); + List chatEventTriggers = config.getStringList("quests." + questKey + + ".stages.ordered." + stageNum + ".chat-event-triggers"); + boolean loadEventFailed = false; + for (int i = 0; i < chatEvents.size(); i++) { + Action action = loadAction(chatEvents.get(i)); + if (action != null) { + oStage.chatActions.put(chatEventTriggers.get(i), action); + } else { + loadEventFailed = true; + throw new StageFormatException("chat-events failed to load " + chatEvents.get(i), quest, stageNum); + } + } + if (loadEventFailed) { + break; + } + } else { + throw new StageFormatException("chat-event-triggers is not in list format", quest, stageNum); + } + } else { + throw new StageFormatException("chat-event-triggers is missing", quest, stageNum); + } + } else { + throw new StageFormatException("chat-events is not in list format", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".command-events")) { + if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".command-events")) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".command-event-triggers")) { + if (config.isList("quests." + questKey + ".stages.ordered." + stageNum + ".command-event-triggers")) { + List commandEvents = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".command-events"); + List commandEventTriggers = config.getStringList("quests." + questKey + + ".stages.ordered." + stageNum + ".command-event-triggers"); + boolean loadEventFailed = false; + for (int i = 0; i < commandEvents.size(); i++) { + Action action = loadAction(commandEvents.get(i)); + if (action != null) { + oStage.commandActions.put(commandEventTriggers.get(i), action); + } else { + loadEventFailed = true; + throw new StageFormatException("command-events failed to load " + commandEvents.get(i), quest, stageNum); + } + } + if (loadEventFailed) { + break; + } + } else { + throw new StageFormatException("command-event-triggers is not in list format", quest, stageNum); + } + } else { + throw new StageFormatException("command-event-triggers is missing", quest, stageNum); + } + } else { + throw new StageFormatException("command-events is not in list format", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delay")) { + if (config.getLong("quests." + questKey + ".stages.ordered." + stageNum + ".delay", -999) != -999) { + oStage.delay = config.getInt("quests." + questKey + ".stages.ordered." + stageNum + ".delay") * 1000; + } else { + throw new StageFormatException("delay is not a number", quest, stageNum); + } + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delay-message")) { + oStage.delayMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".delay-message"); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".start-message")) { + oStage.startMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".start-message"); + } + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".complete-message")) { + oStage.completeMessage = config.getString("quests." + questKey + ".stages.ordered." + stageNum + + ".complete-message"); + } + LinkedList ids = new LinkedList(); + if (npcIdsToTalkTo != null) { + ids.addAll(npcIdsToTalkTo); + } + oStage.citizensToInteract = ids; + quest.getStages().add(oStage); + } + } + + protected Action loadAction(String name) throws ActionFormatException { + if (name == null) { + return null; + } + File legacy = new File(getDataFolder(), "events.yml"); + File actions = new File(getDataFolder(), "actions.yml"); + FileConfiguration data = new YamlConfiguration(); + try { + if (actions.isFile()) { + data.load(actions); + } else { + data.load(legacy); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + String legacyName = "events." + name; + String actionKey = "actions." + name + "."; + if (data.contains(legacyName)) { + actionKey = legacyName + "."; + } + Action action = new Action(this); + action.setName(name); + if (data.contains(actionKey + "message")) { + action.setMessage(ConfigUtil.parseString(data.getString(actionKey + "message"))); + } + if (data.contains(actionKey + "open-book")) { + action.setBook(data.getString(actionKey + "open-book")); + } + if (data.contains(actionKey + "clear-inventory")) { + if (data.isBoolean(actionKey + "clear-inventory")) { + action.setClearInv(data.getBoolean(actionKey + "clear-inventory")); + } else { + throw new ActionFormatException("clear-inventory is not a true/false value", actionKey); + } + } + if (data.contains(actionKey + "fail-quest")) { + if (data.isBoolean(actionKey + "fail-quest")) { + action.setFailQuest(data.getBoolean(actionKey + "fail-quest")); + } else { + throw new ActionFormatException("fail-quest is not a true/false value", actionKey); + } + } + if (data.contains(actionKey + "explosions")) { + if (ConfigUtil.checkList(data.getList(actionKey + "explosions"), String.class)) { + LinkedList explosions = new LinkedList(); + for (String s : data.getStringList(actionKey + "explosions")) { + Location loc = ConfigUtil.getLocation(s); + if (loc == null) { + throw new ActionFormatException("explosions is not in proper \"WorldName x y z\" format", actionKey); + } + explosions.add(loc); + } + action.setExplosions(explosions); + } else { + throw new ActionFormatException("explosions is not a list of locations", actionKey); + } + } + if (data.contains(actionKey + "effects")) { + if (ConfigUtil.checkList(data.getList(actionKey + "effects"), String.class)) { + if (data.contains(actionKey + "effect-locations")) { + if (ConfigUtil.checkList(data.getList(actionKey + "effect-locations"), String.class)) { + List effectList = data.getStringList(actionKey + "effects"); + List effectLocs = data.getStringList(actionKey + "effect-locations"); + Map effects = new HashMap(); + for (String s : effectList) { + Effect effect = null; + try { + effect = Effect.valueOf(s.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new ActionFormatException("effect-locations is not a valid effect name", + actionKey); + } + Location l = ConfigUtil.getLocation(effectLocs.get(effectList.indexOf(s))); + if (l == null) { + throw new ActionFormatException("effect-locations is not in proper \"WorldName x y z\"" + + "format", actionKey); + } + effects.put(l, effect); + } + action.setEffects(effects); + } else { + throw new ActionFormatException("effect-locations is not a list of locations", actionKey); + } + } else { + throw new ActionFormatException("effect-locations is missing", actionKey); + } + } else { + throw new ActionFormatException("effects is not a list of effects", actionKey); + } + } + if (data.contains(actionKey + "items")) { + LinkedList temp = new LinkedList(); + @SuppressWarnings("unchecked") + List stackList = (List) data.get(actionKey + "items"); + if (ConfigUtil.checkList(stackList, ItemStack.class)) { + for (ItemStack stack : stackList) { + if (stack != null) { + temp.add(stack); + } + } + } else { + // Legacy + if (ConfigUtil.checkList(stackList, String.class)) { + List items = data.getStringList(actionKey + "items"); + for (String item : items) { + try { + ItemStack stack = ItemUtil.readItemStack(item); + if (stack != null) { + temp.add(stack); + } + } catch (Exception e) { + throw new ActionFormatException("items is not formatted properly", actionKey); + } + } + } else { + throw new ActionFormatException("items is not a list of items", actionKey); + } + } + action.setItems(temp); + } + if (data.contains(actionKey + "storm-world")) { + World stormWorld = getServer().getWorld(data.getString(actionKey + "storm-world")); + if (stormWorld == null) { + throw new ActionFormatException("storm-world is not a valid world name", actionKey); + } + if (data.contains(actionKey + "storm-duration")) { + if (data.getInt(actionKey + "storm-duration", -999) != -999) { + action.setStormDuration(data.getInt(actionKey + "storm-duration") * 1000); + } else { + throw new ActionFormatException("storm-duration is not a number", actionKey); + } + action.setStormWorld(stormWorld); + } else { + throw new ActionFormatException("storm-duration is missing", actionKey); + } + } + if (data.contains(actionKey + "thunder-world")) { + World thunderWorld = getServer().getWorld(data.getString(actionKey + "thunder-world")); + if (thunderWorld == null) { + throw new ActionFormatException("thunder-world is not a valid world name", actionKey); + } + if (data.contains(actionKey + "thunder-duration")) { + if (data.getInt(actionKey + "thunder-duration", -999) != -999) { + action.setThunderDuration(data.getInt(actionKey + "thunder-duration")); + } else { + throw new ActionFormatException("thunder-duration is not a number", actionKey); + } + action.setThunderWorld(thunderWorld); + } else { + throw new ActionFormatException("thunder-duration is missing", actionKey); + } + } + if (data.contains(actionKey + "mob-spawns")) { + ConfigurationSection section = data.getConfigurationSection(actionKey + "mob-spawns"); + LinkedList mobSpawns = new LinkedList(); + for (String s : section.getKeys(false)) { + String mobName = section.getString(s + ".name"); + Location spawnLocation = ConfigUtil.getLocation(section.getString(s + ".spawn-location")); + EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type")); + Integer mobAmount = section.getInt(s + ".spawn-amounts"); + if (spawnLocation == null) { + throw new ActionFormatException("mob-spawn-locations is not in proper \"WorldName x y z\" format", + actionKey); + } + if (type == null) { + throw new ActionFormatException("mob-spawn-types is not a list of mob types", actionKey); + } + ItemStack[] inventory = new ItemStack[5]; + Float[] dropChances = new Float[5]; + inventory[0] = ItemUtil.readItemStack(section.getString(s + ".held-item")); + dropChances[0] = (float) section.getDouble(s + ".held-item-drop-chance"); + inventory[1] = ItemUtil.readItemStack(section.getString(s + ".boots")); + dropChances[1] = (float) section.getDouble(s + ".boots-drop-chance"); + inventory[2] = ItemUtil.readItemStack(section.getString(s + ".leggings")); + dropChances[2] = (float) section.getDouble(s + ".leggings-drop-chance"); + inventory[3] = ItemUtil.readItemStack(section.getString(s + ".chest-plate")); + dropChances[3] = (float) section.getDouble(s + ".chest-plate-drop-chance"); + inventory[4] = ItemUtil.readItemStack(section.getString(s + ".helmet")); + dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance"); + QuestMob questMob = new QuestMob(type, spawnLocation, mobAmount); + questMob.setInventory(inventory); + questMob.setDropChances(dropChances); + questMob.setName(mobName); + mobSpawns.add(questMob); + } + action.setMobSpawns(mobSpawns); + } + if (data.contains(actionKey + "lightning-strikes")) { + if (ConfigUtil.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) { + LinkedList lightningStrikes = new LinkedList(); + for (String s : data.getStringList(actionKey + "lightning-strikes")) { + Location loc = ConfigUtil.getLocation(s); + if (loc == null) { + throw new ActionFormatException("lightning-strikes is not in proper \"WorldName x y z\" format", + actionKey); + } + lightningStrikes.add(loc); + } + action.setLightningStrikes(lightningStrikes); + } else { + throw new ActionFormatException("lightning-strikes is not a list of locations", actionKey); + } + } + if (data.contains(actionKey + "commands")) { + if (ConfigUtil.checkList(data.getList(actionKey + "commands"), String.class)) { + LinkedList commands = new LinkedList(); + for (String s : data.getStringList(actionKey + "commands")) { + if (s.startsWith("/")) { + s = s.replaceFirst("/", ""); + } + commands.add(s); + } + action.setCommands(commands); + } else { + throw new ActionFormatException("commands is not a list of commands", actionKey); + } + } + if (data.contains(actionKey + "potion-effect-types")) { + if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) { + if (data.contains(actionKey + "potion-effect-durations")) { + if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) { + if (data.contains(actionKey + "potion-effect-amplifiers")) { + if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-amplifiers"), + Integer.class)) { + List types = data.getStringList(actionKey + "potion-effect-types"); + List durations = data.getIntegerList(actionKey + "potion-effect-durations"); + List amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers"); + LinkedList potionEffects = new LinkedList(); + for (String s : types) { + PotionEffectType type = PotionEffectType.getByName(s); + if (type == null) { + throw new ActionFormatException("potion-effect-types is not a list of potion " + + "effect types", actionKey); + } + PotionEffect effect = new PotionEffect(type, durations + .get(types.indexOf(s)), amplifiers.get(types.indexOf(s))); + potionEffects.add(effect); + } + action.setPotionEffects(potionEffects); + } else { + throw new ActionFormatException("potion-effect-amplifiers is not a list of numbers", + actionKey); + } + } else { + throw new ActionFormatException("potion-effect-amplifiers is missing", actionKey); + } + } else { + throw new ActionFormatException("potion-effect-durations is not a list of numbers", actionKey); + } + } else { + throw new ActionFormatException("potion-effect-durations is missing", actionKey); + } + } else { + throw new ActionFormatException("potion-effect-types is not a list of potion effects", actionKey); + } + } + if (data.contains(actionKey + "hunger")) { + if (data.getInt(actionKey + "hunger", -999) != -999) { + action.setHunger(data.getInt(actionKey + "hunger")); + } else { + throw new ActionFormatException("hunger is not a number", actionKey); + } + } + if (data.contains(actionKey + "saturation")) { + if (data.getInt(actionKey + "saturation", -999) != -999) { + action.setSaturation(data.getInt(actionKey + "saturation")); + } else { + throw new ActionFormatException("saturation is not a number", actionKey); + } + } + if (data.contains(actionKey + "health")) { + if (data.getInt(actionKey + "health", -999) != -999) { + action.setHealth(data.getInt(actionKey + "health")); + } else { + throw new ActionFormatException("health is not a number", actionKey); + } + } + if (data.contains(actionKey + "teleport-location")) { + if (data.isString(actionKey + "teleport-location")) { + Location teleport = ConfigUtil.getLocation(data.getString(actionKey + "teleport-location")); + if (teleport == null) { + throw new ActionFormatException("teleport-location is not in proper \"WorldName x y z\" format", + actionKey); + } + action.setTeleport(teleport); + } else { + throw new ActionFormatException("teleport-location is not a location", actionKey); + } + } + if (data.contains(actionKey + "timer")) { + if (data.isInt(actionKey + "timer")) { + action.setTimer(data.getInt(actionKey + "timer")); + } else { + throw new ActionFormatException("timer is not a number", actionKey); + } + } + if (data.contains(actionKey + "cancel-timer")) { + if (data.isBoolean(actionKey + "cancel-timer")) { + action.setCancelTimer(data.getBoolean(actionKey + "cancel-timer")); + } else { + throw new ActionFormatException("cancel-timer is not a true/false value", actionKey); + } + } + if (data.contains(actionKey + "denizen-script")) { + action.setDenizenScript(data.getString(actionKey + "denizen-script")); + } + return action; + } + + private void loadCustomSections(Quest quest, FileConfiguration config, String questKey) + throws StageFormatException, QuestFormatException { + ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered"); + for (String stageNum : questStages.getKeys(false)) { + if (quest == null) { + getLogger().severe("Unable to load custom objectives because quest for " + questKey + " was null"); + return; + } + if (quest.getStage(Integer.valueOf(stageNum) - 1) == null) { + getLogger().severe("Unable to load custom objectives because stage" + (Integer.valueOf(stageNum) - 1) + + " for " + quest.getName() + " was null"); + return; + } + Stage oStage = quest.getStage(Integer.valueOf(stageNum) - 1); + oStage.customObjectives = new LinkedList<>(); + oStage.customObjectiveCounts = new LinkedList<>(); + oStage.customObjectiveData = new LinkedList<>(); + oStage.customObjectiveDisplays = new LinkedList<>(); + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".custom-objectives")) { + ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".stages.ordered." + + stageNum + ".custom-objectives"); + for (String path : sec.getKeys(false)) { + String name = sec.getString(path + ".name"); + int count = sec.getInt(path + ".count"); + Optional found = Optional.empty(); + for (CustomObjective cr : customObjectives) { + if (cr.getName().equalsIgnoreCase(name)) { + found = Optional.of(cr); + break; + } + } + if (!found.isPresent()) { + getLogger().warning("Custom objective \"" + name + "\" for Stage " + stageNum + " of Quest \"" + + quest.getName() + "\" could not be found!"); + continue; + } else { + ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); + oStage.customObjectives.add(found.get()); + if (count <= 0) { + oStage.customObjectiveCounts.add(0); + } else { + oStage.customObjectiveCounts.add(count); + } + for (Entry prompt : found.get().getData()) { + Entry data = populateCustoms(sec2, prompt); + oStage.customObjectiveData.add(data); + } + } + } + } + } + Rewards rews = quest.getRewards(); + if (config.contains("quests." + questKey + ".rewards.custom-rewards")) { + ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + ".rewards.custom-rewards"); + Map> temp = new HashMap>(); + for (String path : sec.getKeys(false)) { + String name = sec.getString(path + ".name"); + Optionalfound = Optional.empty(); + for (CustomReward cr : customRewards) { + if (cr.getName().equalsIgnoreCase(name)) { + found=Optional.of(cr); + break; + } + } + if (!found.isPresent()) { + getLogger().warning("Custom reward \"" + name + "\" for Quest \"" + quest.getName() + + "\" could not be found!"); + continue; + } else { + ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); + Map data = populateCustoms(sec2, found.get().getData()); + temp.put(name, data); + } + } + rews.setCustomRewards(temp); + } + Requirements reqs = quest.getRequirements(); + if (config.contains("quests." + questKey + ".requirements.custom-requirements")) { + ConfigurationSection sec = config.getConfigurationSection("quests." + questKey + + ".requirements.custom-requirements"); + Map> temp = new HashMap>(); + for (String path : sec.getKeys(false)) { + String name = sec.getString(path + ".name"); + Optionalfound=Optional.empty(); + for (CustomRequirement cr : customRequirements) { + if (cr.getName().equalsIgnoreCase(name)) { + found=Optional.of(cr); + break; + } + } + if (!found.isPresent()) { + throw new QuestFormatException(name + " custom requirement not found", questKey); + } else { + ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); + Map data = populateCustoms(sec2,found.get().getData()); + temp.put(name, data); + } + } + reqs.setCustomRequirements(temp); + } + } + + /** + * Permits use of fallbacks for customs maps

+ * + * Avoid null objects in datamap by initializing the entry value with empty string if no fallback present. + * + * @param section The section of configuration to check + * @param datamap The map to process + * @return Populated map + */ + private static Map populateCustoms(ConfigurationSection section, Map datamap) { + Map data = new HashMap(); + if (section != null) { + for (String key : datamap.keySet()) { + data.put(key, section.contains(key) ? section.get(key) : datamap.get(key) != null + ? datamap.get(key) : new String()); + } + } + return data; + } + + /** + * Permits use of fallbacks for customs entries

+ * + * Avoid null objects in datamap by initializing the entry value with empty string if no fallback present. + * + * @param section The section of configuration to check + * @param datamap The entry to process + * @return Populated entry + */ + private static Entry populateCustoms(ConfigurationSection section, Entry datamap) { + String key = null;; + Object value = null;; + if (section != null) { + key = datamap.getKey(); + value = datamap.getValue(); + } + return new AbstractMap.SimpleEntry(key, section.contains(key) ? section.get(key) : value != null + ? value : new String()); + } + + /** + * Load actions from file + */ + public void loadActions() { + YamlConfiguration config = new YamlConfiguration(); + File legacyFile = new File(this.getDataFolder(), "events.yml"); + File actionsFile = new File(this.getDataFolder(), "actions.yml"); + // Using isFile() because exists() and renameTo() can return false positives + if (legacyFile.isFile()) { + getLogger().log(Level.INFO, "Renaming legacy events.yml to actions.yml ..."); + try { + legacyFile.renameTo(actionsFile); + if (actionsFile.isFile()) { + getLogger().log(Level.INFO, "Success! Deleting legacy events.yml ..."); + legacyFile.delete(); + getLogger().log(Level.INFO, "Done!"); + } + } catch (Exception e) { + getLogger().log(Level.WARNING, "Unable to rename events.yml to actions.yml"); + e.printStackTrace(); + } + } + if (actionsFile.length() != 0) { + try { + if (actionsFile.isFile()) { + config.load(actionsFile); + } else { + config.load(legacyFile); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + ConfigurationSection sec = config.getConfigurationSection("actions"); + if (sec == null) { + getLogger().log(Level.INFO, + "Could not find section \"actions\" from actions.yml. Trying legacy \"events\"..."); + sec = config.getConfigurationSection("events"); + } + if (sec != null) { + for (String s : sec.getKeys(false)) { + Action action = null; + try { + action= loadAction(s); + } catch (ActionFormatException e) { + e.printStackTrace(); + } + if (action != null) { + actions.add(action); + } else { + getLogger().log(Level.SEVERE, "Failed to load Action \"" + s + "\". Skipping."); + } + } + } else { + getLogger().log(Level.SEVERE, "Could not find beginning section from actions.yml. Skipping."); + } + } else { + getLogger().log(Level.WARNING, "Empty file actions.yml was not loaded."); + } + } + + public static SkillType getMcMMOSkill(String s) { + return SkillType.getSkill(s); + } + + /** + * @deprecated Use InventoryUtil.removeItem(Inventory, ItemStack) + */ + public static boolean removeItem(Inventory inventory, ItemStack is) { + int amount = is.getAmount(); + HashMap allItems = inventory.all(is.getType()); + HashMap removeFrom = new HashMap(); + int foundAmount = 0; + for (Map.Entry item : allItems.entrySet()) { + if (ItemUtil.compareItems(is, item.getValue(), true) == 0) { + if (item.getValue().getAmount() >= amount - foundAmount) { + removeFrom.put(item.getKey(), amount - foundAmount); + foundAmount = amount; + } else { + foundAmount += item.getValue().getAmount(); + removeFrom.put(item.getKey(), item.getValue().getAmount()); + } + if (foundAmount >= amount) { + break; + } + } + } + if (foundAmount == amount) { + for (Map.Entry toRemove : removeFrom.entrySet()) { + ItemStack item = inventory.getItem(toRemove.getKey()); + if (item.getAmount() - toRemove.getValue() <= 0) { + inventory.clear(toRemove.getKey()); + } else { + item.setAmount(item.getAmount() - toRemove.getValue()); + inventory.setItem(toRemove.getKey(), item); + } + } + return true; + } + return false; + } + + /** + * Checks if player can use Quests + * + * @param uuid the entity UUID to be checked + * @return {@code true} if entity is a Player that has permission + */ + public boolean canUseQuests(UUID uuid) { + return !checkQuester(uuid); + } + + /** + * Checks if player CANNOT use Quests + * + * @param uuid the entity UUID to be checked + * @return {@code true} if entity has no permission or is not a player + * @deprecated Use {@link #canUseQuests(UUID)} + */ + public boolean checkQuester(UUID uuid) { + if (!(Bukkit.getPlayer(uuid) instanceof Player)) { + return true; + } + Player p = Bukkit.getPlayer(uuid); + if (p.isOp()) { + return false; + } + try { + for (PermissionAttachmentInfo pm : p.getEffectivePermissions()) { + if (pm.getPermission().startsWith("quests") + || pm.getPermission().equals("*") + || pm.getPermission().equals("*.*")) { + return false; + } + } + } catch (NullPointerException ne) { + // User has no permissions + } catch (ConcurrentModificationException cme) { + // Bummer. Not much we can do about it + } + return true; + } + + /** + * Get a Quest by ID + * + * @param id ID of the quest + * @return Exact match or null if not found + * @since 3.8.6 + */ + public Quest getQuestById(String id) { + if (id == null) { + return null; + } + for (Quest q : quests) { + if (q.getId().equals(id)) { + return q; + } + } + return null; + } + + /** + * Get a Quest by name + * + * @param name Name of the quest + * @return Closest match or null if not found + */ + public Quest getQuest(String name) { + if (name == null) { + return null; + } + for (Quest q : quests) { + if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { + return q; + } + } + for (Quest q : quests) { + if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return q; + } + } + for (Quest q : quests) { + if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return q; + } + } + return null; + } + + /** + * Get an Action by name + * + * @param name Name of the action + * @return Closest match or null if not found + */ + public Action getAction(String name) { + if (name == null) { + return null; + } + for (Action a : actions) { + if (a.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { + return a; + } + } + for (Action a : actions) { + if (a.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return a; + } + } + for (Action a : actions) { + if (a.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return a; + } + } + return null; + } + + /** + * Checks whether a NPC has a quest that the player may accept + * + * @param npc The giver NPC to check + * @param quester The player to check + * @return true if at least one available quest has not yet been completed + */ + public boolean hasQuest(NPC npc, Quester quester) { + for (Quest q : quests) { + if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == false) { + if (q.npcStart.getId() == npc.getId()) { + boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); + if (ignoreLockedQuests == false || ignoreLockedQuests == true + && q.testRequirements(quester) == true) { + return true; + } + } + } + } + return false; + } + + // Unused internally, left for external use + /** + * Checks whether a NPC has a quest that the player has already completed + * + * @param npc The giver NPC to check + * @param quester The player to check + * @return true if at least one available quest has been completed + */ + public boolean hasCompletedQuest(NPC npc, Quester quester) { + for (Quest q : quests) { + if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == true) { + if (q.npcStart.getId() == npc.getId()) { + boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); + if (ignoreLockedQuests == false || ignoreLockedQuests == true + && q.testRequirements(quester) == true) { + return true; + } + } + } + } + return false; + } + + /** + * Checks whether a NPC has a repeatable quest that the player has already completed + * + * @param npc The giver NPC to check + * @param quester The player to check + * @return true if at least one available, redoable quest has been completed + */ + public boolean hasCompletedRedoableQuest(NPC npc, Quester quester) { + for (Quest q : quests) { + if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == true + && q.getPlanner().getCooldown() > -1) { + if (q.npcStart.getId() == npc.getId()) { + boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); + if (ignoreLockedQuests == false || ignoreLockedQuests == true + && q.testRequirements(quester) == true) { + return true; + } + } + } + } + return false; + } +} 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 11fefce68..bd7b293e0 100644 --- a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java +++ b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java @@ -14,7 +14,6 @@ package me.blackvein.quests.actions; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -22,11 +21,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Effect; import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; @@ -35,33 +32,22 @@ import org.bukkit.conversations.ConversationAbandonedEvent; import org.bukkit.conversations.ConversationAbandonedListener; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationFactory; -import org.bukkit.conversations.FixedSetPrompt; -import org.bukkit.conversations.NumericPrompt; import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import me.blackvein.quests.Quest; import me.blackvein.quests.QuestMob; import me.blackvein.quests.Quester; import me.blackvein.quests.Quests; -import me.blackvein.quests.Stage; -import me.blackvein.quests.Quests.ReloadCallback; -import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt; -import me.blackvein.quests.convo.actions.ActionsEditorStringPrompt; -import me.blackvein.quests.convo.quests.prompts.ItemStackPrompt; -import me.blackvein.quests.events.editor.actions.ActionsEditorPostOpenNumericPromptEvent; -import me.blackvein.quests.events.editor.actions.ActionsEditorPostOpenStringPromptEvent; +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.convo.actions.menu.ActionMenuPrompt; +import me.blackvein.quests.interfaces.ReloadCallback; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; -import me.blackvein.quests.util.MiscUtil; -import me.blackvein.quests.util.RomanNumeral; public class ActionFactory implements ConversationAbandonedListener { @@ -147,381 +133,12 @@ public class ActionFactory implements ConversationAbandonedListener { selectedLightningLocations.remove(player.getUniqueId()); selectedTeleportLocations.remove(player.getUniqueId()); } - - public class ActionMenuPrompt extends ActionsEditorNumericPrompt { - public ActionMenuPrompt(ConversationContext context) { - super(context); - } - - private final int size = 4; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return Lang.get("eventEditorTitle"); - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - case 2: - case 3: - return ChatColor.BLUE; - case 4: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.YELLOW + Lang.get("eventEditorCreate"); - case 2: - return ChatColor.YELLOW + Lang.get("eventEditorEdit"); - case 3: - return ChatColor.YELLOW + Lang.get("eventEditorDelete"); - case 4: - return ChatColor.RED + Lang.get("exit"); - default: - return null; - } - } - - public String getAdditionalText(ConversationContext context, int number) { - return null; - } - - @Override - public String getPromptText(ConversationContext context) { - ActionsEditorPostOpenNumericPromptEvent event = new ActionsEditorPostOpenNumericPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - String text = ChatColor.GOLD + getTitle(context) + "\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; - } - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - final Player player = (Player) context.getForWhom(); - switch (input.intValue()) { - case 1: - if (player.hasPermission("quests.editor.actions.create") - || player.hasPermission("quests.editor.events.create")) { - context.setSessionData(CK.E_OLD_EVENT, ""); - return new ActionSelectCreatePrompt(context); - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new ActionMenuPrompt(context); - } - case 2: - if (player.hasPermission("quests.editor.actions.edit") - || player.hasPermission("quests.editor.events.edit")) { - if (plugin.getActions().isEmpty()) { - ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW - + Lang.get("eventEditorNoneToEdit")); - return new ActionMenuPrompt(context); - } else { - return new ActionSelectEditPrompt(); - } - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new ActionMenuPrompt(context); - } - case 3: - if (player.hasPermission("quests.editor.actions.delete") - || player.hasPermission("quests.editor.events.delete")) { - if (plugin.getActions().isEmpty()) { - ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW - + Lang.get("eventEditorNoneToDelete")); - return new ActionMenuPrompt(context); - } else { - return new ActionSelectDeletePrompt(); - } - } else { - player.sendMessage(ChatColor.RED + Lang.get("noPermission")); - return new ActionMenuPrompt(context); - } - case 4: - ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("exited")); - return Prompt.END_OF_CONVERSATION; - default: - return new ActionMenuPrompt(context); - } - } - } - + public Prompt returnToMenu(ConversationContext context) { return new ActionMainPrompt(context); } - public class ActionMainPrompt extends ActionsEditorNumericPrompt { - public ActionMainPrompt(ConversationContext context) { - super(context); - } - - private final int size = 10; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return Lang.get("event") + ": " + context.getSessionData(CK.E_NAME); - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (plugin.getDependencies().getDenizenAPI() == null) { - return ChatColor.GRAY; - } else { - return ChatColor.BLUE; - } - case 8: - return ChatColor.BLUE; - case 9: - return ChatColor.GREEN; - case 10: - return ChatColor.RED; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.YELLOW + Lang.get("eventEditorSetName"); - case 2: - return ChatColor.GOLD + Lang.get("eventEditorPlayer"); - case 3: - return ChatColor.GOLD + Lang.get("eventEditorTimer"); - case 4: - return ChatColor.GOLD + Lang.get("eventEditorEffect"); - case 5: - return ChatColor.GOLD + Lang.get("eventEditorWeather"); - case 6: - return ChatColor.YELLOW + Lang.get("eventEditorSetMobSpawns"); - case 7: - if (plugin.getDependencies().getDenizenAPI() == null) { - return ChatColor.GRAY + Lang.get("stageEditorDenizenScript"); - } else { - return ChatColor.YELLOW + Lang.get("stageEditorDenizenScript"); - } - case 8: - return ChatColor.YELLOW + Lang.get("eventEditorFailQuest") + ":"; - case 9: - return ChatColor.GREEN + Lang.get("save"); - case 10: - return ChatColor.RED + Lang.get("exit"); - default: - return null; - } - } - - @SuppressWarnings("unchecked") - public String getAdditionalText(ConversationContext context, int number) { - switch (number) { - case 1: - case 2: - case 3: - case 4: - case 5: - return ""; - case 6: - if (context.getSessionData(CK.E_MOB_TYPES) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - LinkedList types = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); - String text = ""; - for (String s : types) { - QuestMob qm = QuestMob.fromString(s); - text += ChatColor.GRAY + " - " + ChatColor.AQUA + qm.getType().name() - + ((qm.getName() != null) ? ": " + qm.getName() : "") + ChatColor.GRAY + " x " - + ChatColor.DARK_AQUA + qm.getSpawnAmounts() + ChatColor.GRAY + " -> " - + ChatColor.GREEN + ConfigUtil.getLocationInfo(qm.getSpawnLocation()) + "\n"; - } - return text; - } - case 7: - if (plugin.getDependencies().getDenizenAPI() == null) { - return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; - } else { - if (context.getSessionData(CK.E_DENIZEN) == null) { - return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; - } else { - return ChatColor.GRAY + "(" + ChatColor.AQUA + context.getSessionData(CK.E_DENIZEN) - + ChatColor.GRAY + ")"; - } - } - case 8: - if (context.getSessionData(CK.E_FAIL_QUEST) == null) { - context.setSessionData(CK.E_FAIL_QUEST, Lang.get("noWord")); - } - return "" + ChatColor.AQUA + context.getSessionData(CK.E_FAIL_QUEST); - case 9: - case 10: - return ""; - default: - return null; - } - } - - @Override - public String getPromptText(ConversationContext context) { - ActionsEditorPostOpenNumericPromptEvent event = new ActionsEditorPostOpenNumericPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = ChatColor.GOLD + "- " + getTitle(context).replaceFirst(": ", ": " + ChatColor.AQUA) - + ChatColor.GOLD + " -\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; - } - return text; - } - - @Override - public Prompt acceptValidatedInput(ConversationContext context, Number input) { - switch (input.intValue()) { - case 1: - return new ActionSetNamePrompt(); - case 2: - return new PlayerPrompt(); - case 3: - return new TimerPrompt(); - case 4: - return new EffectPrompt(); - case 5: - return new WeatherPrompt(); - case 6: - return new MobPrompt(); - case 7: - return new DenizenPrompt(); - case 8: - String s = (String) context.getSessionData(CK.E_FAIL_QUEST); - if (s.equalsIgnoreCase(Lang.get("yesWord"))) { - context.setSessionData(CK.E_FAIL_QUEST, Lang.get("noWord")); - } else { - context.setSessionData(CK.E_FAIL_QUEST, Lang.get("yesWord")); - } - return new ActionMainPrompt(context); - case 9: - if (context.getSessionData(CK.E_OLD_EVENT) != null) { - return new SavePrompt((String) context.getSessionData(CK.E_OLD_EVENT)); - } else { - return new SavePrompt(null); - } - case 10: - return new ExitPrompt(); - default: - return new ActionMainPrompt(context); - } - } - } - - public class ActionSelectCreatePrompt extends ActionsEditorStringPrompt { - public ActionSelectCreatePrompt(ConversationContext context) { - super(context); - } - - public String getTitle(ConversationContext context) { - return Lang.get("eventEditorCreate"); - } - - public String getQueryText(ConversationContext context) { - return Lang.get("eventEditorEnterEventName"); - } - - @Override - public String getPromptText(ConversationContext context) { - ActionsEditorPostOpenStringPromptEvent event = new ActionsEditorPostOpenStringPromptEvent(context, this); - plugin.getServer().getPluginManager().callEvent(event); - - String text = ChatColor.GOLD + getTitle(context) + "\n" + ChatColor.YELLOW + getQueryText(context); - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); - return new ActionSelectCreatePrompt(context); - } - input = input.trim(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Action e : plugin.getActions()) { - if (e.getName().equalsIgnoreCase(input)) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists")); - return new ActionSelectCreatePrompt(context); - } - } - if (editingActionNames.contains(input)) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); - return new ActionSelectCreatePrompt(context); - } - if (StringUtils.isAlphanumeric(input) == false) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha")); - return new ActionSelectCreatePrompt(context); - } - if (input.equals("")) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); - return new ActionSelectCreatePrompt(context); - } - context.setSessionData(CK.E_NAME, input); - editingActionNames.add(input); - return new ActionMainPrompt(context); - } else { - return new ActionMenuPrompt(context); - } - } - } - - private class ActionSelectEditPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEdit") + " -\n"; - for (Action a : plugin.getActions()) { - text += ChatColor.AQUA + a.getName() + ChatColor.GRAY + ", "; - } - text = text.substring(0, text.length() - 2) + "\n"; - text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName"); - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - Action a = plugin.getAction(input); - if (a != null) { - context.setSessionData(CK.E_OLD_EVENT, a.getName()); - context.setSessionData(CK.E_NAME, a.getName()); - loadData(a, context); - return new ActionMainPrompt(context); - } - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound")); - return new ActionSelectEditPrompt(); - } else { - return new ActionMenuPrompt(context); - } - } - } - - public static void loadData(Action event, ConversationContext context) { + public void loadData(Action event, ConversationContext context) { if (event.message != null) { context.setSessionData(CK.E_MESSAGE, event.message); } @@ -615,458 +232,7 @@ public class ActionFactory implements ConversationAbandonedListener { } } - private class ActionSelectDeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorDelete") + " -\n"; - for (Action a : plugin.getActions()) { - text += ChatColor.AQUA + a.getName() + ChatColor.GRAY + ","; - } - text = text.substring(0, text.length() - 1) + "\n"; - text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName"); - return text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - LinkedList used = new LinkedList(); - Action a = plugin.getAction(input); - if (a != null) { - for (Quest quest : plugin.getQuests()) { - for (Stage stage : quest.getStages()) { - if (stage.getFinishAction() != null - && stage.getFinishAction().getName().equalsIgnoreCase(a.getName())) { - used.add(quest.getName()); - break; - } - } - } - if (used.isEmpty()) { - context.setSessionData(CK.ED_EVENT_DELETE, a.getName()); - return new ActionConfirmDeletePrompt(); - } else { - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorEventInUse") - + " \"" + ChatColor.DARK_PURPLE + a.getName() + ChatColor.RED + "\":"); - for (String s : used) { - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "- " + ChatColor.DARK_RED + s); - } - ((Player) context.getForWhom()).sendMessage(ChatColor.RED - + Lang.get("eventEditorMustModifyQuests")); - return new ActionSelectDeletePrompt(); - } - } - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound")); - return new ActionSelectDeletePrompt(); - } else { - return new ActionMenuPrompt(context); - } - } - } - - private class ActionConfirmDeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + "" + ChatColor.GREEN + " - " - + Lang.get("yesWord") + "\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + "" + ChatColor.RED + " - " - + Lang.get("noWord"); - return ChatColor.RED + Lang.get("confirmDelete") + " (" + ChatColor.YELLOW - + (String) context.getSessionData(CK.ED_EVENT_DELETE) + ChatColor.RED + ")\n" + text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - deleteAction(context); - return new ActionMenuPrompt(context); - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new ActionMenuPrompt(context); - } else { - return new ActionConfirmDeletePrompt(); - } - } - } - - private class PlayerPrompt extends FixedSetPrompt { - - public PlayerPrompt() { - super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); - } - - @SuppressWarnings("unchecked") - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorPlayer") + " -\n"; - if (context.getSessionData(CK.E_MESSAGE) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetMessage") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetMessage") + " (" + ChatColor.AQUA - + context.getSessionData(CK.E_MESSAGE) + ChatColor.RESET + ChatColor.YELLOW + ")\n"; - } - if (context.getSessionData(CK.E_CLEAR_INVENTORY) == null) { - context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord")); - } - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorClearInv") + ": " + ChatColor.AQUA - + context.getSessionData(CK.E_CLEAR_INVENTORY) + "\n"; - if (context.getSessionData(CK.E_ITEMS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetItems") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetItems") + "\n"; - LinkedList items = (LinkedList) context.getSessionData(CK.E_ITEMS); - for (ItemStack is : items) { - if (is != null) { - text += ChatColor.GRAY + " - " + ItemUtil.getString(is) + "\n"; - } - } - } - if (context.getSessionData(CK.E_POTION_TYPES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetPotionEffects") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetPotionEffects") + "\n"; - LinkedList types = (LinkedList) context.getSessionData(CK.E_POTION_TYPES); - LinkedList durations = (LinkedList) context.getSessionData(CK.E_POTION_DURATIONS); - LinkedList mags = (LinkedList) context.getSessionData(CK.E_POTION_STRENGHT); - int index = -1; - for (String type : types) { - index++; - text += ChatColor.GRAY + " - " + ChatColor.AQUA + type + ChatColor.DARK_PURPLE + " " - + RomanNumeral.getNumeral(mags.get(index)) + ChatColor.GRAY + " -> " + ChatColor.DARK_AQUA - + MiscUtil.getTime(durations.get(index) * 50L) + "\n"; - } - } - if (context.getSessionData(CK.E_HUNGER) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetHunger") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetHunger") + ChatColor.AQUA + " (" - + (Integer) context.getSessionData(CK.E_HUNGER) + ")\n"; - } - if (context.getSessionData(CK.E_SATURATION) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetSaturation") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetSaturation") + ChatColor.AQUA + " (" - + (Integer) context.getSessionData(CK.E_SATURATION) + ")\n"; - } - if (context.getSessionData(CK.E_HEALTH) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetHealth") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetHealth") + ChatColor.AQUA + " (" - + (Integer) context.getSessionData(CK.E_HEALTH) + ")\n"; - } - if (context.getSessionData(CK.E_TELEPORT) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "8" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetTeleport") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "8" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetTeleport") + ChatColor.AQUA + " (" - + (String) context.getSessionData(CK.E_TELEPORT) + ")\n"; - } - if (context.getSessionData(CK.E_COMMANDS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "9" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetCommands") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "9" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetCommands") + "\n"; - for (String s : (LinkedList) context.getSessionData(CK.E_COMMANDS)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - } - text += ChatColor.GREEN + "" + ChatColor.BOLD + "10 " + ChatColor.RESET + ChatColor.YELLOW + "- " - + Lang.get("done") + "\n"; - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new MessagePrompt(); - } else if (input.equalsIgnoreCase("2")) { - String s = (String) context.getSessionData(CK.E_CLEAR_INVENTORY); - if (s.equalsIgnoreCase(Lang.get("yesWord"))) { - context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord")); - } else { - context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("yesWord")); - } - return new ActionMainPrompt(context); - } else if (input.equalsIgnoreCase("3")) { - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - return new PotionEffectPrompt(); - } else if (input.equalsIgnoreCase("5")) { - return new HungerPrompt(); - } else if (input.equalsIgnoreCase("6")) { - return new SaturationPrompt(); - } else if (input.equalsIgnoreCase("7")) { - return new HealthPrompt(); - } else if (input.equalsIgnoreCase("8")) { - selectedTeleportLocations.put(((Player) context.getForWhom()).getUniqueId(), null); - return new TeleportPrompt(); - } else if (input.equalsIgnoreCase("9")) { - return new CommandsPrompt(); - } - return new ActionMainPrompt(context); - } - } - - private class TimerPrompt extends FixedSetPrompt { - - public TimerPrompt() { - super("1", "2", "3"); - } - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorTimer") + " -\n"; - if (context.getSessionData(CK.E_TIMER) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetTimer") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetTimer") + "(" + ChatColor.AQUA + "\"" - + context.getSessionData(CK.E_TIMER) + "\"" + ChatColor.YELLOW + ")\n"; - } - if (context.getSessionData(CK.E_CANCEL_TIMER) == null) { - context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("noWord")); - } - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorCancelTimer") + ": " + ChatColor.AQUA - + context.getSessionData(CK.E_CANCEL_TIMER) + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.YELLOW + "- " - + Lang.get("done") + "\n"; - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new FailTimerPrompt(); - } else if (input.equalsIgnoreCase("2")) { - String s = (String) context.getSessionData(CK.E_CANCEL_TIMER); - if (s.equalsIgnoreCase(Lang.get("yesWord"))) { - context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("noWord")); - } else { - context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("yesWord")); - } - return new ActionMainPrompt(context); - } - return new ActionMainPrompt(context); - } - } - - private class EffectPrompt extends FixedSetPrompt { - - public EffectPrompt() { - super("1", "2", "3"); - } - - @SuppressWarnings("unchecked") - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEffect") + " -\n"; - if (context.getSessionData(CK.E_EFFECTS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetEffects") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetEffects") + "\n"; - LinkedList effects = (LinkedList) context.getSessionData(CK.E_EFFECTS); - LinkedList locations = (LinkedList) context.getSessionData(CK.E_EFFECTS_LOCATIONS); - for (String effect : effects) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + effect + ChatColor.GRAY + " at " - + ChatColor.DARK_AQUA + locations.get(effects.indexOf(effect)) + "\n"; - } - } - if (context.getSessionData(CK.E_EXPLOSIONS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetExplosions") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetExplosions") + "\n"; - LinkedList locations = (LinkedList) context.getSessionData(CK.E_EXPLOSIONS); - for (String loc : locations) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + loc + "\n"; - } - } - text += ChatColor.GREEN + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.YELLOW + "- " - + Lang.get("done") + "\n"; - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new SoundEffectListPrompt(); - } else if (input.equalsIgnoreCase("2")) { - selectedExplosionLocations.put(((Player) context.getForWhom()).getUniqueId(), null); - return new ExplosionPrompt(); - } - return new ActionMainPrompt(context); - } - } - - private class WeatherPrompt extends FixedSetPrompt { - - public WeatherPrompt() { - super("1", "2", "3", "4"); - } - - @SuppressWarnings("unchecked") - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("eventEditorWeather") + " -\n"; - if (context.getSessionData(CK.E_WORLD_STORM) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetStorm") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetStorm") + " (" + ChatColor.AQUA - + (String) context.getSessionData(CK.E_WORLD_STORM) + ChatColor.YELLOW + " -> " - + ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context - .getSessionData(CK.E_WORLD_STORM_DURATION) * 1000)) + ChatColor.YELLOW + ")\n"; - } - if (context.getSessionData(CK.E_WORLD_THUNDER) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetThunder") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetThunder") + " (" + ChatColor.AQUA - + (String) context.getSessionData(CK.E_WORLD_THUNDER) + ChatColor.YELLOW + " -> " - + ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context - .getSessionData(CK.E_WORLD_THUNDER_DURATION) * 1000)) + ChatColor.YELLOW + ")\n"; - } - - if (context.getSessionData(CK.E_LIGHTNING) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetLightning") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("eventEditorSetLightning") + "\n"; - LinkedList locations = (LinkedList) context.getSessionData(CK.E_LIGHTNING); - for (String loc : locations) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + loc + "\n"; - } - } - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.GREEN + "- " - + Lang.get("done") + "\n"; - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new StormPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new ThunderPrompt(); - } else if (input.equalsIgnoreCase("3")) { - selectedLightningLocations.put(((Player) context.getForWhom()).getUniqueId(), null); - return new LightningPrompt(); - } - return new ActionMainPrompt(context); - } - } - - private class FailTimerPrompt extends NumericPrompt { - - @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number number) { - context.setSessionData(CK.E_TIMER, number); - return new ActionMainPrompt(context); - } - - @Override - public String getPromptText(final ConversationContext conversationContext) { - return ChatColor.YELLOW + Lang.get("eventEditorEnterTimerSeconds"); - } - } - - private class SavePrompt extends StringPrompt { - - String modName = null; - LinkedList modified = new LinkedList(); - - public SavePrompt(String modifiedName) { - if (modifiedName != null) { - modName = modifiedName; - for (Quest q : plugin.getQuests()) { - for (Stage s : q.getStages()) { - if (s.getFinishAction() != null && s.getFinishAction().getName() != null) { - if (s.getFinishAction().getName().equalsIgnoreCase(modifiedName)) { - modified.add(q.getName()); - break; - } - } - } - } - } - } - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA - + context.getSessionData(CK.E_NAME) + ChatColor.YELLOW + "\"?\n"; - if (modified.isEmpty() == false) { - text += ChatColor.RED + Lang.get("eventEditorModifiedNote") + "\n"; - for (String s : modified) { - text += ChatColor.GRAY + " - " + ChatColor.DARK_RED + s + "\n"; - } - text += ChatColor.RED + Lang.get("eventEditorForcedToQuit") + "\n"; - } - return text + ChatColor.GREEN + "1 - " + Lang.get("yesWord") + "\n" + "2 - " + Lang.get("noWord"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - saveAction(context); - return new ActionMenuPrompt(context); - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new ActionMainPrompt(context); - } else { - return new SavePrompt(modName); - } - } - } - - private class ExitPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GREEN + " - " - + Lang.get("yesWord") + "\n" + ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET - + ChatColor.RED + " - " + Lang.get("noWord"); - return ChatColor.YELLOW + Lang.get("confirmDelete") + "\n" + text; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { - context.getForWhom().sendRawMessage(ChatColor.BOLD + "" + ChatColor.YELLOW + Lang.get("exited")); - clearData(context); - return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { - return new ActionMainPrompt(context); - } else { - return new ExitPrompt(); - } - } - } - - public static void clearData(ConversationContext context) { + public void clearData(ConversationContext context) { context.setSessionData(CK.E_OLD_EVENT, null); context.setSessionData(CK.E_NAME, null); context.setSessionData(CK.E_MESSAGE, null); @@ -1095,47 +261,7 @@ public class ActionFactory implements ConversationAbandonedListener { context.setSessionData(CK.E_CANCEL_TIMER, null); } - // Convenience methods to reduce typecasting - private static String getCString(ConversationContext context, String path) { - return (String) context.getSessionData(path); - } - - @SuppressWarnings("unchecked") - private static LinkedList getCStringList(ConversationContext context, String path) { - return (LinkedList) context.getSessionData(path); - } - - private static Integer getCInt(ConversationContext context, String path) { - return (Integer) context.getSessionData(path); - } - - @SuppressWarnings("unchecked") - private static LinkedList getCIntList(ConversationContext context, String path) { - return (LinkedList) context.getSessionData(path); - } - - @SuppressWarnings("unused") - private static Boolean getCBoolean(ConversationContext context, String path) { - return (Boolean) context.getSessionData(path); - } - - @SuppressWarnings({ "unchecked", "unused" }) - private static LinkedList getCBooleanList(ConversationContext context, String path) { - return (LinkedList) context.getSessionData(path); - } - - @SuppressWarnings({ "unused" }) - private static Long getCLong(ConversationContext context, String path) { - return (Long) context.getSessionData(path); - } - - @SuppressWarnings("unchecked") - private static LinkedList getCLongList(ConversationContext context, String path) { - return (LinkedList) context.getSessionData(path); - } - // - - private void deleteAction(ConversationContext context) { + public void deleteAction(ConversationContext context) { YamlConfiguration data = new YamlConfiguration(); File actionsFile = new File(plugin.getDataFolder(), "actions.yml"); try { @@ -1177,7 +303,8 @@ public class ActionFactory implements ConversationAbandonedListener { clearData(context); } - private void saveAction(ConversationContext context) { + @SuppressWarnings("unchecked") + public void saveAction(ConversationContext context) { YamlConfiguration data = new YamlConfiguration(); File actionsFile = new File(plugin.getDataFolder(), "actions.yml"); try { @@ -1208,51 +335,42 @@ public class ActionFactory implements ConversationAbandonedListener { ConfigurationSection section = data.createSection(key + "." + (String) context.getSessionData(CK.E_NAME)); editingActionNames.remove((String) context.getSessionData(CK.E_NAME)); if (context.getSessionData(CK.E_MESSAGE) != null) { - section.set("message", getCString(context, CK.E_MESSAGE)); + section.set("message", (String) context.getSessionData(CK.E_MESSAGE)); } if (context.getSessionData(CK.E_CLEAR_INVENTORY) != null) { - String s = getCString(context, CK.E_CLEAR_INVENTORY); + String s = (String) context.getSessionData(CK.E_CLEAR_INVENTORY); if (s.equalsIgnoreCase(Lang.get("yesWord"))) { section.set("clear-inventory", true); } } if (context.getSessionData(CK.E_FAIL_QUEST) != null) { - String s = getCString(context, CK.E_FAIL_QUEST); + String s = (String) context.getSessionData(CK.E_FAIL_QUEST); if (s.equalsIgnoreCase(Lang.get("yesWord"))) { section.set("fail-quest", true); } } if (context.getSessionData(CK.E_ITEMS) != null) { - @SuppressWarnings("unchecked") - LinkedList items = (LinkedList) context.getSessionData(CK.E_ITEMS); - section.set("items", items); + section.set("items", (LinkedList) context.getSessionData(CK.E_ITEMS)); } if (context.getSessionData(CK.E_EXPLOSIONS) != null) { - LinkedList locations = getCStringList(context, CK.E_EXPLOSIONS); - section.set("explosions", locations); + section.set("explosions", (LinkedList) context.getSessionData(CK.E_EXPLOSIONS)); } if (context.getSessionData(CK.E_EFFECTS) != null) { - LinkedList effects = getCStringList(context, CK.E_EFFECTS); - LinkedList locations = getCStringList(context, CK.E_EFFECTS_LOCATIONS); - section.set("effects", effects); - section.set("effect-locations", locations); + section.set("effects", (LinkedList) context.getSessionData(CK.E_EFFECTS)); + section.set("effect-locations", (LinkedList) context.getSessionData(CK.E_EFFECTS_LOCATIONS)); } if (context.getSessionData(CK.E_WORLD_STORM) != null) { - String world = getCString(context, CK.E_WORLD_STORM); - int duration = getCInt(context, CK.E_WORLD_STORM_DURATION); - section.set("storm-world", world); - section.set("storm-duration", duration); + section.set("storm-world", (String) context.getSessionData(CK.E_WORLD_STORM)); + section.set("storm-duration", (Integer) context.getSessionData(CK.E_WORLD_STORM_DURATION)); } if (context.getSessionData(CK.E_WORLD_THUNDER) != null) { - String world = getCString(context, CK.E_WORLD_THUNDER); - int duration = getCInt(context, CK.E_WORLD_THUNDER_DURATION); - section.set("thunder-world", world); - section.set("thunder-duration", duration); + section.set("thunder-world", (String) context.getSessionData(CK.E_WORLD_THUNDER)); + section.set("thunder-duration", (Integer) context.getSessionData(CK.E_WORLD_THUNDER_DURATION)); } try { if (context.getSessionData(CK.E_MOB_TYPES) != null) { int count = 0; - for (String s : getCStringList(context, CK.E_MOB_TYPES)) { + for (String s : (LinkedList) context.getSessionData(CK.E_MOB_TYPES)) { ConfigurationSection ss = section.getConfigurationSection("mob-spawns." + count); if (ss == null) { ss = section.createSection("mob-spawns." + count); @@ -1282,49 +400,42 @@ public class ActionFactory implements ConversationAbandonedListener { e.printStackTrace(); } if (context.getSessionData(CK.E_LIGHTNING) != null) { - LinkedList locations = getCStringList(context, CK.E_LIGHTNING); - section.set("lightning-strikes", locations); + section.set("lightning-strikes", (LinkedList) context.getSessionData(CK.E_LIGHTNING)); } if (context.getSessionData(CK.E_COMMANDS) != null) { - LinkedList commands = getCStringList(context, CK.E_COMMANDS); + LinkedList commands = (LinkedList) context.getSessionData(CK.E_COMMANDS); if (commands.isEmpty() == false) { section.set("commands", commands); } } if (context.getSessionData(CK.E_POTION_TYPES) != null) { - LinkedList types = getCStringList(context, CK.E_POTION_TYPES); - LinkedList durations = getCLongList(context, CK.E_POTION_DURATIONS); - LinkedList mags = getCIntList(context, CK.E_POTION_STRENGHT); - section.set("potion-effect-types", types); - section.set("potion-effect-durations", durations); - section.set("potion-effect-amplifiers", mags); + section.set("potion-effect-types", (LinkedList) context.getSessionData(CK.E_POTION_TYPES)); + section.set("potion-effect-durations", (LinkedList) context.getSessionData(CK.E_POTION_DURATIONS)); + section.set("potion-effect-amplifiers", (LinkedList) context.getSessionData(CK.E_POTION_STRENGHT)); } if (context.getSessionData(CK.E_HUNGER) != null) { - Integer i = getCInt(context, CK.E_HUNGER); - section.set("hunger", i); + section.set("hunger", (Integer) context.getSessionData(CK.E_HUNGER)); } if (context.getSessionData(CK.E_SATURATION) != null) { - Integer i = getCInt(context, CK.E_SATURATION); - section.set("saturation", i); + section.set("saturation", (Integer) context.getSessionData(CK.E_SATURATION)); } if (context.getSessionData(CK.E_HEALTH) != null) { - Integer i = getCInt(context, CK.E_HEALTH); - section.set("health", i); + section.set("health", (Integer) context.getSessionData(CK.E_HEALTH)); } if (context.getSessionData(CK.E_TELEPORT) != null) { - section.set("teleport-location", getCString(context, CK.E_TELEPORT)); + section.set("teleport-location", (String) context.getSessionData(CK.E_TELEPORT)); } if (context.getSessionData(CK.E_TIMER) != null && (int) context.getSessionData(CK.E_TIMER) > 0) { - section.set("timer", getCInt(context, CK.E_TIMER)); + section.set("timer", (Integer) context.getSessionData(CK.E_TIMER)); } if (context.getSessionData(CK.E_CANCEL_TIMER) != null) { - String s = getCString(context, CK.E_CANCEL_TIMER); + String s = (String) context.getSessionData(CK.E_CANCEL_TIMER); if (s.equalsIgnoreCase(Lang.get("yesWord"))) { section.set("cancel-timer", true); } } if (context.getSessionData(CK.E_DENIZEN) != null) { - section.set("denizen-script", getCString(context, CK.E_DENIZEN)); + section.set("denizen-script", (String) context.getSessionData(CK.E_DENIZEN)); } try { data.save(actionsFile); diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java new file mode 100644 index 000000000..7a7c47d76 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/main/ActionMainPrompt.java @@ -0,0 +1,782 @@ +package me.blackvein.quests.convo.actions.main; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.blackvein.quests.Quest; +import me.blackvein.quests.QuestMob; +import me.blackvein.quests.Quests; +import me.blackvein.quests.Stage; +import me.blackvein.quests.actions.Action; +import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt; +import me.blackvein.quests.convo.actions.menu.ActionMenuPrompt; +import me.blackvein.quests.convo.actions.tasks.EffectPrompt; +import me.blackvein.quests.convo.actions.tasks.PlayerPrompt; +import me.blackvein.quests.convo.actions.tasks.TimerPrompt; +import me.blackvein.quests.convo.actions.tasks.WeatherPrompt; +import me.blackvein.quests.convo.generic.ItemStackPrompt; +import me.blackvein.quests.events.editor.actions.ActionsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ConfigUtil; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; + +public class ActionMainPrompt extends ActionsEditorNumericPrompt { + + private final Quests plugin; + + public ActionMainPrompt(ConversationContext context) { + super(context); + this.plugin = (Quests)context.getPlugin(); + } + + private final int size = 10; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("event") + ": " + context.getSessionData(CK.E_NAME); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + if (plugin.getDependencies().getDenizenAPI() == null) { + return ChatColor.GRAY; + } else { + return ChatColor.BLUE; + } + case 8: + return ChatColor.BLUE; + case 9: + return ChatColor.GREEN; + case 10: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("eventEditorSetName"); + case 2: + return ChatColor.GOLD + Lang.get("eventEditorPlayer"); + case 3: + return ChatColor.GOLD + Lang.get("eventEditorTimer"); + case 4: + return ChatColor.GOLD + Lang.get("eventEditorEffect"); + case 5: + return ChatColor.GOLD + Lang.get("eventEditorWeather"); + case 6: + return ChatColor.YELLOW + Lang.get("eventEditorSetMobSpawns"); + case 7: + if (plugin.getDependencies().getDenizenAPI() == null) { + return ChatColor.GRAY + Lang.get("stageEditorDenizenScript"); + } else { + return ChatColor.YELLOW + Lang.get("stageEditorDenizenScript"); + } + case 8: + return ChatColor.YELLOW + Lang.get("eventEditorFailQuest") + ":"; + case 9: + return ChatColor.GREEN + Lang.get("save"); + case 10: + return ChatColor.RED + Lang.get("exit"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + case 4: + case 5: + return ""; + case 6: + if (context.getSessionData(CK.E_MOB_TYPES) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + LinkedList types = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); + String text = ""; + for (String s : types) { + QuestMob qm = QuestMob.fromString(s); + text += ChatColor.GRAY + " - " + ChatColor.AQUA + qm.getType().name() + + ((qm.getName() != null) ? ": " + qm.getName() : "") + ChatColor.GRAY + " x " + + ChatColor.DARK_AQUA + qm.getSpawnAmounts() + ChatColor.GRAY + " -> " + + ChatColor.GREEN + ConfigUtil.getLocationInfo(qm.getSpawnLocation()) + "\n"; + } + return text; + } + case 7: + if (plugin.getDependencies().getDenizenAPI() == null) { + return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; + } else { + if (context.getSessionData(CK.E_DENIZEN) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + return ChatColor.GRAY + "(" + ChatColor.AQUA + context.getSessionData(CK.E_DENIZEN) + + ChatColor.GRAY + ")"; + } + } + case 8: + if (context.getSessionData(CK.E_FAIL_QUEST) == null) { + context.setSessionData(CK.E_FAIL_QUEST, Lang.get("noWord")); + } + return "" + ChatColor.AQUA + context.getSessionData(CK.E_FAIL_QUEST); + case 9: + case 10: + return ""; + default: + return null; + } + } + + @Override + public String getPromptText(ConversationContext context) { + ActionsEditorPostOpenNumericPromptEvent event = new ActionsEditorPostOpenNumericPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = ChatColor.GOLD + "- " + getTitle(context).replaceFirst(": ", ": " + ChatColor.AQUA) + + ChatColor.GOLD + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; + } + return text; + } + + @Override + public Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch (input.intValue()) { + case 1: + return new ActionNamePrompt(); + case 2: + return new PlayerPrompt(context); + case 3: + return new TimerPrompt(); + case 4: + return new EffectPrompt(context); + case 5: + return new WeatherPrompt(context); + case 6: + return new ActionMobPrompt(); + case 7: + return new ActionDenizenPrompt(); + case 8: + String s = (String) context.getSessionData(CK.E_FAIL_QUEST); + if (s.equalsIgnoreCase(Lang.get("yesWord"))) { + context.setSessionData(CK.E_FAIL_QUEST, Lang.get("noWord")); + } else { + context.setSessionData(CK.E_FAIL_QUEST, Lang.get("yesWord")); + } + return new ActionMainPrompt(context); + case 9: + if (context.getSessionData(CK.E_OLD_EVENT) != null) { + return new ActionSavePrompt((String) context.getSessionData(CK.E_OLD_EVENT)); + } else { + return new ActionSavePrompt(null); + } + case 10: + return new ActionExitPrompt(); + default: + return new ActionMainPrompt(context); + } + } + + private class ActionNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorEnterEventName"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + for (Action a : plugin.getActions()) { + if (a.getName().equalsIgnoreCase(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists")); + return new ActionNamePrompt(); + } + } + List actionNames = plugin.getActionFactory().getNamesOfActionsBeingEdited(); + if (actionNames.contains(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); + return new ActionNamePrompt(); + } + if (input.contains(",")) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); + return new ActionNamePrompt(); + } + actionNames.remove((String) context.getSessionData(CK.E_NAME)); + context.setSessionData(CK.E_NAME, input); + actionNames.add(input); + plugin.getActionFactory().setNamesOfActionsBeingEdited(actionNames); + } + return new ActionMainPrompt(context); + } + } + + private class ActionMobPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("eventEditorMobSpawnsTitle") + "\n"; + if (context.getSessionData(CK.E_MOB_TYPES) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddMobTypes") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + @SuppressWarnings("unchecked") + LinkedList types = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); + for (int i = 0; i < types.size(); i++) { + QuestMob qm = QuestMob.fromString(types.get(i)); + text += ChatColor.BLUE + "" + ChatColor.BOLD + (i + 1) + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("edit") + ": " + ChatColor.AQUA + qm.getType().name() + + ((qm.getName() != null) ? ": " + qm.getName() : "") + ChatColor.GRAY + " x " + + ChatColor.DARK_AQUA + qm.getSpawnAmounts() + ChatColor.GRAY + " -> " + ChatColor.GREEN + + ConfigUtil.getLocationInfo(qm.getSpawnLocation()) + "\n"; + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + (types.size() + 1) + ChatColor.RESET + ChatColor.YELLOW + + " - " + Lang.get("eventEditorAddMobTypes") + "\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + (types.size() + 2) + ChatColor.RESET + ChatColor.YELLOW + + " - " + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + (types.size() + 3) + ChatColor.RESET + ChatColor.YELLOW + + " - " + Lang.get("done"); + } + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (context.getSessionData(CK.E_MOB_TYPES) == null) { + if (input.equalsIgnoreCase("1")) { + return new QuestMobPrompt(0, null); + } else if (input.equalsIgnoreCase("2")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorMobSpawnsCleared")); + context.setSessionData(CK.E_MOB_TYPES, null); + return new ActionMobPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new ActionMainPrompt(context); + } + } else { + @SuppressWarnings("unchecked") + LinkedList types = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); + int inp; + try { + inp = Integer.parseInt(input); + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("reqNotANumber").replace("", input)); + return new ActionMobPrompt(); + } + if (inp == types.size() + 1) { + return new QuestMobPrompt(inp - 1, null); + } else if (inp == types.size() + 2) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorMobSpawnsCleared")); + context.setSessionData(CK.E_MOB_TYPES, null); + return new ActionMobPrompt(); + } else if (inp == types.size() + 3) { + return new ActionMainPrompt(context); + } else if (inp > types.size()) { + return new ActionMobPrompt(); + } else { + return new QuestMobPrompt(inp - 1, QuestMob.fromString(types.get(inp - 1))); + } + } + return new ActionMobPrompt(); + } + } + + private class QuestMobPrompt extends StringPrompt { + + private QuestMob questMob; + private Integer itemIndex = -1; + private final Integer mobIndex; + + public QuestMobPrompt(int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("eventEditorAddMobTypesTitle") + "\n"; + if (questMob == null) { + questMob = new QuestMob(); + } + // Check/add newly made item + if (context.getSessionData("newItem") != null) { + if (itemIndex >= 0) { + questMob.getInventory()[itemIndex] = ((ItemStack) context.getSessionData("tempStack")); + itemIndex = -1; + } + context.setSessionData("newItem", null); + context.setSessionData("tempStack", null); + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobName") + ChatColor.GRAY + " (" + + ((questMob.getName() == null) ? Lang.get("noneSet") : ChatColor.AQUA + questMob.getName()) + + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobType") + ChatColor.GRAY + " (" + + ((questMob.getType() == null) ? Lang.get("noneSet") : ChatColor.AQUA + questMob.getType().name()) + + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddSpawnLocation") + ChatColor.GRAY + " (" + + ((questMob.getSpawnLocation() == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ConfigUtil.getLocationInfo(questMob.getSpawnLocation())) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobSpawnAmount") + ChatColor.GRAY + " (" + + ((questMob.getSpawnAmounts() == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getSpawnAmounts()) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobItemInHand") + ChatColor.GRAY + " (" + + ((questMob.getInventory()[0] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ItemUtil.getDisplayString(questMob.getInventory()[0])) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobItemInHandDrop") + ChatColor.GRAY + " (" + + ((questMob.getDropChances()[0] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getDropChances()[0]) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobBoots") + ChatColor.GRAY + " (" + + ((questMob.getInventory()[1] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ItemUtil.getDisplayString(questMob.getInventory()[1])) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "8" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobBootsDrop") + ChatColor.GRAY + " (" + + ((questMob.getDropChances()[1] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getDropChances()[1]) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "9" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobLeggings") + ChatColor.GRAY + " (" + + ((questMob.getInventory()[2] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ItemUtil.getDisplayString(questMob.getInventory()[2])) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "10" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobLeggingsDrop") + ChatColor.GRAY + " (" + + ((questMob.getDropChances()[2] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getDropChances()[2]) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "11" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobChestPlate") + ChatColor.GRAY + " (" + + ((questMob.getInventory()[3] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ItemUtil.getDisplayString(questMob.getInventory()[3])) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "12" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobChestPlateDrop") + ChatColor.GRAY + " (" + + ((questMob.getDropChances()[3] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getDropChances()[3]) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "13" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobHelmet") + ChatColor.GRAY + " (" + + ((questMob.getInventory()[4] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + ItemUtil.getDisplayString(questMob.getInventory()[4])) + ChatColor.GRAY + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "14" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMobHelmetDrop") + ChatColor.GRAY + " (" + + ((questMob.getDropChances()[4] == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA + + "" + questMob.getDropChances()[4]) + ChatColor.GRAY + ")\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "15" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done") + "\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + "16" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("cancel"); + return text; + } + + @SuppressWarnings("unchecked") + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new MobNamePrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase("2")) { + return new MobTypePrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase("3")) { + Map selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations(); + selectedMobLocations.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); + return new MobLocationPrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase("4")) { + return new MobAmountPrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase("5")) { + itemIndex = 0; + return new ItemStackPrompt(QuestMobPrompt.this); + } else if (input.equalsIgnoreCase("6")) { + return new MobDropPrompt(0, mobIndex, questMob); + } else if (input.equalsIgnoreCase("7")) { + itemIndex = 1; + return new ItemStackPrompt(QuestMobPrompt.this); + } else if (input.equalsIgnoreCase("8")) { + return new MobDropPrompt(1, mobIndex, questMob); + } else if (input.equalsIgnoreCase("9")) { + itemIndex = 2; + return new ItemStackPrompt(QuestMobPrompt.this); + } else if (input.equalsIgnoreCase("10")) { + return new MobDropPrompt(2, mobIndex, questMob); + } else if (input.equalsIgnoreCase("11")) { + itemIndex = 3; + return new ItemStackPrompt(QuestMobPrompt.this); + } else if (input.equalsIgnoreCase("12")) { + return new MobDropPrompt(3, mobIndex, questMob); + } else if (input.equalsIgnoreCase("13")) { + itemIndex = 4; + return new ItemStackPrompt(QuestMobPrompt.this); + } else if (input.equalsIgnoreCase("14")) { + return new MobDropPrompt(4, mobIndex, questMob); + } else if (input.equalsIgnoreCase("15")) { + if (questMob.getType() == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobTypesFirst")); + return new QuestMobPrompt(mobIndex, questMob); + } else if (questMob.getSpawnLocation() == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobLocationFirst")); + return new QuestMobPrompt(mobIndex, questMob); + } else if (questMob.getSpawnAmounts() == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobAmountsFirst")); + return new QuestMobPrompt(mobIndex, questMob); + } + if (context.getSessionData(CK.E_MOB_TYPES) == null + || ((LinkedList) context.getSessionData(CK.E_MOB_TYPES)).isEmpty()) { + LinkedList list = new LinkedList(); + list.add(questMob.serialize()); + context.setSessionData(CK.E_MOB_TYPES, list); + } else { + LinkedList list = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); + if (mobIndex < list.size()) { + list.set(mobIndex, questMob.serialize()); + } else { + list.add(questMob.serialize()); + } + context.setSessionData(CK.E_MOB_TYPES, list); + } + return new ActionMobPrompt(); + } else if (input.equalsIgnoreCase("16")) { + return new ActionMobPrompt(); + } else { + return new QuestMobPrompt(mobIndex, questMob); + } + } + } + + private class MobNamePrompt extends StringPrompt { + + private final QuestMob questMob; + private final Integer mobIndex; + + public MobNamePrompt(int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.YELLOW + Lang.get("eventEditorSetMobNamePrompt"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + return new QuestMobPrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + questMob.setName(null); + return new QuestMobPrompt(mobIndex, questMob); + } else { + input = ChatColor.translateAlternateColorCodes('&', input); + questMob.setName(input); + return new QuestMobPrompt(mobIndex, questMob); + } + } + } + + private class MobTypePrompt extends StringPrompt { + + private final QuestMob questMob; + private final Integer mobIndex; + + public MobTypePrompt(int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + } + + @Override + public String getPromptText(ConversationContext arg0) { + String mobs = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorMobsTitle") + "\n"; + final EntityType[] mobArr = EntityType.values(); + for (int i = 0; i < mobArr.length; i++) { + final EntityType type = mobArr[i]; + if (type.isAlive() == false) { + continue; + } + if (i < (mobArr.length - 1)) { + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", "; + } else { + mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + "\n"; + } + } + return mobs + ChatColor.YELLOW + Lang.get("eventEditorSetMobTypesPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (MiscUtil.getProperMobType(input) != null) { + questMob.setType(MiscUtil.getProperMobType(input)); + } else { + player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + + Lang.get("eventEditorInvalidMob")); + return new MobTypePrompt(mobIndex, questMob); + } + } + return new QuestMobPrompt(mobIndex, questMob); + } + } + + private class MobAmountPrompt extends StringPrompt { + + private final QuestMob questMob; + private final Integer mobIndex; + + public MobAmountPrompt(int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + } + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetMobAmountsPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + try { + int i = Integer.parseInt(input); + if (i < 1) { + player.sendMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("", "1")); + return new MobAmountPrompt(mobIndex, questMob); + } + questMob.setSpawnAmounts(i); + return new QuestMobPrompt(mobIndex, questMob); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", input)); + return new MobAmountPrompt(mobIndex, questMob); + } + } + return new QuestMobPrompt(mobIndex, questMob); + } + } + + private class MobLocationPrompt extends StringPrompt { + + private final QuestMob questMob; + private final Integer mobIndex; + + public MobLocationPrompt(int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + } + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetMobLocationPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) { + Map selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations(); + Block block = selectedMobLocations.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + questMob.setSpawnLocation(loc); + selectedMobLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); + } else { + player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); + return new MobLocationPrompt(mobIndex, questMob); + } + return new QuestMobPrompt(mobIndex, questMob); + } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + Map selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations(); + selectedMobLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); + return new QuestMobPrompt(mobIndex, questMob); + } else { + return new MobLocationPrompt(mobIndex, questMob); + } + } + } + + private class MobDropPrompt extends StringPrompt { + + private final QuestMob questMob; + private final Integer mobIndex; + private final Integer invIndex; + + public MobDropPrompt(int invIndex, int mobIndex, QuestMob questMob) { + this.questMob = questMob; + this.mobIndex = mobIndex; + this.invIndex = invIndex; + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.YELLOW + Lang.get("eventEditorSetDropChance"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + float chance; + if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + return new QuestMobPrompt(mobIndex, questMob); + } + try { + chance = Float.parseFloat(input); + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange") + .replace("", "0.0").replace("", "1.0")); + return new MobDropPrompt(invIndex, mobIndex, questMob); + } + if (chance > 1 || chance < 0) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange") + .replace("", "0.0").replace("", "1.0")); + return new MobDropPrompt(invIndex, mobIndex, questMob); + } + Float[] temp = questMob.getDropChances(); + temp[invIndex] = chance; + questMob.setDropChances(temp); + return new QuestMobPrompt(mobIndex, questMob); + } + } + + private class ActionDenizenPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.DARK_AQUA + "- " + Lang.get("stageEditorDenizenScript") + " -\n"; + for (String s : plugin.getDependencies().getDenizenAPI().getScriptNames()) { + text += ChatColor.AQUA + "- " + s + "\n"; + } + return text + ChatColor.YELLOW + Lang.get("stageEditorScriptPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (plugin.getDependencies().getDenizenAPI().containsScript(input)) { + context.setSessionData(CK.E_DENIZEN, input.toUpperCase()); + return new ActionMainPrompt(context); + } else { + player.sendMessage(ChatColor.RED + Lang.get("stageEditorInvalidScript")); + return new ActionDenizenPrompt(); + } + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_DENIZEN, null); + player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorDenizenCleared")); + return new ActionMainPrompt(context); + } else { + return new ActionMainPrompt(context); + } + } + } + + private class ActionSavePrompt extends StringPrompt { + + String modName = null; + LinkedList modified = new LinkedList(); + + public ActionSavePrompt(String modifiedName) { + if (modifiedName != null) { + modName = modifiedName; + for (Quest q : plugin.getQuests()) { + for (Stage s : q.getStages()) { + if (s.getFinishAction() != null && s.getFinishAction().getName() != null) { + if (s.getFinishAction().getName().equalsIgnoreCase(modifiedName)) { + modified.add(q.getName()); + break; + } + } + } + } + } + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA + + context.getSessionData(CK.E_NAME) + ChatColor.YELLOW + "\"?\n"; + if (modified.isEmpty() == false) { + text += ChatColor.RED + Lang.get("eventEditorModifiedNote") + "\n"; + for (String s : modified) { + text += ChatColor.GRAY + " - " + ChatColor.DARK_RED + s + "\n"; + } + text += ChatColor.RED + Lang.get("eventEditorForcedToQuit") + "\n"; + } + return text + ChatColor.GREEN + "1 - " + Lang.get("yesWord") + "\n" + "2 - " + Lang.get("noWord"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + plugin.getActionFactory().saveAction(context); + return new ActionMenuPrompt(context); + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new ActionMainPrompt(context); + } else { + return new ActionSavePrompt(modName); + } + } + } + + private class ActionExitPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GREEN + " - " + + Lang.get("yesWord") + "\n" + ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + + ChatColor.RED + " - " + Lang.get("noWord"); + return ChatColor.YELLOW + Lang.get("confirmDelete") + "\n" + text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + context.getForWhom().sendRawMessage(ChatColor.BOLD + "" + ChatColor.YELLOW + Lang.get("exited")); + plugin.getActionFactory().clearData(context); + return Prompt.END_OF_CONVERSATION; + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new ActionMainPrompt(context); + } else { + return new ActionExitPrompt(); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/menu/ActionMenuPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/menu/ActionMenuPrompt.java new file mode 100644 index 000000000..920ff42e9 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/menu/ActionMenuPrompt.java @@ -0,0 +1,301 @@ +package me.blackvein.quests.convo.actions.menu; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; + +import me.blackvein.quests.Quest; +import me.blackvein.quests.Quests; +import me.blackvein.quests.Stage; +import me.blackvein.quests.actions.Action; +import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt; +import me.blackvein.quests.convo.actions.ActionsEditorStringPrompt; +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.events.editor.actions.ActionsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.actions.ActionsEditorPostOpenStringPromptEvent; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.Lang; + +public class ActionMenuPrompt extends ActionsEditorNumericPrompt { + + private final Quests plugin; + + public ActionMenuPrompt(ConversationContext context) { + super(context); + this.plugin = (Quests)context.getPlugin(); + } + + private final int size = 4; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("eventEditorTitle"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + return ChatColor.BLUE; + case 4: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("eventEditorCreate"); + case 2: + return ChatColor.YELLOW + Lang.get("eventEditorEdit"); + case 3: + return ChatColor.YELLOW + Lang.get("eventEditorDelete"); + case 4: + return ChatColor.RED + Lang.get("exit"); + default: + return null; + } + } + + public String getAdditionalText(ConversationContext context, int number) { + return null; + } + + @Override + public String getPromptText(ConversationContext context) { + ActionsEditorPostOpenNumericPromptEvent event = new ActionsEditorPostOpenNumericPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + String text = ChatColor.GOLD + getTitle(context) + "\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + "\n"; + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + final Player player = (Player) context.getForWhom(); + switch (input.intValue()) { + case 1: + if (player.hasPermission("quests.editor.actions.create") + || player.hasPermission("quests.editor.events.create")) { + context.setSessionData(CK.E_OLD_EVENT, ""); + return new ActionSelectCreatePrompt(context); + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new ActionMenuPrompt(context); + } + case 2: + if (player.hasPermission("quests.editor.actions.edit") + || player.hasPermission("quests.editor.events.edit")) { + if (plugin.getActions().isEmpty()) { + ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + + Lang.get("eventEditorNoneToEdit")); + return new ActionMenuPrompt(context); + } else { + return new ActionSelectEditPrompt(); + } + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new ActionMenuPrompt(context); + } + case 3: + if (player.hasPermission("quests.editor.actions.delete") + || player.hasPermission("quests.editor.events.delete")) { + if (plugin.getActions().isEmpty()) { + ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + + Lang.get("eventEditorNoneToDelete")); + return new ActionMenuPrompt(context); + } else { + return new ActionSelectDeletePrompt(); + } + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new ActionMenuPrompt(context); + } + case 4: + ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("exited")); + return Prompt.END_OF_CONVERSATION; + default: + return new ActionMenuPrompt(context); + } + } + + public class ActionSelectCreatePrompt extends ActionsEditorStringPrompt { + public ActionSelectCreatePrompt(ConversationContext context) { + super(context); + } + + public String getTitle(ConversationContext context) { + return Lang.get("eventEditorCreate"); + } + + public String getQueryText(ConversationContext context) { + return Lang.get("eventEditorEnterEventName"); + } + + @Override + public String getPromptText(ConversationContext context) { + ActionsEditorPostOpenStringPromptEvent event = new ActionsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = ChatColor.GOLD + getTitle(context) + "\n" + ChatColor.YELLOW + getQueryText(context); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); + return new ActionSelectCreatePrompt(context); + } + input = input.trim(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + for (Action e : plugin.getActions()) { + if (e.getName().equalsIgnoreCase(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists")); + return new ActionSelectCreatePrompt(context); + } + } + if (plugin.getActionFactory().getNamesOfActionsBeingEdited().contains(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); + return new ActionSelectCreatePrompt(context); + } + if (StringUtils.isAlphanumeric(input) == false) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha")); + return new ActionSelectCreatePrompt(context); + } + if (input.equals("")) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); + return new ActionSelectCreatePrompt(context); + } + context.setSessionData(CK.E_NAME, input); + List actionNames = plugin.getActionFactory().getNamesOfActionsBeingEdited(); + actionNames.add(input); + plugin.getActionFactory().setNamesOfActionsBeingEdited(actionNames); + return new ActionMainPrompt(context); + } else { + return new ActionMenuPrompt(context); + } + } + } + + private class ActionSelectEditPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEdit") + " -\n"; + for (Action a : plugin.getActions()) { + text += ChatColor.AQUA + a.getName() + ChatColor.GRAY + ", "; + } + text = text.substring(0, text.length() - 2) + "\n"; + text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + Action a = plugin.getAction(input); + if (a != null) { + context.setSessionData(CK.E_OLD_EVENT, a.getName()); + context.setSessionData(CK.E_NAME, a.getName()); + plugin.getActionFactory().loadData(a, context); + return new ActionMainPrompt(context); + } + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound")); + return new ActionSelectEditPrompt(); + } else { + return new ActionMenuPrompt(context); + } + } + } + + private class ActionSelectDeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorDelete") + " -\n"; + for (Action a : plugin.getActions()) { + text += ChatColor.AQUA + a.getName() + ChatColor.GRAY + ","; + } + text = text.substring(0, text.length() - 1) + "\n"; + text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + LinkedList used = new LinkedList(); + Action a = plugin.getAction(input); + if (a != null) { + for (Quest quest : plugin.getQuests()) { + for (Stage stage : quest.getStages()) { + if (stage.getFinishAction() != null + && stage.getFinishAction().getName().equalsIgnoreCase(a.getName())) { + used.add(quest.getName()); + break; + } + } + } + if (used.isEmpty()) { + context.setSessionData(CK.ED_EVENT_DELETE, a.getName()); + return new ActionConfirmDeletePrompt(); + } else { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorEventInUse") + + " \"" + ChatColor.DARK_PURPLE + a.getName() + ChatColor.RED + "\":"); + for (String s : used) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "- " + ChatColor.DARK_RED + s); + } + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("eventEditorMustModifyQuests")); + return new ActionSelectDeletePrompt(); + } + } + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound")); + return new ActionSelectDeletePrompt(); + } else { + return new ActionMenuPrompt(context); + } + } + } + + private class ActionConfirmDeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + "" + ChatColor.GREEN + " - " + + Lang.get("yesWord") + "\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + "" + ChatColor.RED + " - " + + Lang.get("noWord"); + return ChatColor.RED + Lang.get("confirmDelete") + " (" + ChatColor.YELLOW + + (String) context.getSessionData(CK.ED_EVENT_DELETE) + ChatColor.RED + ")\n" + text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + plugin.getActionFactory().deleteAction(context); + return new ActionMenuPrompt(context); + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new ActionMenuPrompt(context); + } else { + return new ActionConfirmDeletePrompt(); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/tasks/EffectPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/EffectPrompt.java new file mode 100644 index 000000000..2ccab29d9 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/EffectPrompt.java @@ -0,0 +1,313 @@ +package me.blackvein.quests.convo.actions.tasks; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; + +import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ConfigUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; + +public class EffectPrompt extends FixedSetPrompt { + + private final Quests plugin; + + public EffectPrompt(ConversationContext context) { + super("1", "2", "3"); + this.plugin = (Quests)context.getPlugin(); + } + + @SuppressWarnings("unchecked") + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEffect") + " -\n"; + if (context.getSessionData(CK.E_EFFECTS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetEffects") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetEffects") + "\n"; + LinkedList effects = (LinkedList) context.getSessionData(CK.E_EFFECTS); + LinkedList locations = (LinkedList) context.getSessionData(CK.E_EFFECTS_LOCATIONS); + for (String effect : effects) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + effect + ChatColor.GRAY + " at " + + ChatColor.DARK_AQUA + locations.get(effects.indexOf(effect)) + "\n"; + } + } + if (context.getSessionData(CK.E_EXPLOSIONS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetExplosions") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetExplosions") + "\n"; + LinkedList locations = (LinkedList) context.getSessionData(CK.E_EXPLOSIONS); + for (String loc : locations) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + loc + "\n"; + } + } + text += ChatColor.GREEN + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.YELLOW + "- " + + Lang.get("done") + "\n"; + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new SoundEffectListPrompt(); + } else if (input.equalsIgnoreCase("2")) { + Map selectedExplosionLocations = plugin.getActionFactory().getSelectedExplosionLocations(); + selectedExplosionLocations.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getActionFactory().setSelectedExplosionLocations(selectedExplosionLocations); + return new ExplosionPrompt(); + } + return new ActionMainPrompt(context); + } + + private class SoundEffectListPrompt extends FixedSetPrompt { + + public SoundEffectListPrompt() { + super("1", "2", "3", "4"); + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEffects") + " -\n"; + if (context.getSessionData(CK.E_EFFECTS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddEffect") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddEffectLocation") + " (" + Lang.get("eventEditorNoEffects") + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddEffect") + "\n"; + for (String s : getEffects(context)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + if (context.getSessionData(CK.E_EFFECTS_LOCATIONS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddEffectLocation") + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorAddEffectLocation") + "\n"; + for (String s : getEffectLocations(context)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + 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 SoundEffectPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.E_EFFECTS) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustAddEffects")); + return new SoundEffectListPrompt(); + } else { + Map selectedEffectLocations = plugin.getActionFactory().getSelectedEffectLocations(); + selectedEffectLocations.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getActionFactory().setSelectedEffectLocations(selectedEffectLocations); + return new SoundEffectLocationPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorEffectsCleared")); + context.setSessionData(CK.E_EFFECTS, null); + context.setSessionData(CK.E_EFFECTS_LOCATIONS, null); + return new SoundEffectListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + int one; + int two; + if (context.getSessionData(CK.E_EFFECTS) != null) { + one = getEffects(context).size(); + } else { + one = 0; + } + if (context.getSessionData(CK.E_EFFECTS_LOCATIONS) != null) { + two = getEffectLocations(context).size(); + } else { + two = 0; + } + if (one == two) { + return new ActionMainPrompt(context); + } else { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); + return new SoundEffectListPrompt(); + } + } + return null; + } + + @SuppressWarnings("unchecked") + private List getEffects(ConversationContext context) { + return (List) context.getSessionData(CK.E_EFFECTS); + } + + @SuppressWarnings("unchecked") + private List getEffectLocations(ConversationContext context) { + return (List) context.getSessionData(CK.E_EFFECTS_LOCATIONS); + } + } + + private class SoundEffectPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorEffectsTitle") + "\n"; + 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") + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (MiscUtil.getProperEffect(input) != null) { + LinkedList effects; + if (context.getSessionData(CK.E_EFFECTS) != null) { + effects = (LinkedList) context.getSessionData(CK.E_EFFECTS); + } else { + effects = new LinkedList(); + } + effects.add(input.toUpperCase()); + context.setSessionData(CK.E_EFFECTS, effects); + Map selectedEffectLocations = plugin.getActionFactory().getSelectedEffectLocations(); + selectedEffectLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedEffectLocations(selectedEffectLocations); + return new SoundEffectListPrompt(); + } else { + player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + + Lang.get("eventEditorInvalidEffect")); + return new SoundEffectPrompt(); + } + } else { + Map selectedEffectLocations = plugin.getActionFactory().getSelectedEffectLocations(); + selectedEffectLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedEffectLocations(selectedEffectLocations); + return new SoundEffectListPrompt(); + } + } + } + + private class SoundEffectLocationPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorEffectLocationPrompt"); + } + + @SuppressWarnings("unchecked") + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) { + Map selectedEffectLocations = plugin.getActionFactory().getSelectedEffectLocations(); + Block block = selectedEffectLocations.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + LinkedList locs; + if (context.getSessionData(CK.E_EFFECTS_LOCATIONS) != null) { + locs = (LinkedList) context.getSessionData(CK.E_EFFECTS_LOCATIONS); + } else { + locs = new LinkedList(); + } + locs.add(ConfigUtil.getLocationInfo(loc)); + context.setSessionData(CK.E_EFFECTS_LOCATIONS, locs); + selectedEffectLocations.remove(player.getUniqueId()); + } else { + player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); + return new SoundEffectLocationPrompt(); + } + return new SoundEffectListPrompt(); + } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + Map selectedEffectLocations = plugin.getActionFactory().getSelectedEffectLocations(); + selectedEffectLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedEffectLocations(selectedEffectLocations); + return new SoundEffectListPrompt(); + } else { + return new SoundEffectLocationPrompt(); + } + } + } + + public class ExplosionPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorExplosionPrompt"); + } + + @SuppressWarnings("unchecked") + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) { + Map selectedExplosionLocations = plugin.getActionFactory().getSelectedExplosionLocations(); + Block block = selectedExplosionLocations.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + LinkedList locs; + if (context.getSessionData(CK.E_EXPLOSIONS) != null) { + locs = (LinkedList) context.getSessionData(CK.E_EXPLOSIONS); + } else { + locs = new LinkedList(); + } + locs.add(ConfigUtil.getLocationInfo(loc)); + context.setSessionData(CK.E_EXPLOSIONS, locs); + selectedExplosionLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedExplosionLocations(selectedExplosionLocations); + } else { + player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); + return new ExplosionPrompt(); + } + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_EXPLOSIONS, null); + Map selectedExplosionLocations = plugin.getActionFactory().getSelectedExplosionLocations(); + selectedExplosionLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedExplosionLocations(selectedExplosionLocations); + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + Map selectedExplosionLocations = plugin.getActionFactory().getSelectedExplosionLocations(); + selectedExplosionLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedExplosionLocations(selectedExplosionLocations); + return new ActionMainPrompt(context); + } else { + return new ExplosionPrompt(); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/tasks/PlayerPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/PlayerPrompt.java new file mode 100644 index 000000000..b378acf5c --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/PlayerPrompt.java @@ -0,0 +1,616 @@ +package me.blackvein.quests.convo.actions.tasks; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffectType; + +import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.convo.generic.ItemStackPrompt; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ConfigUtil; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; +import me.blackvein.quests.util.RomanNumeral; + +public class PlayerPrompt extends FixedSetPrompt { + + private final Quests plugin; + + public PlayerPrompt(ConversationContext context) { + super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); + this.plugin = (Quests)context.getPlugin(); + } + + @SuppressWarnings("unchecked") + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorPlayer") + " -\n"; + if (context.getSessionData(CK.E_MESSAGE) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMessage") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetMessage") + " (" + ChatColor.AQUA + + context.getSessionData(CK.E_MESSAGE) + ChatColor.RESET + ChatColor.YELLOW + ")\n"; + } + if (context.getSessionData(CK.E_CLEAR_INVENTORY) == null) { + context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord")); + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorClearInv") + ": " + ChatColor.AQUA + + context.getSessionData(CK.E_CLEAR_INVENTORY) + "\n"; + if (context.getSessionData(CK.E_ITEMS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetItems") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetItems") + "\n"; + LinkedList items = (LinkedList) context.getSessionData(CK.E_ITEMS); + for (ItemStack is : items) { + if (is != null) { + text += ChatColor.GRAY + " - " + ItemUtil.getString(is) + "\n"; + } + } + } + if (context.getSessionData(CK.E_POTION_TYPES) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionEffects") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionEffects") + "\n"; + LinkedList types = (LinkedList) context.getSessionData(CK.E_POTION_TYPES); + LinkedList durations = (LinkedList) context.getSessionData(CK.E_POTION_DURATIONS); + LinkedList mags = (LinkedList) context.getSessionData(CK.E_POTION_STRENGHT); + int index = -1; + for (String type : types) { + index++; + text += ChatColor.GRAY + " - " + ChatColor.AQUA + type + ChatColor.DARK_PURPLE + " " + + RomanNumeral.getNumeral(mags.get(index)) + ChatColor.GRAY + " -> " + ChatColor.DARK_AQUA + + MiscUtil.getTime(durations.get(index) * 50L) + "\n"; + } + } + if (context.getSessionData(CK.E_HUNGER) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetHunger") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetHunger") + ChatColor.AQUA + " (" + + (Integer) context.getSessionData(CK.E_HUNGER) + ")\n"; + } + if (context.getSessionData(CK.E_SATURATION) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetSaturation") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetSaturation") + ChatColor.AQUA + " (" + + (Integer) context.getSessionData(CK.E_SATURATION) + ")\n"; + } + if (context.getSessionData(CK.E_HEALTH) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetHealth") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetHealth") + ChatColor.AQUA + " (" + + (Integer) context.getSessionData(CK.E_HEALTH) + ")\n"; + } + if (context.getSessionData(CK.E_TELEPORT) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "8" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetTeleport") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "8" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetTeleport") + ChatColor.AQUA + " (" + + (String) context.getSessionData(CK.E_TELEPORT) + ")\n"; + } + if (context.getSessionData(CK.E_COMMANDS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "9" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetCommands") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "9" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetCommands") + "\n"; + for (String s : (LinkedList) context.getSessionData(CK.E_COMMANDS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + } + text += ChatColor.GREEN + "" + ChatColor.BOLD + "10 " + ChatColor.RESET + ChatColor.YELLOW + "- " + + Lang.get("done") + "\n"; + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new MessagePrompt(); + } else if (input.equalsIgnoreCase("2")) { + String s = (String) context.getSessionData(CK.E_CLEAR_INVENTORY); + if (s.equalsIgnoreCase(Lang.get("yesWord"))) { + context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord")); + } else { + context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("yesWord")); + } + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase("3")) { + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + return new PotionEffectPrompt(); + } else if (input.equalsIgnoreCase("5")) { + return new HungerPrompt(); + } else if (input.equalsIgnoreCase("6")) { + return new SaturationPrompt(); + } else if (input.equalsIgnoreCase("7")) { + return new HealthPrompt(); + } else if (input.equalsIgnoreCase("8")) { + Map selectedTeleportLocations = plugin.getActionFactory().getSelectedTeleportLocations(); + selectedTeleportLocations.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getActionFactory().setSelectedTeleportLocations(selectedTeleportLocations); + return new TeleportPrompt(); + } else if (input.equalsIgnoreCase("9")) { + return new CommandsPrompt(); + } + return new ActionMainPrompt(context); + } + + public class MessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetMessagePrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + context.setSessionData(CK.E_MESSAGE, input); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_MESSAGE, null); + } + return new ActionMainPrompt(context); + } + } + + public class ItemListPrompt extends FixedSetPrompt { + + public ItemListPrompt() { + super("1", "2", "3"); + } + + @Override + public String getPromptText(ConversationContext context) { + // Check/add newly made item + if (context.getSessionData("newItem") != null) { + if (context.getSessionData(CK.E_ITEMS) != null) { + List items = getItems(context); + items.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.E_ITEMS, items); + } else { + LinkedList itemRews = new LinkedList(); + itemRews.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.E_ITEMS, itemRews); + } + context.setSessionData("newItem", null); + context.setSessionData("tempStack", null); + } + String text = ChatColor.GOLD + Lang.get("eventEditorGiveItemsTitle") + "\n"; + if (context.getSessionData(CK.E_ITEMS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("stageEditorDeliveryAddItem") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + for (ItemStack is : getItems(context)) { + text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("stageEditorDeliveryAddItem") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new ItemStackPrompt(ItemListPrompt.this); + } else if (input.equalsIgnoreCase("2")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorItemsCleared")); + context.setSessionData(CK.E_ITEMS, null); + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new ActionMainPrompt(context); + } + return null; + } + + @SuppressWarnings("unchecked") + private List getItems(ConversationContext context) { + return (List) context.getSessionData(CK.E_ITEMS); + } + } + + private class PotionEffectPrompt extends FixedSetPrompt { + + public PotionEffectPrompt() { + super("1", "2", "3", "4", "5"); + } + + @SuppressWarnings("unchecked") + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("eventEditorPotionEffectsTitle") + "\n"; + if (context.getSessionData(CK.E_POTION_TYPES) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionEffectTypes") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionDurations") + " " + Lang.get("noneSet") + "\n"; + text += ChatColor.GRAY + "3 - " + Lang.get("eventEditorSetPotionMagnitudes") + " " + Lang.get("noneSet") + + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionEffectTypes") + "\n"; + for (String s : (LinkedList) context.getSessionData(CK.E_POTION_TYPES)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + if (context.getSessionData(CK.E_POTION_DURATIONS) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionDurations") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "3 - " + Lang.get("eventEditorSetPotionMagnitudes") + " " + + Lang.get("noneSet") + "\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("noneSet") + "\n"; + for (Long l : (LinkedList) context.getSessionData(CK.E_POTION_DURATIONS)) { + text += ChatColor.GRAY + " - " + ChatColor.DARK_AQUA + MiscUtil.getTime(l * 50L) + "\n"; + } + if (context.getSessionData(CK.E_POTION_STRENGHT) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionMagnitudes") + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetPotionMagnitudes") + "\n"; + for (int i : (LinkedList) context.getSessionData(CK.E_POTION_STRENGHT)) { + text += ChatColor.GRAY + " - " + ChatColor.DARK_PURPLE + i + "\n"; + } + } + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } + return text; + } + + @SuppressWarnings("unchecked") + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new PotionTypesPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.E_POTION_TYPES) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetPotionTypesFirst")); + return new PotionEffectPrompt(); + } else { + return new PotionDurationsPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + if (context.getSessionData(CK.E_POTION_TYPES) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("eventEditorMustSetPotionTypesAndDurationsFirst")); + return new PotionEffectPrompt(); + } else if (context.getSessionData(CK.E_POTION_DURATIONS) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("eventEditorMustSetPotionDurationsFirst")); + return new PotionEffectPrompt(); + } else { + return new PotionMagnitudesPrompt(); + } + } else if (input.equalsIgnoreCase("4")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorPotionsCleared")); + context.setSessionData(CK.E_POTION_TYPES, null); + context.setSessionData(CK.E_POTION_DURATIONS, null); + context.setSessionData(CK.E_POTION_STRENGHT, null); + return new PotionEffectPrompt(); + } else if (input.equalsIgnoreCase("5")) { + int one; + int two; + int three; + if (context.getSessionData(CK.E_POTION_TYPES) != null) { + one = ((List) context.getSessionData(CK.E_POTION_TYPES)).size(); + } else { + one = 0; + } + if (context.getSessionData(CK.E_POTION_DURATIONS) != null) { + two = ((List) context.getSessionData(CK.E_POTION_DURATIONS)).size(); + } else { + two = 0; + } + if (context.getSessionData(CK.E_POTION_STRENGHT) != null) { + three = ((List) context.getSessionData(CK.E_POTION_STRENGHT)).size(); + } else { + three = 0; + } + if (one == two && two == three) { + return new ActionMainPrompt(context); + } else { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorListSizeMismatch")); + return new PotionEffectPrompt(); + } + } + return null; + } + } + + private class PotionTypesPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String effs = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorPotionTypesTitle") + "\n"; + for (PotionEffectType pet : PotionEffectType.values()) { + effs += (pet != null && pet.getName() != null) ? (ChatColor.DARK_PURPLE + pet.getName() + "\n") : ""; + } + return effs + ChatColor.YELLOW + Lang.get("eventEditorSetPotionEffectsPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + LinkedList effTypes = new LinkedList(); + for (String s : input.split(" ")) { + if (PotionEffectType.getByName(s.toUpperCase()) != null) { + effTypes.add(PotionEffectType.getByName(s.toUpperCase()).getName()); + context.setSessionData(CK.E_POTION_TYPES, effTypes); + } else { + player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + + Lang.get("eventEditorInvalidPotionType")); + return new PotionTypesPrompt(); + } + } + } + return new PotionEffectPrompt(); + } + } + + private class PotionDurationsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetPotionDurationsPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + LinkedList effDurations = new LinkedList(); + for (String s : input.split(" ")) { + try { + int i = Integer.parseInt(s); + long l = i * 1000; + if (l < 1000) { + player.sendMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("", "1")); + return new PotionDurationsPrompt(); + } + effDurations.add(l / 50L); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", s)); + return new PotionDurationsPrompt(); + } + } + context.setSessionData(CK.E_POTION_DURATIONS, effDurations); + } + return new PotionEffectPrompt(); + } + } + + private class PotionMagnitudesPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetPotionMagnitudesPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + LinkedList magAmounts = new LinkedList(); + for (String s : input.split(" ")) { + try { + int i = Integer.parseInt(s); + if (i < 1) { + player.sendMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("", "1")); + return new PotionMagnitudesPrompt(); + } + magAmounts.add(i); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", s)); + return new PotionMagnitudesPrompt(); + } + } + context.setSessionData(CK.E_POTION_STRENGHT, magAmounts); + } + return new PotionEffectPrompt(); + } + } + + public class HungerPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetHungerPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + try { + int i = Integer.parseInt(input); + if (i < 0) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("invalidMinimum").replace("", "0")); + return new HungerPrompt(); + } else { + context.setSessionData(CK.E_HUNGER, (Integer) i); + } + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("reqNotANumber").replace("", input)); + return new HungerPrompt(); + } + } else { + context.setSessionData(CK.E_HUNGER, null); + } + return new ActionMainPrompt(context); + } + } + + public class SaturationPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetSaturationPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + try { + int i = Integer.parseInt(input); + if (i < 0) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("invalidMinimum").replace("", "0")); + return new SaturationPrompt(); + } else { + context.setSessionData(CK.E_SATURATION, (Integer) i); + } + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("reqNotANumber").replace("", input)); + return new SaturationPrompt(); + } + } else { + context.setSessionData(CK.E_SATURATION, null); + } + return new ActionMainPrompt(context); + } + } + + public class HealthPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetHealthPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + try { + int i = Integer.parseInt(input); + if (i < 0) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("invalidMinimum").replace("", "0")); + return new HealthPrompt(); + } else { + context.setSessionData(CK.E_HEALTH, (Integer) i); + } + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("reqNotANumber").replace("", input)); + return new HealthPrompt(); + } + } else { + context.setSessionData(CK.E_HEALTH, null); + } + return new ActionMainPrompt(context); + } + } + + public class TeleportPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorSetTeleportPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdDone"))) { + Map selectedTeleportLocations = plugin.getActionFactory().getSelectedTeleportLocations(); + Block block = selectedTeleportLocations.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + context.setSessionData(CK.E_TELEPORT, ConfigUtil.getLocationInfo(loc)); + selectedTeleportLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedTeleportLocations(selectedTeleportLocations); + } else { + player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); + return new TeleportPrompt(); + } + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_TELEPORT, null); + Map selectedTeleportLocations = plugin.getActionFactory().getSelectedTeleportLocations(); + selectedTeleportLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedTeleportLocations(selectedTeleportLocations); + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + Map selectedTeleportLocations = plugin.getActionFactory().getSelectedTeleportLocations(); + selectedTeleportLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedTeleportLocations(selectedTeleportLocations); + return new ActionMainPrompt(context); + } else { + return new TeleportPrompt(); + } + } + } + + public class CommandsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "" + ChatColor.ITALIC + Lang.get("eventEditorCommandsNote"); + return ChatColor.YELLOW + Lang.get("eventEditorSetCommandsPrompt") + "\n" + text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + String[] commands = input.split(Lang.get("charSemi")); + LinkedList cmdList = new LinkedList(); + cmdList.addAll(Arrays.asList(commands)); + context.setSessionData(CK.E_COMMANDS, cmdList); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_COMMANDS, null); + } + return new ActionMainPrompt(context); + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/tasks/TimerPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/TimerPrompt.java new file mode 100644 index 000000000..c7bf1d5a8 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/TimerPrompt.java @@ -0,0 +1,70 @@ +package me.blackvein.quests.convo.actions.tasks; + +import org.bukkit.ChatColor; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.NumericPrompt; +import org.bukkit.conversations.Prompt; + +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.Lang; + +public class TimerPrompt extends FixedSetPrompt { + + public TimerPrompt() { + super("1", "2", "3"); + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorTimer") + " -\n"; + if (context.getSessionData(CK.E_TIMER) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetTimer") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetTimer") + "(" + ChatColor.AQUA + "\"" + + context.getSessionData(CK.E_TIMER) + "\"" + ChatColor.YELLOW + ")\n"; + } + if (context.getSessionData(CK.E_CANCEL_TIMER) == null) { + context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("noWord")); + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorCancelTimer") + ": " + ChatColor.AQUA + + context.getSessionData(CK.E_CANCEL_TIMER) + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "3 " + ChatColor.RESET + ChatColor.YELLOW + "- " + + Lang.get("done") + "\n"; + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new FailTimerPrompt(); + } else if (input.equalsIgnoreCase("2")) { + String s = (String) context.getSessionData(CK.E_CANCEL_TIMER); + if (s.equalsIgnoreCase(Lang.get("yesWord"))) { + context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("noWord")); + } else { + context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("yesWord")); + } + return new ActionMainPrompt(context); + } + return new ActionMainPrompt(context); + } + + public class FailTimerPrompt extends NumericPrompt { + + @Override + protected Prompt acceptValidatedInput(final ConversationContext context, final Number number) { + context.setSessionData(CK.E_TIMER, number); + return new ActionMainPrompt(context); + } + + @Override + public String getPromptText(final ConversationContext conversationContext) { + return ChatColor.YELLOW + Lang.get("eventEditorEnterTimerSeconds"); + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/actions/tasks/WeatherPrompt.java b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/WeatherPrompt.java new file mode 100644 index 000000000..430f0f878 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/actions/tasks/WeatherPrompt.java @@ -0,0 +1,369 @@ +package me.blackvein.quests.convo.actions.tasks; + +import java.util.LinkedList; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.NumericPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; + +import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.actions.main.ActionMainPrompt; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ConfigUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; + +public class WeatherPrompt extends FixedSetPrompt { + + private final Quests plugin; + + public WeatherPrompt(ConversationContext context) { + super("1", "2", "3", "4"); + this.plugin = (Quests)context.getPlugin(); + } + + @SuppressWarnings("unchecked") + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + "- " + Lang.get("eventEditorWeather") + " -\n"; + if (context.getSessionData(CK.E_WORLD_STORM) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetStorm") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetStorm") + " (" + ChatColor.AQUA + + (String) context.getSessionData(CK.E_WORLD_STORM) + ChatColor.YELLOW + " -> " + + ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context + .getSessionData(CK.E_WORLD_STORM_DURATION) * 1000)) + ChatColor.YELLOW + ")\n"; + } + if (context.getSessionData(CK.E_WORLD_THUNDER) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetThunder") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetThunder") + " (" + ChatColor.AQUA + + (String) context.getSessionData(CK.E_WORLD_THUNDER) + ChatColor.YELLOW + " -> " + + ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context + .getSessionData(CK.E_WORLD_THUNDER_DURATION) * 1000)) + ChatColor.YELLOW + ")\n"; + } + + if (context.getSessionData(CK.E_LIGHTNING) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetLightning") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetLightning") + "\n"; + LinkedList locations = (LinkedList) context.getSessionData(CK.E_LIGHTNING); + for (String loc : locations) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + loc + "\n"; + } + } + text += ChatColor.GREEN + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.GREEN + "- " + + Lang.get("done") + "\n"; + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new StormPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new ThunderPrompt(); + } else if (input.equalsIgnoreCase("3")) { + Map selectedLightningLocations = plugin.getActionFactory().getSelectedLightningLocations(); + selectedLightningLocations.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getActionFactory().setSelectedLightningLocations(selectedLightningLocations); + return new LightningPrompt(); + } + return new ActionMainPrompt(context); + } + + private class StormPrompt extends FixedSetPrompt { + + public StormPrompt() { + super("1", "2", "3", "4"); + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("eventEditorStormTitle") + "\n"; + if (context.getSessionData(CK.E_WORLD_STORM) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetWorld") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " + + Lang.get("eventEditorSetDuration") + " " + Lang.get("eventEditorNoWorld") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetWorld") + " (" + ChatColor.AQUA + + ((String) context.getSessionData(CK.E_WORLD_STORM)) + ChatColor.YELLOW + ")\n"; + if (context.getSessionData(CK.E_WORLD_STORM_DURATION) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetDuration") + " (" + Lang.get("noneSet") + ")\n"; + } else { + int dur = (int) context.getSessionData(CK.E_WORLD_STORM_DURATION); + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + MiscUtil.getTime(dur * 1000) + + ChatColor.YELLOW + ")\n"; + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + 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 StormWorldPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.E_WORLD_STORM) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSetWorldFirst")); + return new StormPrompt(); + } else { + return new StormDurationPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorStormCleared")); + context.setSessionData(CK.E_WORLD_STORM, null); + context.setSessionData(CK.E_WORLD_STORM_DURATION, null); + return new StormPrompt(); + } else if (input.equalsIgnoreCase("4")) { + if (context.getSessionData(CK.E_WORLD_STORM) != null + && context.getSessionData(CK.E_WORLD_STORM_DURATION) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetStormDuration")); + return new StormPrompt(); + } else { + return new ActionMainPrompt(context); + } + } + return null; + } + } + + private class StormWorldPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorWorldsTitle") + "\n" + ChatColor.DARK_PURPLE; + for (World w : plugin.getServer().getWorlds()) { + effects += w.getName() + ", "; + } + effects = effects.substring(0, effects.length()); + return ChatColor.YELLOW + effects + Lang.get("eventEditorEnterStormWorld"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (plugin.getServer().getWorld(input) != null) { + context.setSessionData(CK.E_WORLD_STORM, plugin.getServer().getWorld(input).getName()); + } else { + player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + + Lang.get("eventEditorInvalidWorld")); + return new StormWorldPrompt(); + } + } + return new StormPrompt(); + } + } + + private class StormDurationPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorEnterDuration"); + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + if (input.intValue() < 1) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("invalidMinimum").replace("", "1")); + return new StormDurationPrompt(); + } else { + context.setSessionData(CK.E_WORLD_STORM_DURATION, input.intValue()); + } + return new StormPrompt(); + } + } + + private class ThunderPrompt extends FixedSetPrompt { + + public ThunderPrompt() { + super("1", "2", "3", "4"); + } + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("eventEditorThunderTitle") + "\n"; + if (context.getSessionData(CK.E_WORLD_THUNDER) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetWorld") + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " + + Lang.get("eventEditorSetDuration") + " " + Lang.get("eventEditorNoWorld") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("done"); + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetWorld") + " (" + ChatColor.AQUA + + ((String) context.getSessionData(CK.E_WORLD_THUNDER)) + ChatColor.YELLOW + ")\n"; + if (context.getSessionData(CK.E_WORLD_THUNDER_DURATION) == null) { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetDuration") + " (" + Lang.get("noneSet") + ")\n"; + } else { + int dur = (int) context.getSessionData(CK.E_WORLD_THUNDER_DURATION); + text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + MiscUtil.getTime(dur * 1000) + + ChatColor.YELLOW + ")\n"; + } + text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + + Lang.get("clear") + "\n"; + text += ChatColor.BLUE + "" + 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 ThunderWorldPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.E_WORLD_THUNDER) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSetWorldFirst")); + return new ThunderPrompt(); + } else { + return new ThunderDurationPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorThunderCleared")); + context.setSessionData(CK.E_WORLD_THUNDER, null); + context.setSessionData(CK.E_WORLD_THUNDER_DURATION, null); + return new ThunderPrompt(); + } else if (input.equalsIgnoreCase("4")) { + if (context.getSessionData(CK.E_WORLD_THUNDER) != null + && context.getSessionData(CK.E_WORLD_THUNDER_DURATION) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetThunderDuration")); + return new ThunderPrompt(); + } else { + return new ActionMainPrompt(context); + } + } + return null; + } + } + + private class ThunderWorldPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorWorldsTitle") + "\n" + ChatColor.DARK_PURPLE; + for (World w : plugin.getServer().getWorlds()) { + effects += w.getName() + ", "; + } + effects = effects.substring(0, effects.length()); + return ChatColor.YELLOW + effects + Lang.get("eventEditorEnterThunderWorld"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (plugin.getServer().getWorld(input) != null) { + context.setSessionData(CK.E_WORLD_THUNDER, plugin.getServer().getWorld(input).getName()); + } else { + player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + + Lang.get("eventEditorInvalidWorld")); + return new ThunderWorldPrompt(); + } + } + return new ThunderPrompt(); + } + } + + private class ThunderDurationPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorEnterDuration"); + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + if (input.intValue() < 1) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("invalidMinimum").replace("", "1")); + return new ThunderDurationPrompt(); + } else { + context.setSessionData(CK.E_WORLD_THUNDER_DURATION, input.intValue()); + } + return new ThunderPrompt(); + } + } + + public class LightningPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("eventEditorLightningPrompt"); + } + + @SuppressWarnings("unchecked") + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) { + Map selectedLightningLocations = plugin.getActionFactory().getSelectedLightningLocations(); + Block block = selectedLightningLocations.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + LinkedList locs; + if (context.getSessionData(CK.E_LIGHTNING) != null) { + locs = (LinkedList) context.getSessionData(CK.E_LIGHTNING); + } else { + locs = new LinkedList(); + } + locs.add(ConfigUtil.getLocationInfo(loc)); + context.setSessionData(CK.E_LIGHTNING, locs); + selectedLightningLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedLightningLocations(selectedLightningLocations); + } else { + player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); + return new LightningPrompt(); + } + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.E_LIGHTNING, null); + Map selectedLightningLocations = plugin.getActionFactory().getSelectedLightningLocations(); + selectedLightningLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedLightningLocations(selectedLightningLocations); + return new ActionMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + Map selectedLightningLocations = plugin.getActionFactory().getSelectedLightningLocations(); + selectedLightningLocations.remove(player.getUniqueId()); + plugin.getActionFactory().setSelectedLightningLocations(selectedLightningLocations); + return new ActionMainPrompt(context); + } else { + return new LightningPrompt(); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemStackPrompt.java b/main/src/main/java/me/blackvein/quests/convo/generic/ItemStackPrompt.java similarity index 99% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemStackPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/generic/ItemStackPrompt.java index 90dfe6573..8f17a06fe 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemStackPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/generic/ItemStackPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.generic; import java.util.ArrayList; import java.util.Arrays; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/OverridePrompt.java b/main/src/main/java/me/blackvein/quests/convo/generic/OverridePrompt.java similarity index 95% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/OverridePrompt.java rename to main/src/main/java/me/blackvein/quests/convo/generic/OverridePrompt.java index 2837f6fc4..c44b37077 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/OverridePrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/generic/OverridePrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.generic; import org.bukkit.ChatColor; import org.bukkit.conversations.ConversationContext; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/QuestOfferPrompt.java b/main/src/main/java/me/blackvein/quests/convo/npcs/NpcOfferQuestPrompt.java similarity index 86% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/QuestOfferPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/npcs/NpcOfferQuestPrompt.java index 4a6bfacf2..1183829a4 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/QuestOfferPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/npcs/NpcOfferQuestPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.npcs; import java.text.MessageFormat; import java.util.HashMap; @@ -31,24 +31,23 @@ import me.blackvein.quests.Quests; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; -public class QuestOfferPrompt extends StringPrompt { +public class NpcOfferQuestPrompt extends StringPrompt { private final Quests plugin; + // TODO are these hashmaps really necessary? private HashMap questerHashMap = new HashMap<>(); private HashMap> questsHashMap = new HashMap<>(); - public QuestOfferPrompt(Quests plugin) { + public NpcOfferQuestPrompt(Quests plugin) { this.plugin = plugin; } @SuppressWarnings("unchecked") @Override - public String getPromptText(ConversationContext cc) { - Quester quester; - LinkedList quests; - quests = (LinkedList) cc.getSessionData("quests"); - quester = plugin.getQuester(((Player) cc.getForWhom()).getUniqueId()); - String npc = (String) cc.getSessionData("npc"); + public String getPromptText(ConversationContext context) { + Quester quester = plugin.getQuester(((Player) context.getForWhom()).getUniqueId()); + LinkedList quests = (LinkedList) context.getSessionData("npcQuests"); + String npc = (String) context.getSessionData("npc"); String text = Lang.get("questNPCListTitle").replace("", npc); String menu = text + "\n"; for (int i = 1; i <= quests.size(); i++) { @@ -65,15 +64,15 @@ public class QuestOfferPrompt extends StringPrompt { menu += ChatColor.GOLD + "" + ChatColor.BOLD + "" + (quests.size() + 1) + ". " + ChatColor.RESET + "" + ChatColor.GRAY + Lang.get("cancel") + "\n"; menu += ChatColor.WHITE + Lang.get("enterAnOption"); - questerHashMap.put(((Player) cc.getForWhom()).getUniqueId(), quester); - questsHashMap.put(((Player) cc.getForWhom()).getUniqueId(), quests); + questerHashMap.put(((Player) context.getForWhom()).getUniqueId(), quester); + questsHashMap.put(((Player) context.getForWhom()).getUniqueId(), quests); return menu; } @Override - public Prompt acceptInput(ConversationContext cc, String input) { - Quester quester = questerHashMap.get(((Player) cc.getForWhom()).getUniqueId()); - LinkedList quests = questsHashMap.get(((Player) cc.getForWhom()).getUniqueId()); + public Prompt acceptInput(ConversationContext context, String input) { + Quester quester = questerHashMap.get(((Player) context.getForWhom()).getUniqueId()); + LinkedList quests = questsHashMap.get(((Player) context.getForWhom()).getUniqueId()); int numInput = -1; try { numInput = Integer.parseInt(input); @@ -81,7 +80,7 @@ public class QuestOfferPrompt extends StringPrompt { // Continue } if (input.equalsIgnoreCase(Lang.get("cancel")) || numInput == (quests.size() + 1)) { - cc.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("cancelled")); + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("cancelled")); return Prompt.END_OF_CONVERSATION; } else { Quest q = null; @@ -108,8 +107,8 @@ public class QuestOfferPrompt extends StringPrompt { } } if (q == null) { - cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption")); - return new QuestOfferPrompt(plugin); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption")); + return new NpcOfferQuestPrompt(plugin); } else { Player player = quester.getPlayer(); if (!quester.getCompletedQuests().contains(q.getName())) { diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java new file mode 100644 index 000000000..6967a5994 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java @@ -0,0 +1,864 @@ +package me.blackvein.quests.convo.quests.main; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.sk89q.worldguard.protection.managers.RegionManager; + +import me.blackvein.quests.Quest; +import me.blackvein.quests.Quests; +import me.blackvein.quests.actions.Action; +import me.blackvein.quests.convo.generic.ItemStackPrompt; +import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; +import me.blackvein.quests.convo.quests.options.OptionsPrompt; +import me.blackvein.quests.convo.quests.planner.PlannerPrompt; +import me.blackvein.quests.convo.quests.requirements.RequirementsPrompt; +import me.blackvein.quests.convo.quests.rewards.RewardsPrompt; +import me.blackvein.quests.convo.quests.stages.StageMenuPrompt; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; +import me.blackvein.quests.reflect.worldguard.WorldGuardAPI; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import net.citizensnpcs.api.CitizensAPI; + +public class QuestMainPrompt extends QuestsEditorNumericPrompt { + + private final Quests plugin; + + public QuestMainPrompt(ConversationContext context) { + super(context); + this.plugin = (Quests)context.getPlugin(); + } + + private final int size = 15; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("quest") + ": " + context.getSessionData(CK.Q_NAME) + "" + ChatColor.GRAY + + (context.getSessionData(CK.Q_ID) != null ? " (" + Lang.get("id") + ":" + + context.getSessionData(CK.Q_ID) + ")": ""); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + case 4: + case 5: + return ChatColor.BLUE; + case 6: + if (plugin.getDependencies().getWorldGuardApi() != null) { + return ChatColor.BLUE; + } else { + return ChatColor.GRAY; + } + case 7: + return ChatColor.BLUE; + case 8: + if (plugin.getDependencies().getCitizens() != null) { + return ChatColor.BLUE; + } else { + return ChatColor.GRAY; + } + case 9: + case 10: + case 11: + case 12: + case 13: + return ChatColor.BLUE; + case 14: + return ChatColor.GREEN; + case 15: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("questEditorName"); + case 2: + if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { + return ChatColor.RED + Lang.get("questEditorAskMessage"); + } else { + return ChatColor.YELLOW + Lang.get("questEditorAskMessage"); + } + case 3: + if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { + return ChatColor.RED + Lang.get("questEditorFinishMessage"); + } else { + return ChatColor.YELLOW + Lang.get("questEditorFinishMessage"); + } + case 4: + if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() + != null) { + return ChatColor.YELLOW + Lang.get("questEditorNPCStart"); + } else if (plugin.getDependencies().getCitizens() != null) { + return ChatColor.YELLOW + Lang.get("questEditorNPCStart"); + } else { + return ChatColor.GRAY + Lang.get("questEditorNPCStart"); + } + case 5: + return ChatColor.YELLOW + Lang.get("questEditorBlockStart"); + case 6: + if (plugin.getDependencies().getWorldGuardApi() != null) { + if (context.getSessionData(CK.Q_REGION) == null) { + return ChatColor.YELLOW + Lang.get("questWGSetRegion"); + } else { + return ChatColor.YELLOW + Lang.get("questWGSetRegion"); + } + } else { + return ChatColor.GRAY + Lang.get("questWGSetRegion"); + } + case 7: + return ChatColor.YELLOW + Lang.get("questEditorInitialEvent"); + case 8: + if (plugin.getDependencies().getCitizens() != null) { + if (context.getSessionData(CK.Q_GUIDISPLAY) == null) { + return ChatColor.YELLOW + Lang.get("questEditorSetGUI"); + } else { + return ChatColor.YELLOW + Lang.get("questEditorSetGUI"); + } + } else { + return ChatColor.GRAY + Lang.get("questEditorSetGUI"); + } + case 9: + return ChatColor.DARK_AQUA + Lang.get("questEditorReqs"); + case 10: + return ChatColor.AQUA + Lang.get("questEditorPln"); + case 11: + return ChatColor.LIGHT_PURPLE + Lang.get("questEditorStages"); + case 12: + return ChatColor.DARK_PURPLE + Lang.get("questEditorRews"); + case 13: + return ChatColor.DARK_GREEN + Lang.get("questEditorOpts"); + case 14: + return ChatColor.GREEN + Lang.get("save"); + case 15: + return ChatColor.RED + Lang.get("exit"); + default: + return null; + } + } + + public String getAdditionalText(ConversationContext context, int number) { + switch (number) { + case 1: + return ""; + case 2: + if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { + return ChatColor.DARK_RED + "(" + Lang.get("questRequiredNoneSet") + ")"; + } else { + return ChatColor.YELLOW + "(" + context.getSessionData(CK.Q_ASK_MESSAGE) + ChatColor.RESET + + ChatColor.YELLOW + ")"; + } + case 3: + if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { + return ChatColor.DARK_RED + "(" + Lang.get("questRequiredNoneSet") + ")"; + } else { + return ChatColor.YELLOW + "(" + context.getSessionData(CK.Q_FINISH_MESSAGE) + ChatColor.RESET + + ChatColor.YELLOW + ")"; + } + case 4: + if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() + != null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else if (plugin.getDependencies().getCitizens() != null) { + return ChatColor.YELLOW + "(" + CitizensAPI.getNPCRegistry().getById((Integer) context + .getSessionData(CK.Q_START_NPC)).getName() + ChatColor.RESET + ChatColor.YELLOW + ")"; + } else { + return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; + } + case 5: + if (context.getSessionData(CK.Q_START_BLOCK) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); + return ChatColor.YELLOW + "(" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + + l.getBlockY() + ", " + l.getBlockZ() + ")"; + } + case 6: + if (plugin.getDependencies().getWorldGuardApi() != null) { + if (context.getSessionData(CK.Q_REGION) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + return ChatColor.YELLOW + "(" + ChatColor.GREEN + + (String) context.getSessionData(CK.Q_REGION) + ChatColor.YELLOW + ")"; + } + } else { + return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; + } + case 7: + if (context.getSessionData(CK.Q_INITIAL_EVENT) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + return ChatColor.YELLOW + "(" + (String) context.getSessionData(CK.Q_INITIAL_EVENT) + ")"; + } + case 8: + if (plugin.getDependencies().getCitizens() != null) { + if (context.getSessionData(CK.Q_GUIDISPLAY) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + return ChatColor.YELLOW + "(" + ItemUtil.getDisplayString((ItemStack) context + .getSessionData(CK.Q_GUIDISPLAY)) + ChatColor.RESET + ChatColor.YELLOW + ")"; + } + } else { + return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; + } + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + return ""; + default: + return null; + } + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = ChatColor.GOLD + "- " + getTitle(context).replaceFirst(": ", ": " + ChatColor.AQUA) + + ChatColor.GOLD + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch (input.intValue()) { + case 1: + return new QuestNamePrompt(); + case 2: + return new QuestAskMessagePrompt(); + case 3: + return new QuestFinishMessagePrompt(); + case 4: + if (plugin.getDependencies().getCitizens() != null) { + return new QuestNPCStartPrompt(); + } else { + return new QuestMainPrompt(context); + } + case 5: + Map blockStarts = plugin.getQuestFactory().getSelectedBlockStarts(); + blockStarts.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getQuestFactory().setSelectedBlockStarts(blockStarts); + return new QuestBlockStartPrompt(); + case 6: + if (plugin.getDependencies().getWorldGuardApi() != null) { + return new QuestRegionPrompt(); + } else { + return new QuestMainPrompt(context); + } + case 7: + return new QuestInitialActionPrompt(); + case 8: + if (plugin.getDependencies().getCitizens() != null) { + return new QuestGuiDisplayPrompt(context); + } else { + return new QuestMainPrompt(context); + } + case 9: + return new RequirementsPrompt(context); + case 10: + return new PlannerPrompt(context); + case 11: + return new StageMenuPrompt(context); + case 12: + return new RewardsPrompt(context); + case 13: + return new OptionsPrompt(context); + case 14: + return new QuestSavePrompt(context); + case 15: + return new QuestExitPrompt(context); + default: + return new QuestMainPrompt(context); + } + } + + public class QuestNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + for (Quest q : plugin.getQuests()) { + if (q.getName().equalsIgnoreCase(input)) { + String s = null; + if (context.getSessionData(CK.ED_QUEST_EDIT) != null) { + s = (String) context.getSessionData(CK.ED_QUEST_EDIT); + } + if (s != null && s.equalsIgnoreCase(input) == false) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNameExists")); + return new QuestNamePrompt(); + } + } + } + List questNames = plugin.getQuestFactory().getNamesOfQuestsBeingEdited(); + if (questNames.contains(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); + return new QuestNamePrompt(); + } + if (input.contains(",")) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); + return new QuestNamePrompt(); + } + questNames.remove((String) context.getSessionData(CK.Q_NAME)); + context.setSessionData(CK.Q_NAME, input); + questNames.add(input); + plugin.getQuestFactory().setNamesOfQuestsBeingEdited(questNames); + } + return new QuestMainPrompt(context); + } + } + + public class QuestAskMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("questEditorEnterAskMessage"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (input.startsWith("++")) { + if (context.getSessionData(CK.Q_ASK_MESSAGE) != null) { + context.setSessionData(CK.Q_ASK_MESSAGE, context.getSessionData(CK.Q_ASK_MESSAGE) + " " + + input.substring(2)); + return new QuestMainPrompt(context); + } + } + context.setSessionData(CK.Q_ASK_MESSAGE, input); + } + return new QuestMainPrompt(context); + } + } + + public class QuestFinishMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("questEditorEnterFinishMessage"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + if (input.startsWith("++")) { + if (context.getSessionData(CK.Q_FINISH_MESSAGE) != null) { + context.setSessionData(CK.Q_FINISH_MESSAGE, context.getSessionData(CK.Q_FINISH_MESSAGE) + " " + + input.substring(2)); + return new QuestMainPrompt(context); + } + } + context.setSessionData(CK.Q_FINISH_MESSAGE, input); + } + return new QuestMainPrompt(context); + } + } + + public class QuestNPCStartPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n" + + ChatColor.GOLD + Lang.get("npcHint"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + try { + int i = Integer.parseInt(input); + if (i > -1) { + if (CitizensAPI.getNPCRegistry().getById(i) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC")); + return new QuestNPCStartPrompt(); + } + context.setSessionData(CK.Q_START_NPC, i); + Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return new QuestMainPrompt(context); + } + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + + Lang.get("reqNotANumber").replace("", input)); + return new QuestNPCStartPrompt(); + } + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.Q_START_NPC, null); + } + Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return new QuestMainPrompt(context); + } + } + + public class QuestBlockStartPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("questEditorEnterBlockStart"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdDone")) || input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + if (input.equalsIgnoreCase(Lang.get("cmdDone"))) { + Map selectedBlockStarts = plugin.getQuestFactory().getSelectedBlockStarts(); + Block block = selectedBlockStarts.get(player.getUniqueId()); + if (block != null) { + Location loc = block.getLocation(); + context.setSessionData(CK.Q_START_BLOCK, loc); + selectedBlockStarts.remove(player.getUniqueId()); + } else { + player.sendMessage(ChatColor.RED + Lang.get("questEditorNoStartBlockSelected")); + return new QuestBlockStartPrompt(); + } + } else { + Map selectedBlockStarts = plugin.getQuestFactory().getSelectedBlockStarts(); + selectedBlockStarts.remove(player.getUniqueId()); + plugin.getQuestFactory().setSelectedBlockStarts(selectedBlockStarts); + } + return new QuestMainPrompt(context); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + Map selectedBlockStarts = plugin.getQuestFactory().getSelectedBlockStarts(); + selectedBlockStarts.remove(player.getUniqueId()); + plugin.getQuestFactory().setSelectedBlockStarts(selectedBlockStarts); + context.setSessionData(CK.Q_START_BLOCK, null); + return new QuestMainPrompt(context); + } + return new QuestBlockStartPrompt(); + } + } + + public class QuestRegionPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.AQUA + Lang.get("questRegionTitle") + "\n"; + boolean any = false; + for (World world : plugin.getServer().getWorlds()) { + WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi(); + RegionManager rm = api.getRegionManager(world); + for (String region : rm.getRegions().keySet()) { + any = true; + text += ChatColor.GREEN + region + ", "; + } + } + if (any) { + text = text.substring(0, text.length() - 2); + text += "\n\n"; + } else { + text += ChatColor.GRAY + "(" + Lang.get("none") + ")\n\n"; + } + return text + ChatColor.YELLOW + Lang.get("questWGPrompt"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + String found = null; + boolean done = false; + for (World world : plugin.getServer().getWorlds()) { + WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi(); + RegionManager rm = api.getRegionManager(world); + for (String region : rm.getRegions().keySet()) { + if (region.equalsIgnoreCase(input)) { + found = region; + done = true; + break; + } + } + if (done) { + break; + } + } + if (found == null) { + String error = Lang.get("questWGInvalidRegion"); + error = error.replace("", ChatColor.RED + input + ChatColor.YELLOW); + player.sendMessage(ChatColor.YELLOW + error); + return new QuestRegionPrompt(); + } else { + context.setSessionData(CK.Q_REGION, found); + return new QuestMainPrompt(context); + } + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.Q_REGION, null); + player.sendMessage(ChatColor.YELLOW + Lang.get("questWGRegionCleared")); + return new QuestMainPrompt(context); + } else { + return new QuestMainPrompt(context); + } + } + } + + public class QuestInitialActionPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.AQUA + Lang.get("eventTitle") + "\n"; + if (plugin.getActions().isEmpty()) { + text += ChatColor.RED + "- " + Lang.get("none"); + } else { + for (Action e : plugin.getActions()) { + text += ChatColor.GREEN + "- " + e.getName() + "\n"; + } + } + return text + ChatColor.YELLOW + Lang.get("questEditorEnterInitialEvent"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false + && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + Action a = plugin.getAction(input); + if (a != null) { + context.setSessionData(CK.Q_INITIAL_EVENT, a.getName()); + return new QuestMainPrompt(context); + } + player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " " + + Lang.get("questEditorInvalidEventName")); + return new QuestInitialActionPrompt(); + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(CK.Q_INITIAL_EVENT, null); + player.sendMessage(ChatColor.YELLOW + Lang.get("questEditorEventCleared")); + return new QuestMainPrompt(context); + } else { + return new QuestMainPrompt(context); + } + } + } + + public class QuestGuiDisplayPrompt extends QuestsEditorNumericPrompt { + + private final Quests plugin; + + public QuestGuiDisplayPrompt(ConversationContext context) { + super(context); + this.plugin = (Quests)context.getPlugin(); + } + + private final int size = 3; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("questGUITitle"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.BLUE; + case 2: + return ChatColor.RED; + case 3: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem"); + case 2: + return ChatColor.YELLOW + Lang.get("clear"); + case 3: + return ChatColor.YELLOW + Lang.get("done"); + default: + return null; + } + } + + public String getAdditionalText(ConversationContext context, int number) { + return null; + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + if (context.getSessionData("tempStack") != null) { + ItemStack stack = (ItemStack) context.getSessionData("tempStack"); + boolean failed = false; + for (Quest quest : plugin.getQuests()) { + if (quest.getGUIDisplay() != null) { + if (ItemUtil.compareItems(stack, quest.getGUIDisplay(), false) == 0) { + String error = Lang.get("questGUIError"); + error = error.replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED); + context.getForWhom().sendRawMessage(ChatColor.RED + error); + failed = true; + break; + } + } + } + if (!failed) { + context.setSessionData(CK.Q_GUIDISPLAY, context.getSessionData("tempStack")); + } + context.setSessionData("tempStack", null); + } + String text = ChatColor.GOLD + getTitle(context) + "\n"; + if (context.getSessionData(CK.Q_GUIDISPLAY) != null) { + ItemStack stack = (ItemStack) context.getSessionData(CK.Q_GUIDISPLAY); + text += " " + ChatColor.RESET + ItemUtil.getDisplayString(stack) + "\n"; + } else { + text += " " + ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n"; + } + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + "\n"; + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch (input.intValue()) { + case 1: + return new ItemStackPrompt(QuestGuiDisplayPrompt.this); + case 2: + context.setSessionData(CK.Q_GUIDISPLAY, null); + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("questGUICleared")); + return new QuestGuiDisplayPrompt(context); + case 3: + return plugin.getQuestFactory().returnToMenu(context); + default: + return new QuestGuiDisplayPrompt(context); + } + } + } + + public class QuestSavePrompt extends QuestsEditorStringPrompt { + public QuestSavePrompt(ConversationContext context) { + super(context); + } + + private final int size = 2; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return null; + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.GREEN; + case 2: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.GREEN + Lang.get("yesWord"); + case 2: + return ChatColor.RED + Lang.get("noWord"); + default: + return null; + } + } + + public String getQueryText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA + + context.getSessionData(CK.Q_NAME) + ChatColor.YELLOW + "\"?"; + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = getQueryText(context) + "\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + "\n"; + } + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedAskMessage")); + return new QuestMainPrompt(context); + } else if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedFinishMessage")); + return new QuestMainPrompt(context); + } else if (new StageMenuPrompt(context).getStages(context) == 0) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNeedStages")); + return new QuestMainPrompt(context); + } + FileConfiguration data = new YamlConfiguration(); + try { + data.load(new File(plugin.getDataFolder(), "quests.yml")); + ConfigurationSection questSection = data.getConfigurationSection("quests"); + if (questSection == null) { + questSection = data.createSection("quests"); + } + ConfigurationSection newSection; + if (context.getSessionData(CK.Q_ID) == null) { + // Creating + int customNum = 1; + while (true) { + if (questSection.contains("custom" + customNum)) { + customNum++; + } else { + break; + } + } + newSection = questSection.createSection("custom" + customNum); + } else { + // Editing + newSection = questSection.createSection((String)context.getSessionData(CK.Q_ID)); + } + plugin.getQuestFactory().saveQuest(context, newSection); + data.save(new File(plugin.getDataFolder(), "quests.yml")); + context.getForWhom().sendRawMessage(ChatColor.GREEN + + Lang.get("questEditorSaved").replace("", "/questadmin " + + Lang.get("COMMAND_QUESTADMIN_RELOAD"))); + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + return Prompt.END_OF_CONVERSATION; + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new QuestMainPrompt(context); + } else { + return new QuestSavePrompt(context); + } + } + } + + public class QuestExitPrompt extends QuestsEditorStringPrompt { + public QuestExitPrompt(ConversationContext context) { + super(context); + } + + private final int size = 2; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return null; + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.GREEN; + case 2: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.GREEN + Lang.get("yesWord"); + case 2: + return ChatColor.RED + Lang.get("noWord"); + default: + return null; + } + } + + public String getQueryText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get("confirmDelete"); + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = getQueryText(context) + "\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + "\n"; + } + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + context.getForWhom().sendRawMessage(ChatColor.BOLD + "" + ChatColor.YELLOW + Lang.get("exited")); + return Prompt.END_OF_CONVERSATION; + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new QuestMainPrompt(context); + } else { + return new QuestExitPrompt(context); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java new file mode 100644 index 000000000..495e7d043 --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java @@ -0,0 +1,277 @@ +package me.blackvein.quests.convo.quests.menu; + +import java.util.LinkedList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.entity.Player; + +import me.blackvein.quests.Quest; +import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; +import me.blackvein.quests.convo.quests.main.QuestMainPrompt; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.Lang; + +public class QuestMenuPrompt extends QuestsEditorNumericPrompt { + + private final Quests plugin; + + public QuestMenuPrompt(ConversationContext context) { + super(context); + this.plugin = (Quests)context.getPlugin(); + } + + private final int size = 4; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("questEditorTitle"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + return ChatColor.BLUE; + case 4: + return ChatColor.RED; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("questEditorCreate"); + case 2: + return ChatColor.YELLOW + Lang.get("questEditorEdit"); + case 3: + return ChatColor.YELLOW + Lang.get("questEditorDelete"); + case 4: + return ChatColor.RED + Lang.get("exit"); + default: + return null; + } + } + + public String getAdditionalText(ConversationContext context, int number) { + return null; + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + String text = ChatColor.GOLD + getTitle(context) + "\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + "\n"; + } + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + final Player player = (Player) context.getForWhom(); + switch (input.intValue()) { + case 1: + if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.create")) { + return new QuestSelectCreatePrompt(context); + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new QuestMenuPrompt(context); + } + case 2: + if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.edit")) { + return new QuestSelectEditPrompt(); + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new QuestMenuPrompt(context); + } + case 3: + if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.delete")) { + return new QuestSelectDeletePrompt(); + } else { + player.sendMessage(ChatColor.RED + Lang.get("noPermission")); + return new QuestMenuPrompt(context); + } + case 4: + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("exited")); + return Prompt.END_OF_CONVERSATION; + default: + return new QuestMenuPrompt(context); + } + } + + public class QuestSelectCreatePrompt extends QuestsEditorStringPrompt { + + public QuestSelectCreatePrompt(ConversationContext context) { + super(context); + } + + public String getTitle(ConversationContext context) { + return Lang.get("questCreateTitle"); + } + + public String getQueryText(ConversationContext context) { + return Lang.get("questEditorEnterQuestName"); + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + + String text = ChatColor.GOLD + getTitle(context)+ "\n" + ChatColor.YELLOW + getQueryText(context); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); + return new QuestSelectCreatePrompt(context); + } + input = input.trim(); + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + for (Quest q : plugin.getQuests()) { + if (q.getName().equalsIgnoreCase(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNameExists")); + return new QuestSelectCreatePrompt(context); + } + } + List questNames = plugin.getQuestFactory().getNamesOfQuestsBeingEdited(); + if (questNames.contains(input)) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); + return new QuestSelectCreatePrompt(context); + } + if (input.contains(".") || input.contains(",")) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); + return new QuestSelectCreatePrompt(context); + } + if (input.equals("")) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); + return new QuestSelectCreatePrompt(context); + } + context.setSessionData(CK.Q_NAME, input); + questNames.add(input); + plugin.getQuestFactory().setNamesOfQuestsBeingEdited(questNames); + return new QuestMainPrompt(context); + } else { + return new QuestMenuPrompt(context); + } + } + } + + public class QuestSelectEditPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String s = ChatColor.GOLD + Lang.get("questEditTitle") + "\n"; + for (Quest q : plugin.getQuests()) { + s += ChatColor.GRAY + "- " + ChatColor.AQUA + q.getName() + "\n"; + } + return s + ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + Quest q = plugin.getQuest(input); + if (q != null) { + plugin.getQuestFactory().loadQuest(context, q); + return new QuestMainPrompt(context); + } + return new QuestSelectEditPrompt(); + } else { + return new QuestMenuPrompt(context); + } + } + } + + public class QuestSelectDeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GOLD + Lang.get("questDeleteTitle") + "\n"; + for (Quest quest : plugin.getQuests()) { + text += ChatColor.AQUA + quest.getName() + ChatColor.GRAY + ","; + } + text = text.substring(0, text.length() - 1) + "\n"; + text += ChatColor.YELLOW + Lang.get("questEditorEnterQuestName"); + return text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + LinkedList used = new LinkedList(); + Quest found = plugin.getQuest(input); + if (found != null) { + for (Quest q : plugin.getQuests()) { + if (q.getRequirements().getNeededQuests().contains(q.getName()) + || q.getRequirements().getBlockQuests().contains(q.getName())) { + used.add(q.getName()); + } + } + if (used.isEmpty()) { + context.setSessionData(CK.ED_QUEST_DELETE, found.getName()); + return new QuestConfirmDeletePrompt(); + } else { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("questEditorQuestAsRequirement1") + " \"" + ChatColor.DARK_PURPLE + + context.getSessionData(CK.ED_QUEST_DELETE) + ChatColor.RED + "\" " + + Lang.get("questEditorQuestAsRequirement2")); + for (String s : used) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "- " + ChatColor.DARK_RED + s); + } + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + + Lang.get("questEditorQuestAsRequirement3")); + return new QuestSelectDeletePrompt(); + } + } + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("questEditorQuestNotFound")); + return new QuestSelectDeletePrompt(); + } else { + return new QuestMenuPrompt(context); + } + } + } + + public class QuestConfirmDeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + "" + ChatColor.GREEN + " - " + + Lang.get("yesWord") + "\n"; + text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + "" + ChatColor.RED + " - " + + Lang.get("noWord"); + return ChatColor.RED + Lang.get("confirmDelete") + " (" + ChatColor.YELLOW + + (String) context.getSessionData(CK.ED_QUEST_DELETE) + ChatColor.RED + ")\n" + text; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + plugin.getQuestFactory().deleteQuest(context); + return Prompt.END_OF_CONVERSATION; + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + return new QuestMenuPrompt(context); + } else { + return new QuestConfirmDeletePrompt(); + } + } + } +} diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/BlocksPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/BlocksPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java index 541fd4668..a2e35dce8 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/BlocksPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java @@ -10,12 +10,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.objectives; import java.util.LinkedList; import java.util.List; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java index 02e900508..06952633d 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/ItemsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java @@ -10,12 +10,14 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.objectives; import java.util.LinkedList; import java.util.List; +import me.blackvein.quests.convo.generic.ItemStackPrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/MobsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/MobsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java index cb6c6173d..ff46c4c79 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/MobsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.objectives; import java.util.Arrays; import java.util.LinkedList; @@ -32,6 +32,7 @@ import org.bukkit.entity.Tameable; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java index 79f236adb..c783a75fd 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.objectives; import java.util.Arrays; import java.util.LinkedList; @@ -27,7 +27,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.generic.ItemStackPrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/OptionsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/options/OptionsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/OptionsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/options/OptionsPrompt.java index 4b9e291d3..02f6f06ba 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/OptionsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/options/OptionsPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.options; import org.bukkit.ChatColor; import org.bukkit.conversations.ConversationContext; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/DateTimePrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/planner/DateTimePrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/DateTimePrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/planner/DateTimePrompt.java index f775342b7..3f01ec3be 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/DateTimePrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/planner/DateTimePrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.planner; import java.text.DecimalFormat; import java.text.SimpleDateFormat; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/PlannerPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/planner/PlannerPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/PlannerPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/planner/PlannerPrompt.java index 0482e114c..1d276db9f 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/PlannerPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/planner/PlannerPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.planner; import java.text.DecimalFormat; import java.text.SimpleDateFormat; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/GUIDisplayPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/prompts/GUIDisplayPrompt.java deleted file mode 100644 index 30141724d..000000000 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/GUIDisplayPrompt.java +++ /dev/null @@ -1,117 +0,0 @@ -package me.blackvein.quests.convo.quests.prompts; - -import org.bukkit.ChatColor; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.Prompt; -import org.bukkit.inventory.ItemStack; - -import me.blackvein.quests.Quest; -import me.blackvein.quests.Quests; -import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; -import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; -import me.blackvein.quests.util.CK; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; - -public class GUIDisplayPrompt extends QuestsEditorNumericPrompt { - private final Quests plugin; - - public GUIDisplayPrompt(ConversationContext context) { - super(context); - this.plugin = (Quests)context.getPlugin(); - } - - private final int size = 3; - - public int getSize() { - return size; - } - - public String getTitle(ConversationContext context) { - return Lang.get("questGUITitle"); - } - - public ChatColor getNumberColor(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.BLUE; - case 2: - return ChatColor.RED; - case 3: - return ChatColor.GREEN; - default: - return null; - } - } - - public String getSelectionText(ConversationContext context, int number) { - switch (number) { - case 1: - return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem"); - case 2: - return ChatColor.YELLOW + Lang.get("clear"); - case 3: - return ChatColor.YELLOW + Lang.get("done"); - default: - return null; - } - } - - public String getAdditionalText(ConversationContext context, int number) { - return null; - } - - @Override - public String getPromptText(ConversationContext context) { - QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - if (context.getSessionData("tempStack") != null) { - ItemStack stack = (ItemStack) context.getSessionData("tempStack"); - boolean failed = false; - for (Quest quest : plugin.getQuests()) { - if (quest.getGUIDisplay() != null) { - if (ItemUtil.compareItems(stack, quest.getGUIDisplay(), false) == 0) { - String error = Lang.get("questGUIError"); - error = error.replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED); - context.getForWhom().sendRawMessage(ChatColor.RED + error); - failed = true; - break; - } - } - } - if (!failed) { - context.setSessionData(CK.Q_GUIDISPLAY, context.getSessionData("tempStack")); - } - context.setSessionData("tempStack", null); - } - String text = ChatColor.GOLD + getTitle(context) + "\n"; - if (context.getSessionData(CK.Q_GUIDISPLAY) != null) { - ItemStack stack = (ItemStack) context.getSessionData(CK.Q_GUIDISPLAY); - text += " " + ChatColor.RESET + ItemUtil.getDisplayString(stack) + "\n"; - } else { - text += " " + ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n"; - } - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; - } - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - switch (input.intValue()) { - case 1: - return new ItemStackPrompt(GUIDisplayPrompt.this); - case 2: - context.setSessionData(CK.Q_GUIDISPLAY, null); - context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("questGUICleared")); - return new GUIDisplayPrompt(context); - case 3: - return plugin.getQuestFactory().returnToMenu(context); - default: - return new GUIDisplayPrompt(context); - } - } -} diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/RequirementsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/RequirementsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java index a28b295c7..8bb0ee55e 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/RequirementsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.requirements; import java.util.Arrays; import java.util.Collections; @@ -32,6 +32,8 @@ import com.herocraftonline.heroes.characters.classes.HeroClass; import me.blackvein.quests.CustomRequirement; import me.blackvein.quests.Quest; import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.generic.ItemStackPrompt; +import me.blackvein.quests.convo.generic.OverridePrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/RewardsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/rewards/RewardsPrompt.java similarity index 97% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/RewardsPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/rewards/RewardsPrompt.java index c5e4c796a..6d2a9e613 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/RewardsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/rewards/RewardsPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.rewards; import java.util.Arrays; import java.util.Collections; @@ -32,6 +32,8 @@ import com.herocraftonline.heroes.characters.classes.HeroClass; import me.blackvein.quests.CustomReward; import me.blackvein.quests.Quests; +import me.blackvein.quests.convo.generic.ItemStackPrompt; +import me.blackvein.quests.convo.generic.OverridePrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java similarity index 99% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMainPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java index b76c6ebbb..be86f1e11 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMainPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.stages; import java.util.AbstractMap; import java.util.Arrays; @@ -32,7 +32,12 @@ import org.bukkit.entity.Player; import me.blackvein.quests.CustomObjective; import me.blackvein.quests.Quests; import me.blackvein.quests.actions.Action; +import me.blackvein.quests.convo.generic.OverridePrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.objectives.BlocksPrompt; +import me.blackvein.quests.convo.quests.objectives.ItemsPrompt; +import me.blackvein.quests.convo.quests.objectives.MobsPrompt; +import me.blackvein.quests.convo.quests.objectives.NPCsPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMenuPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java similarity index 99% rename from main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMenuPrompt.java rename to main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java index 3f8615613..5131c8841 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/StageMenuPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java @@ -10,7 +10,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************************************/ -package me.blackvein.quests.convo.quests.prompts; +package me.blackvein.quests.convo.quests.stages; import org.bukkit.ChatColor; import org.bukkit.conversations.ConversationContext; diff --git a/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java b/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java new file mode 100644 index 000000000..4d00a38fa --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/interfaces/ReloadCallback.java @@ -0,0 +1,5 @@ +package me.blackvein.quests.interfaces; + +public interface ReloadCallback { + public void execute(T response); +} diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 06dd5a30f..0c69cc45a 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -28,13 +28,13 @@ import java.util.Map.Entry; import me.blackvein.quests.Quest; import me.blackvein.quests.Quester; import me.blackvein.quests.Quests; -import me.blackvein.quests.Quests.ReloadCallback; import me.blackvein.quests.Requirements; import me.blackvein.quests.Stage; import me.blackvein.quests.events.command.QuestsCommandPreQuestsEditorEvent; import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent; import me.blackvein.quests.events.command.QuestsCommandPreQuestsListEvent; import me.blackvein.quests.events.quest.QuestQuitEvent; +import me.blackvein.quests.interfaces.ReloadCallback; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; diff --git a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java index b804bf0ed..47c45397d 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java @@ -289,7 +289,7 @@ public class NpcListener implements Listener { quester.showGUIDisplay(evt.getNPC(), npcQuests); } else { Conversation c = plugin.getNpcConversationFactory().buildConversation(player); - c.getContext().setSessionData("quests", npcQuests); + c.getContext().setSessionData("npcQuests", npcQuests); c.getContext().setSessionData("npc", evt.getNPC().getName()); c.begin(); } 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 f5ffa19a3..83dbe39d1 100644 --- a/main/src/main/java/me/blackvein/quests/util/MiscUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/MiscUtil.java @@ -16,6 +16,7 @@ import java.util.LinkedList; import org.bukkit.ChatColor; import org.bukkit.DyeColor; +import org.bukkit.Effect; import org.bukkit.entity.EntityType; public class MiscUtil { @@ -203,6 +204,22 @@ public class MiscUtil { } return null; } + + /** + * Gets effect from name + * + * @param properName Name to get effect from + * @return Effect or null if invalid + */ + public static Effect getProperEffect(String properName) { + properName = properName.replace("_", "").replace(" ", "").toUpperCase(); + for (Effect eff : Effect.values()) { + if (eff.name().replace("_", "").equalsIgnoreCase(properName)) { + return eff; + } + } + return null; + } /** * Split text into multiple lines