diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index 51dd99d8b..4316eba41 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -1,373 +1,375 @@ -package me.blackvein.quests; - -import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import java.util.LinkedList; -import java.util.List; -import me.blackvein.quests.util.ItemUtil; -import net.citizensnpcs.api.npc.NPC; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -public class Quest { - - public String name; - public String description; - public String finished; - public long redoDelay = -1; - public int parties = 0; - LinkedList stages = new LinkedList(); - NPC npcStart; - Location blockStart; - Quests plugin; - Event initialEvent; - - //Requirements - int moneyReq = 0; - int questPointsReq = 0; - - List items = new LinkedList(); - List removeItems = new LinkedList(); - - List neededQuests = new LinkedList(); - List blockQuests = new LinkedList(); - - List permissionReqs = new LinkedList(); - - public String failRequirements = null; - // - - //Rewards - int moneyReward = 0; - int questPoints = 0; - int exp = 0; - List commands = new LinkedList(); - List permissions = new LinkedList(); - LinkedList itemRewards = new LinkedList(); - - //mcMMO - List mcmmoSkills = new LinkedList(); - List mcmmoAmounts = new LinkedList(); - // - - // - public void nextStage(Quester q){ - - String stageCompleteMessage = q.currentStage.completeMessage; - if (stageCompleteMessage != null) { - q.getPlayer().sendMessage(Quests.parseString(stageCompleteMessage, q.currentQuest)); - } - - if(q.currentStage.delay < 0){ - - Player player = q.getPlayer(); - - if(stages.indexOf(q.currentStage) == (stages.size() - 1)){ - - if(q.currentStage.script != null) - plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); - if(q.currentStage.event != null) - q.currentStage.event.happen(q); - - completeQuest(q); - - }else { - - q.reset(); - if(q.currentStage.script != null) - plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); - if(q.currentStage.event != null) - q.currentStage.event.happen(q); - q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1); - q.addEmpties(); - - player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); - for(String s : q.getObjectives()){ - - player.sendMessage(s); - - } - - String stageStartMessage = q.currentStage.startMessage; - if (stageStartMessage != null) { - q.getPlayer().sendMessage(Quests.parseString(stageStartMessage, q.currentQuest)); - } - - } - - q.delayStartTime = 0; - q.delayTimeLeft = -1; - - }else{ - q.startStageTimer(); - - } - - } - - public String getName(){ - return name; - } - - public boolean testRequirements(Quester quester){ - return testRequirements(quester.getPlayer()); - } - - public boolean testRequirements(Player player){ - - Quester quester = plugin.getQuester(player.getName()); - - if(moneyReq != 0 && Quests.economy.getBalance(player.getName()) < moneyReq) - return false; - - PlayerInventory inventory = player.getInventory(); - int num = 0; - - for(ItemStack is : items){ - - for(ItemStack stack : inventory.getContents()){ - - if(stack != null){ - if(ItemUtil.compareItems(is, stack, true) == 0) - num += stack.getAmount(); - } - - } - - if(num < is.getAmount()) - return false; - - num = 0; - - } - - for(String s : permissionReqs){ - - if(player.hasPermission(s) == false) - return false; - - } - - if(quester.questPoints < questPointsReq) - return false; - - if(quester.completedQuests.containsAll(neededQuests) == false) - return false; - - for (String q : blockQuests) { - if (quester.completedQuests.contains(q)) { - return false; - } - } - - return true; - - } - - public void completeQuest(Quester q){ - - Player player = plugin.getServer().getPlayerExact(q.name); - q.reset(); - q.completedQuests.add(name); - String none = ChatColor.GRAY + "- (None)"; - player.sendMessage(Quests.parseString(finished, q.currentQuest)); - if(moneyReward > 0 && Quests.economy != null){ - Quests.economy.depositPlayer(q.name, moneyReward); - none = null; - } - if(redoDelay > -1) - q.completedTimes.put(this.name, System.currentTimeMillis()); - - for(ItemStack i : itemRewards){ - Quests.addItem(player, i); - none = null; - } - - for(String s : commands){ - - s = s.replaceAll("", player.getName()); - - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s); - none = null; - - } - - for(String s : permissions){ - - Quests.permission.playerAdd(player, s); - none = null; - - } - - for(String s : mcmmoSkills){ - - new McMMOPlayer(player).getProfile().skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s))); - none = null; - - } - - if(exp > 0){ - player.giveExp(exp); - none = null; - } - - player.sendMessage(ChatColor.GOLD + "**QUEST COMPLETE: " + ChatColor.YELLOW + q.currentQuest.name + ChatColor.GOLD + "**"); - player.sendMessage(ChatColor.GREEN + "Rewards:"); - - if(questPoints > 0){ - player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " Quest Points"); - q.questPoints += questPoints; - none = null; - } - - for(ItemStack i : itemRewards){ - if(i.hasItemMeta() && i.getItemMeta().hasDisplayName()) - player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount()); - else if(i.getDurability() != 0) - player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount()); - else - player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount()); - - none = null; - } - - if(moneyReward > 1){ - player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true)); - none = null; - }else if(moneyReward == 1){ - player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false)); - none = null; - } - - if(exp > 0){ - player.sendMessage("- " + ChatColor.DARK_GREEN + exp + ChatColor.DARK_PURPLE + " Experience"); - none = null; - } - - if(none != null){ - player.sendMessage(none); - } - q.currentQuest = null; - q.currentStage = null; - - q.saveData(); - player.updateInventory(); - - } - - @Override - public boolean equals(Object o){ - - if(o instanceof Quest){ - - Quest other = (Quest) o; - - if(other.blockStart != null && blockStart != null){ - if(other.blockStart.equals(blockStart) == false) - return false; - }else if(other.blockStart != null && blockStart == null){ - return false; - }else if(other.blockStart == null && blockStart != null) - return false; - - for(String s : other.commands){ - - if(commands.size() >= (other.commands.indexOf(s))){ - - if(commands.get(other.commands.indexOf(s)).equals(s) == false) - return false; - - }else{ - return false; - } - - } - - if(other.description.equals(description) == false) - return false; - - if(other.initialEvent != null && initialEvent != null){ - if(other.initialEvent.equals(initialEvent) == false) - return false; - }else if(other.initialEvent != null && initialEvent == null){ - return false; - }else if(other.initialEvent == null && initialEvent != null) - return false; - - if(other.exp != exp) - return false; - - if(other.failRequirements != null && failRequirements != null){ - if(other.failRequirements.equals(failRequirements) == false) - return false; - }else if(other.failRequirements != null && failRequirements == null){ - return false; - }else if(other.failRequirements == null && failRequirements != null) - return false; - - if(other.finished.equals(finished) == false) - return false; - - if(other.items.equals(items) == false) - return false; - - if(other.itemRewards.equals(itemRewards) == false) - return false; - - if(other.mcmmoAmounts.equals(mcmmoAmounts) == false) - return false; - - if(other.mcmmoSkills.equals(mcmmoSkills) == false) - return false; - - if(other.moneyReq != moneyReq) - return false; - - if(other.moneyReward != moneyReward) - return false; - - if(other.name.equals(name) == false) - return false; - - if(other.neededQuests.equals(neededQuests) == false) - return false; - - if (other.blockQuests.equals(blockQuests) == false) - return false; - - if(other.npcStart != null && npcStart != null){ - if(other.npcStart.equals(npcStart) == false) - return false; - }else if(other.npcStart != null && npcStart == null){ - return false; - }else if(other.npcStart == null && npcStart != null) - return false; - - if(other.permissionReqs.equals(permissionReqs) == false) - return false; - - if(other.permissions.equals(permissions) == false) - return false; - - if(other.questPoints != questPoints) - return false; - - if(other.questPointsReq != questPointsReq) - return false; - - if(other.redoDelay != redoDelay) - return false; - - - if(other.stages.equals(stages) == false) - return false; - - } - - return true; - - } - -} +package me.blackvein.quests; + +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import java.util.LinkedList; +import java.util.List; +import me.blackvein.quests.util.ItemUtil; +import net.citizensnpcs.api.npc.NPC; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +public class Quest { + + public String name; + public String description; + public String finished; + public long redoDelay = -1; + public int parties = 0; + LinkedList stages = new LinkedList(); + NPC npcStart; + Location blockStart; + Quests plugin; + Event initialEvent; + + //Requirements + int moneyReq = 0; + int questPointsReq = 0; + + List items = new LinkedList(); + List removeItems = new LinkedList(); + + List neededQuests = new LinkedList(); + List blockQuests = new LinkedList(); + + List permissionReqs = new LinkedList(); + + public String failRequirements = null; + // + + //Rewards + int moneyReward = 0; + int questPoints = 0; + int exp = 0; + List commands = new LinkedList(); + List permissions = new LinkedList(); + LinkedList itemRewards = new LinkedList(); + + //mcMMO + List mcmmoSkills = new LinkedList(); + List mcmmoAmounts = new LinkedList(); + // + + // + public void nextStage(Quester q){ + + String stageCompleteMessage = q.currentStage.completeMessage; + if (stageCompleteMessage != null) { + q.getPlayer().sendMessage(Quests.parseString(stageCompleteMessage, q.currentQuest)); + } + + if(q.currentStage.delay < 0){ + + Player player = q.getPlayer(); + + if(q.currentStageIndex >= (stages.size() - 1)){ + + if(q.currentStage.script != null) + plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); + if(q.currentStage.event != null) + q.currentStage.event.happen(q); + + completeQuest(q); + + }else { + + q.reset(); + if(q.currentStage.script != null) + plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); + if(q.currentStage.event != null) + q.currentStage.event.happen(q); + q.currentStage = stages.get(stages.indexOf(q.currentStage) + 1); + q.currentStageIndex++; + q.addEmpties(); + + player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); + for(String s : q.getObjectives()){ + + player.sendMessage(s); + + } + + String stageStartMessage = q.currentStage.startMessage; + if (stageStartMessage != null) { + q.getPlayer().sendMessage(Quests.parseString(stageStartMessage, q.currentQuest)); + } + + } + + q.delayStartTime = 0; + q.delayTimeLeft = -1; + + }else{ + q.startStageTimer(); + + } + + } + + public String getName(){ + return name; + } + + public boolean testRequirements(Quester quester){ + return testRequirements(quester.getPlayer()); + } + + public boolean testRequirements(Player player){ + + Quester quester = plugin.getQuester(player.getName()); + + if(moneyReq != 0 && Quests.economy.getBalance(player.getName()) < moneyReq) + return false; + + PlayerInventory inventory = player.getInventory(); + int num = 0; + + for(ItemStack is : items){ + + for(ItemStack stack : inventory.getContents()){ + + if(stack != null){ + if(ItemUtil.compareItems(is, stack, true) == 0) + num += stack.getAmount(); + } + + } + + if(num < is.getAmount()) + return false; + + num = 0; + + } + + for(String s : permissionReqs){ + + if(player.hasPermission(s) == false) + return false; + + } + + if(quester.questPoints < questPointsReq) + return false; + + if(quester.completedQuests.containsAll(neededQuests) == false) + return false; + + for (String q : blockQuests) { + if (quester.completedQuests.contains(q)) { + return false; + } + } + + return true; + + } + + public void completeQuest(Quester q){ + + Player player = plugin.getServer().getPlayerExact(q.name); + q.reset(); + q.completedQuests.add(name); + String none = ChatColor.GRAY + "- (None)"; + player.sendMessage(Quests.parseString(finished, q.currentQuest)); + if(moneyReward > 0 && Quests.economy != null){ + Quests.economy.depositPlayer(q.name, moneyReward); + none = null; + } + if(redoDelay > -1) + q.completedTimes.put(this.name, System.currentTimeMillis()); + + for(ItemStack i : itemRewards){ + Quests.addItem(player, i); + none = null; + } + + for(String s : commands){ + + s = s.replaceAll("", player.getName()); + + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s); + none = null; + + } + + for(String s : permissions){ + + Quests.permission.playerAdd(player, s); + none = null; + + } + + for(String s : mcmmoSkills){ + + new McMMOPlayer(player).getProfile().skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s))); + none = null; + + } + + if(exp > 0){ + player.giveExp(exp); + none = null; + } + + player.sendMessage(ChatColor.GOLD + "**QUEST COMPLETE: " + ChatColor.YELLOW + q.currentQuest.name + ChatColor.GOLD + "**"); + player.sendMessage(ChatColor.GREEN + "Rewards:"); + + if(questPoints > 0){ + player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " Quest Points"); + q.questPoints += questPoints; + none = null; + } + + for(ItemStack i : itemRewards){ + if(i.hasItemMeta() && i.getItemMeta().hasDisplayName()) + player.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount()); + else if(i.getDurability() != 0) + player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ":" + i.getDurability() + ChatColor.GRAY + " x " + i.getAmount()); + else + player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount()); + + none = null; + } + + if(moneyReward > 1){ + player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(true)); + none = null; + }else if(moneyReward == 1){ + player.sendMessage("- " + ChatColor.DARK_GREEN + moneyReward + " " + ChatColor.DARK_PURPLE + Quests.getCurrency(false)); + none = null; + } + + if(exp > 0){ + player.sendMessage("- " + ChatColor.DARK_GREEN + exp + ChatColor.DARK_PURPLE + " Experience"); + none = null; + } + + if(none != null){ + player.sendMessage(none); + } + q.currentQuest = null; + q.currentStage = null; + q.currentStageIndex = 0; + + q.saveData(); + player.updateInventory(); + + } + + @Override + public boolean equals(Object o){ + + if(o instanceof Quest){ + + Quest other = (Quest) o; + + if(other.blockStart != null && blockStart != null){ + if(other.blockStart.equals(blockStart) == false) + return false; + }else if(other.blockStart != null && blockStart == null){ + return false; + }else if(other.blockStart == null && blockStart != null) + return false; + + for(String s : other.commands){ + + if(commands.size() >= (other.commands.indexOf(s))){ + + if(commands.get(other.commands.indexOf(s)).equals(s) == false) + return false; + + }else{ + return false; + } + + } + + if(other.description.equals(description) == false) + return false; + + if(other.initialEvent != null && initialEvent != null){ + if(other.initialEvent.equals(initialEvent) == false) + return false; + }else if(other.initialEvent != null && initialEvent == null){ + return false; + }else if(other.initialEvent == null && initialEvent != null) + return false; + + if(other.exp != exp) + return false; + + if(other.failRequirements != null && failRequirements != null){ + if(other.failRequirements.equals(failRequirements) == false) + return false; + }else if(other.failRequirements != null && failRequirements == null){ + return false; + }else if(other.failRequirements == null && failRequirements != null) + return false; + + if(other.finished.equals(finished) == false) + return false; + + if(other.items.equals(items) == false) + return false; + + if(other.itemRewards.equals(itemRewards) == false) + return false; + + if(other.mcmmoAmounts.equals(mcmmoAmounts) == false) + return false; + + if(other.mcmmoSkills.equals(mcmmoSkills) == false) + return false; + + if(other.moneyReq != moneyReq) + return false; + + if(other.moneyReward != moneyReward) + return false; + + if(other.name.equals(name) == false) + return false; + + if(other.neededQuests.equals(neededQuests) == false) + return false; + + if (other.blockQuests.equals(blockQuests) == false) + return false; + + if(other.npcStart != null && npcStart != null){ + if(other.npcStart.equals(npcStart) == false) + return false; + }else if(other.npcStart != null && npcStart == null){ + return false; + }else if(other.npcStart == null && npcStart != null) + return false; + + if(other.permissionReqs.equals(permissionReqs) == false) + return false; + + if(other.permissions.equals(permissions) == false) + return false; + + if(other.questPoints != questPoints) + return false; + + if(other.questPointsReq != questPointsReq) + return false; + + if(other.redoDelay != redoDelay) + return false; + + + if(other.stages.equals(stages) == false) + return false; + + } + + return true; + + } + +} diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index b2cee570b..94c428fba 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -1,1784 +1,1790 @@ -package me.blackvein.quests; - -import java.io.File; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import me.blackvein.quests.prompts.RequirementsPrompt; -import me.blackvein.quests.prompts.RewardsPrompt; -import me.blackvein.quests.prompts.StagesPrompt; -import me.blackvein.quests.util.CK; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.npc.NPC; -import org.bukkit.ChatColor; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.conversations.*; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class QuestFactory implements ConversationAbandonedListener, ColorUtil { - - public Quests quests; - Map editSessions = new HashMap(); - Map selectedBlockStarts = new HashMap(); - public Map selectedKillLocations = new HashMap(); - public Map selectedReachLocations = new HashMap(); - public List names = new LinkedList(); - ConversationFactory convoCreator; - File questsFile; - - @SuppressWarnings("LeakingThisInConstructor") - public QuestFactory(Quests plugin) { - - quests = plugin; - questsFile = new File(plugin.getDataFolder(), "quests.yml"); - - //Ensure to initialize convoCreator last, to ensure that 'this' is fully initialized before it is passed - this.convoCreator = new ConversationFactory(plugin) - .withModality(false) - .withLocalEcho(false) - .withFirstPrompt(new MenuPrompt()) - .withTimeout(3600) - .thatExcludesNonPlayersWithMessage("Console may not perform this operation!") - .addConversationAbandonedListener(this); - - } - - @Override - public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { - - if (abandonedEvent.getContext().getSessionData(CK.Q_NAME) != null) { - names.remove((String) abandonedEvent.getContext().getSessionData(CK.Q_NAME)); - } - - Player player = (Player) abandonedEvent.getContext().getForWhom(); - selectedBlockStarts.remove(player); - selectedKillLocations.remove(player); - selectedReachLocations.remove(player); - - } - - private class MenuPrompt extends FixedSetPrompt { - - public MenuPrompt() { - - super("1", "2", "3", "4"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = - GOLD + "- Quest Editor -\n" - + BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Create a Quest\n" - + BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Edit a Quest\n" - + BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Delete a Quest\n" - + GOLD + "" + BOLD + "4" + RESET + YELLOW + " - Exit"; - - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - final Player player = (Player) context.getForWhom(); - - if (input.equalsIgnoreCase("1")) { - - if (player.hasPermission("quests.editor.create")) { - return new QuestNamePrompt(); - } else { - player.sendMessage(RED + "You do not have permission to create Quests."); - return new MenuPrompt(); - } - - } else if (input.equalsIgnoreCase("2")) { - - if (player.hasPermission("quests.editor.edit")) { - return new SelectEditPrompt(); - } else { - player.sendMessage(RED + "You do not have permission to edit Quests."); - return new MenuPrompt(); - } - - } else if (input.equalsIgnoreCase("3")) { - - if (player.hasPermission("quests.editor.delete")) { - return new SelectDeletePrompt(); - } else { - player.sendMessage(RED + "You do not have permission to delete Quests."); - return new MenuPrompt(); - } - - } else if (input.equalsIgnoreCase("4")) { - context.getForWhom().sendRawMessage(YELLOW + "Exited."); - return Prompt.END_OF_CONVERSATION; - } - - return null; - - } - } - - public Prompt returnToMenu() { - - return new CreateMenuPrompt(); - - } - - private class CreateMenuPrompt extends FixedSetPrompt { - - public CreateMenuPrompt() { - - super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = - GOLD + "- Quest: " + AQUA + context.getSessionData(CK.Q_NAME) + GOLD + " -\n"; - - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set name\n"; - - if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { - text += BLUE + "" + BOLD + "2" + RESET + RED + " - Set ask message " + DARKRED + "(Required, none set)\n"; - } else { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set ask message (\"" + context.getSessionData(CK.Q_ASK_MESSAGE) + "\")\n"; - } - - - if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { - text += BLUE + "" + BOLD + "3" + RESET + RED + " - Set finish message " + DARKRED + "(Required, none set)\n"; - } else { - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set finish message (\"" + context.getSessionData(CK.Q_FINISH_MESSAGE) + "\")\n"; - } - - - if (context.getSessionData(CK.Q_REDO_DELAY) == null) { - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (None set)\n"; - } else { - - //something here is throwing an exception - try{ - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (" + Quests.getTime((Long) context.getSessionData(CK.Q_REDO_DELAY)) + ")\n"; - }catch(Exception e){ - e.printStackTrace(); - } - - // - } - - if (context.getSessionData(CK.Q_START_NPC) == null && quests.citizens != null) { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (None set)\n"; - } else if (quests.citizens != null) { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (" + CitizensAPI.getNPCRegistry().getById((Integer) context.getSessionData(CK.Q_START_NPC)).getName() + ")\n"; - } - - if (context.getSessionData(CK.Q_START_BLOCK) == null) { - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (None set)\n"; - } else { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (None set)\n"; - } - - } else { - - if (quests.citizens != null) { - Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")\n"; - } else { - Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")\n"; - } - - } - - - if (context.getSessionData(CK.Q_INITIAL_EVENT) == null) { - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set initial Event (None set)\n"; - } else { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set initial Event (None set)\n"; - } - - } else { - - if (quests.citizens != null) { - String s = (String) context.getSessionData(CK.Q_INITIAL_EVENT); - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set initial Event (" + s + ")\n"; - } else { - String s = (String) context.getSessionData(CK.Q_INITIAL_EVENT); - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set initial Event (" + s + ")\n"; - } - - } - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "8" + RESET + DARKAQUA + " - Edit Requirements\n"; - } else { - text += BLUE + "" + BOLD + "7" + RESET + DARKAQUA + " - Edit Requirements\n"; - } - - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "9" + RESET + PINK + " - Edit Stages\n"; - } else { - text += BLUE + "" + BOLD + "8" + RESET + PINK + " - Edit Stages\n"; - } - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "10" + RESET + GREEN + " - Edit Rewards\n"; - } else { - text += BLUE + "" + BOLD + "9" + RESET + GREEN + " - Edit Rewards\n"; - } - - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "11" + RESET + GOLD + " - Save\n"; - } else { - text += BLUE + "" + BOLD + "10" + RESET + GOLD + " - Save\n"; - } - - if (quests.citizens != null) { - text += BLUE + "" + BOLD + "12" + RESET + RED + " - Exit\n"; - } else { - text += BLUE + "" + BOLD + "11" + RESET + RED + " - Exit\n"; - } - - - return text; - - } - - @Override - public Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - - return new SetNamePrompt(); - - } else if (input.equalsIgnoreCase("2")) { - - return new AskMessagePrompt(); - - } else if (input.equalsIgnoreCase("3")) { - - return new FinishMessagePrompt(); - - } else if (input.equalsIgnoreCase("4")) { - - return new RedoDelayPrompt(); - - } else if (input.equalsIgnoreCase("5")) { - - if (quests.citizens != null) { - return new SetNpcStartPrompt(); - } else { - selectedBlockStarts.put((Player) context.getForWhom(), null); - return new BlockStartPrompt(); - } - - } else if (input.equalsIgnoreCase("6")) { - - if (quests.citizens != null) { - selectedBlockStarts.put((Player) context.getForWhom(), null); - return new BlockStartPrompt(); - } else { - return new RequirementsPrompt(quests, QuestFactory.this); - } - - } else if (input.equalsIgnoreCase("6")) { - - if (quests.citizens != null) { - selectedBlockStarts.put((Player) context.getForWhom(), null); - return new BlockStartPrompt(); - } else { - return new InitialEventPrompt(); - } - - } else if (input.equalsIgnoreCase("7")) { - - if (quests.citizens != null) { - return new InitialEventPrompt(); - } else { - return new RequirementsPrompt(quests, QuestFactory.this); - } - - } else if (input.equalsIgnoreCase("8")) { - - if (quests.citizens != null) { - return new RequirementsPrompt(quests, QuestFactory.this); - } else { - return new StagesPrompt(QuestFactory.this); - } - - } else if (input.equalsIgnoreCase("9")) { - - if (quests.citizens != null) { - return new StagesPrompt(QuestFactory.this); - } else { - return new RewardsPrompt(quests, QuestFactory.this); - } - - } else if (input.equalsIgnoreCase("10")) { - - if (quests.citizens != null) { - return new RewardsPrompt(quests, QuestFactory.this); - } else { - return new SavePrompt(); - } - - } else if (input.equalsIgnoreCase("11")) { - - if (quests.citizens != null) { - return new SavePrompt(); - } else { - return new ExitPrompt(); - } - - } else if (input.equalsIgnoreCase("12")) { - - if (quests.citizens != null) { - return new ExitPrompt(); - } else { - return new CreateMenuPrompt(); - } - - } - - return null; - - } - } - - private class SelectEditPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String s = GOLD + "- Edit Quest -\n"; - for (Quest q : quests.getQuests()) { - s += GRAY + "- " + YELLOW + q.getName() + "\n"; - } - - return s + GOLD + "Enter a Quest to edit, or \"cancel\" to return."; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - for (Quest q : quests.getQuests()) { - - if (q.getName().equalsIgnoreCase(input) || q.getName().toLowerCase().contains(input.toLowerCase())) { - loadQuest(context, q); - return new CreateMenuPrompt(); - } - - } - - return new SelectEditPrompt(); - - } else { - return new MenuPrompt(); - } - - } - } - - private class QuestNamePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = GOLD + "- Create Quest -\n"; - text += AQUA + "Create new Quest " + GOLD + "- Enter a name for the Quest (Or enter \'cancel\' to return)"; - - return text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - for (Quest q : quests.quests) { - - if (q.name.equalsIgnoreCase(input)) { - - context.getForWhom().sendRawMessage(ChatColor.RED + "Quest already exists!"); - return new QuestNamePrompt(); - - } - - } - - if (names.contains(input)) { - - context.getForWhom().sendRawMessage(ChatColor.RED + "Someone is creating a Quest with that name!"); - return new QuestNamePrompt(); - - } - - if (input.contains(",")) { - - context.getForWhom().sendRawMessage(ChatColor.RED + "Name may not contain commas!"); - return new QuestNamePrompt(); - - } - - context.setSessionData(CK.Q_NAME, input); - names.add(input); - return new CreateMenuPrompt(); - - } else { - - return new MenuPrompt(); - - } - - } - } - - private class SetNpcStartPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Enter NPC ID, or -1 to clear the NPC start, or -2 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() > -1) { - - if (CitizensAPI.getNPCRegistry().getById(input.intValue()) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + "No NPC exists with that id!"); - return new SetNpcStartPrompt(); - } - - context.setSessionData(CK.Q_START_NPC, input.intValue()); - return new CreateMenuPrompt(); - - } else if (input.intValue() == -1) { - context.setSessionData(CK.Q_START_NPC, null); - return new CreateMenuPrompt(); - } else if (input.intValue() == -2) { - return new CreateMenuPrompt(); - } else { - context.getForWhom().sendRawMessage(ChatColor.RED + "No NPC exists with that id!"); - return new SetNpcStartPrompt(); - } - - } - } - - private class BlockStartPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Right-click on a block to use as a start point, then enter \"done\" to save,\n" - + "or enter \"clear\" to clear the block start, or \"cancel\" to return"; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase("done") || input.equalsIgnoreCase("cancel")) { - - if (input.equalsIgnoreCase("done")) { - - Block block = selectedBlockStarts.get(player); - if (block != null) { - Location loc = block.getLocation(); - context.setSessionData(CK.Q_START_BLOCK, loc); - selectedBlockStarts.remove(player); - } else { - player.sendMessage(ChatColor.RED + "You must select a block first."); - return new BlockStartPrompt(); - } - - } else { - selectedBlockStarts.remove(player); - } - - - return new CreateMenuPrompt(); - - } else if (input.equalsIgnoreCase("clear")) { - - selectedBlockStarts.remove(player); - context.setSessionData(CK.Q_START_BLOCK, null); - return new CreateMenuPrompt(); - - } - - return new BlockStartPrompt(); - - } - } - - private class SetNamePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Enter Quest name (or \'cancel\' to return)"; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - for (Quest q : quests.quests) { - - if (q.name.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(RED + "A Quest with that name already exists!"); - return new SetNamePrompt(); - } - } - - } - - if (names.contains(input)) { - context.getForWhom().sendRawMessage(RED + "Someone is creating/editing a Quest with that name!"); - return new SetNamePrompt(); - } - - if (input.contains(",")) { - - context.getForWhom().sendRawMessage(ChatColor.RED + "Name may not contain commas!"); - return new QuestNamePrompt(); - - } - - names.remove((String) context.getSessionData(CK.Q_NAME)); - context.setSessionData(CK.Q_NAME, input); - names.add(input); - - } - - return new CreateMenuPrompt(); - - } - } - - private class AskMessagePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Enter ask message (or \'cancel\' to return)"; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - context.setSessionData(CK.Q_ASK_MESSAGE, input); - } - - return new CreateMenuPrompt(); - - } - } - - private class FinishMessagePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Enter finish message (or \'cancel\' to return)"; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - context.setSessionData(CK.Q_FINISH_MESSAGE, input); - } - - return new CreateMenuPrompt(); - - } - } - - private class InitialEventPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = DARKGREEN + "- Events -\n"; - if (quests.events.isEmpty()) { - text += RED + "- None"; - } else { - for (Event e : quests.events) { - text += GREEN + "- " + e.getName() + "\n"; - } - } - - return text + YELLOW + "Enter an Event name, or enter \"clear\" to clear the initial Event, or \"cancel\" to return"; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - Player player = (Player) context.getForWhom(); - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - Event found = null; - - for (Event e : quests.events) { - - if (e.getName().equalsIgnoreCase(input)) { - found = e; - break; - } - - } - - if (found == null) { - player.sendMessage(RED + input + YELLOW + " is not a valid event name!"); - return new InitialEventPrompt(); - } else { - context.setSessionData(CK.Q_INITIAL_EVENT, found.getName()); - return new CreateMenuPrompt(); - } - - } else if (input.equalsIgnoreCase("clear")) { - context.setSessionData(CK.Q_INITIAL_EVENT, null); - player.sendMessage(YELLOW + "Initial Event cleared."); - return new CreateMenuPrompt(); - } else { - return new CreateMenuPrompt(); - } - - } - } - - private class RedoDelayPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return ChatColor.YELLOW + "Enter amount of time (in milliseconds), or 0 to clear the redo delay, or -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.longValue() < -1) { - context.getForWhom().sendRawMessage(ChatColor.RED + "Amount must be a positive number."); - } else if (input.longValue() == 0) { - context.setSessionData(CK.Q_REDO_DELAY, null); - } else if (input.longValue() != -1) { - context.setSessionData(CK.Q_REDO_DELAY, input.longValue()); - } - - return new CreateMenuPrompt(); - - } - } - - private class SavePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = GREEN - + "1 - Yes\n" - + "2 - No"; - return ChatColor.YELLOW + "Finish and save \"" + AQUA + context.getSessionData(CK.Q_NAME) + YELLOW + "\"?\n" + text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("Yes")) { - - if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { - context.getForWhom().sendRawMessage(RED + "You must set an ask message!"); - return new CreateMenuPrompt(); - } else if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { - context.getForWhom().sendRawMessage(RED + "You must set a finish message!"); - return new CreateMenuPrompt(); - } else if (StagesPrompt.getStages(context) == 0) { - context.getForWhom().sendRawMessage(RED + "Your Quest has no Stages!"); - return new CreateMenuPrompt(); - } - - FileConfiguration data = new YamlConfiguration(); - try { - data.load(new File(quests.getDataFolder(), "quests.yml")); - ConfigurationSection questSection = data.getConfigurationSection("quests"); - - int customNum = 1; - while (true) { - - if (questSection.contains("custom" + customNum)) { - customNum++; - } else { - break; - } - - } - - ConfigurationSection newSection = questSection.createSection("custom" + customNum); - saveQuest(context, newSection); - data.save(new File(quests.getDataFolder(), "quests.yml")); - context.getForWhom().sendRawMessage(BOLD + "Quest saved! (You will need to perform a Quest reload for it to appear)"); - - } catch (Exception e) { - e.printStackTrace(); - } - - return Prompt.END_OF_CONVERSATION; - - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("No")) { - return new CreateMenuPrompt(); - } else { - return new SavePrompt(); - } - - } - } - - private class ExitPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = GREEN - + "1 - Yes\n" - + "2 - No"; - return ChatColor.YELLOW + "Are you sure you want to exit without saving?\n" + text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("Yes")) { - - context.getForWhom().sendRawMessage(BOLD + "" + YELLOW + "Exited."); - return Prompt.END_OF_CONVERSATION; - - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("No")) { - return new CreateMenuPrompt(); - } else { - return new ExitPrompt(); - } - - } - } - - @SuppressWarnings("unchecked") - public static void saveQuest(ConversationContext cc, ConfigurationSection cs) { - - String edit = null; - if (cc.getSessionData(CK.ED_QUEST_EDIT) != null) { - edit = (String) cc.getSessionData(CK.ED_QUEST_EDIT); - } - - if (edit != null) { - - ConfigurationSection questList = cs.getParent(); - - for (String key : questList.getKeys(false)) { - - String name = questList.getString(key + ".name"); - if (name.equalsIgnoreCase(edit)) { - - questList.set(key, null); - break; - - } - - } - - } - - String name = (String) cc.getSessionData(CK.Q_NAME); - String desc = (String) cc.getSessionData(CK.Q_ASK_MESSAGE); - String finish = (String) cc.getSessionData(CK.Q_FINISH_MESSAGE); - Long redo = null; - Integer npcStart = null; - String blockStart = null; - String initialEvent = null; - - Integer moneyReq = null; - Integer questPointsReq = null; - LinkedList itemReqs = null; - LinkedList removeItemReqs = null; - LinkedList permReqs = null; - LinkedList questReqs = null; - LinkedList questBlocks = null; - String failMessage = null; - - Integer moneyRew = null; - Integer questPointsRew = null; - LinkedList itemRews = new LinkedList(); - Integer expRew = null; - LinkedList commandRews = null; - LinkedList permRews = null; - LinkedList mcMMOSkillRews = null; - LinkedList mcMMOSkillAmounts = null; - - - - if (cc.getSessionData(CK.Q_REDO_DELAY) != null) { - redo = (Long) cc.getSessionData(CK.Q_REDO_DELAY); - } - - if (cc.getSessionData(CK.Q_START_NPC) != null) { - npcStart = (Integer) cc.getSessionData(CK.Q_START_NPC); - } - - if (cc.getSessionData(CK.Q_START_BLOCK) != null) { - blockStart = Quests.getLocationInfo((Location) cc.getSessionData(CK.Q_START_BLOCK)); - } - - - - if (cc.getSessionData(CK.REQ_MONEY) != null) { - moneyReq = (Integer) cc.getSessionData(CK.REQ_MONEY); - } - - if (cc.getSessionData(CK.REQ_QUEST_POINTS) != null) { - questPointsReq = (Integer) cc.getSessionData(CK.REQ_QUEST_POINTS); - } - - if (cc.getSessionData(CK.REQ_ITEMS) != null) { - itemReqs = (LinkedList) cc.getSessionData(CK.REQ_ITEMS); - removeItemReqs = (LinkedList) cc.getSessionData(CK.REQ_ITEMS_REMOVE); - } - - if (cc.getSessionData(CK.REQ_PERMISSION) != null) { - permReqs = (LinkedList) cc.getSessionData(CK.REQ_PERMISSION); - } - - if (cc.getSessionData(CK.REQ_QUEST) != null) { - questReqs = (LinkedList) cc.getSessionData(CK.REQ_QUEST); - } - - if (cc.getSessionData(CK.REQ_QUEST_BLOCK) != null) { - questBlocks = (LinkedList) cc.getSessionData(CK.REQ_QUEST_BLOCK); - } - - if (cc.getSessionData(CK.Q_FAIL_MESSAGE) != null) { - failMessage = (String) cc.getSessionData(CK.Q_FAIL_MESSAGE); - } - - if (cc.getSessionData(CK.Q_INITIAL_EVENT) != null) { - initialEvent = (String) cc.getSessionData(CK.Q_INITIAL_EVENT); - } - - if (cc.getSessionData(CK.REW_MONEY) != null) { - moneyRew = (Integer) cc.getSessionData(CK.REW_MONEY); - } - - if (cc.getSessionData(CK.REW_QUEST_POINTS) != null) { - questPointsRew = (Integer) cc.getSessionData(CK.REW_QUEST_POINTS); - } - - if (cc.getSessionData(CK.REW_ITEMS) != null) { - for (ItemStack is : (LinkedList) cc.getSessionData(CK.REW_ITEMS)) { - itemRews.add(ItemUtil.serialize(is)); - } - } - - if (cc.getSessionData(CK.REW_EXP) != null) { - expRew = (Integer) cc.getSessionData(CK.REW_EXP); - } - - if (cc.getSessionData(CK.REW_COMMAND) != null) { - commandRews = (LinkedList) cc.getSessionData(CK.REW_COMMAND); - } - - if (cc.getSessionData(CK.REW_PERMISSION) != null) { - permRews = (LinkedList) cc.getSessionData(CK.REW_PERMISSION); - } - - if (cc.getSessionData(CK.REW_MCMMO_SKILLS) != null) { - mcMMOSkillRews = (LinkedList) cc.getSessionData(CK.REW_MCMMO_SKILLS); - mcMMOSkillAmounts = (LinkedList) cc.getSessionData(CK.REW_MCMMO_AMOUNTS); - } - - - - cs.set("name", name); - cs.set("npc-giver-id", npcStart); - cs.set("block-start", blockStart); - cs.set("redo-delay", redo); - cs.set("ask-message", desc); - cs.set("finish-message", finish); - cs.set(CK.S_EVENT, initialEvent); - - - if (moneyReq != null || questPointsReq != null || itemReqs != null && itemReqs.isEmpty() == false || permReqs != null && permReqs.isEmpty() == false || (questReqs != null && questReqs.isEmpty() == false) || (questBlocks != null && questBlocks.isEmpty() == false)) { - - ConfigurationSection reqs = cs.createSection("requirements"); - List items = new LinkedList(); - if(itemReqs != null){ - - for (ItemStack is : itemReqs) { - items.add(ItemUtil.serialize(is)); - } - - } - - reqs.set("items", (items.isEmpty() == false) ? items : null); - reqs.set("remove-items", removeItemReqs); - reqs.set("money", moneyReq); - reqs.set("quest-points", questPointsReq); - reqs.set("permissions", permReqs); - reqs.set("quests", questReqs); - reqs.set("quests-blocks", questBlocks); - reqs.set("fail-requirement-message", failMessage); - - } else { - cs.set("requirements", null); - } - - - ConfigurationSection stages = cs.createSection("stages"); - ConfigurationSection ordered = stages.createSection("ordered"); - - String pref; - - LinkedList breakIds; - LinkedList breakAmounts; - - LinkedList damageIds; - LinkedList damageAmounts; - - LinkedList placeIds; - LinkedList placeAmounts; - - LinkedList useIds; - LinkedList useAmounts; - - LinkedList cutIds; - LinkedList cutAmounts; - - Integer fish; - Integer players; - - LinkedList enchantments; - LinkedList enchantmentIds; - LinkedList enchantmentAmounts; - - LinkedList deliveryItems; - LinkedList deliveryNPCIds; - LinkedList deliveryMessages; - - LinkedList npcTalkIds; - - LinkedList npcKillIds; - LinkedList npcKillAmounts; - - LinkedList bossIds; - LinkedList bossAmounts; - - LinkedList mobs; - LinkedList mobAmounts; - LinkedList mobLocs; - LinkedList mobRadii; - LinkedList mobLocNames; - - LinkedList reachLocs; - LinkedList reachRadii; - LinkedList reachNames; - - LinkedList tames; - LinkedList tameAmounts; - - LinkedList shearColors; - LinkedList shearAmounts; - - String script; - String event; - Long delay; - String delayMessage; - String startMessage; - String completeMessage; - - for (int i = 1; i <= StagesPrompt.getStages(cc); i++) { - - pref = "stage" + i; - ConfigurationSection stage = ordered.createSection("" + i); - - breakIds = null; - breakAmounts = null; - - damageIds = null; - damageAmounts = null; - - placeIds = null; - placeAmounts = null; - - useIds = null; - useAmounts = null; - - cutIds = null; - cutAmounts = null; - - fish = null; - players = null; - - enchantments = null; - enchantmentIds = null; - enchantmentAmounts = null; - - deliveryItems = null; - deliveryNPCIds = null; - deliveryMessages = null; - - npcTalkIds = null; - - npcKillIds = null; - npcKillAmounts = null; - - bossIds = null; - bossAmounts = null; - - mobs = null; - mobAmounts = null; - mobLocs = null; - mobRadii = null; - mobLocNames = null; - - reachLocs = null; - reachRadii = null; - reachNames = null; - - tames = null; - tameAmounts = null; - - shearColors = null; - shearAmounts = null; - - script = null; - event = null; - delay = null; - delayMessage = null; - startMessage = null; - completeMessage = null; - - - if (cc.getSessionData(pref + CK.S_BREAK_IDS) != null) { - breakIds = (LinkedList) cc.getSessionData(pref + CK.S_BREAK_IDS); - breakAmounts = (LinkedList) cc.getSessionData(pref + CK.S_BREAK_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_DAMAGE_IDS) != null) { - damageIds = (LinkedList) cc.getSessionData(pref + CK.S_DAMAGE_IDS); - damageAmounts = (LinkedList) cc.getSessionData(pref + CK.S_DAMAGE_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_PLACE_IDS) != null) { - placeIds = (LinkedList) cc.getSessionData(pref + CK.S_PLACE_IDS); - placeAmounts = (LinkedList) cc.getSessionData(pref + CK.S_PLACE_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_USE_IDS) != null) { - useIds = (LinkedList) cc.getSessionData(pref + CK.S_USE_IDS); - useAmounts = (LinkedList) cc.getSessionData(pref + CK.S_USE_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_CUT_IDS) != null) { - cutIds = (LinkedList) cc.getSessionData(pref + CK.S_CUT_IDS); - cutAmounts = (LinkedList) cc.getSessionData(pref + CK.S_CUT_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_FISH) != null) { - fish = (Integer) cc.getSessionData(pref + CK.S_FISH); - } - - if (cc.getSessionData(pref + CK.S_PLAYER_KILL) != null) { - players = (Integer) cc.getSessionData(pref + CK.S_PLAYER_KILL); - } - - if (cc.getSessionData(pref + CK.S_ENCHANT_TYPES) != null) { - enchantments = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_TYPES); - enchantmentIds = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_IDS); - enchantmentAmounts = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) { - deliveryItems = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_ITEMS); - deliveryNPCIds = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_NPCS); - deliveryMessages = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_MESSAGES); - } - - if (cc.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null) { - npcTalkIds = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_TALK_TO); - } - - if (cc.getSessionData(pref + CK.S_NPCS_TO_KILL) != null) { - npcKillIds = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_KILL); - npcKillAmounts = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_BOSS_IDS) != null) { - bossIds = (LinkedList) cc.getSessionData(pref + CK.S_BOSS_IDS); - bossAmounts = (LinkedList) cc.getSessionData(pref + CK.S_BOSS_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_MOB_TYPES) != null) { - mobs = (LinkedList) cc.getSessionData(pref + CK.S_MOB_TYPES); - mobAmounts = (LinkedList) cc.getSessionData(pref + CK.S_MOB_AMOUNTS); - if (cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) != null) { - mobLocs = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS); - mobRadii = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS); - mobLocNames = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES); - } - } - - if (cc.getSessionData(pref + CK.S_TAME_TYPES) != null) { - tames = (LinkedList) cc.getSessionData(pref + CK.S_TAME_TYPES); - tameAmounts = (LinkedList) cc.getSessionData(pref + CK.S_TAME_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_SHEAR_COLORS) != null) { - shearColors = (LinkedList) cc.getSessionData(pref + CK.S_SHEAR_COLORS); - shearAmounts = (LinkedList) cc.getSessionData(pref + CK.S_SHEAR_AMOUNTS); - } - - if (cc.getSessionData(pref + CK.S_EVENT) != null) { - event = (String) cc.getSessionData(pref + CK.S_EVENT); - } - - if (cc.getSessionData(pref + CK.S_DELAY) != null) { - delay = (Long) cc.getSessionData(pref + CK.S_DELAY); - delayMessage = (String) cc.getSessionData(pref + CK.S_DELAY_MESSAGE); - } - - if (cc.getSessionData(pref + CK.S_DENIZEN) != null) { - script = (String) cc.getSessionData(pref + CK.S_DENIZEN); - } - - if (cc.getSessionData(pref + CK.S_START_MESSAGE) != null) { - startMessage = (String) cc.getSessionData(pref + CK.S_START_MESSAGE); - } - - if (cc.getSessionData(pref + CK.S_COMPLETE_MESSAGE) != null) { - completeMessage = (String) cc.getSessionData(pref + CK.S_COMPLETE_MESSAGE); - } - - if (breakIds != null && breakIds.isEmpty() == false) { - stage.set("break-block-ids", breakIds); - stage.set("break-block-amounts", breakAmounts); - } - - if (damageIds != null && damageIds.isEmpty() == false) { - stage.set("damage-block-ids", damageIds); - stage.set("damage-block-amounts", damageAmounts); - } - - if (placeIds != null && placeIds.isEmpty() == false) { - stage.set("place-block-ids", placeIds); - stage.set("place-block-amounts", placeAmounts); - } - - if (useIds != null && useIds.isEmpty() == false) { - stage.set("use-block-ids", useIds); - stage.set("use-block-amounts", useAmounts); - } - - if (cutIds != null && cutIds.isEmpty() == false) { - stage.set("cut-block-ids", cutIds); - stage.set("cut-block-amounts", cutAmounts); - } - - stage.set("fish-to-catch", fish); - stage.set("players-to-kill", players); - stage.set("enchantments", enchantments); - stage.set("enchantment-item-ids", enchantmentIds); - stage.set("enchantment-amounts", enchantmentAmounts); - if(deliveryItems != null && deliveryItems.isEmpty() == false){ - LinkedList items = new LinkedList(); - for(ItemStack is : deliveryItems) - items.add(ItemUtil.serialize(is)); - stage.set("items-to-deliver", items); - }else{ - stage.set("items-to-deliver", null); - } - stage.set("npc-delivery-ids", deliveryNPCIds); - stage.set("delivery-messages", deliveryMessages); - stage.set("npc-ids-to-talk-to", npcTalkIds); - stage.set("npc-ids-to-kill", npcKillIds); - stage.set("npc-kill-amounts", npcKillAmounts); - stage.set("boss-ids-to-kill", bossIds); - stage.set("boss-amounts-to-kill", bossAmounts); - stage.set("mobs-to-kill", mobs); - stage.set("mob-amounts", mobAmounts); - stage.set("locations-to-kill", mobLocs); - stage.set("kill-location-radii", mobRadii); - stage.set("kill-location-names", mobLocNames); - stage.set("locations-to-reach", reachLocs); - stage.set("reach-location-radii", reachRadii); - stage.set("reach-location-names", reachNames); - stage.set("mobs-to-tame", tames); - stage.set("mob-tame-amounts", tameAmounts); - stage.set("sheep-to-shear", shearColors); - stage.set("sheep-amounts", shearAmounts); - stage.set("script-to-run", script); - stage.set("event", event); - stage.set("delay", delay); - stage.set("delay-message", delayMessage); - stage.set("start-message", startMessage); - stage.set("complete-message", completeMessage); - - } - - - if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null) { - - ConfigurationSection rews = cs.createSection("rewards"); - - rews.set("items", (itemRews.isEmpty() == false) ? itemRews : null); - rews.set("money", moneyRew); - rews.set("quest-points", questPointsRew); - rews.set("exp", expRew); - rews.set("permissions", permRews); - rews.set("commands", commandRews); - rews.set("mcmmo-skills", mcMMOSkillRews); - rews.set("mcmmo-levels", mcMMOSkillAmounts); - - } else { - cs.set("rewards", null); - } - - } - - public static void loadQuest(ConversationContext cc, Quest q) { - - cc.setSessionData(CK.ED_QUEST_EDIT, q.name); - cc.setSessionData(CK.Q_NAME, q.name); - if (q.npcStart != null) { - cc.setSessionData(CK.Q_START_NPC, q.npcStart.getId()); - } - cc.setSessionData(CK.Q_START_BLOCK, q.blockStart); - if (q.redoDelay != -1) { - cc.setSessionData(CK.Q_REDO_DELAY, q.redoDelay); - } - cc.setSessionData(CK.Q_ASK_MESSAGE, q.description); - cc.setSessionData(CK.Q_FINISH_MESSAGE, q.finished); - if (q.initialEvent != null) { - cc.setSessionData(CK.Q_INITIAL_EVENT, q.initialEvent.getName()); - } - - //Requirements - if (q.moneyReq != 0) { - cc.setSessionData(CK.REQ_MONEY, q.moneyReq); - } - if (q.questPointsReq != 0) { - cc.setSessionData(CK.REQ_QUEST_POINTS, q.questPointsReq); - } - - if (q.items.isEmpty() == false) { - - cc.setSessionData(CK.REQ_ITEMS, q.items); - cc.setSessionData(CK.REQ_ITEMS_REMOVE, q.removeItems); - - } - - if (q.neededQuests.isEmpty() == false) { - cc.setSessionData(CK.REQ_QUEST, q.neededQuests); - } - - if (q.blockQuests.isEmpty() == false) { - cc.setSessionData(CK.REQ_QUEST_BLOCK, q.blockQuests); - } - - if (q.permissionReqs.isEmpty() == false) { - cc.setSessionData(CK.REQ_PERMISSION, q.permissionReqs); - } - - if (q.failRequirements != null) { - cc.setSessionData(CK.Q_FAIL_MESSAGE, q.failRequirements); - } - // - - //Rewards - if (q.moneyReward != 0) { - cc.setSessionData(CK.REW_MONEY, q.moneyReward); - } - - if (q.questPoints != 0) { - cc.setSessionData(CK.REW_QUEST_POINTS, q.questPoints); - } - - if (q.exp != 0) { - cc.setSessionData(CK.REW_EXP, q.exp); - } - - if (q.commands.isEmpty() == false) { - cc.setSessionData(CK.REW_COMMAND, q.commands); - } - - if (q.permissions.isEmpty() == false) { - cc.setSessionData(CK.REW_PERMISSION, q.permissions); - } - - if (q.mcmmoSkills.isEmpty() == false) { - cc.setSessionData(CK.REW_MCMMO_SKILLS, q.mcmmoSkills); - cc.setSessionData(CK.REW_MCMMO_AMOUNTS, q.mcmmoAmounts); - } - // - - //Stages - for (Stage stage : q.stages) { - final String pref = "stage" + (q.stages.indexOf(stage) + 1); - cc.setSessionData(pref, Boolean.TRUE); - - if (stage.blocksToBreak != null) { - - LinkedList ids = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.blocksToBreak.entrySet()) { - - ids.add(((Material) e.getKey()).getId()); - amnts.add((Integer) e.getValue()); - - } - - cc.setSessionData(pref + CK.S_BREAK_IDS, ids); - cc.setSessionData(pref + CK.S_BREAK_AMOUNTS, amnts); - - } - - - if (stage.blocksToDamage != null) { - - LinkedList ids = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.blocksToDamage.entrySet()) { - - ids.add(((Material) e.getKey()).getId()); - amnts.add((Integer) e.getValue()); - - } - - cc.setSessionData(pref + CK.S_DAMAGE_IDS, ids); - cc.setSessionData(pref + CK.S_DAMAGE_AMOUNTS, amnts); - - } - - - if (stage.blocksToPlace != null) { - - LinkedList ids = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.blocksToPlace.entrySet()) { - - ids.add(((Material) e.getKey()).getId()); - amnts.add((Integer) e.getValue()); - - } - - cc.setSessionData(pref + CK.S_PLACE_IDS, ids); - cc.setSessionData(pref + CK.S_PLACE_AMOUNTS, amnts); - - } - - if (stage.blocksToUse != null) { - - LinkedList ids = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.blocksToUse.entrySet()) { - - ids.add(((Material) e.getKey()).getId()); - amnts.add((Integer) e.getValue()); - - } - - cc.setSessionData(pref + CK.S_USE_IDS, ids); - cc.setSessionData(pref + CK.S_USE_AMOUNTS, amnts); - - } - - - if (stage.blocksToCut != null) { - - LinkedList ids = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.blocksToCut.entrySet()) { - - ids.add(((Material) e.getKey()).getId()); - amnts.add((Integer) e.getValue()); - - } - - cc.setSessionData(pref + CK.S_CUT_IDS, ids); - cc.setSessionData(pref + CK.S_CUT_AMOUNTS, amnts); - - } - - - if (stage.fishToCatch != null) { - cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch); - } - - - if (stage.playersToKill != null) { - cc.setSessionData(pref + CK.S_PLAYER_KILL, stage.playersToKill); - } - - - if (stage.itemsToEnchant.isEmpty() == false) { - - LinkedList enchants = new LinkedList(); - LinkedList ids = new LinkedList(); - LinkedList amounts = new LinkedList(); - - for (Entry, Integer> e : stage.itemsToEnchant.entrySet()) { - - amounts.add(e.getValue()); - for (Entry e2 : e.getKey().entrySet()) { - - ids.add(e2.getValue().getId()); - enchants.add(Quester.prettyEnchantmentString(e2.getKey())); - - } - - } - - cc.setSessionData(pref + CK.S_ENCHANT_TYPES, enchants); - cc.setSessionData(pref + CK.S_ENCHANT_IDS, ids); - cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts); - - } - - - if (stage.itemsToDeliver.isEmpty() == false) { - - LinkedList items = new LinkedList(); - LinkedList npcs = new LinkedList(); - - for (ItemStack is : stage.itemsToDeliver) { - items.add(is); - } - - for (NPC n : stage.itemDeliveryTargets) { - npcs.add(n.getId()); - } - - cc.setSessionData(pref + CK.S_DELIVERY_ITEMS, items); - cc.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); - cc.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.deliverMessages); - - } - - - if (stage.citizensToInteract.isEmpty() == false) { - - LinkedList npcs = new LinkedList(); - for (NPC n : stage.citizensToInteract) { - npcs.add(n.getId()); - } - - cc.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); - - } - - - if (stage.citizensToKill.isEmpty() == false) { - - LinkedList npcs = new LinkedList(); - for (NPC n : stage.citizensToKill) { - npcs.add(n.getId()); - } - - cc.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); - cc.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.citizenNumToKill); - - } - - - if (stage.bossesToKill.isEmpty() == false) { - - cc.setSessionData(pref + CK.S_BOSS_IDS, stage.bossesToKill); - cc.setSessionData(pref + CK.S_BOSS_AMOUNTS, stage.bossAmountsToKill); - - } - - - if (stage.mobsToKill.isEmpty() == false) { - - LinkedList mobs = new LinkedList(); - for (EntityType et : stage.mobsToKill) { - mobs.add(Quester.prettyMobString(et)); - } - - cc.setSessionData(pref + CK.S_MOB_TYPES, mobs); - cc.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.mobNumToKill); - - if (stage.locationsToKillWithin.isEmpty() == false) { - - LinkedList locs = new LinkedList(); - for (Location l : stage.locationsToKillWithin) { - locs.add(Quests.getLocationInfo(l)); - } - - cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locs); - cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.radiiToKillWithin); - cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.areaNames); - - } - - } - - - if (stage.locationsToReach.isEmpty() == false) { - - LinkedList locs = new LinkedList(); - for (Location l : stage.locationsToReach) { - locs.add(Quests.getLocationInfo(l)); - } - - cc.setSessionData(pref + CK.S_REACH_LOCATIONS, locs); - cc.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.radiiToReachWithin); - cc.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.locationNames); - - } - - - if (stage.mobsToTame.isEmpty() == false) { - - LinkedList mobs = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.mobsToTame.entrySet()) { - - mobs.add(Quester.prettyMobString(e.getKey())); - amnts.add(e.getValue()); - - } - - cc.setSessionData(pref + CK.S_TAME_TYPES, mobs); - cc.setSessionData(pref + CK.S_TAME_AMOUNTS, amnts); - - } - - - if (stage.sheepToShear.isEmpty() == false) { - - LinkedList colors = new LinkedList(); - LinkedList amnts = new LinkedList(); - - for (Entry e : stage.sheepToShear.entrySet()) { - colors.add(Quester.prettyColorString(e.getKey())); - amnts.add(e.getValue()); - } - - cc.setSessionData(pref + CK.S_SHEAR_COLORS, colors); - cc.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amnts); - - } - - - if (stage.event != null) { - cc.setSessionData(pref + CK.S_EVENT, stage.event.getName()); - } - - - if (stage.delay != -1) { - cc.setSessionData(pref + CK.S_DELAY, stage.delay); - if (stage.delayMessage != null) { - cc.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.delayMessage); - } - } - - if (stage.script != null) { - cc.setSessionData(pref + CK.S_DENIZEN, stage.script); - } - - if (stage.completeMessage != null) { - cc.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.completeMessage); - } - - if (stage.startMessage != null) { - cc.setSessionData(pref + CK.S_START_MESSAGE, stage.startMessage); - } - - } - // - - } - - private class SelectDeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = GOLD + "- " + "Delete Quest" + " -\n"; - - for (Quest quest : quests.quests) { - text += AQUA + quest.name + YELLOW + ","; - } - - text = text.substring(0, text.length() - 1) + "\n"; - text += YELLOW + "Enter a Quest name, or \"cancel\" to return."; - - return text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - - LinkedList used = new LinkedList(); - - for (Quest quest : quests.quests) { - - if (quest.name.equalsIgnoreCase(input) || quest.name.toLowerCase().contains(input.toLowerCase())) { - - for (Quest q : quests.quests) { - - if (q.neededQuests.contains(q.name) || q.blockQuests.contains(q.name)) { - used.add(q.name); - } - - } - - if (used.isEmpty()) { - context.setSessionData(CK.ED_QUEST_DELETE, quest.name); - return new DeletePrompt(); - } else { - ((Player) context.getForWhom()).sendMessage(RED + "The following Quests have \"" + PURPLE + context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\" as a requirement:"); - for (String s : used) { - ((Player) context.getForWhom()).sendMessage(RED + "- " + DARKRED + s); - } - ((Player) context.getForWhom()).sendMessage(RED + "You must modify these Quests so that they do not use it before deleting it."); - return new SelectDeletePrompt(); - } - } - - } - - ((Player) context.getForWhom()).sendMessage(RED + "Quest not found!"); - return new SelectDeletePrompt(); - - } else { - return new MenuPrompt(); - } - - } - } - - private class DeletePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String text = - RED + "Are you sure you want to delete the Quest " + " \"" + GOLD + (String) context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\"?\n"; - text += YELLOW + Lang.get("yes") + "/" + Lang.get("no"); - - return text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase(Lang.get("yes"))) { - deleteQuest(context); - return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase(Lang.get("no"))) { - return new MenuPrompt(); - } else { - return new DeletePrompt(); - } - - } - } - - private void deleteQuest(ConversationContext context) { - - YamlConfiguration data = new YamlConfiguration(); - - try { - data.load(questsFile); - } catch (Exception e) { - e.printStackTrace(); - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "Error reading Quests file."); - return; - } - - String quest = (String) context.getSessionData(CK.ED_QUEST_DELETE); - ConfigurationSection sec = data.getConfigurationSection("quests"); - for (String key : sec.getKeys(false)) { - - if (sec.getString(key + ".name").equalsIgnoreCase(quest)) { - sec.set(key, null); - break; - } - - } - - - try { - data.save(questsFile); - } catch (Exception e) { - ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "An error occurred while saving."); - return; - } - - quests.reloadQuests(); - - context.getForWhom().sendRawMessage(WHITE + "" + BOLD + "Quest deleted! Quests and Events have been reloaded."); - - - } -} +package me.blackvein.quests; + +import java.io.File; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import me.blackvein.quests.prompts.RequirementsPrompt; +import me.blackvein.quests.prompts.RewardsPrompt; +import me.blackvein.quests.prompts.StagesPrompt; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.npc.NPC; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.*; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class QuestFactory implements ConversationAbandonedListener, ColorUtil { + + public Quests quests; + Map editSessions = new HashMap(); + Map selectedBlockStarts = new HashMap(); + public Map selectedKillLocations = new HashMap(); + public Map selectedReachLocations = new HashMap(); + public List names = new LinkedList(); + ConversationFactory convoCreator; + File questsFile; + + @SuppressWarnings("LeakingThisInConstructor") + public QuestFactory(Quests plugin) { + + quests = plugin; + questsFile = new File(plugin.getDataFolder(), "quests.yml"); + + //Ensure to initialize convoCreator last, to ensure that 'this' is fully initialized before it is passed + this.convoCreator = new ConversationFactory(plugin) + .withModality(false) + .withLocalEcho(false) + .withFirstPrompt(new MenuPrompt()) + .withTimeout(3600) + .thatExcludesNonPlayersWithMessage("Console may not perform this operation!") + .addConversationAbandonedListener(this); + + } + + @Override + public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { + + if (abandonedEvent.getContext().getSessionData(CK.Q_NAME) != null) { + names.remove((String) abandonedEvent.getContext().getSessionData(CK.Q_NAME)); + } + + Player player = (Player) abandonedEvent.getContext().getForWhom(); + selectedBlockStarts.remove(player); + selectedKillLocations.remove(player); + selectedReachLocations.remove(player); + + } + + private class MenuPrompt extends FixedSetPrompt { + + public MenuPrompt() { + + super("1", "2", "3", "4"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = + GOLD + "- Quest Editor -\n" + + BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Create a Quest\n" + + BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Edit a Quest\n" + + BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Delete a Quest\n" + + GOLD + "" + BOLD + "4" + RESET + YELLOW + " - Exit"; + + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + final Player player = (Player) context.getForWhom(); + + if (input.equalsIgnoreCase("1")) { + + if (player.hasPermission("quests.editor.create")) { + return new QuestNamePrompt(); + } else { + player.sendMessage(RED + "You do not have permission to create Quests."); + return new MenuPrompt(); + } + + } else if (input.equalsIgnoreCase("2")) { + + if (player.hasPermission("quests.editor.edit")) { + return new SelectEditPrompt(); + } else { + player.sendMessage(RED + "You do not have permission to edit Quests."); + return new MenuPrompt(); + } + + } else if (input.equalsIgnoreCase("3")) { + + if (player.hasPermission("quests.editor.delete")) { + return new SelectDeletePrompt(); + } else { + player.sendMessage(RED + "You do not have permission to delete Quests."); + return new MenuPrompt(); + } + + } else if (input.equalsIgnoreCase("4")) { + context.getForWhom().sendRawMessage(YELLOW + "Exited."); + return Prompt.END_OF_CONVERSATION; + } + + return null; + + } + } + + public Prompt returnToMenu() { + + return new CreateMenuPrompt(); + + } + + private class CreateMenuPrompt extends FixedSetPrompt { + + public CreateMenuPrompt() { + + super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = + GOLD + "- Quest: " + AQUA + context.getSessionData(CK.Q_NAME) + GOLD + " -\n"; + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set name\n"; + + if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { + text += BLUE + "" + BOLD + "2" + RESET + RED + " - Set ask message " + DARKRED + "(Required, none set)\n"; + } else { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set ask message (\"" + context.getSessionData(CK.Q_ASK_MESSAGE) + "\")\n"; + } + + + if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { + text += BLUE + "" + BOLD + "3" + RESET + RED + " - Set finish message " + DARKRED + "(Required, none set)\n"; + } else { + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set finish message (\"" + context.getSessionData(CK.Q_FINISH_MESSAGE) + "\")\n"; + } + + + if (context.getSessionData(CK.Q_REDO_DELAY) == null) { + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (None set)\n"; + } else { + + //something here is throwing an exception + try{ + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set redo delay (" + Quests.getTime((Long) context.getSessionData(CK.Q_REDO_DELAY)) + ")\n"; + }catch(Exception e){ + e.printStackTrace(); + } + + // + } + + if (context.getSessionData(CK.Q_START_NPC) == null && quests.citizens != null) { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (None set)\n"; + } else if (quests.citizens != null) { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set NPC start (" + CitizensAPI.getNPCRegistry().getById((Integer) context.getSessionData(CK.Q_START_NPC)).getName() + ")\n"; + } + + if (context.getSessionData(CK.Q_START_BLOCK) == null) { + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (None set)\n"; + } else { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (None set)\n"; + } + + } else { + + if (quests.citizens != null) { + Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")\n"; + } else { + Location l = (Location) context.getSessionData(CK.Q_START_BLOCK); + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Block start (" + l.getWorld().getName() + ", " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + ")\n"; + } + + } + + + if (context.getSessionData(CK.Q_INITIAL_EVENT) == null) { + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set initial Event (None set)\n"; + } else { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set initial Event (None set)\n"; + } + + } else { + + if (quests.citizens != null) { + String s = (String) context.getSessionData(CK.Q_INITIAL_EVENT); + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set initial Event (" + s + ")\n"; + } else { + String s = (String) context.getSessionData(CK.Q_INITIAL_EVENT); + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set initial Event (" + s + ")\n"; + } + + } + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "8" + RESET + DARKAQUA + " - Edit Requirements\n"; + } else { + text += BLUE + "" + BOLD + "7" + RESET + DARKAQUA + " - Edit Requirements\n"; + } + + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "9" + RESET + PINK + " - Edit Stages\n"; + } else { + text += BLUE + "" + BOLD + "8" + RESET + PINK + " - Edit Stages\n"; + } + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "10" + RESET + GREEN + " - Edit Rewards\n"; + } else { + text += BLUE + "" + BOLD + "9" + RESET + GREEN + " - Edit Rewards\n"; + } + + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "11" + RESET + GOLD + " - Save\n"; + } else { + text += BLUE + "" + BOLD + "10" + RESET + GOLD + " - Save\n"; + } + + if (quests.citizens != null) { + text += BLUE + "" + BOLD + "12" + RESET + RED + " - Exit\n"; + } else { + text += BLUE + "" + BOLD + "11" + RESET + RED + " - Exit\n"; + } + + + return text; + + } + + @Override + public Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + + return new SetNamePrompt(); + + } else if (input.equalsIgnoreCase("2")) { + + return new AskMessagePrompt(); + + } else if (input.equalsIgnoreCase("3")) { + + return new FinishMessagePrompt(); + + } else if (input.equalsIgnoreCase("4")) { + + return new RedoDelayPrompt(); + + } else if (input.equalsIgnoreCase("5")) { + + if (quests.citizens != null) { + return new SetNpcStartPrompt(); + } else { + selectedBlockStarts.put((Player) context.getForWhom(), null); + return new BlockStartPrompt(); + } + + } else if (input.equalsIgnoreCase("6")) { + + if (quests.citizens != null) { + selectedBlockStarts.put((Player) context.getForWhom(), null); + return new BlockStartPrompt(); + } else { + return new RequirementsPrompt(quests, QuestFactory.this); + } + + } else if (input.equalsIgnoreCase("6")) { + + if (quests.citizens != null) { + selectedBlockStarts.put((Player) context.getForWhom(), null); + return new BlockStartPrompt(); + } else { + return new InitialEventPrompt(); + } + + } else if (input.equalsIgnoreCase("7")) { + + if (quests.citizens != null) { + return new InitialEventPrompt(); + } else { + return new RequirementsPrompt(quests, QuestFactory.this); + } + + } else if (input.equalsIgnoreCase("8")) { + + if (quests.citizens != null) { + return new RequirementsPrompt(quests, QuestFactory.this); + } else { + return new StagesPrompt(QuestFactory.this); + } + + } else if (input.equalsIgnoreCase("9")) { + + if (quests.citizens != null) { + return new StagesPrompt(QuestFactory.this); + } else { + return new RewardsPrompt(quests, QuestFactory.this); + } + + } else if (input.equalsIgnoreCase("10")) { + + if (quests.citizens != null) { + return new RewardsPrompt(quests, QuestFactory.this); + } else { + return new SavePrompt(); + } + + } else if (input.equalsIgnoreCase("11")) { + + if (quests.citizens != null) { + return new SavePrompt(); + } else { + return new ExitPrompt(); + } + + } else if (input.equalsIgnoreCase("12")) { + + if (quests.citizens != null) { + return new ExitPrompt(); + } else { + return new CreateMenuPrompt(); + } + + } + + return null; + + } + } + + private class SelectEditPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String s = GOLD + "- Edit Quest -\n"; + for (Quest q : quests.getQuests()) { + s += GRAY + "- " + YELLOW + q.getName() + "\n"; + } + + return s + GOLD + "Enter a Quest to edit, or \"cancel\" to return."; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + for (Quest q : quests.getQuests()) { + + if (q.getName().equalsIgnoreCase(input) || q.getName().toLowerCase().contains(input.toLowerCase())) { + loadQuest(context, q); + return new CreateMenuPrompt(); + } + + } + + return new SelectEditPrompt(); + + } else { + return new MenuPrompt(); + } + + } + } + + private class QuestNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = GOLD + "- Create Quest -\n"; + text += AQUA + "Create new Quest " + GOLD + "- Enter a name for the Quest (Or enter \'cancel\' to return)"; + + return text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + for (Quest q : quests.quests) { + + if (q.name.equalsIgnoreCase(input)) { + + context.getForWhom().sendRawMessage(ChatColor.RED + "Quest already exists!"); + return new QuestNamePrompt(); + + } + + } + + if (names.contains(input)) { + + context.getForWhom().sendRawMessage(ChatColor.RED + "Someone is creating a Quest with that name!"); + return new QuestNamePrompt(); + + } + + if (input.contains(",")) { + + context.getForWhom().sendRawMessage(ChatColor.RED + "Name may not contain commas!"); + return new QuestNamePrompt(); + + } + + context.setSessionData(CK.Q_NAME, input); + names.add(input); + return new CreateMenuPrompt(); + + } else { + + return new MenuPrompt(); + + } + + } + } + + private class SetNpcStartPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Enter NPC ID, or -1 to clear the NPC start, or -2 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() > -1) { + + if (CitizensAPI.getNPCRegistry().getById(input.intValue()) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + "No NPC exists with that id!"); + return new SetNpcStartPrompt(); + } + + context.setSessionData(CK.Q_START_NPC, input.intValue()); + return new CreateMenuPrompt(); + + } else if (input.intValue() == -1) { + context.setSessionData(CK.Q_START_NPC, null); + return new CreateMenuPrompt(); + } else if (input.intValue() == -2) { + return new CreateMenuPrompt(); + } else { + context.getForWhom().sendRawMessage(ChatColor.RED + "No NPC exists with that id!"); + return new SetNpcStartPrompt(); + } + + } + } + + private class BlockStartPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Right-click on a block to use as a start point, then enter \"done\" to save,\n" + + "or enter \"clear\" to clear the block start, or \"cancel\" to return"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + Player player = (Player) context.getForWhom(); + if (input.equalsIgnoreCase("done") || input.equalsIgnoreCase("cancel")) { + + if (input.equalsIgnoreCase("done")) { + + Block block = selectedBlockStarts.get(player); + if (block != null) { + Location loc = block.getLocation(); + context.setSessionData(CK.Q_START_BLOCK, loc); + selectedBlockStarts.remove(player); + } else { + player.sendMessage(ChatColor.RED + "You must select a block first."); + return new BlockStartPrompt(); + } + + } else { + selectedBlockStarts.remove(player); + } + + + return new CreateMenuPrompt(); + + } else if (input.equalsIgnoreCase("clear")) { + + selectedBlockStarts.remove(player); + context.setSessionData(CK.Q_START_BLOCK, null); + return new CreateMenuPrompt(); + + } + + return new BlockStartPrompt(); + + } + } + + private class SetNamePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Enter Quest name (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + for (Quest q : quests.quests) { + + if (q.name.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(RED + "A Quest with that name already exists!"); + return new SetNamePrompt(); + } + } + + } + + if (names.contains(input)) { + context.getForWhom().sendRawMessage(RED + "Someone is creating/editing a Quest with that name!"); + return new SetNamePrompt(); + } + + if (input.contains(",")) { + + context.getForWhom().sendRawMessage(ChatColor.RED + "Name may not contain commas!"); + return new QuestNamePrompt(); + + } + + names.remove((String) context.getSessionData(CK.Q_NAME)); + context.setSessionData(CK.Q_NAME, input); + names.add(input); + + } + + return new CreateMenuPrompt(); + + } + } + + private class AskMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Enter ask message (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + context.setSessionData(CK.Q_ASK_MESSAGE, input); + } + + return new CreateMenuPrompt(); + + } + } + + private class FinishMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Enter finish message (or \'cancel\' to return)"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + context.setSessionData(CK.Q_FINISH_MESSAGE, input); + } + + return new CreateMenuPrompt(); + + } + } + + private class InitialEventPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = DARKGREEN + "- Events -\n"; + if (quests.events.isEmpty()) { + text += RED + "- None"; + } else { + for (Event e : quests.events) { + text += GREEN + "- " + e.getName() + "\n"; + } + } + + return text + YELLOW + "Enter an Event name, or enter \"clear\" to clear the initial Event, or \"cancel\" to return"; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + Player player = (Player) context.getForWhom(); + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + Event found = null; + + for (Event e : quests.events) { + + if (e.getName().equalsIgnoreCase(input)) { + found = e; + break; + } + + } + + if (found == null) { + player.sendMessage(RED + input + YELLOW + " is not a valid event name!"); + return new InitialEventPrompt(); + } else { + context.setSessionData(CK.Q_INITIAL_EVENT, found.getName()); + return new CreateMenuPrompt(); + } + + } else if (input.equalsIgnoreCase("clear")) { + context.setSessionData(CK.Q_INITIAL_EVENT, null); + player.sendMessage(YELLOW + "Initial Event cleared."); + return new CreateMenuPrompt(); + } else { + return new CreateMenuPrompt(); + } + + } + } + + private class RedoDelayPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return ChatColor.YELLOW + "Enter amount of time (in milliseconds), or 0 to clear the redo delay, or -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.longValue() < -1) { + context.getForWhom().sendRawMessage(ChatColor.RED + "Amount must be a positive number."); + } else if (input.longValue() == 0) { + context.setSessionData(CK.Q_REDO_DELAY, null); + } else if (input.longValue() != -1) { + context.setSessionData(CK.Q_REDO_DELAY, input.longValue()); + } + + return new CreateMenuPrompt(); + + } + } + + private class SavePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = GREEN + + "1 - Yes\n" + + "2 - No"; + return ChatColor.YELLOW + "Finish and save \"" + AQUA + context.getSessionData(CK.Q_NAME) + YELLOW + "\"?\n" + text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("Yes")) { + + if (context.getSessionData(CK.Q_ASK_MESSAGE) == null) { + context.getForWhom().sendRawMessage(RED + "You must set an ask message!"); + return new CreateMenuPrompt(); + } else if (context.getSessionData(CK.Q_FINISH_MESSAGE) == null) { + context.getForWhom().sendRawMessage(RED + "You must set a finish message!"); + return new CreateMenuPrompt(); + } else if (StagesPrompt.getStages(context) == 0) { + context.getForWhom().sendRawMessage(RED + "Your Quest has no Stages!"); + return new CreateMenuPrompt(); + } + + FileConfiguration data = new YamlConfiguration(); + try { + data.load(new File(quests.getDataFolder(), "quests.yml")); + ConfigurationSection questSection = data.getConfigurationSection("quests"); + + int customNum = 1; + while (true) { + + if (questSection.contains("custom" + customNum)) { + customNum++; + } else { + break; + } + + } + + ConfigurationSection newSection = questSection.createSection("custom" + customNum); + saveQuest(context, newSection); + data.save(new File(quests.getDataFolder(), "quests.yml")); + context.getForWhom().sendRawMessage(BOLD + "Quest saved! (You will need to perform a Quest reload for it to appear)"); + + } catch (Exception e) { + e.printStackTrace(); + } + + return Prompt.END_OF_CONVERSATION; + + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("No")) { + return new CreateMenuPrompt(); + } else { + return new SavePrompt(); + } + + } + } + + private class ExitPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = GREEN + + "1 - Yes\n" + + "2 - No"; + return ChatColor.YELLOW + "Are you sure you want to exit without saving?\n" + text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("Yes")) { + + context.getForWhom().sendRawMessage(BOLD + "" + YELLOW + "Exited."); + return Prompt.END_OF_CONVERSATION; + + } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("No")) { + return new CreateMenuPrompt(); + } else { + return new ExitPrompt(); + } + + } + } + + @SuppressWarnings("unchecked") + public static void saveQuest(ConversationContext cc, ConfigurationSection cs) { + + String edit = null; + if (cc.getSessionData(CK.ED_QUEST_EDIT) != null) { + edit = (String) cc.getSessionData(CK.ED_QUEST_EDIT); + } + + if (edit != null) { + + ConfigurationSection questList = cs.getParent(); + + for (String key : questList.getKeys(false)) { + + String name = questList.getString(key + ".name"); + if (name.equalsIgnoreCase(edit)) { + + questList.set(key, null); + break; + + } + + } + + } + + String name = (String) cc.getSessionData(CK.Q_NAME); + String desc = (String) cc.getSessionData(CK.Q_ASK_MESSAGE); + String finish = (String) cc.getSessionData(CK.Q_FINISH_MESSAGE); + Long redo = null; + Integer npcStart = null; + String blockStart = null; + String initialEvent = null; + + Integer moneyReq = null; + Integer questPointsReq = null; + LinkedList itemReqs = null; + LinkedList removeItemReqs = null; + LinkedList permReqs = null; + LinkedList questReqs = null; + LinkedList questBlocks = null; + String failMessage = null; + + Integer moneyRew = null; + Integer questPointsRew = null; + LinkedList itemRews = new LinkedList(); + Integer expRew = null; + LinkedList commandRews = null; + LinkedList permRews = null; + LinkedList mcMMOSkillRews = null; + LinkedList mcMMOSkillAmounts = null; + + + + if (cc.getSessionData(CK.Q_REDO_DELAY) != null) { + redo = (Long) cc.getSessionData(CK.Q_REDO_DELAY); + } + + if (cc.getSessionData(CK.Q_START_NPC) != null) { + npcStart = (Integer) cc.getSessionData(CK.Q_START_NPC); + } + + if (cc.getSessionData(CK.Q_START_BLOCK) != null) { + blockStart = Quests.getLocationInfo((Location) cc.getSessionData(CK.Q_START_BLOCK)); + } + + + + if (cc.getSessionData(CK.REQ_MONEY) != null) { + moneyReq = (Integer) cc.getSessionData(CK.REQ_MONEY); + } + + if (cc.getSessionData(CK.REQ_QUEST_POINTS) != null) { + questPointsReq = (Integer) cc.getSessionData(CK.REQ_QUEST_POINTS); + } + + if (cc.getSessionData(CK.REQ_ITEMS) != null) { + itemReqs = (LinkedList) cc.getSessionData(CK.REQ_ITEMS); + removeItemReqs = (LinkedList) cc.getSessionData(CK.REQ_ITEMS_REMOVE); + } + + if (cc.getSessionData(CK.REQ_PERMISSION) != null) { + permReqs = (LinkedList) cc.getSessionData(CK.REQ_PERMISSION); + } + + if (cc.getSessionData(CK.REQ_QUEST) != null) { + questReqs = (LinkedList) cc.getSessionData(CK.REQ_QUEST); + } + + if (cc.getSessionData(CK.REQ_QUEST_BLOCK) != null) { + questBlocks = (LinkedList) cc.getSessionData(CK.REQ_QUEST_BLOCK); + } + + if (cc.getSessionData(CK.Q_FAIL_MESSAGE) != null) { + failMessage = (String) cc.getSessionData(CK.Q_FAIL_MESSAGE); + } + + if (cc.getSessionData(CK.Q_INITIAL_EVENT) != null) { + initialEvent = (String) cc.getSessionData(CK.Q_INITIAL_EVENT); + } + + if (cc.getSessionData(CK.REW_MONEY) != null) { + moneyRew = (Integer) cc.getSessionData(CK.REW_MONEY); + } + + if (cc.getSessionData(CK.REW_QUEST_POINTS) != null) { + questPointsRew = (Integer) cc.getSessionData(CK.REW_QUEST_POINTS); + } + + if (cc.getSessionData(CK.REW_ITEMS) != null) { + for (ItemStack is : (LinkedList) cc.getSessionData(CK.REW_ITEMS)) { + itemRews.add(ItemUtil.serialize(is)); + } + } + + if (cc.getSessionData(CK.REW_EXP) != null) { + expRew = (Integer) cc.getSessionData(CK.REW_EXP); + } + + if (cc.getSessionData(CK.REW_COMMAND) != null) { + commandRews = (LinkedList) cc.getSessionData(CK.REW_COMMAND); + } + + if (cc.getSessionData(CK.REW_PERMISSION) != null) { + permRews = (LinkedList) cc.getSessionData(CK.REW_PERMISSION); + } + + if (cc.getSessionData(CK.REW_MCMMO_SKILLS) != null) { + mcMMOSkillRews = (LinkedList) cc.getSessionData(CK.REW_MCMMO_SKILLS); + mcMMOSkillAmounts = (LinkedList) cc.getSessionData(CK.REW_MCMMO_AMOUNTS); + } + + + + cs.set("name", name); + cs.set("npc-giver-id", npcStart); + cs.set("block-start", blockStart); + cs.set("redo-delay", redo); + cs.set("ask-message", desc); + cs.set("finish-message", finish); + cs.set(CK.S_EVENT, initialEvent); + + + if (moneyReq != null || questPointsReq != null || itemReqs != null && itemReqs.isEmpty() == false || permReqs != null && permReqs.isEmpty() == false || (questReqs != null && questReqs.isEmpty() == false) || (questBlocks != null && questBlocks.isEmpty() == false)) { + + ConfigurationSection reqs = cs.createSection("requirements"); + List items = new LinkedList(); + if(itemReqs != null){ + + for (ItemStack is : itemReqs) { + items.add(ItemUtil.serialize(is)); + } + + } + + reqs.set("items", (items.isEmpty() == false) ? items : null); + reqs.set("remove-items", removeItemReqs); + reqs.set("money", moneyReq); + reqs.set("quest-points", questPointsReq); + reqs.set("permissions", permReqs); + reqs.set("quests", questReqs); + reqs.set("quests-blocks", questBlocks); + reqs.set("fail-requirement-message", failMessage); + + } else { + cs.set("requirements", null); + } + + + ConfigurationSection stages = cs.createSection("stages"); + ConfigurationSection ordered = stages.createSection("ordered"); + + String pref; + + LinkedList breakIds; + LinkedList breakAmounts; + + LinkedList damageIds; + LinkedList damageAmounts; + + LinkedList placeIds; + LinkedList placeAmounts; + + LinkedList useIds; + LinkedList useAmounts; + + LinkedList cutIds; + LinkedList cutAmounts; + + Integer fish; + Integer players; + + LinkedList enchantments; + LinkedList enchantmentIds; + LinkedList enchantmentAmounts; + + LinkedList deliveryItems; + LinkedList deliveryNPCIds; + LinkedList deliveryMessages; + + LinkedList npcTalkIds; + + LinkedList npcKillIds; + LinkedList npcKillAmounts; + + LinkedList bossIds; + LinkedList bossAmounts; + + LinkedList mobs; + LinkedList mobAmounts; + LinkedList mobLocs; + LinkedList mobRadii; + LinkedList mobLocNames; + + LinkedList reachLocs; + LinkedList reachRadii; + LinkedList reachNames; + + LinkedList tames; + LinkedList tameAmounts; + + LinkedList shearColors; + LinkedList shearAmounts; + + String script; + String event; + Long delay; + String delayMessage; + String startMessage; + String completeMessage; + + for (int i = 1; i <= StagesPrompt.getStages(cc); i++) { + + pref = "stage" + i; + ConfigurationSection stage = ordered.createSection("" + i); + + breakIds = null; + breakAmounts = null; + + damageIds = null; + damageAmounts = null; + + placeIds = null; + placeAmounts = null; + + useIds = null; + useAmounts = null; + + cutIds = null; + cutAmounts = null; + + fish = null; + players = null; + + enchantments = null; + enchantmentIds = null; + enchantmentAmounts = null; + + deliveryItems = null; + deliveryNPCIds = null; + deliveryMessages = null; + + npcTalkIds = null; + + npcKillIds = null; + npcKillAmounts = null; + + bossIds = null; + bossAmounts = null; + + mobs = null; + mobAmounts = null; + mobLocs = null; + mobRadii = null; + mobLocNames = null; + + reachLocs = null; + reachRadii = null; + reachNames = null; + + tames = null; + tameAmounts = null; + + shearColors = null; + shearAmounts = null; + + script = null; + event = null; + delay = null; + delayMessage = null; + startMessage = null; + completeMessage = null; + + + if (cc.getSessionData(pref + CK.S_BREAK_IDS) != null) { + breakIds = (LinkedList) cc.getSessionData(pref + CK.S_BREAK_IDS); + breakAmounts = (LinkedList) cc.getSessionData(pref + CK.S_BREAK_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_DAMAGE_IDS) != null) { + damageIds = (LinkedList) cc.getSessionData(pref + CK.S_DAMAGE_IDS); + damageAmounts = (LinkedList) cc.getSessionData(pref + CK.S_DAMAGE_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_PLACE_IDS) != null) { + placeIds = (LinkedList) cc.getSessionData(pref + CK.S_PLACE_IDS); + placeAmounts = (LinkedList) cc.getSessionData(pref + CK.S_PLACE_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_USE_IDS) != null) { + useIds = (LinkedList) cc.getSessionData(pref + CK.S_USE_IDS); + useAmounts = (LinkedList) cc.getSessionData(pref + CK.S_USE_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_CUT_IDS) != null) { + cutIds = (LinkedList) cc.getSessionData(pref + CK.S_CUT_IDS); + cutAmounts = (LinkedList) cc.getSessionData(pref + CK.S_CUT_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_FISH) != null) { + fish = (Integer) cc.getSessionData(pref + CK.S_FISH); + } + + if (cc.getSessionData(pref + CK.S_PLAYER_KILL) != null) { + players = (Integer) cc.getSessionData(pref + CK.S_PLAYER_KILL); + } + + if (cc.getSessionData(pref + CK.S_ENCHANT_TYPES) != null) { + enchantments = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_TYPES); + enchantmentIds = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_IDS); + enchantmentAmounts = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) { + deliveryItems = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_ITEMS); + deliveryNPCIds = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_NPCS); + deliveryMessages = (LinkedList) cc.getSessionData(pref + CK.S_DELIVERY_MESSAGES); + } + + if (cc.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null) { + npcTalkIds = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_TALK_TO); + } + + if (cc.getSessionData(pref + CK.S_NPCS_TO_KILL) != null) { + npcKillIds = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_KILL); + npcKillAmounts = (LinkedList) cc.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_BOSS_IDS) != null) { + bossIds = (LinkedList) cc.getSessionData(pref + CK.S_BOSS_IDS); + bossAmounts = (LinkedList) cc.getSessionData(pref + CK.S_BOSS_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_MOB_TYPES) != null) { + mobs = (LinkedList) cc.getSessionData(pref + CK.S_MOB_TYPES); + mobAmounts = (LinkedList) cc.getSessionData(pref + CK.S_MOB_AMOUNTS); + if (cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) != null) { + mobLocs = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS); + mobRadii = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS); + mobLocNames = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES); + } + } + + if (cc.getSessionData(pref + CK.S_REACH_LOCATIONS) != null) { + reachLocs = (LinkedList) cc.getSessionData(pref + CK.S_REACH_LOCATIONS); + reachRadii = (LinkedList) cc.getSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS); + reachNames = (LinkedList) cc.getSessionData(pref + CK.S_REACH_LOCATIONS_NAMES); + } + + if (cc.getSessionData(pref + CK.S_TAME_TYPES) != null) { + tames = (LinkedList) cc.getSessionData(pref + CK.S_TAME_TYPES); + tameAmounts = (LinkedList) cc.getSessionData(pref + CK.S_TAME_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_SHEAR_COLORS) != null) { + shearColors = (LinkedList) cc.getSessionData(pref + CK.S_SHEAR_COLORS); + shearAmounts = (LinkedList) cc.getSessionData(pref + CK.S_SHEAR_AMOUNTS); + } + + if (cc.getSessionData(pref + CK.S_EVENT) != null) { + event = (String) cc.getSessionData(pref + CK.S_EVENT); + } + + if (cc.getSessionData(pref + CK.S_DELAY) != null) { + delay = (Long) cc.getSessionData(pref + CK.S_DELAY); + delayMessage = (String) cc.getSessionData(pref + CK.S_DELAY_MESSAGE); + } + + if (cc.getSessionData(pref + CK.S_DENIZEN) != null) { + script = (String) cc.getSessionData(pref + CK.S_DENIZEN); + } + + if (cc.getSessionData(pref + CK.S_START_MESSAGE) != null) { + startMessage = (String) cc.getSessionData(pref + CK.S_START_MESSAGE); + } + + if (cc.getSessionData(pref + CK.S_COMPLETE_MESSAGE) != null) { + completeMessage = (String) cc.getSessionData(pref + CK.S_COMPLETE_MESSAGE); + } + + if (breakIds != null && breakIds.isEmpty() == false) { + stage.set("break-block-ids", breakIds); + stage.set("break-block-amounts", breakAmounts); + } + + if (damageIds != null && damageIds.isEmpty() == false) { + stage.set("damage-block-ids", damageIds); + stage.set("damage-block-amounts", damageAmounts); + } + + if (placeIds != null && placeIds.isEmpty() == false) { + stage.set("place-block-ids", placeIds); + stage.set("place-block-amounts", placeAmounts); + } + + if (useIds != null && useIds.isEmpty() == false) { + stage.set("use-block-ids", useIds); + stage.set("use-block-amounts", useAmounts); + } + + if (cutIds != null && cutIds.isEmpty() == false) { + stage.set("cut-block-ids", cutIds); + stage.set("cut-block-amounts", cutAmounts); + } + + stage.set("fish-to-catch", fish); + stage.set("players-to-kill", players); + stage.set("enchantments", enchantments); + stage.set("enchantment-item-ids", enchantmentIds); + stage.set("enchantment-amounts", enchantmentAmounts); + if(deliveryItems != null && deliveryItems.isEmpty() == false){ + LinkedList items = new LinkedList(); + for(ItemStack is : deliveryItems) + items.add(ItemUtil.serialize(is)); + stage.set("items-to-deliver", items); + }else{ + stage.set("items-to-deliver", null); + } + stage.set("npc-delivery-ids", deliveryNPCIds); + stage.set("delivery-messages", deliveryMessages); + stage.set("npc-ids-to-talk-to", npcTalkIds); + stage.set("npc-ids-to-kill", npcKillIds); + stage.set("npc-kill-amounts", npcKillAmounts); + stage.set("boss-ids-to-kill", bossIds); + stage.set("boss-amounts-to-kill", bossAmounts); + stage.set("mobs-to-kill", mobs); + stage.set("mob-amounts", mobAmounts); + stage.set("locations-to-kill", mobLocs); + stage.set("kill-location-radii", mobRadii); + stage.set("kill-location-names", mobLocNames); + stage.set("locations-to-reach", reachLocs); + stage.set("reach-location-radii", reachRadii); + stage.set("reach-location-names", reachNames); + stage.set("mobs-to-tame", tames); + stage.set("mob-tame-amounts", tameAmounts); + stage.set("sheep-to-shear", shearColors); + stage.set("sheep-amounts", shearAmounts); + stage.set("script-to-run", script); + stage.set("event", event); + stage.set("delay", delay); + stage.set("delay-message", delayMessage); + stage.set("start-message", startMessage); + stage.set("complete-message", completeMessage); + + } + + + if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null) { + + ConfigurationSection rews = cs.createSection("rewards"); + + rews.set("items", (itemRews.isEmpty() == false) ? itemRews : null); + rews.set("money", moneyRew); + rews.set("quest-points", questPointsRew); + rews.set("exp", expRew); + rews.set("permissions", permRews); + rews.set("commands", commandRews); + rews.set("mcmmo-skills", mcMMOSkillRews); + rews.set("mcmmo-levels", mcMMOSkillAmounts); + + } else { + cs.set("rewards", null); + } + + } + + public static void loadQuest(ConversationContext cc, Quest q) { + + cc.setSessionData(CK.ED_QUEST_EDIT, q.name); + cc.setSessionData(CK.Q_NAME, q.name); + if (q.npcStart != null) { + cc.setSessionData(CK.Q_START_NPC, q.npcStart.getId()); + } + cc.setSessionData(CK.Q_START_BLOCK, q.blockStart); + if (q.redoDelay != -1) { + cc.setSessionData(CK.Q_REDO_DELAY, q.redoDelay); + } + cc.setSessionData(CK.Q_ASK_MESSAGE, q.description); + cc.setSessionData(CK.Q_FINISH_MESSAGE, q.finished); + if (q.initialEvent != null) { + cc.setSessionData(CK.Q_INITIAL_EVENT, q.initialEvent.getName()); + } + + //Requirements + if (q.moneyReq != 0) { + cc.setSessionData(CK.REQ_MONEY, q.moneyReq); + } + if (q.questPointsReq != 0) { + cc.setSessionData(CK.REQ_QUEST_POINTS, q.questPointsReq); + } + + if (q.items.isEmpty() == false) { + + cc.setSessionData(CK.REQ_ITEMS, q.items); + cc.setSessionData(CK.REQ_ITEMS_REMOVE, q.removeItems); + + } + + if (q.neededQuests.isEmpty() == false) { + cc.setSessionData(CK.REQ_QUEST, q.neededQuests); + } + + if (q.blockQuests.isEmpty() == false) { + cc.setSessionData(CK.REQ_QUEST_BLOCK, q.blockQuests); + } + + if (q.permissionReqs.isEmpty() == false) { + cc.setSessionData(CK.REQ_PERMISSION, q.permissionReqs); + } + + if (q.failRequirements != null) { + cc.setSessionData(CK.Q_FAIL_MESSAGE, q.failRequirements); + } + // + + //Rewards + if (q.moneyReward != 0) { + cc.setSessionData(CK.REW_MONEY, q.moneyReward); + } + + if (q.questPoints != 0) { + cc.setSessionData(CK.REW_QUEST_POINTS, q.questPoints); + } + + if (q.exp != 0) { + cc.setSessionData(CK.REW_EXP, q.exp); + } + + if (q.commands.isEmpty() == false) { + cc.setSessionData(CK.REW_COMMAND, q.commands); + } + + if (q.permissions.isEmpty() == false) { + cc.setSessionData(CK.REW_PERMISSION, q.permissions); + } + + if (q.mcmmoSkills.isEmpty() == false) { + cc.setSessionData(CK.REW_MCMMO_SKILLS, q.mcmmoSkills); + cc.setSessionData(CK.REW_MCMMO_AMOUNTS, q.mcmmoAmounts); + } + // + + //Stages + for (Stage stage : q.stages) { + final String pref = "stage" + (q.stages.indexOf(stage) + 1); + cc.setSessionData(pref, Boolean.TRUE); + + if (stage.blocksToBreak != null) { + + LinkedList ids = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.blocksToBreak.entrySet()) { + + ids.add(((Material) e.getKey()).getId()); + amnts.add((Integer) e.getValue()); + + } + + cc.setSessionData(pref + CK.S_BREAK_IDS, ids); + cc.setSessionData(pref + CK.S_BREAK_AMOUNTS, amnts); + + } + + + if (stage.blocksToDamage != null) { + + LinkedList ids = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.blocksToDamage.entrySet()) { + + ids.add(((Material) e.getKey()).getId()); + amnts.add((Integer) e.getValue()); + + } + + cc.setSessionData(pref + CK.S_DAMAGE_IDS, ids); + cc.setSessionData(pref + CK.S_DAMAGE_AMOUNTS, amnts); + + } + + + if (stage.blocksToPlace != null) { + + LinkedList ids = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.blocksToPlace.entrySet()) { + + ids.add(((Material) e.getKey()).getId()); + amnts.add((Integer) e.getValue()); + + } + + cc.setSessionData(pref + CK.S_PLACE_IDS, ids); + cc.setSessionData(pref + CK.S_PLACE_AMOUNTS, amnts); + + } + + if (stage.blocksToUse != null) { + + LinkedList ids = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.blocksToUse.entrySet()) { + + ids.add(((Material) e.getKey()).getId()); + amnts.add((Integer) e.getValue()); + + } + + cc.setSessionData(pref + CK.S_USE_IDS, ids); + cc.setSessionData(pref + CK.S_USE_AMOUNTS, amnts); + + } + + + if (stage.blocksToCut != null) { + + LinkedList ids = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.blocksToCut.entrySet()) { + + ids.add(((Material) e.getKey()).getId()); + amnts.add((Integer) e.getValue()); + + } + + cc.setSessionData(pref + CK.S_CUT_IDS, ids); + cc.setSessionData(pref + CK.S_CUT_AMOUNTS, amnts); + + } + + + if (stage.fishToCatch != null) { + cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch); + } + + + if (stage.playersToKill != null) { + cc.setSessionData(pref + CK.S_PLAYER_KILL, stage.playersToKill); + } + + + if (stage.itemsToEnchant.isEmpty() == false) { + + LinkedList enchants = new LinkedList(); + LinkedList ids = new LinkedList(); + LinkedList amounts = new LinkedList(); + + for (Entry, Integer> e : stage.itemsToEnchant.entrySet()) { + + amounts.add(e.getValue()); + for (Entry e2 : e.getKey().entrySet()) { + + ids.add(e2.getValue().getId()); + enchants.add(Quester.prettyEnchantmentString(e2.getKey())); + + } + + } + + cc.setSessionData(pref + CK.S_ENCHANT_TYPES, enchants); + cc.setSessionData(pref + CK.S_ENCHANT_IDS, ids); + cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts); + + } + + + if (stage.itemsToDeliver.isEmpty() == false) { + + LinkedList items = new LinkedList(); + LinkedList npcs = new LinkedList(); + + for (ItemStack is : stage.itemsToDeliver) { + items.add(is); + } + + for (NPC n : stage.itemDeliveryTargets) { + npcs.add(n.getId()); + } + + cc.setSessionData(pref + CK.S_DELIVERY_ITEMS, items); + cc.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); + cc.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.deliverMessages); + + } + + + if (stage.citizensToInteract.isEmpty() == false) { + + LinkedList npcs = new LinkedList(); + for (NPC n : stage.citizensToInteract) { + npcs.add(n.getId()); + } + + cc.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); + + } + + + if (stage.citizensToKill.isEmpty() == false) { + + LinkedList npcs = new LinkedList(); + for (NPC n : stage.citizensToKill) { + npcs.add(n.getId()); + } + + cc.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); + cc.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.citizenNumToKill); + + } + + + if (stage.bossesToKill.isEmpty() == false) { + + cc.setSessionData(pref + CK.S_BOSS_IDS, stage.bossesToKill); + cc.setSessionData(pref + CK.S_BOSS_AMOUNTS, stage.bossAmountsToKill); + + } + + + if (stage.mobsToKill.isEmpty() == false) { + + LinkedList mobs = new LinkedList(); + for (EntityType et : stage.mobsToKill) { + mobs.add(Quester.prettyMobString(et)); + } + + cc.setSessionData(pref + CK.S_MOB_TYPES, mobs); + cc.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.mobNumToKill); + + if (stage.locationsToKillWithin.isEmpty() == false) { + + LinkedList locs = new LinkedList(); + for (Location l : stage.locationsToKillWithin) { + locs.add(Quests.getLocationInfo(l)); + } + + cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locs); + cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.radiiToKillWithin); + cc.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.areaNames); + + } + + } + + + if (stage.locationsToReach.isEmpty() == false) { + + LinkedList locs = new LinkedList(); + for (Location l : stage.locationsToReach) { + locs.add(Quests.getLocationInfo(l)); + } + + cc.setSessionData(pref + CK.S_REACH_LOCATIONS, locs); + cc.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.radiiToReachWithin); + cc.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.locationNames); + + } + + + if (stage.mobsToTame.isEmpty() == false) { + + LinkedList mobs = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.mobsToTame.entrySet()) { + + mobs.add(Quester.prettyMobString(e.getKey())); + amnts.add(e.getValue()); + + } + + cc.setSessionData(pref + CK.S_TAME_TYPES, mobs); + cc.setSessionData(pref + CK.S_TAME_AMOUNTS, amnts); + + } + + + if (stage.sheepToShear.isEmpty() == false) { + + LinkedList colors = new LinkedList(); + LinkedList amnts = new LinkedList(); + + for (Entry e : stage.sheepToShear.entrySet()) { + colors.add(Quester.prettyColorString(e.getKey())); + amnts.add(e.getValue()); + } + + cc.setSessionData(pref + CK.S_SHEAR_COLORS, colors); + cc.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amnts); + + } + + + if (stage.event != null) { + cc.setSessionData(pref + CK.S_EVENT, stage.event.getName()); + } + + + if (stage.delay != -1) { + cc.setSessionData(pref + CK.S_DELAY, stage.delay); + if (stage.delayMessage != null) { + cc.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.delayMessage); + } + } + + if (stage.script != null) { + cc.setSessionData(pref + CK.S_DENIZEN, stage.script); + } + + if (stage.completeMessage != null) { + cc.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.completeMessage); + } + + if (stage.startMessage != null) { + cc.setSessionData(pref + CK.S_START_MESSAGE, stage.startMessage); + } + + } + // + + } + + private class SelectDeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = GOLD + "- " + "Delete Quest" + " -\n"; + + for (Quest quest : quests.quests) { + text += AQUA + quest.name + YELLOW + ","; + } + + text = text.substring(0, text.length() - 1) + "\n"; + text += YELLOW + "Enter a Quest name, or \"cancel\" to return."; + + return text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + + LinkedList used = new LinkedList(); + + for (Quest quest : quests.quests) { + + if (quest.name.equalsIgnoreCase(input) || quest.name.toLowerCase().contains(input.toLowerCase())) { + + for (Quest q : quests.quests) { + + if (q.neededQuests.contains(q.name) || q.blockQuests.contains(q.name)) { + used.add(q.name); + } + + } + + if (used.isEmpty()) { + context.setSessionData(CK.ED_QUEST_DELETE, quest.name); + return new DeletePrompt(); + } else { + ((Player) context.getForWhom()).sendMessage(RED + "The following Quests have \"" + PURPLE + context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\" as a requirement:"); + for (String s : used) { + ((Player) context.getForWhom()).sendMessage(RED + "- " + DARKRED + s); + } + ((Player) context.getForWhom()).sendMessage(RED + "You must modify these Quests so that they do not use it before deleting it."); + return new SelectDeletePrompt(); + } + } + + } + + ((Player) context.getForWhom()).sendMessage(RED + "Quest not found!"); + return new SelectDeletePrompt(); + + } else { + return new MenuPrompt(); + } + + } + } + + private class DeletePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String text = + RED + "Are you sure you want to delete the Quest " + " \"" + GOLD + (String) context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\"?\n"; + text += YELLOW + Lang.get("yes") + "/" + Lang.get("no"); + + return text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase(Lang.get("yes"))) { + deleteQuest(context); + return Prompt.END_OF_CONVERSATION; + } else if (input.equalsIgnoreCase(Lang.get("no"))) { + return new MenuPrompt(); + } else { + return new DeletePrompt(); + } + + } + } + + private void deleteQuest(ConversationContext context) { + + YamlConfiguration data = new YamlConfiguration(); + + try { + data.load(questsFile); + } catch (Exception e) { + e.printStackTrace(); + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "Error reading Quests file."); + return; + } + + String quest = (String) context.getSessionData(CK.ED_QUEST_DELETE); + ConfigurationSection sec = data.getConfigurationSection("quests"); + for (String key : sec.getKeys(false)) { + + if (sec.getString(key + ".name").equalsIgnoreCase(quest)) { + sec.set(key, null); + break; + } + + } + + + try { + data.save(questsFile); + } catch (Exception e) { + ((Player) context.getForWhom()).sendMessage(ChatColor.RED + "An error occurred while saving."); + return; + } + + quests.reloadQuests(); + + context.getForWhom().sendRawMessage(WHITE + "" + BOLD + "Quest deleted! Quests and Events have been reloaded."); + + + } +} diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index df0083683..65369eab9 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -1,2732 +1,2733 @@ -package me.blackvein.quests; - -import java.io.File; -import java.util.*; -import java.util.Map.Entry; -import me.ThaH3lper.com.LoadBosses.LoadBoss; -import me.blackvein.quests.util.ItemUtil; -import net.citizensnpcs.api.CitizensAPI; -import net.citizensnpcs.api.npc.NPC; -import org.bukkit.ChatColor; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.Potion; - -public class Quester { - - String name; - boolean editorMode = false; - boolean holdingQuestItemFromStorage = false; - boolean delayOver = true; - public Quest currentQuest; - public String questToTake; - Stage currentStage; - int questPoints = 0; - Quests plugin; - public LinkedList completedQuests = new LinkedList(); - Map completedTimes = new HashMap(); - Map blocksDamaged = new EnumMap(Material.class); - Map blocksBroken = new EnumMap(Material.class); - Map blocksPlaced = new EnumMap(Material.class); - Map blocksUsed = new EnumMap(Material.class); - Map blocksCut = new EnumMap(Material.class); - Map potionsBrewed = new HashMap(); - Map itemsDelivered = new HashMap(); - int fishCaught = 0; - int playersKilled = 0; - long delayStartTime = 0; - long delayTimeLeft = -1; - Map playerKillTimes = new HashMap(); - Map, Integer> itemsEnchanted = new HashMap, Integer>(); - LinkedList mobsKilled = new LinkedList(); - LinkedList mobNumKilled = new LinkedList(); - LinkedList locationsToKillWithin = new LinkedList(); - LinkedList radiiToKillWithin = new LinkedList(); - Map citizensInteracted = new HashMap(); - LinkedList citizensKilled = new LinkedList(); - LinkedList citizenNumKilled = new LinkedList(); - LinkedList bossesKilled = new LinkedList(); - LinkedList bossAmountsKilled = new LinkedList(); - LinkedList locationsReached = new LinkedList(); - LinkedList hasReached = new LinkedList(); - LinkedList radiiToReachWithin = new LinkedList(); - Map mobsTamed = new EnumMap(EntityType.class); - Map sheepSheared = new EnumMap(DyeColor.class); - final Random random = new Random(); - - public Quester(Quests newPlugin) { - - plugin = newPlugin; - - } - - public Player getPlayer() { - - return plugin.getServer().getPlayerExact(name); - - } - - public void takeQuest(Quest q) { - - Player player = plugin.getServer().getPlayer(name); - - if (q.testRequirements(player) == true) { - - currentQuest = q; - currentStage = q.stages.getFirst(); - addEmpties(); - if (q.moneyReq > 0) { - Quests.economy.withdrawPlayer(name, q.moneyReq); - } - - for (ItemStack is : q.items) { - if (q.removeItems.get(q.items.indexOf(is)) == true) { - Quests.removeItem(player.getInventory(), is); - } - } - - player.sendMessage(ChatColor.GREEN + "Quest accepted: " + q.name); - player.sendMessage(""); - player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); - for (String s : getObjectives()) { - player.sendMessage(s); - } - - String stageStartMessage = currentStage.startMessage; - if (stageStartMessage != null) { - getPlayer().sendMessage(Quests.parseString(stageStartMessage, currentQuest)); - } - if(q.initialEvent != null) - q.initialEvent.happen(this); - - } else { - - player.sendMessage(q.failRequirements); - - } - - } - - public LinkedList getObjectives() { - - LinkedList unfinishedObjectives = new LinkedList(); - LinkedList finishedObjectives = new LinkedList(); - LinkedList objectives = new LinkedList(); - - for (Entry e : currentStage.blocksToDamage.entrySet()) { - - for (Entry e2 : blocksDamaged.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Damage " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Damage " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : currentStage.blocksToBreak.entrySet()) { - - for (Entry e2 : blocksBroken.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Break " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Break " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : currentStage.blocksToPlace.entrySet()) { - - for (Entry e2 : blocksPlaced.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : currentStage.blocksToUse.entrySet()) { - - for (Entry e2 : blocksUsed.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Use " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Use " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : currentStage.blocksToCut.entrySet()) { - - for (Entry e2 : blocksCut.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Cut " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Cut " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - if (currentStage.fishToCatch != null) { - - if (fishCaught < currentStage.fishToCatch) { - - unfinishedObjectives.add(ChatColor.GREEN + "Catch Fish: " + fishCaught + "/" + currentStage.fishToCatch); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Catch Fish: " + fishCaught + "/" + currentStage.fishToCatch); - - } - - } - - 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 : currentStage.itemsToEnchant.entrySet()) { - - for (Entry, Integer> e2 : 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) { - - if (num1 < num2) { - - unfinishedObjectives.add(ChatColor.GREEN + "Enchant " + Quester.prettyItemString(mat.getId()) + " with " + Quester.prettyEnchantmentString(enchantment) + ": " + num1 + "/" + num2); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Enchant " + Quester.prettyItemString(mat.getId()) + " with " + Quester.prettyEnchantmentString(enchantment) + ": " + num1 + "/" + num2); - - } - - } - - } - - } - - for (EntityType e : currentStage.mobsToKill) { - - for (EntityType e2 : mobsKilled) { - - if (e == e2) { - - if (mobNumKilled.get(mobsKilled.indexOf(e2)) < currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e))) { - - if (currentStage.locationsToKillWithin.isEmpty()) { - unfinishedObjectives.add(ChatColor.GREEN + "Kill " + Quester.prettyMobString(e) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); - } else { - unfinishedObjectives.add(ChatColor.GREEN + "Kill " + Quester.prettyMobString(e) + " at " + currentStage.areaNames.get(currentStage.mobsToKill.indexOf(e)) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); - } - } else { - - if (currentStage.locationsToKillWithin.isEmpty()) { - finishedObjectives.add(ChatColor.GRAY + "Kill " + Quester.prettyMobString(e) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); - } else { - finishedObjectives.add(ChatColor.GRAY + "Kill " + Quester.prettyMobString(e) + " at " + currentStage.areaNames.get(currentStage.mobsToKill.indexOf(e)) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); - } - - } - - } - - } - - } - - if (currentStage.playersToKill != null) { - - if (playersKilled < currentStage.playersToKill) { - - unfinishedObjectives.add(ChatColor.GREEN + "Kill a Player: " + playersKilled + "/" + currentStage.playersToKill); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Kill a Player: " + playersKilled + "/" + currentStage.playersToKill); - - } - - } - - for (ItemStack is : currentStage.itemsToDeliver) { - - int delivered = itemsDelivered.get(is); - int amt = is.getAmount(); - NPC npc = currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(is)); - - if (delivered < amt) { - - unfinishedObjectives.add(ChatColor.GREEN + "Deliver " + ItemUtil.getName(is) + " to " + npc.getName() + ": " + delivered + "/" + amt); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Deliver " + ItemUtil.getName(is) + " to " + npc.getName() + ": " + delivered + "/" + amt); - - } - - - } - - for (NPC n : currentStage.citizensToInteract) { - - for (Entry e : citizensInteracted.entrySet()) { - - if (e.getKey().equals(n)) { - - if ( e.getValue() == false) { - - unfinishedObjectives.add(ChatColor.GREEN + "Talk to " + n.getFullName()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Talk to " + n.getName()); - - } - - } - - } - - } - - for (NPC n : currentStage.citizensToKill) { - - for (NPC n2 : citizensKilled) { - - if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) { - - unfinishedObjectives.add(ChatColor.GREEN + "Kill " + n.getName() + ChatColor.GREEN + " " + citizenNumKilled.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Kill " + n.getName() + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); - - } - - } - - } - - for (String boss : currentStage.bossesToKill) { - - if (bossAmountsKilled.get(bossesKilled.indexOf(boss)) < currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))) { - - unfinishedObjectives.add(ChatColor.GREEN + "Kill " + ChatColor.ITALIC + boss + ChatColor.RESET + ChatColor.GREEN + " " + bossAmountsKilled.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))); - - } else { - - unfinishedObjectives.add(ChatColor.GRAY + "Kill " + ChatColor.ITALIC + boss + ChatColor.RESET + ChatColor.GRAY + " " + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))); - - } - - } - - for (Entry e : currentStage.mobsToTame.entrySet()) { - - for (Entry e2 : mobsTamed.entrySet()) { - - if (e.getKey().equals(e2.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Tame " + getCapitalized(e.getKey().getName()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Tame " + getCapitalized(e.getKey().getName()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : currentStage.sheepToShear.entrySet()) { - - for (Entry e2 : sheepSheared.entrySet()) { - - if (e.getKey().equals(e2.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + "Shear " + e.getKey().name().toString().toLowerCase() + " sheep: " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Shear " + e.getKey().name().toString().toLowerCase() + " sheep: " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Location l : currentStage.locationsToReach) { - - for (Location l2 : locationsReached) { - - if (l.equals(l2)) { - - if (hasReached.get(locationsReached.indexOf(l2)) == false) { - - unfinishedObjectives.add(ChatColor.GREEN + "Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(l))); - - } else { - - finishedObjectives.add(ChatColor.GRAY + "Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(l))); - - } - - } - - } - - } - - objectives.addAll(unfinishedObjectives); - objectives.addAll(finishedObjectives); - - return objectives; - - } - - public boolean hasObjective(String s) { - - if (currentStage == null) { - return false; - } - - if (s.equalsIgnoreCase("damageBlock")) { - - if (currentStage.blocksToDamage.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("breakBlock")) { - - if (currentStage.blocksToBreak.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("placeBlock")) { - - if (currentStage.blocksToPlace.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("useBlock")) { - - if (currentStage.blocksToUse.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("cutBlock")) { - - if (currentStage.blocksToCut.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("catchFish")) { - - if (currentStage.fishToCatch == null) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("enchantItem")) { - - if (currentStage.itemsToEnchant.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("killMob")) { - - if (currentStage.mobsToKill.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("deliverItem")) { - - if (currentStage.itemsToDeliver.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("killPlayer")) { - - if (currentStage.playersToKill == null) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("talkToNPC")) { - - if (currentStage.citizensToInteract.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("killNPC")) { - - if (currentStage.citizensToKill.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("killBoss")) { - - if (currentStage.bossesToKill.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("tameMob")) { - - if (currentStage.mobsToTame.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("shearSheep")) { - - if (currentStage.sheepToShear.isEmpty()) { - return false; - } else { - return true; - } - - } else if (s.equalsIgnoreCase("craftItem")) { - - if (currentStage.itemsToCraft.isEmpty()) { - return false; - } else { - return true; - } - - } else { - - if (currentStage.locationsToReach.isEmpty()) { - return false; - } else { - return true; - } - - } - - } - - public void damageBlock(Material m) { - - if (blocksDamaged.containsKey(m)) { - - if (blocksDamaged.get(m) < currentStage.blocksToDamage.get(m)) { - int i = blocksDamaged.get(m); - blocksDamaged.put(m, (i + 1)); - - if (blocksDamaged.get(m).equals(currentStage.blocksToDamage.get(m))) { - finishObjective("damageBlock", m, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void breakBlock(Material m) { - - if (blocksBroken.containsKey(m)) { - - if (blocksBroken.get(m) < currentStage.blocksToBreak.get(m)) { - int i = blocksBroken.get(m); - blocksBroken.put(m, (i + 1)); - - if (blocksBroken.get(m).equals(currentStage.blocksToBreak.get(m))) { - finishObjective("breakBlock", m, null, null, null, null, null, null, null, null); - } - } - - } - - } - - public void placeBlock(Material m) { - - if (blocksPlaced.containsKey(m)) { - - if (blocksPlaced.get(m) < currentStage.blocksToPlace.get(m)) { - int i = blocksPlaced.get(m); - blocksPlaced.put(m, (i + 1)); - - if (blocksPlaced.get(m).equals(currentStage.blocksToPlace.get(m))) { - finishObjective("placeBlock", m, null, null, null, null, null, null, null, null); - } - } - - } - - } - - public void useBlock(Material m) { - - if (blocksUsed.containsKey(m)) { - - if (blocksUsed.get(m) < currentStage.blocksToUse.get(m)) { - int i = blocksUsed.get(m); - blocksUsed.put(m, (i + 1)); - - if (blocksUsed.get(m).equals(currentStage.blocksToUse.get(m))) { - finishObjective("useBlock", m, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void cutBlock(Material m) { - - if (blocksCut.containsKey(m)) { - - if (blocksCut.get(m) < currentStage.blocksToCut.get(m)) { - int i = blocksCut.get(m); - blocksCut.put(m, (i + 1)); - - if (blocksCut.get(m).equals(currentStage.blocksToCut.get(m))) { - finishObjective("cutBlock", m, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void catchFish() { - - if (fishCaught < currentStage.fishToCatch) { - fishCaught++; - - if (((Integer) fishCaught).equals(currentStage.fishToCatch)) { - finishObjective("catchFish", null, null, null, null, null, null, null, null, null); - } - - } - - } - - public void enchantItem(Enchantment e, Material m) { - - for (Entry entry : itemsEnchanted.entrySet()) { - - if (((Map) entry.getKey()).containsKey(e) && ((Map) entry.getKey()).containsValue(m)) { - - for (Entry entry2 : currentStage.itemsToEnchant.entrySet()) { - - if (((Map) entry2.getKey()).containsKey(e) && ((Map) entry2.getKey()).containsValue(m)) { - - if ((Integer) entry.getValue() < (Integer) entry2.getValue()) { - - Integer num = (Integer) entry.getValue() + 1; - itemsEnchanted.put(((Map) entry.getKey()), (num)); - - if ((num).equals((Integer) entry2.getValue())) { - finishObjective("enchantItem", m, null, e, null, null, null, null, null, null); - } - - } - break; - - } - - } - - break; - - } - - } - - } - - public void killMob(Location l, EntityType e) { - - if (mobsKilled.contains(e)) { - - if (locationsToKillWithin.isEmpty() == false) { - - int index = mobsKilled.indexOf(e); - Location locationToKillWithin = locationsToKillWithin.get(index); - double radius = radiiToKillWithin.get(index); - int numKilled = mobNumKilled.get(index); - if (l.getX() < (locationToKillWithin.getX() + radius) && l.getX() > (locationToKillWithin.getX() - radius)) { - - if (l.getZ() < (locationToKillWithin.getZ() + radius) && l.getZ() > (locationToKillWithin.getZ() - radius)) { - - if (l.getY() < (locationToKillWithin.getY() + radius) && l.getY() > (locationToKillWithin.getY() - radius)) { - - if (numKilled < currentStage.mobNumToKill.get(index)) { - - Integer numKilledInteger = numKilled + 1; - - mobNumKilled.set(index, numKilledInteger); - - if ((numKilledInteger).equals(currentStage.mobNumToKill.get(index))) { - finishObjective("killMob", null, null, null, e, null, null, null, null, null); - } - - } - - } - - } - - } - - } else { - - if (mobNumKilled.get(mobsKilled.indexOf(e)) < currentStage.mobNumToKill.get(mobsKilled.indexOf(e))) { - - mobNumKilled.set(mobsKilled.indexOf(e), mobNumKilled.get(mobsKilled.indexOf(e)) + 1); - - if ((mobNumKilled.get(mobsKilled.indexOf(e))).equals(currentStage.mobNumToKill.get(mobsKilled.indexOf(e)))) { - finishObjective("killMob", null, null, null, e, null, null, null, null, null); - } - - } - - } - - } - - } - - public void killPlayer(String player) { - - if (playerKillTimes.containsKey(player)) { - - long killTime = playerKillTimes.get(player); - long comparator = plugin.killDelay * 1000; - long currentTime = System.currentTimeMillis(); - - if ((currentTime - killTime) < comparator) { - - plugin.getServer().getPlayer(name).sendMessage(ChatColor.RED + "[Quests] Kill did not count. You must wait " + ChatColor.DARK_PURPLE + Quests.getTime(comparator - (currentTime - killTime)) + ChatColor.RED + " before you can kill " + ChatColor.DARK_PURPLE + player + ChatColor.RED + " again."); - return; - - } - - } - - playerKillTimes.put(player, System.currentTimeMillis()); - - if (playersKilled < currentStage.playersToKill) { - playersKilled++; - - if (((Integer) playersKilled).equals(currentStage.playersToKill)) { - finishObjective("killPlayer", null, null, null, null, null, null, null, null, null); - } - - } - - } - - public void interactWithNPC(NPC n) { - - if (citizensInteracted.containsKey(n)) { - - if (citizensInteracted.get(n) == false) { - citizensInteracted.put(n, true); - finishObjective("talkToNPC", null, null, null, null, null, n, null, null, null); - } - - } - - } - - public void killNPC(NPC n) { - - if (citizensKilled.contains(n)) { - - int index = citizensKilled.indexOf(n); - if (citizenNumKilled.get(index) < currentStage.citizenNumToKill.get(index)) { - citizenNumKilled.set(index, citizenNumKilled.get(index) + 1); - if (citizenNumKilled.get(index) == currentStage.citizenNumToKill.get(index)) { - finishObjective("killNPC", null, null, null, null, null, n, null, null, null); - } - } - - } - - } - - public void killBoss(String boss) { - - for(String s : bossesKilled){ - - if (s.equalsIgnoreCase(boss)) { - - int index = bossesKilled.indexOf(s); - if (bossAmountsKilled.get(index) < currentStage.bossAmountsToKill.get(index)) { - bossAmountsKilled.set(index, bossAmountsKilled.get(index) + 1); - if (bossAmountsKilled.get(index) == currentStage.bossAmountsToKill.get(index)) { - finishObjective("killBoss", null, null, null, null, null, null, null, null, boss); - } - } - - } - - } - - } - - public void reachLocation(Location l) { - - for (Location location : locationsReached) { - - int index = locationsReached.indexOf(location); - Location locationToReach = currentStage.locationsToReach.get(index); - double radius = radiiToReachWithin.get(index); - if (l.getX() < (locationToReach.getX() + radius) && l.getX() > (locationToReach.getX() - radius)) { - - if (l.getZ() < (locationToReach.getZ() + radius) && l.getZ() > (locationToReach.getZ() - radius)) { - - if (l.getY() < (locationToReach.getY() + radius) && l.getY() > (locationToReach.getY() - radius)) { - - if (hasReached.get(index) == false) { - - hasReached.set(index, true); - finishObjective("reachLocation", null, null, null, null, null, null, location, null, null); - - } - - } - - } - - } - - } - - } - - public void tameMob(EntityType entity) { - - if (mobsTamed.containsKey(entity)) { - - mobsTamed.put(entity, (mobsTamed.get(entity) + 1)); - - if (mobsTamed.get(entity).equals(currentStage.mobsToTame.get(entity))) { - finishObjective("tameMob", null, null, null, entity, null, null, null, null, null); - } - - } - - } - - public void shearSheep(DyeColor color) { - - if (sheepSheared.containsKey(color)) { - - sheepSheared.put(color, (sheepSheared.get(color) + 1)); - - if (sheepSheared.get(color).equals(currentStage.sheepToShear.get(color))) { - finishObjective("shearSheep", null, null, null, null, null, null, null, color, null); - } - - } - - } - - public void deliverItem(ItemStack i) { - - Player player = plugin.getServer().getPlayer(name); - - ItemStack found = null; - - for(ItemStack is : itemsDelivered.keySet()){ - - if(ItemUtil.compareItems(i, is, true) == 0){ - found = is; - break; - } - - } - if (found != null) { - - int amount = itemsDelivered.get(found); - int req = currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(found)).getAmount(); - - if (amount < req) { - - if ((i.getAmount() + amount) > req) { - - itemsDelivered.put(found, req); - int index = player.getInventory().first(i); - i.setAmount(i.getAmount() - (req - amount)); //Take away the remaining amount needed to be delivered from the item stack - player.getInventory().setItem(index, i); - player.updateInventory(); - finishObjective("deliverItem", null, found, null, null, null, null, null, null, null); - - } else if ((i.getAmount() + amount) == req) { - - itemsDelivered.put(found, req); - player.getInventory().setItem(player.getInventory().first(i), null); - player.updateInventory(); - finishObjective("deliverItem", null, found, null, null, null, null, null, null, null); - - } else { - - itemsDelivered.put(found, (amount + i.getAmount())); - player.getInventory().setItem(player.getInventory().first(i), null); - player.updateInventory(); - String message = Quests.parseString(currentStage.deliverMessages.get(random.nextInt(currentStage.deliverMessages.size())), currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(found))); - player.sendMessage(message); - - } - - } - - } - - } - - public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color, String boss) { - - Player p = plugin.getServer().getPlayerExact(name); - - if (objective.equalsIgnoreCase("damageBlock")) { - - String message = ChatColor.GREEN + "(Completed) Damage " + prettyItemString(material.getId()); - message = message + " " + currentStage.blocksToDamage.get(material) + "/" + currentStage.blocksToDamage.get(material); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("breakBlock")) { - - String message = ChatColor.GREEN + "(Completed) Break " + prettyItemString(material.getId()); - message = message + " " + currentStage.blocksToBreak.get(material) + "/" + currentStage.blocksToBreak.get(material); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("placeBlock")) { - - String message = ChatColor.GREEN + "(Completed) Place " + prettyItemString(material.getId()); - message = message + " " + currentStage.blocksToPlace.get(material) + "/" + currentStage.blocksToPlace.get(material); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("useBlock")) { - - String message = ChatColor.GREEN + "(Completed) Use " + prettyItemString(material.getId()); - message = message + " " + currentStage.blocksToUse.get(material) + "/" + currentStage.blocksToUse.get(material); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("cutBlock")) { - - String message = ChatColor.GREEN + "(Completed) Cut " + prettyItemString(material.getId()); - message = message + " " + currentStage.blocksToCut.get(material) + "/" + currentStage.blocksToCut.get(material); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("catchFish")) { - - String message = ChatColor.GREEN + "(Completed) Catch Fish "; - message = message + " " + currentStage.fishToCatch + "/" + currentStage.fishToCatch; - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("enchantItem")) { - - String message = ChatColor.GREEN + "(Completed) Enchant " + prettyItemString(material.getId()) + " with " + Quester.prettyEnchantmentString(enchantment); - for (Map map : currentStage.itemsToEnchant.keySet()) { - - if (map.containsKey(enchantment)) { - - message = message + " " + currentStage.itemsToEnchant.get(map) + "/" + currentStage.itemsToEnchant.get(map); - break; - - } - - } - - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("deliverItem")) { - - String message = ChatColor.GREEN + "(Completed) Deliver " + ItemUtil.getString(currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(itemstack))) + " " + ItemUtil.getName(itemstack) + " to " + currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(itemstack)).getName(); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("killMob")) { - - String message = ChatColor.GREEN + "(Completed) Kill " + mob.getName(); - message = message + " " + currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(mob)) + "/" + currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(mob)); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("killPlayer")) { - - String message = ChatColor.GREEN + "(Completed) Kill a Player"; - message = message + " " + currentStage.playersToKill + "/" + currentStage.playersToKill; - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("talkToNPC")) { - - String message = ChatColor.GREEN + "(Completed) Talk to " + npc.getName(); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("killNPC")) { - - String message = ChatColor.GREEN + "(Completed) Kill " + npc.getName(); - message = message + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("killBoss")) { - - LoadBoss b = Quests.getBoss(boss); - String message = ChatColor.GREEN + "(Completed) Kill " + ChatColor.ITALIC + b.getName() + ChatColor.RESET + ChatColor.GREEN; - message = message + " " + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("tameMob")) { - - String message = ChatColor.GREEN + "(Completed) Tame " + getCapitalized(mob.getName()); - message = message + " " + currentStage.mobsToTame.get(mob) + "/" + currentStage.mobsToTame.get(mob); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else if (objective.equalsIgnoreCase("shearSheep")) { - - String message = ChatColor.GREEN + "(Completed) Shear " + color.name().toString().toLowerCase() + " sheep"; - message = message + " " + currentStage.sheepToShear.get(color) + "/" + currentStage.sheepToShear.get(color); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } else { - - String message = ChatColor.GREEN + "(Completed) Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(location)); - p.sendMessage(message); - if (testComplete()) { - currentQuest.nextStage(this); - } - - } - - } - - public boolean testComplete() { - - for (String s : getObjectives()) { - - if (s.contains(ChatColor.GREEN.toString())) { - return false; - } - - } - return true; - - } - - public void addEmpties() { - - if (currentStage.blocksToDamage.isEmpty() == false) { - for (Material m : currentStage.blocksToDamage.keySet()) { - - blocksDamaged.put(m, 0); - - } - } - - if (currentStage.blocksToBreak.isEmpty() == false) { - for (Material m : currentStage.blocksToBreak.keySet()) { - - blocksBroken.put(m, 0); - - } - } - - if (currentStage.blocksToPlace.isEmpty() == false) { - for (Material m : currentStage.blocksToPlace.keySet()) { - - blocksPlaced.put(m, 0); - - } - } - - if (currentStage.blocksToUse.isEmpty() == false) { - for (Material m : currentStage.blocksToUse.keySet()) { - - blocksUsed.put(m, 0); - - } - } - - if (currentStage.blocksToCut.isEmpty() == false) { - for (Material m : currentStage.blocksToCut.keySet()) { - - blocksCut.put(m, 0); - - } - } - - fishCaught = 0; - - if (currentStage.itemsToEnchant.isEmpty() == false) { - for (Entry e : currentStage.itemsToEnchant.entrySet()) { - - Map map = (Map) e.getKey(); - itemsEnchanted.put(map, 0); - - } - } - - if (currentStage.mobsToKill.isEmpty() == false) { - for (EntityType e : currentStage.mobsToKill) { - - mobsKilled.add(e); - mobNumKilled.add(0); - if (currentStage.locationsToKillWithin.isEmpty() == false) { - locationsToKillWithin.add(currentStage.locationsToKillWithin.get(mobsKilled.indexOf(e))); - } - if (currentStage.radiiToKillWithin.isEmpty() == false) { - radiiToKillWithin.add(currentStage.radiiToKillWithin.get(mobsKilled.indexOf(e))); - } - - } - } - - playersKilled = 0; - - if (currentStage.itemsToDeliver.isEmpty() == false) { - for (ItemStack is : currentStage.itemsToDeliver) { - - itemsDelivered.put(is, 0); - - } - } - - if (currentStage.citizensToInteract.isEmpty() == false) { - for (NPC n : currentStage.citizensToInteract) { - - citizensInteracted.put(n, false); - - } - } - - if (currentStage.citizensToKill.isEmpty() == false) { - for (NPC n : currentStage.citizensToKill) { - - citizensKilled.add(n); - citizenNumKilled.add(0); - - } - } - - if (currentStage.bossesToKill.isEmpty() == false) { - for (String s : currentStage.bossesToKill) { - - bossesKilled.add(s); - bossAmountsKilled.add(0); - - } - } - - if (currentStage.blocksToCut.isEmpty() == false) { - for (Material m : currentStage.blocksToCut.keySet()) { - - blocksCut.put(m, 0); - - } - } - - if (currentStage.locationsToReach.isEmpty() == false) { - for (Location l : currentStage.locationsToReach) { - - locationsReached.add(l); - hasReached.add(false); - radiiToReachWithin.add(currentStage.radiiToReachWithin.get(locationsReached.indexOf(l))); - - } - } - - if (currentStage.mobsToTame.isEmpty() == false) { - for (EntityType e : currentStage.mobsToTame.keySet()) { - - mobsTamed.put(e, 0); - - } - } - - if (currentStage.sheepToShear.isEmpty() == false) { - for (DyeColor d : currentStage.sheepToShear.keySet()) { - - sheepSheared.put(d, 0); - - } - } - - } - - public void reset() { - - blocksDamaged.clear(); - blocksBroken.clear(); - blocksPlaced.clear(); - blocksUsed.clear(); - blocksCut.clear(); - fishCaught = 0; - itemsEnchanted.clear(); - mobsKilled.clear(); - mobNumKilled.clear(); - locationsToKillWithin.clear(); - radiiToKillWithin.clear(); - playersKilled = 0; - itemsDelivered.clear(); - citizensInteracted.clear(); - citizensKilled.clear(); - citizenNumKilled.clear(); - locationsReached.clear(); - hasReached.clear(); - radiiToReachWithin.clear(); - mobsTamed.clear(); - sheepSheared.clear(); - bossesKilled.clear(); - bossAmountsKilled.clear(); - - } - - public static String getCapitalized(String target) { - String firstLetter = target.substring(0, 1); - String remainder = target.substring(1); - String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase(); - - return capitalized; - } - - public static String prettyItemString(int itemID) { - String baseString = Material.getMaterial(itemID).toString(); - String[] substrings = baseString.split("_"); - String prettyString = ""; - int size = 1; - - for (String s : substrings) { - prettyString = prettyString.concat(Quester.getCapitalized(s)); - - if (size < substrings.length) { - prettyString = prettyString.concat(" "); - } - - size++; - } - - return prettyString; - } - - public static String fullPotionString(short dv) { - - Potion potion = Potion.fromDamage(dv); - String potionName = ""; - boolean isPrimary = false; - - try { - - potionName = "Potion of " + potion.getType().getEffectType().getName(); - - } catch (NullPointerException e) { // Potion is primary - - isPrimary = true; - - if (dv == 0) { - potionName = "Water Bottle"; - } else if (dv == 16) { - potionName = "Awkward Potion"; - } else if (dv == 32) { - potionName = "Thick Potion"; - } else if (dv == 64) { - potionName = "Mundane Potion (Extended)"; - } else if (dv == 8192) { - potionName = "Mundane Potion"; - } - - } - - if (isPrimary == false) { - - if (potion.hasExtendedDuration()) { - potionName = potionName + " (Extended)"; - } else if (potion.getLevel() == 2) { - potionName = potionName + " II"; - } - - if (potion.isSplash()) { - potionName = "Splash " + potionName; - } - - } - - return potionName; - - } - - public static String prettyMobString(EntityType type) { - - String baseString = type.toString(); - String[] substrings = baseString.split("_"); - String prettyString = ""; - int size = 1; - - for (String s : substrings) { - prettyString = prettyString.concat(Quester.getCapitalized(s)); - - if (size < substrings.length) { - prettyString = prettyString.concat(" "); - } - - size++; - } - - if (type.equals((EntityType.OCELOT))) { - prettyString = "Ocelot"; - } - - return prettyString; - } - - public static String prettyString(String s) { - - String[] substrings = s.split("_"); - String prettyString = ""; - int size = 1; - - for (String sb : substrings) { - prettyString = prettyString.concat(Quester.getCapitalized(sb)); - - if (size < substrings.length) { - prettyString = prettyString.concat(" "); - } - - size++; - } - - return prettyString; - - } - - public static String prettyEnchantmentString(Enchantment e) { - - String prettyString = ""; - - if (e.equals(Enchantment.ARROW_DAMAGE)) { - prettyString = "Power"; - } else if (e.equals(Enchantment.ARROW_FIRE)) { - prettyString = "Flame"; - } else if (e.equals(Enchantment.ARROW_INFINITE)) { - prettyString = "Infinity"; - } else if (e.equals(Enchantment.ARROW_KNOCKBACK)) { - prettyString = "Punch"; - } else if (e.equals(Enchantment.DAMAGE_ALL)) { - prettyString = "Sharpness"; - } else if (e.equals(Enchantment.DAMAGE_ARTHROPODS)) { - prettyString = "Bane of Arthropods"; - } else if (e.equals(Enchantment.DAMAGE_UNDEAD)) { - prettyString = "Smite"; - } else if (e.equals(Enchantment.DIG_SPEED)) { - prettyString = "Efficiency"; - } else if (e.equals(Enchantment.DURABILITY)) { - prettyString = "Unbreaking"; - } else if (e.equals(Enchantment.FIRE_ASPECT)) { - prettyString = "Fire Aspect"; - } else if (e.equals(Enchantment.KNOCKBACK)) { - prettyString = "Knockback"; - } else if (e.equals(Enchantment.LOOT_BONUS_BLOCKS)) { - prettyString = "Fortune"; - } else if (e.equals(Enchantment.LOOT_BONUS_MOBS)) { - prettyString = "Looting"; - } else if (e.equals(Enchantment.OXYGEN)) { - prettyString = "Respiration"; - } else if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) { - prettyString = "Protection"; - } else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS)) { - prettyString = "Blast Protection"; - } else if (e.equals(Enchantment.PROTECTION_FALL)) { - prettyString = "Feather Falling"; - } else if (e.equals(Enchantment.PROTECTION_FIRE)) { - prettyString = "Fire Protection"; - } else if (e.equals(Enchantment.PROTECTION_PROJECTILE)) { - prettyString = "Projectile Protection"; - } else if (e.equals(Enchantment.SILK_TOUCH)) { - prettyString = "Silk Touch"; - } else if (e.equals(Enchantment.THORNS)) { - prettyString = "Thorns"; - } else if (e.equals(Enchantment.WATER_WORKER)) { - prettyString = "Aqua Affinity"; - } - - return prettyString; - - } - - public static String enchantmentString(Enchantment e) { - - String string = ""; - - if (e.equals(Enchantment.ARROW_DAMAGE)) { - string = "Power"; - } else if (e.equals(Enchantment.ARROW_FIRE)) { - string = "Flame"; - } else if (e.equals(Enchantment.ARROW_INFINITE)) { - string = "Infinity"; - } else if (e.equals(Enchantment.ARROW_KNOCKBACK)) { - string = "Punch"; - } else if (e.equals(Enchantment.DAMAGE_ALL)) { - string = "Sharpness"; - } else if (e.equals(Enchantment.DAMAGE_ARTHROPODS)) { - string = "BaneOfArthropods"; - } else if (e.equals(Enchantment.DAMAGE_UNDEAD)) { - string = "Smite"; - } else if (e.equals(Enchantment.DIG_SPEED)) { - string = "Efficiency"; - } else if (e.equals(Enchantment.DURABILITY)) { - string = "Unbreaking"; - } else if (e.equals(Enchantment.FIRE_ASPECT)) { - string = "FireAspect"; - } else if (e.equals(Enchantment.KNOCKBACK)) { - string = "Knockback"; - } else if (e.equals(Enchantment.LOOT_BONUS_BLOCKS)) { - string = "Fortune"; - } else if (e.equals(Enchantment.LOOT_BONUS_MOBS)) { - string = "Looting"; - } else if (e.equals(Enchantment.OXYGEN)) { - string = "Respiration"; - } else if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) { - string = "Protection"; - } else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS)) { - string = "BlastProtection"; - } else if (e.equals(Enchantment.PROTECTION_FALL)) { - string = "FeatherFalling"; - } else if (e.equals(Enchantment.PROTECTION_FIRE)) { - string = "FireProtection"; - } else if (e.equals(Enchantment.PROTECTION_PROJECTILE)) { - string = "ProjectileProtection"; - } else if (e.equals(Enchantment.SILK_TOUCH)) { - string = "SilkTouch"; - } else if (e.equals(Enchantment.THORNS)) { - string = "Thorns"; - } else if (e.equals(Enchantment.WATER_WORKER)) { - string = "AquaAffinity"; - } - - return string; - - } - - public static String prettyColorString(DyeColor color) { - - if (color.equals(DyeColor.BLACK)) { - return "Black"; - } else if (color.equals(DyeColor.BLUE)) { - return "Blue"; - } else if (color.equals(DyeColor.BROWN)) { - return "Brown"; - } else if (color.equals(DyeColor.CYAN)) { - return "Cyan"; - } else if (color.equals(DyeColor.GRAY)) { - return "Gray"; - } else if (color.equals(DyeColor.GREEN)) { - return "Green"; - } else if (color.equals(DyeColor.LIGHT_BLUE)) { - return "LightBlue"; - } else if (color.equals(DyeColor.LIME)) { - return "Lime"; - } else if (color.equals(DyeColor.MAGENTA)) { - return "Magenta"; - } else if (color.equals(DyeColor.ORANGE)) { - return "Orange"; - } else if (color.equals(DyeColor.PINK)) { - return "Pink"; - } else if (color.equals(DyeColor.PURPLE)) { - return "Purple"; - } else if (color.equals(DyeColor.RED)) { - return "Red"; - } else if (color.equals(DyeColor.SILVER)) { - return "Silver"; - } else if (color.equals(DyeColor.WHITE)) { - return "White"; - } else { - return "Yellow"; - } - - } - - public void saveData() { - - FileConfiguration data = getBaseData(); - try { - data.save(new File(plugin.getDataFolder(), "data/" + name + ".yml")); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - public long getDifference(Quest q) { - - long currentTime = System.currentTimeMillis(); - long lastTime; - if (completedTimes.containsKey(q.name) == false) { - lastTime = System.currentTimeMillis(); - completedTimes.put(q.name, System.currentTimeMillis()); - } else { - lastTime = completedTimes.get(q.name); - } - long comparator = q.redoDelay; - long difference = (comparator - (currentTime - lastTime)); - - return difference; - - - } - - public FileConfiguration getBaseData() { - - FileConfiguration data = new YamlConfiguration(); - - if (completedTimes.isEmpty() == false) { - - List questTimeNames = new LinkedList(); - List questTimes = new LinkedList(); - - for (String s : completedTimes.keySet()) { - - questTimeNames.add(s); - questTimes.add(completedTimes.get(s)); - - } - - data.set("completedRedoableQuests", questTimeNames); - data.set("completedQuestTimes", questTimes); - - } - - if (currentQuest != null) { - - data.set("currentQuest", currentQuest.name); - data.set("currentStage", currentQuest.stages.indexOf(currentStage)); - data.set("quest-points", questPoints); - - if (blocksDamaged.isEmpty() == false) { - - LinkedList blockIds = new LinkedList(); - LinkedList blockAmounts = new LinkedList(); - - for (Material m : blocksDamaged.keySet()) { - blockIds.add(m.getId()); - blockAmounts.add(blocksDamaged.get(m)); - } - - data.set("blocks-damaged-ids", blockIds); - data.set("blocks-damaged-amounts", blockAmounts); - - } - - if (blocksBroken.isEmpty() == false) { - - LinkedList blockIds = new LinkedList(); - LinkedList blockAmounts = new LinkedList(); - - for (Material m : blocksBroken.keySet()) { - blockIds.add(m.getId()); - blockAmounts.add(blocksBroken.get(m)); - } - - data.set("blocks-broken-ids", blockIds); - data.set("blocks-broken-amounts", blockAmounts); - - } - - if (blocksPlaced.isEmpty() == false) { - - LinkedList blockIds = new LinkedList(); - LinkedList blockAmounts = new LinkedList(); - - for (Material m : blocksPlaced.keySet()) { - blockIds.add(m.getId()); - blockAmounts.add(blocksPlaced.get(m)); - } - - data.set("blocks-placed-ids", blockIds); - data.set("blocks-placed-amounts", blockAmounts); - - } - - if (blocksUsed.isEmpty() == false) { - - LinkedList blockIds = new LinkedList(); - LinkedList blockAmounts = new LinkedList(); - - for (Material m : blocksUsed.keySet()) { - blockIds.add(m.getId()); - blockAmounts.add(blocksUsed.get(m)); - } - - data.set("blocks-used-ids", blockIds); - data.set("blocks-used-amounts", blockAmounts); - - } - - if (blocksCut.isEmpty() == false) { - - LinkedList blockIds = new LinkedList(); - LinkedList blockAmounts = new LinkedList(); - - for (Material m : blocksCut.keySet()) { - blockIds.add(m.getId()); - blockAmounts.add(blocksCut.get(m)); - } - - data.set("blocks-cut-ids", blockIds); - data.set("blocks-cut-amounts", blockAmounts); - - } - - if (currentStage.fishToCatch != null) { - data.set("fish-caught", fishCaught); - } - - if (currentStage.playersToKill != null) { - data.set("players-killed", playersKilled); - } - - if (itemsEnchanted.isEmpty() == false) { - - LinkedList enchantments = new LinkedList(); - LinkedList itemIds = new LinkedList(); - LinkedList enchAmounts = new LinkedList(); - - for (Entry e : itemsEnchanted.entrySet()) { - - Map enchMap = (Map) e.getKey(); - enchAmounts.add(itemsEnchanted.get(enchMap)); - for (Entry e2 : enchMap.entrySet()) { - - enchantments.add(Quester.prettyEnchantmentString((Enchantment) e2.getKey())); - itemIds.add(((Material) e2.getValue()).getId()); - - } - - - } - - data.set("enchantments", enchantments); - data.set("enchantment-item-ids", itemIds); - data.set("times-enchanted", enchAmounts); - - } - - if (mobsKilled.isEmpty() == false) { - - LinkedList mobNames = new LinkedList(); - LinkedList mobAmounts = new LinkedList(); - LinkedList locations = new LinkedList(); - LinkedList radii = new LinkedList(); - - for (EntityType e : mobsKilled) { - - mobNames.add(Quester.prettyMobString(e)); - - } - - for (int i : mobNumKilled) { - - mobAmounts.add(i); - - } - - data.set("mobs-killed", mobNames); - data.set("mobs-killed-amounts", mobAmounts); - - if (locationsToKillWithin.isEmpty() == false) { - - for (Location l : locationsToKillWithin) { - - locations.add(l.getWorld().getName() + " " + l.getX() + " " + l.getY() + " " + l.getZ()); - - } - - for (int i : radiiToKillWithin) { - - radii.add(i); - - } - - data.set("mob-kill-locations", locations); - data.set("mob-kill-location-radii", radii); - - } - - } - - if (itemsDelivered.isEmpty() == false) { - - LinkedList deliveryAmounts = new LinkedList(); - - for (Entry e : itemsDelivered.entrySet()) { - - deliveryAmounts.add(e.getValue()); - - } - - data.set("item-delivery-amounts", deliveryAmounts); - - } - - if (citizensInteracted.isEmpty() == false) { - - LinkedList npcIds = new LinkedList(); - LinkedList hasTalked = new LinkedList(); - - for (NPC n : citizensInteracted.keySet()) { - - npcIds.add(n.getId()); - hasTalked.add(citizensInteracted.get(n)); - - } - - data.set("citizen-ids-to-talk-to", npcIds); - data.set("has-talked-to", hasTalked); - - } - - if (citizensKilled.isEmpty() == false) { - - LinkedList npcIds = new LinkedList(); - - for (NPC n : citizensKilled) { - - npcIds.add(n.getId()); - - } - - data.set("citizen-ids-killed", npcIds); - data.set("citizen-amounts-killed", citizenNumKilled); - - } - - if (bossesKilled.isEmpty() == false) { - - data.set("bosses-killed", bossesKilled); - data.set("boss-amounts-killed", bossAmountsKilled); - - } - - if (locationsReached.isEmpty() == false) { - - LinkedList locations = new LinkedList(); - LinkedList has = new LinkedList(); - LinkedList radii = new LinkedList(); - - for (Location l : locationsReached) { - - locations.add(l.getWorld().getName() + " " + l.getX() + " " + l.getY() + " " + l.getZ()); - - } - - for (boolean b : hasReached) { - has.add(b); - } - - for (int i : radiiToReachWithin) { - radii.add(i); - } - - data.set("locations-to-reach", locations); - data.set("has-reached-location", has); - data.set("radii-to-reach-within", radii); - - } - - if (potionsBrewed.isEmpty() == false) { - - LinkedList potionIds = new LinkedList(); - LinkedList potionAmounts = new LinkedList(); - - for (Entry entry : potionsBrewed.entrySet()) { - - potionIds.add((Integer) entry.getKey()); - potionAmounts.add((Integer) entry.getValue()); - - } - - data.set("potions-brewed-ids", potionIds); - data.set("potions-brewed-amounts", potionAmounts); - - } - - if (mobsTamed.isEmpty() == false) { - - LinkedList mobNames = new LinkedList(); - LinkedList mobAmounts = new LinkedList(); - - for (EntityType e : mobsTamed.keySet()) { - - mobNames.add(Quester.prettyMobString(e)); - mobAmounts.add(mobsTamed.get(e)); - - } - - data.set("mobs-to-tame", mobNames); - data.set("mob-tame-amounts", mobAmounts); - - } - - if (sheepSheared.isEmpty() == false) { - - LinkedList colors = new LinkedList(); - LinkedList shearAmounts = new LinkedList(); - - for (DyeColor d : sheepSheared.keySet()) { - - colors.add(Quester.prettyColorString(d)); - shearAmounts.add(sheepSheared.get(d)); - - } - - data.set("sheep-to-shear", colors); - data.set("sheep-sheared", shearAmounts); - - } - - if (delayTimeLeft > 0) { - data.set("stage-delay", delayTimeLeft); - } - - - } else { - - data.set("currentQuest", "none"); - data.set("currentStage", "none"); - data.set("quest-points", questPoints); - - } - - if (completedQuests.isEmpty()) { - - data.set("completed-Quests", "none"); - - } else { - - String[] completed = new String[completedQuests.size()]; - for (String s : completedQuests) { - - completed[completedQuests.indexOf(s)] = s; - - } - data.set("completed-Quests", completed); - - } - - return data; - - } - - public boolean loadData() { - - FileConfiguration data = new YamlConfiguration(); - try { - data.load(new File(plugin.getDataFolder(), "data/" + name + ".yml")); - } catch (Exception e) { - return false; - } - - if (data.contains("completedRedoableQuests")) { - - for (String s : data.getStringList("completedRedoableQuests")) { - - for (Object o : data.getList("completedQuestTimes")) { - - for (Quest q : plugin.quests) { - - if (q.name.equalsIgnoreCase(s)) { - completedTimes.put(q.name, (Long) o); - break; - } - - } - - } - - } - - } - - questPoints = data.getInt("quest-points"); - - if (data.isList("completed-Quests")) { - - for (String s : data.getStringList("completed-Quests")) { - - for (Quest q : plugin.quests) { - - if (q.name.equalsIgnoreCase(s)) { - completedQuests.add(q.name); - break; - } - - } - - } - - } else { - completedQuests.clear(); - } - - if (data.getString("currentQuest").equalsIgnoreCase("none") == false) { - - Quest quest = null; - Stage stage = null; - - for (Quest q : plugin.quests) { - - if (q.name.equalsIgnoreCase(data.getString("currentQuest"))) { - quest = q; - break; - } - - } - - if (quest == null) { - return true; - } - - int stageIndex = data.getInt("currentStage"); - - for (Stage s : quest.stages) { - - if (quest.stages.indexOf(s) == (stageIndex)) { - stage = s; - break; - } - - } - - currentQuest = quest; - currentStage = stage; - - addEmpties(); - - if (data.contains("blocks-damaged-ids")) { - - List ids = data.getIntegerList("blocks-damaged-ids"); - List amounts = data.getIntegerList("blocks-damaged-amounts"); - - for (int i : ids) { - - blocksDamaged.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("blocks-broken-ids")) { - - List ids = data.getIntegerList("blocks-broken-ids"); - List amounts = data.getIntegerList("blocks-broken-amounts"); - - for (int i : ids) { - - blocksBroken.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("blocks-placed-ids")) { - - List ids = data.getIntegerList("blocks-placed-ids"); - List amounts = data.getIntegerList("blocks-placed-amounts"); - - for (int i : ids) { - - blocksPlaced.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("blocks-used-ids")) { - - List ids = data.getIntegerList("blocks-used-ids"); - List amounts = data.getIntegerList("blocks-used-amounts"); - - for (int i : ids) { - - blocksUsed.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("blocks-cut-ids")) { - - List ids = data.getIntegerList("blocks-cut-ids"); - List amounts = data.getIntegerList("blocks-cut-amounts"); - - for (int i : ids) { - - blocksCut.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("fish-caught")) { - fishCaught = data.getInt("fish-caught"); - } - - if (data.contains("players-killed")) { - - playersKilled = data.getInt("players-killed"); - - List playerNames = data.getStringList("player-killed-names"); - List killTimes = data.getLongList("kill-times"); - - for (String s : playerNames) { - - playerKillTimes.put(s, killTimes.get(playerNames.indexOf(s))); - - } - - } - - if (data.contains("enchantments")) { - - LinkedList enchantments = new LinkedList(); - LinkedList materials = new LinkedList(); - LinkedList amounts = new LinkedList(); - - List enchantNames = data.getStringList("enchantments"); - List ids = data.getIntegerList("enchantment-item-ids"); - - for (String s : enchantNames) { - - if (s.equalsIgnoreCase("Power")) { - - enchantments.add(Enchantment.ARROW_DAMAGE); - - } else if (s.equalsIgnoreCase("Flame")) { - - enchantments.add(Enchantment.ARROW_FIRE); - - } else if (s.equalsIgnoreCase("Infinity")) { - - enchantments.add(Enchantment.ARROW_INFINITE); - - } else if (s.equalsIgnoreCase("Punch")) { - - enchantments.add(Enchantment.ARROW_KNOCKBACK); - - } else if (s.equalsIgnoreCase("Sharpness")) { - - enchantments.add(Enchantment.DAMAGE_ALL); - - } else if (s.equalsIgnoreCase("BaneOfArthropods")) { - - enchantments.add(Enchantment.DAMAGE_ARTHROPODS); - - } else if (s.equalsIgnoreCase("Smite")) { - - enchantments.add(Enchantment.DAMAGE_UNDEAD); - - } else if (s.equalsIgnoreCase("Efficiency")) { - - enchantments.add(Enchantment.DIG_SPEED); - - } else if (s.equalsIgnoreCase("Unbreaking")) { - - enchantments.add(Enchantment.DURABILITY); - - } else if (s.equalsIgnoreCase("FireAspect")) { - - enchantments.add(Enchantment.FIRE_ASPECT); - - } else if (s.equalsIgnoreCase("Knockback")) { - - enchantments.add(Enchantment.KNOCKBACK); - - } else if (s.equalsIgnoreCase("Fortune")) { - - enchantments.add(Enchantment.LOOT_BONUS_BLOCKS); - - } else if (s.equalsIgnoreCase("Looting")) { - - enchantments.add(Enchantment.LOOT_BONUS_MOBS); - - } else if (s.equalsIgnoreCase("Respiration")) { - - enchantments.add(Enchantment.OXYGEN); - - } else if (s.equalsIgnoreCase("Protection")) { - - enchantments.add(Enchantment.PROTECTION_ENVIRONMENTAL); - - } else if (s.equalsIgnoreCase("BlastProtection")) { - - enchantments.add(Enchantment.PROTECTION_EXPLOSIONS); - - } else if (s.equalsIgnoreCase("FeatherFalling")) { - - enchantments.add(Enchantment.PROTECTION_FALL); - - } else if (s.equalsIgnoreCase("FireProtection")) { - - enchantments.add(Enchantment.PROTECTION_FIRE); - - } else if (s.equalsIgnoreCase("ProjectileProtection")) { - - enchantments.add(Enchantment.PROTECTION_PROJECTILE); - - } else if (s.equalsIgnoreCase("SilkTouch")) { - - enchantments.add(Enchantment.SILK_TOUCH); - - } else if (s.equalsIgnoreCase("AquaAffinity")) { - - enchantments.add(Enchantment.WATER_WORKER); - - } - - materials.add(Material.getMaterial(ids.get(enchantNames.indexOf(s)))); - amounts.add(enchantNames.indexOf(s)); - - } - - for (Enchantment e : enchantments) { - - Map map = new HashMap(); - map.put(e, materials.get(enchantments.indexOf(e))); - - itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e))); - - } - - } - - if (data.contains("mobs-killed")) { - - LinkedList mobs = new LinkedList(); - List amounts = data.getIntegerList("mobs-killed-amounts"); - - for (String s : data.getStringList("mobs-killed")) { - - EntityType mob = Quests.getMobType(s); - if(mob != null) - mobs.add(mob); - - mobsKilled.clear(); - mobNumKilled.clear(); - - for (EntityType e : mobs) { - - mobsKilled.add(e); - mobNumKilled.add(amounts.get(mobs.indexOf(e))); - - } - - if (data.contains("mob-kill-locations")) { - - LinkedList locations = new LinkedList(); - List radii = data.getIntegerList("mob-kill-location-radii"); - - for (String loc : data.getStringList("mob-kill-locations")) { - - String[] info = loc.split(" "); - double x = Double.parseDouble(info[1]); - double y = Double.parseDouble(info[2]); - double z = Double.parseDouble(info[3]); - Location finalLocation = new Location(plugin.getServer().getWorld(info[0]), x, y, z); - locations.add(finalLocation); - - } - - locationsToKillWithin = locations; - radiiToKillWithin.clear(); - for (int i : radii) { - radiiToKillWithin.add(i); - } - - } - - } - - } - - if (data.contains("item-delivery-amounts")) { - - List deliveryAmounts = data.getIntegerList("item-delivery-amounts"); - - for (int i = 0; i < deliveryAmounts.size(); i++) { - - itemsDelivered.put(currentStage.itemsToDeliver.get(i), deliveryAmounts.get(i)); - - } - - } - - if (data.contains("citizen-ids-to-talk-to")) { - - List ids = data.getIntegerList("citizen-ids-to-talk-to"); - List has = data.getBooleanList("has-talked-to"); - - for (int i : ids) { - - citizensInteracted.put(CitizensAPI.getNPCRegistry().getById(i), has.get(ids.indexOf(i))); - - } - - } - - if (data.contains("citizen-ids-killed")) { - - List ids = data.getIntegerList("citizen-ids-killed"); - List num = data.getIntegerList("citizen-amounts-killed"); - - for (int i : ids) { - - citizensKilled.add(CitizensAPI.getNPCRegistry().getById(i)); - citizenNumKilled.add(num.get(ids.indexOf(i))); - - } - - } - - if (data.contains("bosses-killed")) { - - List ids = data.getStringList("bosses-killed"); - List num = data.getIntegerList("boss-amounts-killed"); - - for (String s : ids) { - - bossesKilled.add(s); - bossAmountsKilled.add(num.get(ids.indexOf(s))); - - } - - } - - if (data.contains("locations-to-reach")) { - - LinkedList locations = new LinkedList(); - List has = data.getBooleanList("has-reached-location"); - List radii = data.getIntegerList("radii-to-reach-within"); - - for (String loc : data.getStringList("locations-to-reach")) { - - String[] info = loc.split(" "); - double x = Double.parseDouble(info[1]); - double y = Double.parseDouble(info[2]); - double z = Double.parseDouble(info[3]); - Location finalLocation = new Location(plugin.getServer().getWorld(info[0]), x, y, z); - locations.add(finalLocation); - - } - - locationsReached = locations; - hasReached.clear(); - radiiToReachWithin.clear(); - - for (boolean b : has) { - hasReached.add(b); - } - - for (int i : radii) { - radiiToReachWithin.add(i); - } - - } - - if (data.contains("potions-brewed-ids")) { - - List ids = data.getIntegerList("potions-brewed-ids"); - List amounts = data.getIntegerList("potions-brewed-amounts"); - - for (int i : ids) { - - potionsBrewed.put(i, amounts.get(ids.indexOf(i))); - - } - - } - - if (data.contains("mobs-to-tame")) { - - List mobs = data.getStringList("mobs-to-tame"); - List amounts = data.getIntegerList("mob-tame-amounts"); - - for (String mob : mobs) { - - if (mob.equalsIgnoreCase("Wolf")) { - - mobsTamed.put(EntityType.WOLF, amounts.get(mobs.indexOf(mob))); - - } else { - - mobsTamed.put(EntityType.OCELOT, amounts.get(mobs.indexOf(mob))); - - } - - } - - } - - if (data.contains("sheep-to-shear")) { - - List colors = data.getStringList("sheep-to-shear"); - List amounts = data.getIntegerList("sheep-sheared"); - - for (String color : colors) { - - if (color.equalsIgnoreCase("Black")) { - - sheepSheared.put(DyeColor.BLACK, amounts.get(colors.indexOf(color))); - - } else if (color.equalsIgnoreCase("Blue")) { - - sheepSheared.put(DyeColor.BLUE, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Brown")) { - - sheepSheared.put(DyeColor.BROWN, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Cyan")) { - - sheepSheared.put(DyeColor.CYAN, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Gray")) { - - sheepSheared.put(DyeColor.GRAY, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Green")) { - - sheepSheared.put(DyeColor.GREEN, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("LightBlue")) { - - sheepSheared.put(DyeColor.LIGHT_BLUE, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Lime")) { - - sheepSheared.put(DyeColor.LIME, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Magenta")) { - - sheepSheared.put(DyeColor.MAGENTA, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Orange")) { - - sheepSheared.put(DyeColor.ORANGE, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Pink")) { - - sheepSheared.put(DyeColor.PINK, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Purple")) { - - sheepSheared.put(DyeColor.PURPLE, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Red")) { - - sheepSheared.put(DyeColor.RED, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Silver")) { - - sheepSheared.put(DyeColor.SILVER, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("White")) { - - sheepSheared.put(DyeColor.WHITE, amounts.get(colors.indexOf(color))); - - } - if (color.equalsIgnoreCase("Yellow")) { - - sheepSheared.put(DyeColor.YELLOW, amounts.get(colors.indexOf(color))); - - } - - } - - } - - if (data.contains("stage-delay")) { - - delayTimeLeft = data.getLong("stage-delay"); - - } - - } - - return true; - - } - - public void startStageTimer() { - - if (delayTimeLeft > -1) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (delayTimeLeft * 0.02)); - } else { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (currentStage.delay * 0.02)); - plugin.getServer().getPlayer(name).sendMessage(Quests.parseString((currentStage.delayMessage), currentQuest)); - } - - delayStartTime = System.currentTimeMillis(); - - } - - public void stopStageTimer() { - - if (delayTimeLeft > -1) { - delayTimeLeft = delayTimeLeft - (System.currentTimeMillis() - delayStartTime); - } else { - delayTimeLeft = currentStage.delay - (System.currentTimeMillis() - delayStartTime); - } - - delayOver = false; - - } - - public long getStageTime() { - - if (delayTimeLeft > -1) { - return delayTimeLeft - (System.currentTimeMillis() - delayStartTime); - } else { - return currentStage.delay - (System.currentTimeMillis() - delayStartTime); - } - - } - - public void checkQuest() { - - if (currentQuest != null) { - - boolean exists = false; - - for (Quest q : plugin.quests) { - - if (q.name.equalsIgnoreCase(currentQuest.name)) { - - exists = true; - if (q.equals(currentQuest) == false) { - - currentStage = null; - reset(); - if (plugin.getServer().getPlayer(name) != null) { - plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " has been modified. You have been forced to quit the Quest."); - } - currentQuest = null; - - } - - break; - - } - - } - - if (exists == false) { - - currentStage = null; - reset(); - if (plugin.getServer().getPlayer(name) != null) { - plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " no longer exists. You have been forced to quit the Quest."); - } - currentQuest = null; - - } - - } - - } - - public static String checkPlacement(Inventory inv, int rawSlot) { - - if (rawSlot < 0) { - return "You may not drop Quest items."; - } - - InventoryType type = inv.getType(); - - if (type.equals(InventoryType.BREWING)) { - - if (rawSlot < 4) { - return "You may not brew using Quest items."; - } - - } else if (type.equals(InventoryType.CHEST)) { - - if (inv.getContents().length == 27) { - if (rawSlot < 27) { - return "You may not store Quest items."; - } - - } else { - if (rawSlot < 54) { - return "You may not store Quest items."; - } - - } - - } else if (type.equals(InventoryType.CRAFTING)) { - - if (rawSlot < 5) { - return "You may not craft using Quest items."; - } else if (rawSlot < 9) { - return "You may not equip Quest items."; - } - - } else if (type.equals(InventoryType.DISPENSER)) { - - if (rawSlot < 9) { - return "You may not put Quest items in dispensers."; - } - - } else if (type.equals(InventoryType.ENCHANTING)) { - - if (rawSlot == 0) { - return "You may not enchant Quest items."; - } - - } else if (type.equals(InventoryType.ENDER_CHEST)) { - - if (rawSlot < 27) { - return "You may not store Quest items."; - } - - } else if (type.equals(InventoryType.FURNACE)) { - - if (rawSlot < 3) { - return "You may not smelt using Quest items."; - } - - } else if (type.equals(InventoryType.WORKBENCH)) { - - if (rawSlot < 10) { - return "You may not craft using Quest items."; - } - - } - return null; - - } - - public static List getChangedSlots(Inventory inInv, ItemStack inNew) { - List changed = new ArrayList(); - if (inInv.contains(inNew.getType())) { - int amount = inNew.getAmount(); - HashMap items = inInv.all(inNew.getType()); - for (int i = 0; i < inInv.getSize(); i++) { - if (!items.containsKey((Integer) i)) { - continue; - } - - ItemStack item = items.get((Integer) i); - int slotamount = item.getMaxStackSize() - item.getAmount(); - if (slotamount > 1) { - if (amount > slotamount) { - int toAdd = slotamount - amount; - amount = amount - toAdd; - changed.add(i); - } else { - changed.add(i); - amount = 0; - break; - } - } - } - - if (amount > 0) { - if (inInv.firstEmpty() != -1) { - changed.add(inInv.firstEmpty()); - } - } - } else { - if (inInv.firstEmpty() != -1) { - changed.add(inInv.firstEmpty()); - } - } - return changed; - } -} +package me.blackvein.quests; + +import java.io.File; +import java.util.*; +import java.util.Map.Entry; +import me.ThaH3lper.com.LoadBosses.LoadBoss; +import me.blackvein.quests.util.ItemUtil; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.npc.NPC; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.Potion; + +public class Quester { + + String name; + boolean editorMode = false; + boolean holdingQuestItemFromStorage = false; + boolean delayOver = true; + public Quest currentQuest; + public String questToTake; + Stage currentStage; + public int currentStageIndex = 0; + int questPoints = 0; + Quests plugin; + public LinkedList completedQuests = new LinkedList(); + Map completedTimes = new HashMap(); + Map blocksDamaged = new EnumMap(Material.class); + Map blocksBroken = new EnumMap(Material.class); + Map blocksPlaced = new EnumMap(Material.class); + Map blocksUsed = new EnumMap(Material.class); + Map blocksCut = new EnumMap(Material.class); + Map potionsBrewed = new HashMap(); + Map itemsDelivered = new HashMap(); + int fishCaught = 0; + int playersKilled = 0; + long delayStartTime = 0; + long delayTimeLeft = -1; + Map playerKillTimes = new HashMap(); + Map, Integer> itemsEnchanted = new HashMap, Integer>(); + LinkedList mobsKilled = new LinkedList(); + LinkedList mobNumKilled = new LinkedList(); + LinkedList locationsToKillWithin = new LinkedList(); + LinkedList radiiToKillWithin = new LinkedList(); + Map citizensInteracted = new HashMap(); + LinkedList citizensKilled = new LinkedList(); + LinkedList citizenNumKilled = new LinkedList(); + LinkedList bossesKilled = new LinkedList(); + LinkedList bossAmountsKilled = new LinkedList(); + LinkedList locationsReached = new LinkedList(); + LinkedList hasReached = new LinkedList(); + LinkedList radiiToReachWithin = new LinkedList(); + Map mobsTamed = new EnumMap(EntityType.class); + Map sheepSheared = new EnumMap(DyeColor.class); + final Random random = new Random(); + + public Quester(Quests newPlugin) { + + plugin = newPlugin; + + } + + public Player getPlayer() { + + return plugin.getServer().getPlayerExact(name); + + } + + public void takeQuest(Quest q) { + + Player player = plugin.getServer().getPlayer(name); + + if (q.testRequirements(player) == true) { + + currentQuest = q; + currentStage = q.stages.getFirst(); + addEmpties(); + if (q.moneyReq > 0) { + Quests.economy.withdrawPlayer(name, q.moneyReq); + } + + for (ItemStack is : q.items) { + if (q.removeItems.get(q.items.indexOf(is)) == true) { + Quests.removeItem(player.getInventory(), is); + } + } + + player.sendMessage(ChatColor.GREEN + "Quest accepted: " + q.name); + player.sendMessage(""); + player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); + for (String s : getObjectives()) { + player.sendMessage(s); + } + + String stageStartMessage = currentStage.startMessage; + if (stageStartMessage != null) { + getPlayer().sendMessage(Quests.parseString(stageStartMessage, currentQuest)); + } + if(q.initialEvent != null) + q.initialEvent.happen(this); + + } else { + + player.sendMessage(q.failRequirements); + + } + + } + + public LinkedList getObjectives() { + + LinkedList unfinishedObjectives = new LinkedList(); + LinkedList finishedObjectives = new LinkedList(); + LinkedList objectives = new LinkedList(); + + for (Entry e : currentStage.blocksToDamage.entrySet()) { + + for (Entry e2 : blocksDamaged.entrySet()) { + + if (e2.getKey().equals(e.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Damage " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Damage " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Entry e : currentStage.blocksToBreak.entrySet()) { + + for (Entry e2 : blocksBroken.entrySet()) { + + if (e2.getKey().equals(e.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Break " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Break " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Entry e : currentStage.blocksToPlace.entrySet()) { + + for (Entry e2 : blocksPlaced.entrySet()) { + + if (e2.getKey().equals(e.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Place " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Entry e : currentStage.blocksToUse.entrySet()) { + + for (Entry e2 : blocksUsed.entrySet()) { + + if (e2.getKey().equals(e.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Use " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Use " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Entry e : currentStage.blocksToCut.entrySet()) { + + for (Entry e2 : blocksCut.entrySet()) { + + if (e2.getKey().equals(e.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Cut " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Cut " + Quester.prettyItemString(e2.getKey().getId()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + if (currentStage.fishToCatch != null) { + + if (fishCaught < currentStage.fishToCatch) { + + unfinishedObjectives.add(ChatColor.GREEN + "Catch Fish: " + fishCaught + "/" + currentStage.fishToCatch); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Catch Fish: " + fishCaught + "/" + currentStage.fishToCatch); + + } + + } + + 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 : currentStage.itemsToEnchant.entrySet()) { + + for (Entry, Integer> e2 : 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) { + + if (num1 < num2) { + + unfinishedObjectives.add(ChatColor.GREEN + "Enchant " + Quester.prettyItemString(mat.getId()) + " with " + Quester.prettyEnchantmentString(enchantment) + ": " + num1 + "/" + num2); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Enchant " + Quester.prettyItemString(mat.getId()) + " with " + Quester.prettyEnchantmentString(enchantment) + ": " + num1 + "/" + num2); + + } + + } + + } + + } + + for (EntityType e : currentStage.mobsToKill) { + + for (EntityType e2 : mobsKilled) { + + if (e == e2) { + + if (mobNumKilled.get(mobsKilled.indexOf(e2)) < currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e))) { + + if (currentStage.locationsToKillWithin.isEmpty()) { + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + Quester.prettyMobString(e) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); + } else { + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + Quester.prettyMobString(e) + " at " + currentStage.areaNames.get(currentStage.mobsToKill.indexOf(e)) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); + } + } else { + + if (currentStage.locationsToKillWithin.isEmpty()) { + finishedObjectives.add(ChatColor.GRAY + "Kill " + Quester.prettyMobString(e) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); + } else { + finishedObjectives.add(ChatColor.GRAY + "Kill " + Quester.prettyMobString(e) + " at " + currentStage.areaNames.get(currentStage.mobsToKill.indexOf(e)) + ": " + (mobNumKilled.get(mobsKilled.indexOf(e2))) + "/" + (currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(e)))); + } + + } + + } + + } + + } + + if (currentStage.playersToKill != null) { + + if (playersKilled < currentStage.playersToKill) { + + unfinishedObjectives.add(ChatColor.GREEN + "Kill a Player: " + playersKilled + "/" + currentStage.playersToKill); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Kill a Player: " + playersKilled + "/" + currentStage.playersToKill); + + } + + } + + for (ItemStack is : currentStage.itemsToDeliver) { + + int delivered = itemsDelivered.get(is); + int amt = is.getAmount(); + NPC npc = currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(is)); + + if (delivered < amt) { + + unfinishedObjectives.add(ChatColor.GREEN + "Deliver " + ItemUtil.getName(is) + " to " + npc.getName() + ": " + delivered + "/" + amt); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Deliver " + ItemUtil.getName(is) + " to " + npc.getName() + ": " + delivered + "/" + amt); + + } + + + } + + for (NPC n : currentStage.citizensToInteract) { + + for (Entry e : citizensInteracted.entrySet()) { + + if (e.getKey().equals(n)) { + + if ( e.getValue() == false) { + + unfinishedObjectives.add(ChatColor.GREEN + "Talk to " + n.getFullName()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Talk to " + n.getName()); + + } + + } + + } + + } + + for (NPC n : currentStage.citizensToKill) { + + for (NPC n2 : citizensKilled) { + + if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) { + + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + n.getName() + ChatColor.GREEN + " " + citizenNumKilled.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Kill " + n.getName() + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); + + } + + } + + } + + for (String boss : currentStage.bossesToKill) { + + if (bossAmountsKilled.get(bossesKilled.indexOf(boss)) < currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))) { + + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + ChatColor.ITALIC + boss + ChatColor.RESET + ChatColor.GREEN + " " + bossAmountsKilled.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))); + + } else { + + unfinishedObjectives.add(ChatColor.GRAY + "Kill " + ChatColor.ITALIC + boss + ChatColor.RESET + ChatColor.GRAY + " " + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss))); + + } + + } + + for (Entry e : currentStage.mobsToTame.entrySet()) { + + for (Entry e2 : mobsTamed.entrySet()) { + + if (e.getKey().equals(e2.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Tame " + getCapitalized(e.getKey().getName()) + ": " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Tame " + getCapitalized(e.getKey().getName()) + ": " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Entry e : currentStage.sheepToShear.entrySet()) { + + for (Entry e2 : sheepSheared.entrySet()) { + + if (e.getKey().equals(e2.getKey())) { + + if (e2.getValue() < e.getValue()) { + + unfinishedObjectives.add(ChatColor.GREEN + "Shear " + e.getKey().name().toString().toLowerCase() + " sheep: " + e2.getValue() + "/" + e.getValue()); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Shear " + e.getKey().name().toString().toLowerCase() + " sheep: " + e2.getValue() + "/" + e.getValue()); + + } + + } + + } + + } + + for (Location l : currentStage.locationsToReach) { + + for (Location l2 : locationsReached) { + + if (l.equals(l2)) { + + if (hasReached.get(locationsReached.indexOf(l2)) == false) { + + unfinishedObjectives.add(ChatColor.GREEN + "Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(l))); + + } else { + + finishedObjectives.add(ChatColor.GRAY + "Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(l))); + + } + + } + + } + + } + + objectives.addAll(unfinishedObjectives); + objectives.addAll(finishedObjectives); + + return objectives; + + } + + public boolean hasObjective(String s) { + + if (currentStage == null) { + return false; + } + + if (s.equalsIgnoreCase("damageBlock")) { + + if (currentStage.blocksToDamage.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("breakBlock")) { + + if (currentStage.blocksToBreak.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("placeBlock")) { + + if (currentStage.blocksToPlace.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("useBlock")) { + + if (currentStage.blocksToUse.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("cutBlock")) { + + if (currentStage.blocksToCut.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("catchFish")) { + + if (currentStage.fishToCatch == null) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("enchantItem")) { + + if (currentStage.itemsToEnchant.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("killMob")) { + + if (currentStage.mobsToKill.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("deliverItem")) { + + if (currentStage.itemsToDeliver.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("killPlayer")) { + + if (currentStage.playersToKill == null) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("talkToNPC")) { + + if (currentStage.citizensToInteract.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("killNPC")) { + + if (currentStage.citizensToKill.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("killBoss")) { + + if (currentStage.bossesToKill.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("tameMob")) { + + if (currentStage.mobsToTame.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("shearSheep")) { + + if (currentStage.sheepToShear.isEmpty()) { + return false; + } else { + return true; + } + + } else if (s.equalsIgnoreCase("craftItem")) { + + if (currentStage.itemsToCraft.isEmpty()) { + return false; + } else { + return true; + } + + } else { + + if (currentStage.locationsToReach.isEmpty()) { + return false; + } else { + return true; + } + + } + + } + + public void damageBlock(Material m) { + + if (blocksDamaged.containsKey(m)) { + + if (blocksDamaged.get(m) < currentStage.blocksToDamage.get(m)) { + int i = blocksDamaged.get(m); + blocksDamaged.put(m, (i + 1)); + + if (blocksDamaged.get(m).equals(currentStage.blocksToDamage.get(m))) { + finishObjective("damageBlock", m, null, null, null, null, null, null, null, null); + } + + } + + } + + } + + public void breakBlock(Material m) { + + if (blocksBroken.containsKey(m)) { + + if (blocksBroken.get(m) < currentStage.blocksToBreak.get(m)) { + int i = blocksBroken.get(m); + blocksBroken.put(m, (i + 1)); + + if (blocksBroken.get(m).equals(currentStage.blocksToBreak.get(m))) { + finishObjective("breakBlock", m, null, null, null, null, null, null, null, null); + } + } + + } + + } + + public void placeBlock(Material m) { + + if (blocksPlaced.containsKey(m)) { + + if (blocksPlaced.get(m) < currentStage.blocksToPlace.get(m)) { + int i = blocksPlaced.get(m); + blocksPlaced.put(m, (i + 1)); + + if (blocksPlaced.get(m).equals(currentStage.blocksToPlace.get(m))) { + finishObjective("placeBlock", m, null, null, null, null, null, null, null, null); + } + } + + } + + } + + public void useBlock(Material m) { + + if (blocksUsed.containsKey(m)) { + + if (blocksUsed.get(m) < currentStage.blocksToUse.get(m)) { + int i = blocksUsed.get(m); + blocksUsed.put(m, (i + 1)); + + if (blocksUsed.get(m).equals(currentStage.blocksToUse.get(m))) { + finishObjective("useBlock", m, null, null, null, null, null, null, null, null); + } + + } + + } + + } + + public void cutBlock(Material m) { + + if (blocksCut.containsKey(m)) { + + if (blocksCut.get(m) < currentStage.blocksToCut.get(m)) { + int i = blocksCut.get(m); + blocksCut.put(m, (i + 1)); + + if (blocksCut.get(m).equals(currentStage.blocksToCut.get(m))) { + finishObjective("cutBlock", m, null, null, null, null, null, null, null, null); + } + + } + + } + + } + + public void catchFish() { + + if (fishCaught < currentStage.fishToCatch) { + fishCaught++; + + if (((Integer) fishCaught).equals(currentStage.fishToCatch)) { + finishObjective("catchFish", null, null, null, null, null, null, null, null, null); + } + + } + + } + + public void enchantItem(Enchantment e, Material m) { + + for (Entry entry : itemsEnchanted.entrySet()) { + + if (((Map) entry.getKey()).containsKey(e) && ((Map) entry.getKey()).containsValue(m)) { + + for (Entry entry2 : currentStage.itemsToEnchant.entrySet()) { + + if (((Map) entry2.getKey()).containsKey(e) && ((Map) entry2.getKey()).containsValue(m)) { + + if ((Integer) entry.getValue() < (Integer) entry2.getValue()) { + + Integer num = (Integer) entry.getValue() + 1; + itemsEnchanted.put(((Map) entry.getKey()), (num)); + + if ((num).equals((Integer) entry2.getValue())) { + finishObjective("enchantItem", m, null, e, null, null, null, null, null, null); + } + + } + break; + + } + + } + + break; + + } + + } + + } + + public void killMob(Location l, EntityType e) { + + if (mobsKilled.contains(e)) { + + if (locationsToKillWithin.isEmpty() == false) { + + int index = mobsKilled.indexOf(e); + Location locationToKillWithin = locationsToKillWithin.get(index); + double radius = radiiToKillWithin.get(index); + int numKilled = mobNumKilled.get(index); + if (l.getX() < (locationToKillWithin.getX() + radius) && l.getX() > (locationToKillWithin.getX() - radius)) { + + if (l.getZ() < (locationToKillWithin.getZ() + radius) && l.getZ() > (locationToKillWithin.getZ() - radius)) { + + if (l.getY() < (locationToKillWithin.getY() + radius) && l.getY() > (locationToKillWithin.getY() - radius)) { + + if (numKilled < currentStage.mobNumToKill.get(index)) { + + Integer numKilledInteger = numKilled + 1; + + mobNumKilled.set(index, numKilledInteger); + + if ((numKilledInteger).equals(currentStage.mobNumToKill.get(index))) { + finishObjective("killMob", null, null, null, e, null, null, null, null, null); + } + + } + + } + + } + + } + + } else { + + if (mobNumKilled.get(mobsKilled.indexOf(e)) < currentStage.mobNumToKill.get(mobsKilled.indexOf(e))) { + + mobNumKilled.set(mobsKilled.indexOf(e), mobNumKilled.get(mobsKilled.indexOf(e)) + 1); + + if ((mobNumKilled.get(mobsKilled.indexOf(e))).equals(currentStage.mobNumToKill.get(mobsKilled.indexOf(e)))) { + finishObjective("killMob", null, null, null, e, null, null, null, null, null); + } + + } + + } + + } + + } + + public void killPlayer(String player) { + + if (playerKillTimes.containsKey(player)) { + + long killTime = playerKillTimes.get(player); + long comparator = plugin.killDelay * 1000; + long currentTime = System.currentTimeMillis(); + + if ((currentTime - killTime) < comparator) { + + plugin.getServer().getPlayer(name).sendMessage(ChatColor.RED + "[Quests] Kill did not count. You must wait " + ChatColor.DARK_PURPLE + Quests.getTime(comparator - (currentTime - killTime)) + ChatColor.RED + " before you can kill " + ChatColor.DARK_PURPLE + player + ChatColor.RED + " again."); + return; + + } + + } + + playerKillTimes.put(player, System.currentTimeMillis()); + + if (playersKilled < currentStage.playersToKill) { + playersKilled++; + + if (((Integer) playersKilled).equals(currentStage.playersToKill)) { + finishObjective("killPlayer", null, null, null, null, null, null, null, null, null); + } + + } + + } + + public void interactWithNPC(NPC n) { + + if (citizensInteracted.containsKey(n)) { + + if (citizensInteracted.get(n) == false) { + citizensInteracted.put(n, true); + finishObjective("talkToNPC", null, null, null, null, null, n, null, null, null); + } + + } + + } + + public void killNPC(NPC n) { + + if (citizensKilled.contains(n)) { + + int index = citizensKilled.indexOf(n); + if (citizenNumKilled.get(index) < currentStage.citizenNumToKill.get(index)) { + citizenNumKilled.set(index, citizenNumKilled.get(index) + 1); + if (citizenNumKilled.get(index) == currentStage.citizenNumToKill.get(index)) { + finishObjective("killNPC", null, null, null, null, null, n, null, null, null); + } + } + + } + + } + + public void killBoss(String boss) { + + for(String s : bossesKilled){ + + if (s.equalsIgnoreCase(boss)) { + + int index = bossesKilled.indexOf(s); + if (bossAmountsKilled.get(index) < currentStage.bossAmountsToKill.get(index)) { + bossAmountsKilled.set(index, bossAmountsKilled.get(index) + 1); + if (bossAmountsKilled.get(index) == currentStage.bossAmountsToKill.get(index)) { + finishObjective("killBoss", null, null, null, null, null, null, null, null, boss); + } + } + + } + + } + + } + + public void reachLocation(Location l) { + + for (Location location : locationsReached) { + + int index = locationsReached.indexOf(location); + Location locationToReach = currentStage.locationsToReach.get(index); + double radius = radiiToReachWithin.get(index); + if (l.getX() < (locationToReach.getX() + radius) && l.getX() > (locationToReach.getX() - radius)) { + + if (l.getZ() < (locationToReach.getZ() + radius) && l.getZ() > (locationToReach.getZ() - radius)) { + + if (l.getY() < (locationToReach.getY() + radius) && l.getY() > (locationToReach.getY() - radius)) { + + if (hasReached.get(index) == false) { + + hasReached.set(index, true); + finishObjective("reachLocation", null, null, null, null, null, null, location, null, null); + + } + + } + + } + + } + + } + + } + + public void tameMob(EntityType entity) { + + if (mobsTamed.containsKey(entity)) { + + mobsTamed.put(entity, (mobsTamed.get(entity) + 1)); + + if (mobsTamed.get(entity).equals(currentStage.mobsToTame.get(entity))) { + finishObjective("tameMob", null, null, null, entity, null, null, null, null, null); + } + + } + + } + + public void shearSheep(DyeColor color) { + + if (sheepSheared.containsKey(color)) { + + sheepSheared.put(color, (sheepSheared.get(color) + 1)); + + if (sheepSheared.get(color).equals(currentStage.sheepToShear.get(color))) { + finishObjective("shearSheep", null, null, null, null, null, null, null, color, null); + } + + } + + } + + public void deliverItem(ItemStack i) { + + Player player = plugin.getServer().getPlayer(name); + + ItemStack found = null; + + for(ItemStack is : itemsDelivered.keySet()){ + + if(ItemUtil.compareItems(i, is, true) == 0){ + found = is; + break; + } + + } + if (found != null) { + + int amount = itemsDelivered.get(found); + int req = currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(found)).getAmount(); + + if (amount < req) { + + if ((i.getAmount() + amount) > req) { + + itemsDelivered.put(found, req); + int index = player.getInventory().first(i); + i.setAmount(i.getAmount() - (req - amount)); //Take away the remaining amount needed to be delivered from the item stack + player.getInventory().setItem(index, i); + player.updateInventory(); + finishObjective("deliverItem", null, found, null, null, null, null, null, null, null); + + } else if ((i.getAmount() + amount) == req) { + + itemsDelivered.put(found, req); + player.getInventory().setItem(player.getInventory().first(i), null); + player.updateInventory(); + finishObjective("deliverItem", null, found, null, null, null, null, null, null, null); + + } else { + + itemsDelivered.put(found, (amount + i.getAmount())); + player.getInventory().setItem(player.getInventory().first(i), null); + player.updateInventory(); + String message = Quests.parseString(currentStage.deliverMessages.get(random.nextInt(currentStage.deliverMessages.size())), currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(found))); + player.sendMessage(message); + + } + + } + + } + + } + + public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color, String boss) { + + Player p = plugin.getServer().getPlayerExact(name); + + if (objective.equalsIgnoreCase("damageBlock")) { + + String message = ChatColor.GREEN + "(Completed) Damage " + prettyItemString(material.getId()); + message = message + " " + currentStage.blocksToDamage.get(material) + "/" + currentStage.blocksToDamage.get(material); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("breakBlock")) { + + String message = ChatColor.GREEN + "(Completed) Break " + prettyItemString(material.getId()); + message = message + " " + currentStage.blocksToBreak.get(material) + "/" + currentStage.blocksToBreak.get(material); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("placeBlock")) { + + String message = ChatColor.GREEN + "(Completed) Place " + prettyItemString(material.getId()); + message = message + " " + currentStage.blocksToPlace.get(material) + "/" + currentStage.blocksToPlace.get(material); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("useBlock")) { + + String message = ChatColor.GREEN + "(Completed) Use " + prettyItemString(material.getId()); + message = message + " " + currentStage.blocksToUse.get(material) + "/" + currentStage.blocksToUse.get(material); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("cutBlock")) { + + String message = ChatColor.GREEN + "(Completed) Cut " + prettyItemString(material.getId()); + message = message + " " + currentStage.blocksToCut.get(material) + "/" + currentStage.blocksToCut.get(material); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("catchFish")) { + + String message = ChatColor.GREEN + "(Completed) Catch Fish "; + message = message + " " + currentStage.fishToCatch + "/" + currentStage.fishToCatch; + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("enchantItem")) { + + String message = ChatColor.GREEN + "(Completed) Enchant " + prettyItemString(material.getId()) + " with " + Quester.prettyEnchantmentString(enchantment); + for (Map map : currentStage.itemsToEnchant.keySet()) { + + if (map.containsKey(enchantment)) { + + message = message + " " + currentStage.itemsToEnchant.get(map) + "/" + currentStage.itemsToEnchant.get(map); + break; + + } + + } + + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("deliverItem")) { + + String message = ChatColor.GREEN + "(Completed) Deliver " + ItemUtil.getString(currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(itemstack))) + " " + ItemUtil.getName(itemstack) + " to " + currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(itemstack)).getName(); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("killMob")) { + + String message = ChatColor.GREEN + "(Completed) Kill " + mob.getName(); + message = message + " " + currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(mob)) + "/" + currentStage.mobNumToKill.get(currentStage.mobsToKill.indexOf(mob)); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("killPlayer")) { + + String message = ChatColor.GREEN + "(Completed) Kill a Player"; + message = message + " " + currentStage.playersToKill + "/" + currentStage.playersToKill; + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("talkToNPC")) { + + String message = ChatColor.GREEN + "(Completed) Talk to " + npc.getName(); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("killNPC")) { + + String message = ChatColor.GREEN + "(Completed) Kill " + npc.getName(); + message = message + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("killBoss")) { + + LoadBoss b = Quests.getBoss(boss); + String message = ChatColor.GREEN + "(Completed) Kill " + ChatColor.ITALIC + b.getName() + ChatColor.RESET + ChatColor.GREEN; + message = message + " " + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)) + "/" + currentStage.bossAmountsToKill.get(currentStage.bossesToKill.indexOf(boss)); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("tameMob")) { + + String message = ChatColor.GREEN + "(Completed) Tame " + getCapitalized(mob.getName()); + message = message + " " + currentStage.mobsToTame.get(mob) + "/" + currentStage.mobsToTame.get(mob); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else if (objective.equalsIgnoreCase("shearSheep")) { + + String message = ChatColor.GREEN + "(Completed) Shear " + color.name().toString().toLowerCase() + " sheep"; + message = message + " " + currentStage.sheepToShear.get(color) + "/" + currentStage.sheepToShear.get(color); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } else { + + String message = ChatColor.GREEN + "(Completed) Go to " + currentStage.locationNames.get(currentStage.locationsToReach.indexOf(location)); + p.sendMessage(message); + if (testComplete()) { + currentQuest.nextStage(this); + } + + } + + } + + public boolean testComplete() { + + for (String s : getObjectives()) { + + if (s.contains(ChatColor.GREEN.toString())) { + return false; + } + + } + return true; + + } + + public void addEmpties() { + + if (currentStage.blocksToDamage.isEmpty() == false) { + for (Material m : currentStage.blocksToDamage.keySet()) { + + blocksDamaged.put(m, 0); + + } + } + + if (currentStage.blocksToBreak.isEmpty() == false) { + for (Material m : currentStage.blocksToBreak.keySet()) { + + blocksBroken.put(m, 0); + + } + } + + if (currentStage.blocksToPlace.isEmpty() == false) { + for (Material m : currentStage.blocksToPlace.keySet()) { + + blocksPlaced.put(m, 0); + + } + } + + if (currentStage.blocksToUse.isEmpty() == false) { + for (Material m : currentStage.blocksToUse.keySet()) { + + blocksUsed.put(m, 0); + + } + } + + if (currentStage.blocksToCut.isEmpty() == false) { + for (Material m : currentStage.blocksToCut.keySet()) { + + blocksCut.put(m, 0); + + } + } + + fishCaught = 0; + + if (currentStage.itemsToEnchant.isEmpty() == false) { + for (Entry e : currentStage.itemsToEnchant.entrySet()) { + + Map map = (Map) e.getKey(); + itemsEnchanted.put(map, 0); + + } + } + + if (currentStage.mobsToKill.isEmpty() == false) { + for (EntityType e : currentStage.mobsToKill) { + + mobsKilled.add(e); + mobNumKilled.add(0); + if (currentStage.locationsToKillWithin.isEmpty() == false) { + locationsToKillWithin.add(currentStage.locationsToKillWithin.get(mobsKilled.indexOf(e))); + } + if (currentStage.radiiToKillWithin.isEmpty() == false) { + radiiToKillWithin.add(currentStage.radiiToKillWithin.get(mobsKilled.indexOf(e))); + } + + } + } + + playersKilled = 0; + + if (currentStage.itemsToDeliver.isEmpty() == false) { + for (ItemStack is : currentStage.itemsToDeliver) { + + itemsDelivered.put(is, 0); + + } + } + + if (currentStage.citizensToInteract.isEmpty() == false) { + for (NPC n : currentStage.citizensToInteract) { + + citizensInteracted.put(n, false); + + } + } + + if (currentStage.citizensToKill.isEmpty() == false) { + for (NPC n : currentStage.citizensToKill) { + + citizensKilled.add(n); + citizenNumKilled.add(0); + + } + } + + if (currentStage.bossesToKill.isEmpty() == false) { + for (String s : currentStage.bossesToKill) { + + bossesKilled.add(s); + bossAmountsKilled.add(0); + + } + } + + if (currentStage.blocksToCut.isEmpty() == false) { + for (Material m : currentStage.blocksToCut.keySet()) { + + blocksCut.put(m, 0); + + } + } + + if (currentStage.locationsToReach.isEmpty() == false) { + for (Location l : currentStage.locationsToReach) { + + locationsReached.add(l); + hasReached.add(false); + radiiToReachWithin.add(currentStage.radiiToReachWithin.get(locationsReached.indexOf(l))); + + } + } + + if (currentStage.mobsToTame.isEmpty() == false) { + for (EntityType e : currentStage.mobsToTame.keySet()) { + + mobsTamed.put(e, 0); + + } + } + + if (currentStage.sheepToShear.isEmpty() == false) { + for (DyeColor d : currentStage.sheepToShear.keySet()) { + + sheepSheared.put(d, 0); + + } + } + + } + + public void reset() { + + blocksDamaged.clear(); + blocksBroken.clear(); + blocksPlaced.clear(); + blocksUsed.clear(); + blocksCut.clear(); + fishCaught = 0; + itemsEnchanted.clear(); + mobsKilled.clear(); + mobNumKilled.clear(); + locationsToKillWithin.clear(); + radiiToKillWithin.clear(); + playersKilled = 0; + itemsDelivered.clear(); + citizensInteracted.clear(); + citizensKilled.clear(); + citizenNumKilled.clear(); + locationsReached.clear(); + hasReached.clear(); + radiiToReachWithin.clear(); + mobsTamed.clear(); + sheepSheared.clear(); + bossesKilled.clear(); + bossAmountsKilled.clear(); + + } + + public static String getCapitalized(String target) { + String firstLetter = target.substring(0, 1); + String remainder = target.substring(1); + String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase(); + + return capitalized; + } + + public static String prettyItemString(int itemID) { + String baseString = Material.getMaterial(itemID).toString(); + String[] substrings = baseString.split("_"); + String prettyString = ""; + int size = 1; + + for (String s : substrings) { + prettyString = prettyString.concat(Quester.getCapitalized(s)); + + if (size < substrings.length) { + prettyString = prettyString.concat(" "); + } + + size++; + } + + return prettyString; + } + + public static String fullPotionString(short dv) { + + Potion potion = Potion.fromDamage(dv); + String potionName = ""; + boolean isPrimary = false; + + try { + + potionName = "Potion of " + potion.getType().getEffectType().getName(); + + } catch (NullPointerException e) { // Potion is primary + + isPrimary = true; + + if (dv == 0) { + potionName = "Water Bottle"; + } else if (dv == 16) { + potionName = "Awkward Potion"; + } else if (dv == 32) { + potionName = "Thick Potion"; + } else if (dv == 64) { + potionName = "Mundane Potion (Extended)"; + } else if (dv == 8192) { + potionName = "Mundane Potion"; + } + + } + + if (isPrimary == false) { + + if (potion.hasExtendedDuration()) { + potionName = potionName + " (Extended)"; + } else if (potion.getLevel() == 2) { + potionName = potionName + " II"; + } + + if (potion.isSplash()) { + potionName = "Splash " + potionName; + } + + } + + return potionName; + + } + + public static String prettyMobString(EntityType type) { + + String baseString = type.toString(); + String[] substrings = baseString.split("_"); + String prettyString = ""; + int size = 1; + + for (String s : substrings) { + prettyString = prettyString.concat(Quester.getCapitalized(s)); + + if (size < substrings.length) { + prettyString = prettyString.concat(" "); + } + + size++; + } + + if (type.equals((EntityType.OCELOT))) { + prettyString = "Ocelot"; + } + + return prettyString; + } + + public static String prettyString(String s) { + + String[] substrings = s.split("_"); + String prettyString = ""; + int size = 1; + + for (String sb : substrings) { + prettyString = prettyString.concat(Quester.getCapitalized(sb)); + + if (size < substrings.length) { + prettyString = prettyString.concat(" "); + } + + size++; + } + + return prettyString; + + } + + public static String prettyEnchantmentString(Enchantment e) { + + String prettyString = ""; + + if (e.equals(Enchantment.ARROW_DAMAGE)) { + prettyString = "Power"; + } else if (e.equals(Enchantment.ARROW_FIRE)) { + prettyString = "Flame"; + } else if (e.equals(Enchantment.ARROW_INFINITE)) { + prettyString = "Infinity"; + } else if (e.equals(Enchantment.ARROW_KNOCKBACK)) { + prettyString = "Punch"; + } else if (e.equals(Enchantment.DAMAGE_ALL)) { + prettyString = "Sharpness"; + } else if (e.equals(Enchantment.DAMAGE_ARTHROPODS)) { + prettyString = "Bane of Arthropods"; + } else if (e.equals(Enchantment.DAMAGE_UNDEAD)) { + prettyString = "Smite"; + } else if (e.equals(Enchantment.DIG_SPEED)) { + prettyString = "Efficiency"; + } else if (e.equals(Enchantment.DURABILITY)) { + prettyString = "Unbreaking"; + } else if (e.equals(Enchantment.FIRE_ASPECT)) { + prettyString = "Fire Aspect"; + } else if (e.equals(Enchantment.KNOCKBACK)) { + prettyString = "Knockback"; + } else if (e.equals(Enchantment.LOOT_BONUS_BLOCKS)) { + prettyString = "Fortune"; + } else if (e.equals(Enchantment.LOOT_BONUS_MOBS)) { + prettyString = "Looting"; + } else if (e.equals(Enchantment.OXYGEN)) { + prettyString = "Respiration"; + } else if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) { + prettyString = "Protection"; + } else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS)) { + prettyString = "Blast Protection"; + } else if (e.equals(Enchantment.PROTECTION_FALL)) { + prettyString = "Feather Falling"; + } else if (e.equals(Enchantment.PROTECTION_FIRE)) { + prettyString = "Fire Protection"; + } else if (e.equals(Enchantment.PROTECTION_PROJECTILE)) { + prettyString = "Projectile Protection"; + } else if (e.equals(Enchantment.SILK_TOUCH)) { + prettyString = "Silk Touch"; + } else if (e.equals(Enchantment.THORNS)) { + prettyString = "Thorns"; + } else if (e.equals(Enchantment.WATER_WORKER)) { + prettyString = "Aqua Affinity"; + } + + return prettyString; + + } + + public static String enchantmentString(Enchantment e) { + + String string = ""; + + if (e.equals(Enchantment.ARROW_DAMAGE)) { + string = "Power"; + } else if (e.equals(Enchantment.ARROW_FIRE)) { + string = "Flame"; + } else if (e.equals(Enchantment.ARROW_INFINITE)) { + string = "Infinity"; + } else if (e.equals(Enchantment.ARROW_KNOCKBACK)) { + string = "Punch"; + } else if (e.equals(Enchantment.DAMAGE_ALL)) { + string = "Sharpness"; + } else if (e.equals(Enchantment.DAMAGE_ARTHROPODS)) { + string = "BaneOfArthropods"; + } else if (e.equals(Enchantment.DAMAGE_UNDEAD)) { + string = "Smite"; + } else if (e.equals(Enchantment.DIG_SPEED)) { + string = "Efficiency"; + } else if (e.equals(Enchantment.DURABILITY)) { + string = "Unbreaking"; + } else if (e.equals(Enchantment.FIRE_ASPECT)) { + string = "FireAspect"; + } else if (e.equals(Enchantment.KNOCKBACK)) { + string = "Knockback"; + } else if (e.equals(Enchantment.LOOT_BONUS_BLOCKS)) { + string = "Fortune"; + } else if (e.equals(Enchantment.LOOT_BONUS_MOBS)) { + string = "Looting"; + } else if (e.equals(Enchantment.OXYGEN)) { + string = "Respiration"; + } else if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) { + string = "Protection"; + } else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS)) { + string = "BlastProtection"; + } else if (e.equals(Enchantment.PROTECTION_FALL)) { + string = "FeatherFalling"; + } else if (e.equals(Enchantment.PROTECTION_FIRE)) { + string = "FireProtection"; + } else if (e.equals(Enchantment.PROTECTION_PROJECTILE)) { + string = "ProjectileProtection"; + } else if (e.equals(Enchantment.SILK_TOUCH)) { + string = "SilkTouch"; + } else if (e.equals(Enchantment.THORNS)) { + string = "Thorns"; + } else if (e.equals(Enchantment.WATER_WORKER)) { + string = "AquaAffinity"; + } + + return string; + + } + + public static String prettyColorString(DyeColor color) { + + if (color.equals(DyeColor.BLACK)) { + return "Black"; + } else if (color.equals(DyeColor.BLUE)) { + return "Blue"; + } else if (color.equals(DyeColor.BROWN)) { + return "Brown"; + } else if (color.equals(DyeColor.CYAN)) { + return "Cyan"; + } else if (color.equals(DyeColor.GRAY)) { + return "Gray"; + } else if (color.equals(DyeColor.GREEN)) { + return "Green"; + } else if (color.equals(DyeColor.LIGHT_BLUE)) { + return "LightBlue"; + } else if (color.equals(DyeColor.LIME)) { + return "Lime"; + } else if (color.equals(DyeColor.MAGENTA)) { + return "Magenta"; + } else if (color.equals(DyeColor.ORANGE)) { + return "Orange"; + } else if (color.equals(DyeColor.PINK)) { + return "Pink"; + } else if (color.equals(DyeColor.PURPLE)) { + return "Purple"; + } else if (color.equals(DyeColor.RED)) { + return "Red"; + } else if (color.equals(DyeColor.SILVER)) { + return "Silver"; + } else if (color.equals(DyeColor.WHITE)) { + return "White"; + } else { + return "Yellow"; + } + + } + + public void saveData() { + + FileConfiguration data = getBaseData(); + try { + data.save(new File(plugin.getDataFolder(), "data/" + name + ".yml")); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public long getDifference(Quest q) { + + long currentTime = System.currentTimeMillis(); + long lastTime; + if (completedTimes.containsKey(q.name) == false) { + lastTime = System.currentTimeMillis(); + completedTimes.put(q.name, System.currentTimeMillis()); + } else { + lastTime = completedTimes.get(q.name); + } + long comparator = q.redoDelay; + long difference = (comparator - (currentTime - lastTime)); + + return difference; + + + } + + public FileConfiguration getBaseData() { + + FileConfiguration data = new YamlConfiguration(); + + if (completedTimes.isEmpty() == false) { + + List questTimeNames = new LinkedList(); + List questTimes = new LinkedList(); + + for (String s : completedTimes.keySet()) { + + questTimeNames.add(s); + questTimes.add(completedTimes.get(s)); + + } + + data.set("completedRedoableQuests", questTimeNames); + data.set("completedQuestTimes", questTimes); + + } + + if (currentQuest != null) { + + data.set("currentQuest", currentQuest.name); + data.set("currentStage", currentStageIndex); + data.set("quest-points", questPoints); + + if (blocksDamaged.isEmpty() == false) { + + LinkedList blockIds = new LinkedList(); + LinkedList blockAmounts = new LinkedList(); + + for (Material m : blocksDamaged.keySet()) { + blockIds.add(m.getId()); + blockAmounts.add(blocksDamaged.get(m)); + } + + data.set("blocks-damaged-ids", blockIds); + data.set("blocks-damaged-amounts", blockAmounts); + + } + + if (blocksBroken.isEmpty() == false) { + + LinkedList blockIds = new LinkedList(); + LinkedList blockAmounts = new LinkedList(); + + for (Material m : blocksBroken.keySet()) { + blockIds.add(m.getId()); + blockAmounts.add(blocksBroken.get(m)); + } + + data.set("blocks-broken-ids", blockIds); + data.set("blocks-broken-amounts", blockAmounts); + + } + + if (blocksPlaced.isEmpty() == false) { + + LinkedList blockIds = new LinkedList(); + LinkedList blockAmounts = new LinkedList(); + + for (Material m : blocksPlaced.keySet()) { + blockIds.add(m.getId()); + blockAmounts.add(blocksPlaced.get(m)); + } + + data.set("blocks-placed-ids", blockIds); + data.set("blocks-placed-amounts", blockAmounts); + + } + + if (blocksUsed.isEmpty() == false) { + + LinkedList blockIds = new LinkedList(); + LinkedList blockAmounts = new LinkedList(); + + for (Material m : blocksUsed.keySet()) { + blockIds.add(m.getId()); + blockAmounts.add(blocksUsed.get(m)); + } + + data.set("blocks-used-ids", blockIds); + data.set("blocks-used-amounts", blockAmounts); + + } + + if (blocksCut.isEmpty() == false) { + + LinkedList blockIds = new LinkedList(); + LinkedList blockAmounts = new LinkedList(); + + for (Material m : blocksCut.keySet()) { + blockIds.add(m.getId()); + blockAmounts.add(blocksCut.get(m)); + } + + data.set("blocks-cut-ids", blockIds); + data.set("blocks-cut-amounts", blockAmounts); + + } + + if (currentStage.fishToCatch != null) { + data.set("fish-caught", fishCaught); + } + + if (currentStage.playersToKill != null) { + data.set("players-killed", playersKilled); + } + + if (itemsEnchanted.isEmpty() == false) { + + LinkedList enchantments = new LinkedList(); + LinkedList itemIds = new LinkedList(); + LinkedList enchAmounts = new LinkedList(); + + for (Entry e : itemsEnchanted.entrySet()) { + + Map enchMap = (Map) e.getKey(); + enchAmounts.add(itemsEnchanted.get(enchMap)); + for (Entry e2 : enchMap.entrySet()) { + + enchantments.add(Quester.prettyEnchantmentString((Enchantment) e2.getKey())); + itemIds.add(((Material) e2.getValue()).getId()); + + } + + + } + + data.set("enchantments", enchantments); + data.set("enchantment-item-ids", itemIds); + data.set("times-enchanted", enchAmounts); + + } + + if (mobsKilled.isEmpty() == false) { + + LinkedList mobNames = new LinkedList(); + LinkedList mobAmounts = new LinkedList(); + LinkedList locations = new LinkedList(); + LinkedList radii = new LinkedList(); + + for (EntityType e : mobsKilled) { + + mobNames.add(Quester.prettyMobString(e)); + + } + + for (int i : mobNumKilled) { + + mobAmounts.add(i); + + } + + data.set("mobs-killed", mobNames); + data.set("mobs-killed-amounts", mobAmounts); + + if (locationsToKillWithin.isEmpty() == false) { + + for (Location l : locationsToKillWithin) { + + locations.add(l.getWorld().getName() + " " + l.getX() + " " + l.getY() + " " + l.getZ()); + + } + + for (int i : radiiToKillWithin) { + + radii.add(i); + + } + + data.set("mob-kill-locations", locations); + data.set("mob-kill-location-radii", radii); + + } + + } + + if (itemsDelivered.isEmpty() == false) { + + LinkedList deliveryAmounts = new LinkedList(); + + for (Entry e : itemsDelivered.entrySet()) { + + deliveryAmounts.add(e.getValue()); + + } + + data.set("item-delivery-amounts", deliveryAmounts); + + } + + if (citizensInteracted.isEmpty() == false) { + + LinkedList npcIds = new LinkedList(); + LinkedList hasTalked = new LinkedList(); + + for (NPC n : citizensInteracted.keySet()) { + + npcIds.add(n.getId()); + hasTalked.add(citizensInteracted.get(n)); + + } + + data.set("citizen-ids-to-talk-to", npcIds); + data.set("has-talked-to", hasTalked); + + } + + if (citizensKilled.isEmpty() == false) { + + LinkedList npcIds = new LinkedList(); + + for (NPC n : citizensKilled) { + + npcIds.add(n.getId()); + + } + + data.set("citizen-ids-killed", npcIds); + data.set("citizen-amounts-killed", citizenNumKilled); + + } + + if (bossesKilled.isEmpty() == false) { + + data.set("bosses-killed", bossesKilled); + data.set("boss-amounts-killed", bossAmountsKilled); + + } + + if (locationsReached.isEmpty() == false) { + + LinkedList locations = new LinkedList(); + LinkedList has = new LinkedList(); + LinkedList radii = new LinkedList(); + + for (Location l : locationsReached) { + + locations.add(l.getWorld().getName() + " " + l.getX() + " " + l.getY() + " " + l.getZ()); + + } + + for (boolean b : hasReached) { + has.add(b); + } + + for (int i : radiiToReachWithin) { + radii.add(i); + } + + data.set("locations-to-reach", locations); + data.set("has-reached-location", has); + data.set("radii-to-reach-within", radii); + + } + + if (potionsBrewed.isEmpty() == false) { + + LinkedList potionIds = new LinkedList(); + LinkedList potionAmounts = new LinkedList(); + + for (Entry entry : potionsBrewed.entrySet()) { + + potionIds.add((Integer) entry.getKey()); + potionAmounts.add((Integer) entry.getValue()); + + } + + data.set("potions-brewed-ids", potionIds); + data.set("potions-brewed-amounts", potionAmounts); + + } + + if (mobsTamed.isEmpty() == false) { + + LinkedList mobNames = new LinkedList(); + LinkedList mobAmounts = new LinkedList(); + + for (EntityType e : mobsTamed.keySet()) { + + mobNames.add(Quester.prettyMobString(e)); + mobAmounts.add(mobsTamed.get(e)); + + } + + data.set("mobs-to-tame", mobNames); + data.set("mob-tame-amounts", mobAmounts); + + } + + if (sheepSheared.isEmpty() == false) { + + LinkedList colors = new LinkedList(); + LinkedList shearAmounts = new LinkedList(); + + for (DyeColor d : sheepSheared.keySet()) { + + colors.add(Quester.prettyColorString(d)); + shearAmounts.add(sheepSheared.get(d)); + + } + + data.set("sheep-to-shear", colors); + data.set("sheep-sheared", shearAmounts); + + } + + if (delayTimeLeft > 0) { + data.set("stage-delay", delayTimeLeft); + } + + + } else { + + data.set("currentQuest", "none"); + data.set("currentStage", "none"); + data.set("quest-points", questPoints); + + } + + if (completedQuests.isEmpty()) { + + data.set("completed-Quests", "none"); + + } else { + + String[] completed = new String[completedQuests.size()]; + for (String s : completedQuests) { + + completed[completedQuests.indexOf(s)] = s; + + } + data.set("completed-Quests", completed); + + } + + return data; + + } + + public boolean loadData() { + + FileConfiguration data = new YamlConfiguration(); + try { + data.load(new File(plugin.getDataFolder(), "data/" + name + ".yml")); + } catch (Exception e) { + return false; + } + + if (data.contains("completedRedoableQuests")) { + + for (String s : data.getStringList("completedRedoableQuests")) { + + for (Object o : data.getList("completedQuestTimes")) { + + for (Quest q : plugin.quests) { + + if (q.name.equalsIgnoreCase(s)) { + completedTimes.put(q.name, (Long) o); + break; + } + + } + + } + + } + + } + + questPoints = data.getInt("quest-points"); + + if (data.isList("completed-Quests")) { + + for (String s : data.getStringList("completed-Quests")) { + + for (Quest q : plugin.quests) { + + if (q.name.equalsIgnoreCase(s)) { + completedQuests.add(q.name); + break; + } + + } + + } + + } else { + completedQuests.clear(); + } + + if (data.getString("currentQuest").equalsIgnoreCase("none") == false) { + + Quest quest = null; + Stage stage = null; + + for (Quest q : plugin.quests) { + + if (q.name.equalsIgnoreCase(data.getString("currentQuest"))) { + quest = q; + break; + } + + } + + if (quest == null) { + return true; + } + + int stageIndex = data.getInt("currentStage"); + + for (Stage s : quest.stages) { + + if (quest.stages.indexOf(s) == (stageIndex)) { + stage = s; + break; + } + + } + + currentQuest = quest; + currentStage = stage; + + addEmpties(); + + if (data.contains("blocks-damaged-ids")) { + + List ids = data.getIntegerList("blocks-damaged-ids"); + List amounts = data.getIntegerList("blocks-damaged-amounts"); + + for (int i : ids) { + + blocksDamaged.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("blocks-broken-ids")) { + + List ids = data.getIntegerList("blocks-broken-ids"); + List amounts = data.getIntegerList("blocks-broken-amounts"); + + for (int i : ids) { + + blocksBroken.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("blocks-placed-ids")) { + + List ids = data.getIntegerList("blocks-placed-ids"); + List amounts = data.getIntegerList("blocks-placed-amounts"); + + for (int i : ids) { + + blocksPlaced.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("blocks-used-ids")) { + + List ids = data.getIntegerList("blocks-used-ids"); + List amounts = data.getIntegerList("blocks-used-amounts"); + + for (int i : ids) { + + blocksUsed.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("blocks-cut-ids")) { + + List ids = data.getIntegerList("blocks-cut-ids"); + List amounts = data.getIntegerList("blocks-cut-amounts"); + + for (int i : ids) { + + blocksCut.put(Material.getMaterial(i), amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("fish-caught")) { + fishCaught = data.getInt("fish-caught"); + } + + if (data.contains("players-killed")) { + + playersKilled = data.getInt("players-killed"); + + List playerNames = data.getStringList("player-killed-names"); + List killTimes = data.getLongList("kill-times"); + + for (String s : playerNames) { + + playerKillTimes.put(s, killTimes.get(playerNames.indexOf(s))); + + } + + } + + if (data.contains("enchantments")) { + + LinkedList enchantments = new LinkedList(); + LinkedList materials = new LinkedList(); + LinkedList amounts = new LinkedList(); + + List enchantNames = data.getStringList("enchantments"); + List ids = data.getIntegerList("enchantment-item-ids"); + + for (String s : enchantNames) { + + if (s.equalsIgnoreCase("Power")) { + + enchantments.add(Enchantment.ARROW_DAMAGE); + + } else if (s.equalsIgnoreCase("Flame")) { + + enchantments.add(Enchantment.ARROW_FIRE); + + } else if (s.equalsIgnoreCase("Infinity")) { + + enchantments.add(Enchantment.ARROW_INFINITE); + + } else if (s.equalsIgnoreCase("Punch")) { + + enchantments.add(Enchantment.ARROW_KNOCKBACK); + + } else if (s.equalsIgnoreCase("Sharpness")) { + + enchantments.add(Enchantment.DAMAGE_ALL); + + } else if (s.equalsIgnoreCase("BaneOfArthropods")) { + + enchantments.add(Enchantment.DAMAGE_ARTHROPODS); + + } else if (s.equalsIgnoreCase("Smite")) { + + enchantments.add(Enchantment.DAMAGE_UNDEAD); + + } else if (s.equalsIgnoreCase("Efficiency")) { + + enchantments.add(Enchantment.DIG_SPEED); + + } else if (s.equalsIgnoreCase("Unbreaking")) { + + enchantments.add(Enchantment.DURABILITY); + + } else if (s.equalsIgnoreCase("FireAspect")) { + + enchantments.add(Enchantment.FIRE_ASPECT); + + } else if (s.equalsIgnoreCase("Knockback")) { + + enchantments.add(Enchantment.KNOCKBACK); + + } else if (s.equalsIgnoreCase("Fortune")) { + + enchantments.add(Enchantment.LOOT_BONUS_BLOCKS); + + } else if (s.equalsIgnoreCase("Looting")) { + + enchantments.add(Enchantment.LOOT_BONUS_MOBS); + + } else if (s.equalsIgnoreCase("Respiration")) { + + enchantments.add(Enchantment.OXYGEN); + + } else if (s.equalsIgnoreCase("Protection")) { + + enchantments.add(Enchantment.PROTECTION_ENVIRONMENTAL); + + } else if (s.equalsIgnoreCase("BlastProtection")) { + + enchantments.add(Enchantment.PROTECTION_EXPLOSIONS); + + } else if (s.equalsIgnoreCase("FeatherFalling")) { + + enchantments.add(Enchantment.PROTECTION_FALL); + + } else if (s.equalsIgnoreCase("FireProtection")) { + + enchantments.add(Enchantment.PROTECTION_FIRE); + + } else if (s.equalsIgnoreCase("ProjectileProtection")) { + + enchantments.add(Enchantment.PROTECTION_PROJECTILE); + + } else if (s.equalsIgnoreCase("SilkTouch")) { + + enchantments.add(Enchantment.SILK_TOUCH); + + } else if (s.equalsIgnoreCase("AquaAffinity")) { + + enchantments.add(Enchantment.WATER_WORKER); + + } + + materials.add(Material.getMaterial(ids.get(enchantNames.indexOf(s)))); + amounts.add(enchantNames.indexOf(s)); + + } + + for (Enchantment e : enchantments) { + + Map map = new HashMap(); + map.put(e, materials.get(enchantments.indexOf(e))); + + itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e))); + + } + + } + + if (data.contains("mobs-killed")) { + + LinkedList mobs = new LinkedList(); + List amounts = data.getIntegerList("mobs-killed-amounts"); + + for (String s : data.getStringList("mobs-killed")) { + + EntityType mob = Quests.getMobType(s); + if(mob != null) + mobs.add(mob); + + mobsKilled.clear(); + mobNumKilled.clear(); + + for (EntityType e : mobs) { + + mobsKilled.add(e); + mobNumKilled.add(amounts.get(mobs.indexOf(e))); + + } + + if (data.contains("mob-kill-locations")) { + + LinkedList locations = new LinkedList(); + List radii = data.getIntegerList("mob-kill-location-radii"); + + for (String loc : data.getStringList("mob-kill-locations")) { + + String[] info = loc.split(" "); + double x = Double.parseDouble(info[1]); + double y = Double.parseDouble(info[2]); + double z = Double.parseDouble(info[3]); + Location finalLocation = new Location(plugin.getServer().getWorld(info[0]), x, y, z); + locations.add(finalLocation); + + } + + locationsToKillWithin = locations; + radiiToKillWithin.clear(); + for (int i : radii) { + radiiToKillWithin.add(i); + } + + } + + } + + } + + if (data.contains("item-delivery-amounts")) { + + List deliveryAmounts = data.getIntegerList("item-delivery-amounts"); + + for (int i = 0; i < deliveryAmounts.size(); i++) { + + itemsDelivered.put(currentStage.itemsToDeliver.get(i), deliveryAmounts.get(i)); + + } + + } + + if (data.contains("citizen-ids-to-talk-to")) { + + List ids = data.getIntegerList("citizen-ids-to-talk-to"); + List has = data.getBooleanList("has-talked-to"); + + for (int i : ids) { + + citizensInteracted.put(CitizensAPI.getNPCRegistry().getById(i), has.get(ids.indexOf(i))); + + } + + } + + if (data.contains("citizen-ids-killed")) { + + List ids = data.getIntegerList("citizen-ids-killed"); + List num = data.getIntegerList("citizen-amounts-killed"); + + for (int i : ids) { + + citizensKilled.add(CitizensAPI.getNPCRegistry().getById(i)); + citizenNumKilled.add(num.get(ids.indexOf(i))); + + } + + } + + if (data.contains("bosses-killed")) { + + List ids = data.getStringList("bosses-killed"); + List num = data.getIntegerList("boss-amounts-killed"); + + for (String s : ids) { + + bossesKilled.add(s); + bossAmountsKilled.add(num.get(ids.indexOf(s))); + + } + + } + + if (data.contains("locations-to-reach")) { + + LinkedList locations = new LinkedList(); + List has = data.getBooleanList("has-reached-location"); + List radii = data.getIntegerList("radii-to-reach-within"); + + for (String loc : data.getStringList("locations-to-reach")) { + + String[] info = loc.split(" "); + double x = Double.parseDouble(info[1]); + double y = Double.parseDouble(info[2]); + double z = Double.parseDouble(info[3]); + Location finalLocation = new Location(plugin.getServer().getWorld(info[0]), x, y, z); + locations.add(finalLocation); + + } + + locationsReached = locations; + hasReached.clear(); + radiiToReachWithin.clear(); + + for (boolean b : has) { + hasReached.add(b); + } + + for (int i : radii) { + radiiToReachWithin.add(i); + } + + } + + if (data.contains("potions-brewed-ids")) { + + List ids = data.getIntegerList("potions-brewed-ids"); + List amounts = data.getIntegerList("potions-brewed-amounts"); + + for (int i : ids) { + + potionsBrewed.put(i, amounts.get(ids.indexOf(i))); + + } + + } + + if (data.contains("mobs-to-tame")) { + + List mobs = data.getStringList("mobs-to-tame"); + List amounts = data.getIntegerList("mob-tame-amounts"); + + for (String mob : mobs) { + + if (mob.equalsIgnoreCase("Wolf")) { + + mobsTamed.put(EntityType.WOLF, amounts.get(mobs.indexOf(mob))); + + } else { + + mobsTamed.put(EntityType.OCELOT, amounts.get(mobs.indexOf(mob))); + + } + + } + + } + + if (data.contains("sheep-to-shear")) { + + List colors = data.getStringList("sheep-to-shear"); + List amounts = data.getIntegerList("sheep-sheared"); + + for (String color : colors) { + + if (color.equalsIgnoreCase("Black")) { + + sheepSheared.put(DyeColor.BLACK, amounts.get(colors.indexOf(color))); + + } else if (color.equalsIgnoreCase("Blue")) { + + sheepSheared.put(DyeColor.BLUE, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Brown")) { + + sheepSheared.put(DyeColor.BROWN, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Cyan")) { + + sheepSheared.put(DyeColor.CYAN, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Gray")) { + + sheepSheared.put(DyeColor.GRAY, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Green")) { + + sheepSheared.put(DyeColor.GREEN, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("LightBlue")) { + + sheepSheared.put(DyeColor.LIGHT_BLUE, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Lime")) { + + sheepSheared.put(DyeColor.LIME, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Magenta")) { + + sheepSheared.put(DyeColor.MAGENTA, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Orange")) { + + sheepSheared.put(DyeColor.ORANGE, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Pink")) { + + sheepSheared.put(DyeColor.PINK, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Purple")) { + + sheepSheared.put(DyeColor.PURPLE, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Red")) { + + sheepSheared.put(DyeColor.RED, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Silver")) { + + sheepSheared.put(DyeColor.SILVER, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("White")) { + + sheepSheared.put(DyeColor.WHITE, amounts.get(colors.indexOf(color))); + + } + if (color.equalsIgnoreCase("Yellow")) { + + sheepSheared.put(DyeColor.YELLOW, amounts.get(colors.indexOf(color))); + + } + + } + + } + + if (data.contains("stage-delay")) { + + delayTimeLeft = data.getLong("stage-delay"); + + } + + } + + return true; + + } + + public void startStageTimer() { + + if (delayTimeLeft > -1) { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (delayTimeLeft * 0.02)); + } else { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new StageTimer(plugin, this), (long) (currentStage.delay * 0.02)); + plugin.getServer().getPlayer(name).sendMessage(Quests.parseString((currentStage.delayMessage), currentQuest)); + } + + delayStartTime = System.currentTimeMillis(); + + } + + public void stopStageTimer() { + + if (delayTimeLeft > -1) { + delayTimeLeft = delayTimeLeft - (System.currentTimeMillis() - delayStartTime); + } else { + delayTimeLeft = currentStage.delay - (System.currentTimeMillis() - delayStartTime); + } + + delayOver = false; + + } + + public long getStageTime() { + + if (delayTimeLeft > -1) { + return delayTimeLeft - (System.currentTimeMillis() - delayStartTime); + } else { + return currentStage.delay - (System.currentTimeMillis() - delayStartTime); + } + + } + + public void checkQuest() { + + if (currentQuest != null) { + + boolean exists = false; + + for (Quest q : plugin.quests) { + + if (q.name.equalsIgnoreCase(currentQuest.name)) { + + exists = true; + if (q.equals(currentQuest) == false) { + + currentStage = null; + reset(); + if (plugin.getServer().getPlayer(name) != null) { + plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " has been modified. You have been forced to quit the Quest."); + } + currentQuest = null; + + } + + break; + + } + + } + + if (exists == false) { + + currentStage = null; + reset(); + if (plugin.getServer().getPlayer(name) != null) { + plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " no longer exists. You have been forced to quit the Quest."); + } + currentQuest = null; + + } + + } + + } + + public static String checkPlacement(Inventory inv, int rawSlot) { + + if (rawSlot < 0) { + return "You may not drop Quest items."; + } + + InventoryType type = inv.getType(); + + if (type.equals(InventoryType.BREWING)) { + + if (rawSlot < 4) { + return "You may not brew using Quest items."; + } + + } else if (type.equals(InventoryType.CHEST)) { + + if (inv.getContents().length == 27) { + if (rawSlot < 27) { + return "You may not store Quest items."; + } + + } else { + if (rawSlot < 54) { + return "You may not store Quest items."; + } + + } + + } else if (type.equals(InventoryType.CRAFTING)) { + + if (rawSlot < 5) { + return "You may not craft using Quest items."; + } else if (rawSlot < 9) { + return "You may not equip Quest items."; + } + + } else if (type.equals(InventoryType.DISPENSER)) { + + if (rawSlot < 9) { + return "You may not put Quest items in dispensers."; + } + + } else if (type.equals(InventoryType.ENCHANTING)) { + + if (rawSlot == 0) { + return "You may not enchant Quest items."; + } + + } else if (type.equals(InventoryType.ENDER_CHEST)) { + + if (rawSlot < 27) { + return "You may not store Quest items."; + } + + } else if (type.equals(InventoryType.FURNACE)) { + + if (rawSlot < 3) { + return "You may not smelt using Quest items."; + } + + } else if (type.equals(InventoryType.WORKBENCH)) { + + if (rawSlot < 10) { + return "You may not craft using Quest items."; + } + + } + return null; + + } + + public static List getChangedSlots(Inventory inInv, ItemStack inNew) { + List changed = new ArrayList(); + if (inInv.contains(inNew.getType())) { + int amount = inNew.getAmount(); + HashMap items = inInv.all(inNew.getType()); + for (int i = 0; i < inInv.getSize(); i++) { + if (!items.containsKey((Integer) i)) { + continue; + } + + ItemStack item = items.get((Integer) i); + int slotamount = item.getMaxStackSize() - item.getAmount(); + if (slotamount > 1) { + if (amount > slotamount) { + int toAdd = slotamount - amount; + amount = amount - toAdd; + changed.add(i); + } else { + changed.add(i); + amount = 0; + break; + } + } + } + + if (amount > 0) { + if (inInv.firstEmpty() != -1) { + changed.add(inInv.firstEmpty()); + } + } + } else { + if (inInv.firstEmpty() != -1) { + changed.add(inInv.firstEmpty()); + } + } + return changed; + } +}