diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index 8c2c37d18..04a76d5a7 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -1,3443 +1,3443 @@ -package me.blackvein.quests; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import me.blackvein.quests.util.MiscUtil; -import net.citizensnpcs.api.npc.NPC; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.DyeColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.potion.Potion; - -public class Quester { - - UUID id; - boolean editorMode = false; - boolean hasJournal = false; - - public String questToTake; - public ConcurrentHashMap currentQuests = new ConcurrentHashMap() { - - private static final long serialVersionUID = 6361484975823846780L; - - @Override - public Integer put(Quest key, Integer val) { - Integer data = super.put(key, val); - updateJournal(); - return data; - } - - @Override - public Integer remove(Object key) { - Integer i = super.remove(key); - updateJournal(); - return i; - } - - @Override - public void clear() { - super.clear(); - updateJournal(); - } - - @Override - public void putAll(Map m) { - super.putAll(m); - updateJournal(); - } - - }; - - int questPoints = 0; - Quests plugin; - public LinkedList completedQuests = new LinkedList() { - - private static final long serialVersionUID = -269110128568487000L; - - @Override - public boolean add(String e) { - boolean b = super.add(e); - updateJournal(); - return b; - } - - @Override - public void add(int index, String element) { - super.add(index, element); - updateJournal(); - } - - @Override - public boolean addAll(Collection c) { - boolean b = super.addAll(c); - updateJournal(); - return b; - } - - @Override - public boolean addAll(int index, Collection c) { - boolean b = super.addAll(index, c); - updateJournal(); - return b; - } - - @Override - public void clear() { - super.clear(); - updateJournal(); - } - - @Override - public boolean remove(Object o) { - boolean b = super.remove(o); - updateJournal(); - return b; - } - - @Override - public String remove(int index) { - String s = super.remove(index); - updateJournal(); - return s; - } - - @Override - public String set(int index, String element) { - String s = super.set(index, element); - updateJournal(); - return s; - } - - }; - - Map completedTimes = new HashMap(); - - Map amountsCompleted = new HashMap() { - - private static final long serialVersionUID = 5475202358792520975L; - - /*@SuppressWarnings("unused") - public void hardClear() { - super.clear(); - }*/ - - @Override - public Integer put(String key, Integer val) { - Integer data = super.put(key, val); - updateJournal(); - return data; - } - - @Override - public Integer remove(Object key) { - Integer i = super.remove(key); - updateJournal(); - return i; - } - - @Override - public void clear() { - super.clear(); - updateJournal(); - } - - @Override - public void putAll(Map m) { - super.putAll(m); - updateJournal(); - } - - }; - - - Map questData = new HashMap() { - - private static final long serialVersionUID = -4607112433003926066L; - - @Override - public QuestData put(Quest key, QuestData val) { - QuestData data = super.put(key, val); - updateJournal(); - return data; - } - - @Override - public QuestData remove(Object key) { - QuestData data = super.remove(key); - updateJournal(); - return data; - } - - @Override - public void clear() { - super.clear(); - updateJournal(); - } - - @Override - public void putAll(Map m) { - super.putAll(m); - updateJournal(); - } - - }; - - final Random random = new Random(); - - public Quester(Quests newPlugin) { - - plugin = newPlugin; - - } - - public Player getPlayer() { - - return Bukkit.getServer().getPlayer(id); - - } - - public OfflinePlayer getOfflinePlayer() { - - return Bukkit.getServer().getOfflinePlayer(id); - - } - - public void updateJournal() { - - if(!hasJournal) - return; - - Inventory inv = getPlayer().getInventory(); - ItemStack[] arr = inv.getContents(); - int index = -1; - - for(int i = 0; i < arr.length; i++) { - - if(arr[i] != null) { - - if(ItemUtil.isJournal(arr[i])) { - index = i; - break; - } - - } - - } - - if(index != -1) { - - ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - - BookMeta book = (BookMeta) meta; - book.setTitle(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - book.setAuthor(getPlayer().getName()); - - if(currentQuests.isEmpty()) { - - book.addPage(ChatColor.DARK_RED + Lang.get("journalNoQuests")); - - } else { - - int currentLength = 0; - int currentLines = 0; - String page = ""; - - for(Quest quest : currentQuests.keySet()) { - - if((currentLength + quest.name.length() > 240) || (currentLines + ((quest.name.length() % 19) == 0 ? (quest.name.length() / 19) : ((quest.name.length() / 19) + 1))) > 13) { - - book.addPage(page); - page += ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + quest.name + "\n"; - currentLength = quest.name.length(); - currentLines = (quest.name.length() % 19) == 0 ? (quest.name.length() / 19) : (quest.name.length() + 1); - - } else { - - page += ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + quest.name + "\n"; - currentLength += quest.name.length(); - currentLines += (quest.name.length() / 19); - - } - - for(String obj : getObjectivesReal(quest)) { - - //Length/Line check - if((currentLength + obj.length() > 240) || (currentLines + ((obj.length() % 19) == 0 ? (obj.length() / 19) : ((obj.length() / 19) + 1))) > 13) { - book.addPage(page); - page = obj + "\n"; - currentLength = obj.length(); - currentLines = (obj.length() % 19) == 0 ? (obj.length() / 19) : (obj.length() + 1); - } else { - page += obj + "\n"; - currentLength += obj.length(); - currentLines += (obj.length() / 19); - } - - } - - if(currentLines < 13) - page += "\n"; - - book.addPage(page); - page = ""; - currentLines = 0; - currentLength = 0; - - } - - } - - stack.setItemMeta(book); - inv.setItem(index, stack); - - } - - } - - public Stage getCurrentStage(Quest quest) { - if (currentQuests.containsKey(quest)) { - return quest.getStage(currentQuests.get(quest)); - } - return null; - } - - public QuestData getQuestData(Quest quest) { - if (questData.containsKey(quest)) { - return questData.get(quest); - } - return null; - } - - public void takeQuest(Quest q, boolean override) { - - Player player = getPlayer(); - - if (q.testRequirements(player) == true || override) { - - addEmpties(q); - currentQuests.put(q, 0); - Stage stage = q.getStage(0); - - if (!override) { - - if (q.moneyReq > 0) { - Quests.economy.withdrawPlayer(getOfflinePlayer(), q.moneyReq); - } - - for (ItemStack is : q.items) { - if (q.removeItems.get(q.items.indexOf(is)) == true) { - Quests.removeItem(player.getInventory(), is); - } - } - - String accepted = Lang.get("questAccepted"); - accepted = accepted.replaceAll("", q.name); - - player.sendMessage(ChatColor.GREEN + accepted); - player.sendMessage(""); - - } - - String msg = Lang.get("questObjectivesTitle"); - msg = msg.replaceAll("", q.name); - getPlayer().sendMessage(ChatColor.GOLD + msg); - - for (String s : getObjectivesReal(q)) { - player.sendMessage(s); - } - - String stageStartMessage = stage.startMessage; - if (stageStartMessage != null) { - getPlayer().sendMessage(Quests.parseString(stageStartMessage, q)); - } - - if (stage.chatEvents.isEmpty() == false) { - - for (String chatTrigger : stage.chatEvents.keySet()) { - - questData.get(q).eventFired.put(chatTrigger, false); - - } - - } - - if (q.initialEvent != null) { - q.initialEvent.fire(this, q); - } - if (stage.startEvent != null) { - stage.startEvent.fire(this, q); - } - - saveData(); - - } else { - - player.sendMessage(q.failRequirements); - - } - - } - - public LinkedList getObjectivesReal(Quest quest) { - - if (getCurrentStage(quest).objectiveOverride != null) { - LinkedList objectives = new LinkedList(); - objectives.add(ChatColor.GREEN + getCurrentStage(quest).objectiveOverride); - return objectives; - } else { - return getObjectives(quest); - } - - } - - public LinkedList getObjectives(Quest quest) { - - if(getQuestData(quest) == null) - return new LinkedList(); - - LinkedList unfinishedObjectives = new LinkedList(); - LinkedList finishedObjectives = new LinkedList(); - LinkedList objectives = new LinkedList(); - - for (Entry e : getCurrentStage(quest).blocksToDamage.entrySet()) { - - for (Entry e2 : getQuestData(quest).blocksDamaged.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("damage") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("damage") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : getCurrentStage(quest).blocksToBreak.entrySet()) { - - for (Entry e2 : getQuestData(quest).blocksBroken.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("break") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("break") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : getCurrentStage(quest).blocksToPlace.entrySet()) { - - for (Entry e2 : getQuestData(quest).blocksPlaced.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("place") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("place") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : getCurrentStage(quest).blocksToUse.entrySet()) { - - for (Entry e2 : getQuestData(quest).blocksUsed.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("use") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("use") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : getCurrentStage(quest).blocksToCut.entrySet()) { - - for (Entry e2 : getQuestData(quest).blocksCut.entrySet()) { - - if (e2.getKey().equals(e.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("cut") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("cut") + " " + Quester.prettyItemString(e2.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - if (getCurrentStage(quest).fishToCatch != null) { - - if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("catchFish") + ": " + getQuestData(quest).getFishCaught() + "/" + getCurrentStage(quest).fishToCatch); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("catchFish") + ": " + getQuestData(quest).getFishCaught() + "/" + getCurrentStage(quest).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 : getCurrentStage(quest).itemsToEnchant.entrySet()) { - - for (Entry, Integer> e2 : getQuestData(quest).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) { - - String obj = Lang.get("enchantItem"); - obj = obj.replaceAll("", Quester.prettyItemString(mat.name())); - obj = obj.replaceAll("", Quester.prettyEnchantmentString(enchantment)); - unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + num1 + "/" + num2); - - } else { - - String obj = Lang.get("enchantItem"); - obj = obj.replaceAll("", Quester.prettyItemString(mat.name())); - obj = obj.replaceAll("", Quester.prettyEnchantmentString(enchantment)); - finishedObjectives.add(ChatColor.GRAY + obj + ": " + num1 + "/" + num2); - - } - - } - - } - - } - - for (EntityType e : getCurrentStage(quest).mobsToKill) { - - for (EntityType e2 : getQuestData(quest).mobsKilled) { - - if (e == e2) { - if (getQuestData(quest).mobNumKilled.size() > getQuestData(quest).mobsKilled.indexOf(e2) && getCurrentStage(quest).mobNumToKill.size() > getCurrentStage(quest).mobsToKill.indexOf(e)) { - - if (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2)) < getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e))) { - - if (getCurrentStage(quest).locationsToKillWithin.isEmpty()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("kill") + " " + Quester.prettyMobString(e) + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); - } else { - String obj = Lang.get("killAtLocation"); - obj = obj.replaceAll("", Quester.prettyMobString(e)); - obj = obj.replaceAll("", getCurrentStage(quest).areaNames.get(getCurrentStage(quest).mobsToKill.indexOf(e))); - unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); - } - } else { - - if (getCurrentStage(quest).locationsToKillWithin.isEmpty()) { - finishedObjectives.add(ChatColor.GRAY + Lang.get("kill") + " " + Quester.prettyMobString(e) + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); - } else { - String obj = Lang.get("killAtLocation"); - obj = obj.replaceAll("", Quester.prettyMobString(e)); - obj = obj.replaceAll("", getCurrentStage(quest).areaNames.get(getCurrentStage(quest).mobsToKill.indexOf(e))); - finishedObjectives.add(ChatColor.GRAY + obj + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); - } - - } - } - - } - - } - - } - - if (getCurrentStage(quest).playersToKill != null) { - - if (getQuestData(quest).getPlayersKilled() < getCurrentStage(quest).playersToKill) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("killPlayer") + ": " + getQuestData(quest).getPlayersKilled() + "/" + getCurrentStage(quest).playersToKill); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("killPlayer") + ": " + getQuestData(quest).getPlayersKilled() + "/" + getCurrentStage(quest).playersToKill); - - } - - } - - for (ItemStack is : getCurrentStage(quest).itemsToDeliver) { - - int delivered = getQuestData(quest).itemsDelivered.get(is); - int amt = is.getAmount(); - Integer npc = getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(is)); - - if (delivered < amt) { - - String obj = Lang.get("deliver"); - obj = obj.replaceAll("", ItemUtil.getName(is)); - obj = obj.replaceAll("", plugin.getNPCName(npc)); - unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + delivered + "/" + amt); - - } else { - - String obj = Lang.get("deliver"); - obj = obj.replaceAll("", ItemUtil.getName(is)); - obj = obj.replaceAll("", plugin.getNPCName(npc)); - finishedObjectives.add(ChatColor.GRAY + obj + ": " + delivered + "/" + amt); - - } - - } - - for (Integer n : getCurrentStage(quest).citizensToInteract) { - - for (Entry e : getQuestData(quest).citizensInteracted.entrySet()) { - - if (e.getKey().equals(n)) { - - if (e.getValue() == false) { - - String obj = Lang.get("talkTo"); - obj = obj.replaceAll("", plugin.getNPCName(n)); - unfinishedObjectives.add(ChatColor.GREEN + obj); - - } else { - - String obj = Lang.get("talkTo"); - obj = obj.replaceAll("", plugin.getNPCName(n)); - finishedObjectives.add(ChatColor.GRAY + obj); - - } - - } - - } - - } - - for (Integer n : getCurrentStage(quest).citizensToKill) { - - for (Integer n2 : getQuestData(quest).citizensKilled) { - - if (n.equals(n2)) { - if (getQuestData(quest).citizenNumKilled.size() > getQuestData(quest).citizensKilled.indexOf(n2) && getCurrentStage(quest).citizenNumToKill.size() > getCurrentStage(quest).citizensToKill.indexOf(n)) { - - if (getQuestData(quest).citizenNumKilled.get(getQuestData(quest).citizensKilled.indexOf(n2)) < getCurrentStage(quest).citizenNumToKill.get(getCurrentStage(quest).citizensToKill.indexOf(n))) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("kill") + " " + plugin.getNPCName(n) + ChatColor.GREEN + " " + getQuestData(quest).citizenNumKilled.get(getCurrentStage(quest).citizensToKill.indexOf(n)) + "/" + getCurrentStage(quest).citizenNumToKill.get(getCurrentStage(quest).citizensToKill.indexOf(n))); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("kill") + " " + plugin.getNPCName(n) + " " + getCurrentStage(quest).citizenNumToKill.get(getCurrentStage(quest).citizensToKill.indexOf(n)) + "/" + getCurrentStage(quest).citizenNumToKill.get(getCurrentStage(quest).citizensToKill.indexOf(n))); - - } - } - } - - } - - } - - for (Entry e : getCurrentStage(quest).mobsToTame.entrySet()) { - - for (Entry e2 : getQuestData(quest).mobsTamed.entrySet()) { - - if (e.getKey().equals(e2.getKey())) { - - if (e2.getValue() < e.getValue()) { - - unfinishedObjectives.add(ChatColor.GREEN + Lang.get("tame") + " " + getCapitalized(e.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - finishedObjectives.add(ChatColor.GRAY + Lang.get("tame") + " " + getCapitalized(e.getKey().name()) + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Entry e : getCurrentStage(quest).sheepToShear.entrySet()) { - - for (Entry e2 : getQuestData(quest).sheepSheared.entrySet()) { - - if (e.getKey().equals(e2.getKey())) { - - if (e2.getValue() < e.getValue()) { - - String obj = Lang.get("shearSheep"); - obj = obj.replaceAll("", e.getKey().name().toLowerCase()); - unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + e2.getValue() + "/" + e.getValue()); - - } else { - - String obj = Lang.get("shearSheep"); - obj = obj.replaceAll("", e.getKey().name().toLowerCase()); - finishedObjectives.add(ChatColor.GRAY + obj + ": " + e2.getValue() + "/" + e.getValue()); - - } - - } - - } - - } - - for (Location l : getCurrentStage(quest).locationsToReach) { - - for (Location l2 : getQuestData(quest).locationsReached) { - - if (l.equals(l2)) { - if (!getQuestData(quest).hasReached.isEmpty()) { - - if (getQuestData(quest).hasReached.get(getQuestData(quest).locationsReached.indexOf(l2)) == false) { - - String obj = Lang.get("goTo"); - obj = obj.replaceAll("", getCurrentStage(quest).locationNames.get(getCurrentStage(quest).locationsToReach.indexOf(l))); - unfinishedObjectives.add(ChatColor.GREEN + obj); - - } else { - - String obj = Lang.get("goTo"); - obj = obj.replaceAll("", getCurrentStage(quest).locationNames.get(getCurrentStage(quest).locationsToReach.indexOf(l))); - finishedObjectives.add(ChatColor.GRAY + obj); - - } - - } - - } - - } - - } - - for (String s : getCurrentStage(quest).passwordDisplays) { - - if (getQuestData(quest).passwordsSaid.get(s) == false) { - - unfinishedObjectives.add(ChatColor.GREEN + s); - - } else { - - finishedObjectives.add(ChatColor.GRAY + s); - - } - - } - - int index = 0; - for (CustomObjective co : getCurrentStage(quest).customObjectives) { - - for (Entry entry : getQuestData(quest).customObjectiveCounts.entrySet()) { - - if (co.getName().equals(entry.getKey())) { - - String display = co.getDisplay(); - - Map datamap = getCurrentStage(quest).customObjectiveData.get(index); - for (String key : co.datamap.keySet()) { - display = display.replaceAll("%" + ((String) key) + "%", ((String) datamap.get(key))); - } - - if (entry.getValue() < getCurrentStage(quest).customObjectiveCounts.get(index)) { - if (co.isCountShown() && co.isEnableCount()) { - display = display.replaceAll("%count%", entry.getValue() + "/" + getCurrentStage(quest).customObjectiveCounts.get(index)); - } - unfinishedObjectives.add(ChatColor.GREEN + display); - } else { - if (co.isCountShown() && co.isEnableCount()) { - display = display.replaceAll("%count%", getCurrentStage(quest).customObjectiveCounts.get(index) + "/" + getCurrentStage(quest).customObjectiveCounts.get(index)); - } - finishedObjectives.add(ChatColor.GRAY + display); - } - - } - - } - - index++; - - } - - objectives.addAll(unfinishedObjectives); - objectives.addAll(finishedObjectives); - - return objectives; - - } - - public boolean hasObjective(Quest quest, String s) { - - if (getCurrentStage(quest) == null) { - return false; - } - - if (s.equalsIgnoreCase("damageBlock")) { - return !getCurrentStage(quest).blocksToDamage.isEmpty(); - - } else if (s.equalsIgnoreCase("breakBlock")) { - return !getCurrentStage(quest).blocksToBreak.isEmpty(); - - } else if (s.equalsIgnoreCase("placeBlock")) { - return !getCurrentStage(quest).blocksToPlace.isEmpty(); - - } else if (s.equalsIgnoreCase("useBlock")) { - return !getCurrentStage(quest).blocksToUse.isEmpty(); - - } else if (s.equalsIgnoreCase("cutBlock")) { - return !getCurrentStage(quest).blocksToCut.isEmpty(); - - } else if (s.equalsIgnoreCase("catchFish")) { - return getCurrentStage(quest).fishToCatch != null; - - } else if (s.equalsIgnoreCase("enchantItem")) { - return !getCurrentStage(quest).itemsToEnchant.isEmpty(); - - } else if (s.equalsIgnoreCase("killMob")) { - return !getCurrentStage(quest).mobsToKill.isEmpty(); - - } else if (s.equalsIgnoreCase("deliverItem")) { - return !getCurrentStage(quest).itemsToDeliver.isEmpty(); - - } else if (s.equalsIgnoreCase("killPlayer")) { - return getCurrentStage(quest).playersToKill != null; - - } else if (s.equalsIgnoreCase("talkToNPC")) { - return !getCurrentStage(quest).citizensToInteract.isEmpty(); - - } else if (s.equalsIgnoreCase("killNPC")) { - return !getCurrentStage(quest).citizensToKill.isEmpty(); - - } else if (s.equalsIgnoreCase("tameMob")) { - return !getCurrentStage(quest).mobsToTame.isEmpty(); - - } else if (s.equalsIgnoreCase("shearSheep")) { - return !getCurrentStage(quest).sheepToShear.isEmpty(); - - } else if (s.equalsIgnoreCase("craftItem")) { - return !getCurrentStage(quest).itemsToCraft.isEmpty(); - - } else if (s.equalsIgnoreCase("password")) { - return !getCurrentStage(quest).passwordPhrases.isEmpty(); - - } else { - return !getCurrentStage(quest).locationsToReach.isEmpty(); - - } - - } - - public boolean hasCustomObjective(Quest quest, String s) { - - if (getQuestData(quest).customObjectiveCounts.containsKey(s)) { - - int count = getQuestData(quest).customObjectiveCounts.get(s); - - int index = -1; - for (int i = 0; i < getCurrentStage(quest).customObjectives.size(); i++) { - if (getCurrentStage(quest).customObjectives.get(i).getName().equals(s)) { - index = i; - break; - } - } - - int count2 = getCurrentStage(quest).customObjectiveCounts.get(index); - - return count <= count2; - - } - - return false; - - } - - public void damageBlock(Quest quest, Material m) { - - if (getQuestData(quest).blocksDamaged.containsKey(m)) { - - if (getQuestData(quest).blocksDamaged.get(m) < getCurrentStage(quest).blocksToDamage.get(m)) { - int i = getQuestData(quest).blocksDamaged.get(m); - getQuestData(quest).blocksDamaged.put(m, (i + 1)); - - if (getQuestData(quest).blocksDamaged.get(m).equals(getCurrentStage(quest).blocksToDamage.get(m))) { - finishObjective(quest, "damageBlock", m, null, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void breakBlock(Quest quest, Material m) { - - if (getQuestData(quest).blocksBroken.containsKey(m)) { - - if (getQuestData(quest).blocksBroken.get(m) < getCurrentStage(quest).blocksToBreak.get(m)) { - int i = getQuestData(quest).blocksBroken.get(m); - getQuestData(quest).blocksBroken.put(m, (i + 1)); - - if (getQuestData(quest).blocksBroken.get(m).equals(getCurrentStage(quest).blocksToBreak.get(m))) { - finishObjective(quest, "breakBlock", m, null, null, null, null, null, null, null, null, null); - } - } - - } - - } - - public void placeBlock(Quest quest, Material m) { - - if (getQuestData(quest).blocksPlaced.containsKey(m)) { - - if (getQuestData(quest).blocksPlaced.get(m) < getCurrentStage(quest).blocksToPlace.get(m)) { - int i = getQuestData(quest).blocksPlaced.get(m); - getQuestData(quest).blocksPlaced.put(m, (i + 1)); - - if (getQuestData(quest).blocksPlaced.get(m).equals(getCurrentStage(quest).blocksToPlace.get(m))) { - finishObjective(quest, "placeBlock", m, null, null, null, null, null, null, null, null, null); - } - } - - } - - } - - public void useBlock(Quest quest, Material m) { - - if (getQuestData(quest).blocksUsed.containsKey(m)) { - - if (getQuestData(quest).blocksUsed.get(m) < getCurrentStage(quest).blocksToUse.get(m)) { - int i = getQuestData(quest).blocksUsed.get(m); - getQuestData(quest).blocksUsed.put(m, (i + 1)); - - if (getQuestData(quest).blocksUsed.get(m).equals(getCurrentStage(quest).blocksToUse.get(m))) { - finishObjective(quest, "useBlock", m, null, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void cutBlock(Quest quest, Material m) { - - if (getQuestData(quest).blocksCut.containsKey(m)) { - - if (getQuestData(quest).blocksCut.get(m) < getCurrentStage(quest).blocksToCut.get(m)) { - int i = getQuestData(quest).blocksCut.get(m); - getQuestData(quest).blocksCut.put(m, (i + 1)); - - if (getQuestData(quest).blocksCut.get(m).equals(getCurrentStage(quest).blocksToCut.get(m))) { - finishObjective(quest, "cutBlock", m, null, null, null, null, null, null, null, null, null); - } - - } - - } - - } - - public void catchFish(Quest quest) { - - if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) { - getQuestData(quest).setFishCaught(getQuestData(quest).getFishCaught() + 1); - - if (((Integer) getQuestData(quest).getFishCaught()).equals(getCurrentStage(quest).fishToCatch)) { - finishObjective(quest, "catchFish", null, null, null, null, null, null, null, null, null, null); - } - - } - - } - - public void enchantItem(Quest quest, Enchantment e, Material m) { - - for (Entry, Integer> entry : getQuestData(quest).itemsEnchanted.entrySet()) { - - if (entry.getKey().containsKey(e) && entry.getKey().containsValue(m)) { - - for (Entry, Integer> entry2 : getCurrentStage(quest).itemsToEnchant.entrySet()) { - - if (entry2.getKey().containsKey(e) && entry2.getKey().containsValue(m)) { - - if (entry.getValue() < entry2.getValue()) { - - Integer num = entry.getValue() + 1; - getQuestData(quest).itemsEnchanted.put(entry.getKey(), num); - - if (num.equals(entry2.getValue())) { - finishObjective(quest, "enchantItem", m, null, e, null, null, null, null, null, null, null); - } - - } - break; - - } - - } - - break; - - } - - } - - } - - public void killMob(Quest quest, Location l, EntityType e) { - - if (getQuestData(quest).mobsKilled.contains(e)) { - - if (getQuestData(quest).locationsToKillWithin.isEmpty() == false) { - - int index = getQuestData(quest).mobsKilled.indexOf(e); - Location locationToKillWithin = getQuestData(quest).locationsToKillWithin.get(index); - double radius = getQuestData(quest).radiiToKillWithin.get(index); - int numKilled = getQuestData(quest).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 < getCurrentStage(quest).mobNumToKill.get(index)) { - - Integer numKilledInteger = numKilled + 1; - - getQuestData(quest).mobNumKilled.set(index, numKilledInteger); - - if ((numKilledInteger).equals(getCurrentStage(quest).mobNumToKill.get(index))) { - finishObjective(quest, "killMob", null, null, null, e, null, null, null, null, null, null); - } - - } - - } - - } - - } - - } else { - - if (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e)) < getCurrentStage(quest).mobNumToKill.get(getQuestData(quest).mobsKilled.indexOf(e))) { - - getQuestData(quest).mobNumKilled.set(getQuestData(quest).mobsKilled.indexOf(e), getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e)) + 1); - - if ((getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e))).equals(getCurrentStage(quest).mobNumToKill.get(getQuestData(quest).mobsKilled.indexOf(e)))) { - finishObjective(quest, "killMob", null, null, null, e, null, null, null, null, null, null); - } - - } - - } - - } - - } - - public void killPlayer(Quest quest, Player player) { - - if (getQuestData(quest).playerKillTimes.containsKey(player.getUniqueId())) { - - long killTime = getQuestData(quest).playerKillTimes.get(player.getUniqueId()); - long comparator = plugin.killDelay * 1000; - long currentTime = System.currentTimeMillis(); - - if ((currentTime - killTime) < comparator) { - - String error = Lang.get("killNotValid"); - error = error.replaceAll("