diff --git a/src/main/java/me/blackvein/quests/EventFactory.java b/src/main/java/me/blackvein/quests/EventFactory.java index c6c3f3832..957e69894 100644 --- a/src/main/java/me/blackvein/quests/EventFactory.java +++ b/src/main/java/me/blackvein/quests/EventFactory.java @@ -51,22 +51,22 @@ import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; +import me.blackvein.quests.util.RomanNumeral; public class EventFactory implements ConversationAbandonedListener { - Quests quests; - Map editSessions = new HashMap(); + private Quests plugin; public Map selectedExplosionLocations = new HashMap(); public Map selectedEffectLocations = new HashMap(); public Map selectedMobLocations = new HashMap(); public Map selectedLightningLocations = new HashMap(); public Map selectedTeleportLocations = new HashMap(); List names = new LinkedList(); - ConversationFactory convoCreator; + private ConversationFactory convoCreator; File eventsFile; public EventFactory(Quests plugin) { - quests = plugin; + this.plugin = plugin; // 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).withPrefix(new QuestCreatorPrefix()).withFirstPrompt(new MenuPrompt()).withTimeout(3600).thatExcludesNonPlayersWithMessage("Console may not perform this operation!").addConversationAbandonedListener(this); } @@ -80,6 +80,10 @@ public class EventFactory implements ConversationAbandonedListener { selectedLightningLocations.remove(player.getUniqueId()); selectedTeleportLocations.remove(player.getUniqueId()); } + + public ConversationFactory getConversationFactory() { + return convoCreator; + } private class QuestCreatorPrefix implements ConversationPrefix { @@ -114,7 +118,7 @@ public class EventFactory implements ConversationAbandonedListener { } } else if (input.equalsIgnoreCase("2")) { if (player.hasPermission("quests.editor.events.edit")) { - if (quests.events.isEmpty()) { + if (plugin.getEvents().isEmpty()) { ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorNoneToEdit")); return new MenuPrompt(); } else { @@ -126,7 +130,7 @@ public class EventFactory implements ConversationAbandonedListener { } } else if (input.equalsIgnoreCase("3")) { if (player.hasPermission("quests.editor.events.delete")) { - if (quests.events.isEmpty()) { + if (plugin.getEvents().isEmpty()) { ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorNoneToDelete")); return new MenuPrompt(); } else { @@ -276,7 +280,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEdit") + " -\n"; - for (Event evt : quests.events) { + for (Event evt : plugin.getEvents()) { text += ChatColor.AQUA + evt.getName() + ChatColor.YELLOW + ", "; } text = text.substring(0, text.length() - 2) + "\n"; @@ -287,7 +291,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Event evt : quests.events) { + for (Event evt : plugin.getEvents()) { if (evt.getName().toLowerCase().startsWith(input.toLowerCase())) { context.setSessionData(CK.E_OLD_EVENT, evt.getName()); context.setSessionData(CK.E_NAME, evt.getName()); @@ -308,7 +312,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String text = ChatColor.GOLD + "- " + Lang.get("eventEditorDelete") + " -\n"; - for (Event evt : quests.events) { + for (Event evt : plugin.getEvents()) { text += ChatColor.AQUA + evt.getName() + ChatColor.YELLOW + ","; } text = text.substring(0, text.length() - 1) + "\n"; @@ -320,9 +324,9 @@ public class EventFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { LinkedList used = new LinkedList(); - for (Event evt : quests.events) { + for (Event evt : plugin.getEvents()) { if (evt.getName().equalsIgnoreCase(input)) { - for (Quest quest : quests.getQuests()) { + for (Quest quest : plugin.getQuests()) { for (Stage stage : quest.getStages()) { if (stage.finishEvent != null && stage.finishEvent.getName().equalsIgnoreCase(evt.getName())) { used.add(quest.getName()); @@ -466,7 +470,7 @@ public class EventFactory implements ConversationAbandonedListener { int index = -1; for (String type : types) { index++; - text += ChatColor.GRAY + " - " + ChatColor.AQUA + type + ChatColor.DARK_PURPLE + " " + Quests.getNumeral(mags.get(index)) + ChatColor.GRAY + " -> " + ChatColor.DARK_AQUA + Quests.getTime(durations.get(index) * 50L) + "\n"; + text += ChatColor.GRAY + " - " + ChatColor.AQUA + type + ChatColor.DARK_PURPLE + " " + RomanNumeral.getNumeral(mags.get(index)) + ChatColor.GRAY + " -> " + ChatColor.DARK_AQUA + Quests.getTime(durations.get(index) * 50L) + "\n"; } } if (context.getSessionData(CK.E_HUNGER) == null) { @@ -630,7 +634,7 @@ public class EventFactory implements ConversationAbandonedListener { public FinishPrompt(String modifiedName) { if (modifiedName != null) { modName = modifiedName; - for (Quest q : quests.getQuests()) { + for (Quest q : plugin.getQuests()) { for (Stage s : q.getStages()) { if (s.finishEvent != null && s.finishEvent.getName() != null) { if (s.finishEvent.getName().equalsIgnoreCase(modifiedName)) { @@ -714,7 +718,7 @@ public class EventFactory implements ConversationAbandonedListener { private void deleteEvent(ConversationContext context) { YamlConfiguration data = new YamlConfiguration(); try { - eventsFile = new File(quests.getDataFolder(), "events.yml"); + eventsFile = new File(plugin.getDataFolder(), "events.yml"); data.load(eventsFile); } catch (IOException e) { e.printStackTrace(); @@ -734,9 +738,9 @@ public class EventFactory implements ConversationAbandonedListener { ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorErrorSaving")); return; } - quests.reloadQuests(); + plugin.reloadQuests(); ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorDeleted")); - for (Quester q : quests.questers.values()) { + for (Quester q : plugin.getQuesters()) { for (Quest quest : q.currentQuests.keySet()) { q.checkQuest(quest); } @@ -747,7 +751,7 @@ public class EventFactory implements ConversationAbandonedListener { private void saveEvent(ConversationContext context) { YamlConfiguration data = new YamlConfiguration(); try { - eventsFile = new File(quests.getDataFolder(), "events.yml"); + eventsFile = new File(plugin.getDataFolder(), "events.yml"); data.load(eventsFile); } catch (IOException e) { e.printStackTrace(); @@ -760,7 +764,9 @@ public class EventFactory implements ConversationAbandonedListener { } if (((String) context.getSessionData(CK.E_OLD_EVENT)).isEmpty() == false) { data.set("events." + (String) context.getSessionData(CK.E_OLD_EVENT), null); - quests.events.remove(quests.getEvent((String) context.getSessionData(CK.E_OLD_EVENT))); + LinkedList temp = plugin.getEvents(); + temp.remove(plugin.getEvent((String) context.getSessionData(CK.E_OLD_EVENT))); + plugin.setEvents(temp); } ConfigurationSection section = data.createSection("events." + (String) context.getSessionData(CK.E_NAME)); names.remove((String) context.getSessionData(CK.E_NAME)); @@ -890,9 +896,9 @@ public class EventFactory implements ConversationAbandonedListener { ((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorErrorSaving")); return; } - quests.reloadQuests(); + plugin.reloadQuests(); ((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorSaved")); - for (Quester q : quests.questers.values()) { + for (Quester q : plugin.getQuesters()) { for (Quest quest : q.currentQuests.keySet()) { q.checkQuest(quest); } @@ -912,7 +918,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Event e : quests.events) { + for (Event e : plugin.getEvents()) { if (e.getName().equalsIgnoreCase(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists")); return new EventNamePrompt(); @@ -987,7 +993,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Event e : quests.events) { + for (Event e : plugin.getEvents()) { if (e.getName().equalsIgnoreCase(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists")); return new SetNamePrompt(); @@ -1313,7 +1319,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorWorldsTitle") + "\n" + ChatColor.DARK_PURPLE; - for (World w : quests.getServer().getWorlds()) { + for (World w : plugin.getServer().getWorlds()) { effects += w.getName() + ", "; } effects = effects.substring(0, effects.length()); @@ -1324,8 +1330,8 @@ public class EventFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { Player player = (Player) context.getForWhom(); if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (quests.getServer().getWorld(input) != null) { - context.setSessionData(CK.E_WORLD_STORM, quests.getServer().getWorld(input).getName()); + if (plugin.getServer().getWorld(input) != null) { + context.setSessionData(CK.E_WORLD_STORM, plugin.getServer().getWorld(input).getName()); } else { player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + Lang.get("eventEditorInvalidWorld")); return new StormWorldPrompt(); @@ -1414,7 +1420,7 @@ public class EventFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String effects = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorWorldsTitle") + "\n" + ChatColor.DARK_PURPLE; - for (World w : quests.getServer().getWorlds()) { + for (World w : plugin.getServer().getWorlds()) { effects += w.getName() + ", "; } effects = effects.substring(0, effects.length()); @@ -1425,8 +1431,8 @@ public class EventFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { Player player = (Player) context.getForWhom(); if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - if (quests.getServer().getWorld(input) != null) { - context.setSessionData(CK.E_WORLD_THUNDER, quests.getServer().getWorld(input).getName()); + if (plugin.getServer().getWorld(input) != null) { + context.setSessionData(CK.E_WORLD_THUNDER, plugin.getServer().getWorld(input).getName()); } else { player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + Lang.get("eventEditorInvalidWorld")); return new ThunderWorldPrompt(); diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index 5f25e3a1d..44eb955c4 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -58,8 +58,7 @@ import net.citizensnpcs.api.CitizensAPI; public class QuestFactory implements ConversationAbandonedListener { - public final Quests plugin; - Map editSessions = new HashMap(); + private final Quests plugin; public Map selectedBlockStarts = new HashMap(); public Map selectedKillLocations = new HashMap(); public Map selectedReachLocations = new HashMap(); @@ -85,6 +84,10 @@ public class QuestFactory implements ConversationAbandonedListener { selectedKillLocations.remove(player.getUniqueId()); selectedReachLocations.remove(player.getUniqueId()); } + + public ConversationFactory getConversationFactory() { + return convoCreator; + } private class MenuPrompt extends FixedSetPrompt { @@ -236,7 +239,7 @@ public class QuestFactory implements ConversationAbandonedListener { } else if (input.equalsIgnoreCase("10")) { return new PlannerPrompt(plugin, QuestFactory.this); } else if (input.equalsIgnoreCase("11")) { - return new StagesPrompt(QuestFactory.this); + return new StagesPrompt(plugin, QuestFactory.this); } else if (input.equalsIgnoreCase("12")) { return new RewardsPrompt(plugin, QuestFactory.this); } else if (input.equalsIgnoreCase("13")) { @@ -300,7 +303,7 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getName().equalsIgnoreCase(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorNameExists")); return new QuestNamePrompt(); @@ -402,7 +405,7 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getName().equalsIgnoreCase(input)) { String s = null; if (context.getSessionData(CK.ED_QUEST_EDIT) != null) { @@ -479,10 +482,10 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String text = ChatColor.DARK_GREEN + Lang.get("eventTitle") + "\n"; - if (plugin.events.isEmpty()) { + if (plugin.getEvents().isEmpty()) { text += ChatColor.RED + "- " + Lang.get("none"); } else { - for (Event e : plugin.events) { + for (Event e : plugin.getEvents()) { text += ChatColor.GREEN + "- " + e.getName() + "\n"; } } @@ -494,7 +497,7 @@ public class QuestFactory implements ConversationAbandonedListener { Player player = (Player) context.getForWhom(); if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { Event found = null; - for (Event e : plugin.events) { + for (Event e : plugin.getEvents()) { if (e.getName().equalsIgnoreCase(input)) { found = e; break; @@ -528,7 +531,7 @@ public class QuestFactory implements ConversationAbandonedListener { if (context.getSessionData("tempStack") != null) { ItemStack stack = (ItemStack) context.getSessionData("tempStack"); boolean failed = false; - for (Quest quest : plugin.quests) { + for (Quest quest : plugin.getQuests()) { if (quest.guiDisplay != null) { if (ItemUtil.compareItems(stack, quest.guiDisplay, false) == 0) { String error = Lang.get("questGUIError"); @@ -669,8 +672,10 @@ public class QuestFactory implements ConversationAbandonedListener { data.save(new File(plugin.getDataFolder(), "quests.yml")); if (context.getSessionData(CK.Q_START_NPC) != null && context.getSessionData(CK.Q_GUIDISPLAY) != null) { int i = (Integer) context.getSessionData(CK.Q_START_NPC); - if (!plugin.questNPCGUIs.contains(i)) { - plugin.questNPCGUIs.add(i); + if (!plugin.getQuestNpcGuis().contains(i)) { + LinkedList temp = plugin.getQuestNpcGuis(); + temp.add(i); + plugin.setQuestNpcGuis(temp); } plugin.updateData(); } @@ -1643,7 +1648,7 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { String text = ChatColor.GOLD + Lang.get("questDeleteTitle") + "\n"; - for (Quest quest : plugin.quests) { + for (Quest quest : plugin.getQuests()) { text += ChatColor.AQUA + quest.getName() + ChatColor.YELLOW + ","; } text = text.substring(0, text.length() - 1) + "\n"; @@ -1655,9 +1660,9 @@ public class QuestFactory implements ConversationAbandonedListener { public Prompt acceptInput(ConversationContext context, String input) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { LinkedList used = new LinkedList(); - Quest found = plugin.findQuest(input); + Quest found = plugin.getQuest(input); if (found != null) { - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getRequirements().getNeededQuests().contains(q.getName()) || q.getRequirements().getBlockQuests().contains(q.getName())) { used.add(q.getName()); } diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index 44ed85df7..5c2bf8491 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -2171,7 +2171,7 @@ public class Quester { List redoNames = data.getStringList("completedRedoableQuests"); List redoTimes = data.getLongList("completedQuestTimes"); for (String s : redoNames) { - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getName().equalsIgnoreCase(s)) { completedTimes.put(q.getName(), redoTimes.get(redoNames.indexOf(s))); break; @@ -2190,7 +2190,7 @@ public class Quester { hasJournal = data.getBoolean("hasJournal"); if (data.isList("completed-Quests")) { for (String s : data.getStringList("completed-Quests")) { - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getName().equalsIgnoreCase(s)) { if (!completedQuests.contains(q.getName())) { completedQuests.add(q.getName()); @@ -2648,7 +2648,7 @@ public class Quester { public void checkQuest(Quest quest) { if (quest != null) { boolean exists = false; - for (Quest q : plugin.quests) { + for (Quest q : plugin.getQuests()) { if (q.getName().equalsIgnoreCase(quest.getName())) { Stage stage = getCurrentStage(quest); quest.updateCompass(this, stage); @@ -2879,4 +2879,17 @@ public class Quester { break; } } + + public boolean hasItem(ItemStack is) { + Inventory inv = getPlayer().getInventory(); + int playerAmount = 0; + for (ItemStack stack : inv.getContents()) { + if (stack != null) { + if (ItemUtil.compareItems(is, stack, false) == 0) { + playerAmount += stack.getAmount(); + } + } + } + return playerAmount >= is.getAmount(); + } } diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 95fc60f98..e8a207a45 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -24,14 +24,10 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -51,13 +47,11 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; +import org.bukkit.command.CommandExecutor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.conversations.Conversable; import org.bukkit.conversations.ConversationAbandonedEvent; import org.bukkit.conversations.ConversationAbandonedListener; import org.bukkit.conversations.ConversationContext; @@ -72,7 +66,6 @@ import org.bukkit.entity.Tameable; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -96,7 +89,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import me.blackvein.quests.exceptions.InvalidStageException; +import me.blackvein.quests.listeners.CmdExecutor; import me.blackvein.quests.listeners.NpcListener; import me.blackvein.quests.listeners.PartiesListener; import me.blackvein.quests.listeners.PlayerListener; @@ -157,17 +150,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener // Interfaces public HashMap commands = new HashMap(); public HashMap adminCommands = new HashMap(); - public final Map questers = new HashMap(); public final List customRequirements = new LinkedList(); public final List customRewards = new LinkedList(); public final List customObjectives = new LinkedList(); - public final LinkedList quests = new LinkedList(); - public final LinkedList events = new LinkedList(); - public final LinkedList questNPCs = new LinkedList(); - public final LinkedList questNPCGUIs = new LinkedList(); + private LinkedList questers = new LinkedList(); + private LinkedList quests = new LinkedList(); + private LinkedList events = new LinkedList(); + private LinkedList questNpcs = new LinkedList(); + private LinkedList questNpcGuis = new LinkedList(); // Classes - public ConversationFactory conversationFactory; - public ConversationFactory NPCConversationFactory; + public CommandExecutor cmdExecutor; + private ConversationFactory conversationFactory; + private ConversationFactory npcConversationFactory; public QuestFactory questFactory; public EventFactory eventFactory; public PlayerListener playerListener; @@ -195,6 +189,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener partiesListener = new PartiesListener(); questFactory = new QuestFactory(this); eventFactory = new EventFactory(this); + cmdExecutor = new CmdExecutor(this); //Load main config before plugins because GPS is optional loadConfig(); @@ -217,15 +212,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener e.printStackTrace(); } loadData(); - loadCommands(); // Save config with any new options getConfig().options().copyDefaults(true); saveConfig(); - //Setup conversation factory after timeout has loaded + // Setup commands + loadSubCommands(); + getCommand("quests").setExecutor(cmdExecutor); + getCommand("questadmin").setExecutor(cmdExecutor); + getCommand("quest").setExecutor(cmdExecutor); + + // Setup conversation factory after timeout has loaded this.conversationFactory = new ConversationFactory(this).withModality(false).withPrefix(new QuestsPrefix()).withFirstPrompt(new QuestPrompt()).withTimeout(acceptTimeout).thatExcludesNonPlayersWithMessage("Console may not perform this conversation!").addConversationAbandonedListener(this); - this.NPCConversationFactory = new ConversationFactory(this).withModality(false).withFirstPrompt(new QuestAcceptPrompt(this)).withTimeout(acceptTimeout).withLocalEcho(false).addConversationAbandonedListener(this); + this.npcConversationFactory = new ConversationFactory(this).withModality(false).withFirstPrompt(new QuestAcceptPrompt(this)).withTimeout(acceptTimeout).withLocalEcho(false).addConversationAbandonedListener(this); getServer().getPluginManager().registerEvents(playerListener, this); if (npcEffects) { @@ -236,7 +236,114 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } delayLoadQuestInfo(); } + + @Override + public void onDisable() { + getLogger().info("Saving Quester data."); + for (Player p : getServer().getOnlinePlayers()) { + if (gpsapi != null) { + if (gpsapi.gpsIsActive(p)) { + gpsapi.stopGPS(p); + } + } + Quester quester = getQuester(p.getUniqueId()); + quester.saveData(); + } + updateData(); + } + + public LinkedList getQuests() { + return quests; + } + + public LinkedList getEvents() { + return events; + } + + public void setEvents(LinkedList events) { + this.events = events; + } + + public LinkedList getQuesters() { + return questers; + } + + public void setQuesters(LinkedList questers) { + this.questers = questers; + } + + public LinkedList getQuestNpcs() { + return questNpcs; + } + + public void setQuestNpcs(LinkedList questNpcs) { + this.questNpcs = questNpcs; + } + + public LinkedList getQuestNpcGuis() { + return questNpcGuis; + } + + public void setQuestNpcGuis(LinkedList questNpcGuis) { + this.questNpcGuis = questNpcGuis; + } + + public ConversationFactory getConversationFactory() { + return conversationFactory; + } + + public ConversationFactory getNpcConversationFactory() { + return npcConversationFactory; + } + @Override + public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { + if (abandonedEvent.gracefulExit() == false) { + if (abandonedEvent.getContext().getForWhom() != null) { + try { + abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW + + Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout")); + } catch (Exception e) { + } + } + } + } + + private class QuestPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return ChatColor.YELLOW + Lang.get((Player) context.getForWhom(), "acceptQuest") + " " + ChatColor.GREEN + Lang.get("yesWord") + " / " + Lang.get("noWord"); + } + + @Override + public Prompt acceptInput(ConversationContext context, String s) { + Player player = (Player) context.getForWhom(); + if (s.equalsIgnoreCase(Lang.get(player, "yesWord"))) { + try { + getQuester(player.getUniqueId()).takeQuest(getQuest(getQuester(player.getUniqueId()).questToTake), false); + } catch (Exception e) { + e.printStackTrace(); + } + return Prompt.END_OF_CONVERSATION; + } else if (s.equalsIgnoreCase(Lang.get("noWord"))) { + player.sendMessage(ChatColor.YELLOW + Lang.get("cancelled")); + return Prompt.END_OF_CONVERSATION; + } else { + player.sendMessage(ChatColor.RED + Lang.get("questInvalidChoice")); + return new QuestPrompt(); + } + } + } + + private class QuestsPrefix implements ConversationPrefix { + + @Override + public String getPrefix(ConversationContext context) { + return ChatColor.GRAY.toString(); + } + } + /** * Transfer language files from jar to disk */ @@ -322,12 +429,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener getLogger().log(Level.INFO, "" + quests.size() + " Quest(s) loaded."); getLogger().log(Level.INFO, "" + events.size() + " Event(s) loaded."); getLogger().log(Level.INFO, "" + Lang.size() + " Phrase(s) loaded."); - questers.putAll(getOnlineQuesters()); + questers.addAll(getOnlineQuesters()); } }, 5L); } - public void loadCommands() { + private void loadSubCommands() { // [] - required // {} - optional if (translateSubCommands) { @@ -379,44 +486,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener adminCommands.put("togglegui", 2); // togglegui [npc id] adminCommands.put("reload", 1); // reload } - } - public String checkCommand(String cmd, String[] args) { - if (cmd.equalsIgnoreCase("quest") || args.length == 0) { - return null; - } - if (cmd.equalsIgnoreCase("quests")) { - if (commands.containsKey(args[0].toLowerCase())) { - int min = commands.get(args[0].toLowerCase()); - if (args.length < min) - return getQuestsCommandUsage(args[0]); - else - return null; - } - return ChatColor.YELLOW + Lang.get("questsUnknownCommand"); - } else if (cmd.equalsIgnoreCase("questsadmin") || cmd.equalsIgnoreCase("questadmin")) { - if (adminCommands.containsKey(args[0].toLowerCase())) { - int min = adminCommands.get(args[0].toLowerCase()); - if (args.length < min) - return getQuestadminCommandUsage(args[0]); - else - return null; - } - return ChatColor.YELLOW + Lang.get("questsUnknownAdminCommand"); - } - return "NULL"; - } - - public String getQuestsCommandUsage(String cmd) { - return ChatColor.RED + Lang.get("usage") + ": " + ChatColor.YELLOW + "/quests " + Lang.get(Lang.getCommandKey(cmd) + "_HELP"); - } - - public String getQuestadminCommandUsage(String cmd) { - return ChatColor.RED + Lang.get("usage") + ": " + ChatColor.YELLOW + "/questadmin " + Lang.get(Lang.getCommandKey(cmd) + "_HELP"); - } - - private boolean isPluginReady(String pluginName) { + public boolean isPluginAvailable(String pluginName) { if (getServer().getPluginManager().getPlugin(pluginName) != null ) { if (!getServer().getPluginManager().getPlugin(pluginName).isEnabled()) { getLogger().warning(pluginName + " was detected, but is not enabled! Fix "+ pluginName + " to allow linkage."); @@ -429,7 +501,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener private void linkOtherPlugins() { try { - if (isPluginReady("Citizens")) { + if (isPluginAvailable("Citizens")) { citizens = (CitizensPlugin) getServer().getPluginManager().getPlugin("Citizens"); } if (citizens != null) { @@ -438,35 +510,35 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } catch (Exception e) { getLogger().warning("Legacy version of Citizens found. Citizens in Quests not enabled."); } - if (isPluginReady("WorldGuard")) { + if (isPluginAvailable("WorldGuard")) { worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"); } - if (isPluginReady("Denizen")) { + if (isPluginAvailable("Denizen")) { denizen = (Denizen) getServer().getPluginManager().getPlugin("Denizen"); } - if (isPluginReady("mcMMO")) { + if (isPluginAvailable("mcMMO")) { mcmmo = (mcMMO) getServer().getPluginManager().getPlugin("mcMMO"); } - if (useGPS && isPluginReady("GPS")) { + if (useGPS && isPluginAvailable("GPS")) { gpsapi = new GPSAPI(this); } - if (isPluginReady("Heroes")) { + if (isPluginAvailable("Heroes")) { heroes = (Heroes) getServer().getPluginManager().getPlugin("Heroes"); } - if (isPluginReady("PhatLoots")) { + if (isPluginAvailable("PhatLoots")) { phatLoots = (PhatLoots) getServer().getPluginManager().getPlugin("PhatLoots"); } - if (isPluginReady("PlaceholderAPI")) { + if (isPluginAvailable("PlaceholderAPI")) { placeholder = (PlaceholderAPIPlugin) getServer().getPluginManager().getPlugin("PlaceholderAPI"); } - if (isPluginReady("CitizensBooks")) { + if (isPluginAvailable("CitizensBooks")) { citizensBooks = ((CitizensBooksPlugin) getServer().getPluginManager().getPlugin("CitizensBooks")).getAPI(); } - if (isPluginReady("Parties")) { + if (isPluginAvailable("Parties")) { parties = Parties.getApi(); Vars.getInstance().setMaxDistanceToEntry(9999.0); } - if (isPluginReady("Vault")) { + if (isPluginAvailable("Vault")) { if (!setupEconomy()) { getLogger().warning("Economy not found."); } @@ -477,73 +549,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } - @Override - public void onDisable() { - getLogger().info("Saving Quester data."); - for (Player p : getServer().getOnlinePlayers()) { - if (gpsapi != null) { - if (gpsapi.gpsIsActive(p)) { - gpsapi.stopGPS(p); - } - } - Quester quester = getQuester(p.getUniqueId()); - quester.saveData(); - } - updateData(); - } - - public LinkedList getQuests() { - return quests; - } - - @Override - public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { - if (abandonedEvent.gracefulExit() == false) { - if (abandonedEvent.getContext().getForWhom() != null) { - try { - abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW - + Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout")); - } catch (Exception e) { - } - } - } - } - - private class QuestPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get((Player) context.getForWhom(), "acceptQuest") + " " + ChatColor.GREEN + Lang.get("yesWord") + " / " + Lang.get("noWord"); - } - - @Override - public Prompt acceptInput(ConversationContext context, String s) { - Player player = (Player) context.getForWhom(); - if (s.equalsIgnoreCase(Lang.get(player, "yesWord"))) { - try { - getQuester(player.getUniqueId()).takeQuest(getQuest(getQuester(player.getUniqueId()).questToTake), false); - } catch (Exception e) { - e.printStackTrace(); - } - return Prompt.END_OF_CONVERSATION; - } else if (s.equalsIgnoreCase(Lang.get("noWord"))) { - player.sendMessage(ChatColor.YELLOW + Lang.get("cancelled")); - return Prompt.END_OF_CONVERSATION; - } else { - player.sendMessage(ChatColor.RED + Lang.get("questInvalidChoice")); - return new QuestPrompt(); - } - } - } - - private class QuestsPrefix implements ConversationPrefix { - - @Override - public String getPrefix(ConversationContext context) { - return ChatColor.GRAY.toString(); - } - } - public void loadConfig() { FileConfiguration config = getConfig(); acceptTimeout = config.getInt("accept-timeout", 20); @@ -587,8 +592,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } if (config.contains("npc-gui")) { List ids = config.getIntegerList("npc-gui"); - questNPCGUIs.clear(); - questNPCGUIs.addAll(ids); + questNpcGuis.clear(); + questNpcGuis.addAll(ids); } } @@ -718,1191 +723,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } - @Override - public boolean onCommand(final CommandSender cs, Command cmd, String label, String[] args) { - if (cs instanceof Player) { - if (checkQuester(((Player) cs).getUniqueId()) == true) { - cs.sendMessage(ChatColor.RED + Lang.get((Player) cs, "noPermission")); - return true; - } - } - String error = checkCommand(cmd.getName(), args); - if (error != null) { - cs.sendMessage(error); - return true; - } - if (cmd.getName().equalsIgnoreCase("quest")) { - return questCommandHandler(cs, args); - } else if (cmd.getName().equalsIgnoreCase("quests")) { - return questActionsCommandHandler(cs, args); - } else if (cmd.getName().equalsIgnoreCase("questadmin")) { - return questAdminCommandHandler(cs, args); - } - return false; - } - - private boolean questAdminCommandHandler(final CommandSender cs, String[] args) { - if (args.length == 0) { - adminHelp(cs); - return true; - } - if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_STATS") : "stats")) { - adminStats(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_GIVE") : "give")) { - adminGive(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_QUIT") : "quit")) { - adminQuit(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_POINTS") : "points")) { - adminPoints(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_TAKEPOINTS") : "takepoints")) { - adminTakePoints(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_GIVEPOINTS") : "givepoints")) { - adminGivePoints(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_POINTSALL") : "pointsall")) { - adminPointsAll(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_FINISH") : "finish")) { - adminFinish(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE") : "nextstage")) { - adminNextStage(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_SETSTAGE") : "setstage")) { - adminSetStage(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_RESET") : "reset")) { - adminReset(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_REMOVE") : "remove")) { - adminRemove(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_TOGGLEGUI") : "togglegui")) { - adminToggieGUI(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUESTADMIN_RELOAD") : "reload")) { - adminReload(cs); - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownAdminCommand")); - } - return true; - } - - private void adminHelp(final CommandSender cs) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin")) { - printAdminHelp(cs); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminReload(final CommandSender cs) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.reload")) { - reloadQuests(); - cs.sendMessage(ChatColor.GOLD + Lang.get("questsReloaded")); - String msg = Lang.get("numQuestsLoaded"); - msg = msg.replace("", ChatColor.DARK_PURPLE + String.valueOf(quests.size()) + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminToggieGUI(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.togglegui")) { - try { - int i = Integer.parseInt(args[1]); - if (citizens.getNPCRegistry().getById(i) == null) { - String msg = Lang.get("errorNPCID"); - msg = msg.replace("errorNPCID", ChatColor.DARK_PURPLE + "" + i + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - } else if (questNPCGUIs.contains(i)) { - questNPCGUIs.remove(questNPCGUIs.indexOf(i)); - updateData(); - String msg = Lang.get("disableNPCGUI"); - msg = msg.replace("", ChatColor.DARK_PURPLE + citizens.getNPCRegistry().getById(i).getName() + ChatColor.YELLOW); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - questNPCGUIs.add(i); - updateData(); - String msg = Lang.get("enableNPCGUI"); - msg = msg.replace("", ChatColor.DARK_PURPLE + citizens.getNPCRegistry().getById(i).getName() + ChatColor.YELLOW); - cs.sendMessage(ChatColor.YELLOW + msg); - } - } catch (NumberFormatException nfe) { - cs.sendMessage(ChatColor.RED + Lang.get("inputNum")); - } catch (Exception ex) { - ex.printStackTrace(); - cs.sendMessage(ChatColor.RED + Lang.get("unknownError")); - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminGivePoints(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.givepoints")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().equalsIgnoreCase(args[1])) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - int points; - try { - points = Integer.parseInt(args[2]); - Quester quester = getQuester(target.getUniqueId()); - quester.questPoints += Math.abs(points); - String msg1 = Lang.get("giveQuestPoints"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questPointsGiven"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - quester.saveData(); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminTakePoints(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.takepoints")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().equalsIgnoreCase(args[1])) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - int points; - try { - points = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); - return; - } - Quester quester = getQuester(target.getUniqueId()); - quester.questPoints -= Math.abs(points); - String msg1 = Lang.get("takeQuestPoints"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questPointsTaken"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - quester.saveData(); - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminPoints(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.points")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().equalsIgnoreCase(args[1])) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - int points; - try { - points = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); - return; - } - Quester quester = getQuester(target.getUniqueId()); - quester.questPoints = points; - String msg1 = Lang.get("setQuestPoints"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get("questPointsSet"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + "" + points + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - quester.saveData(); - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminGive(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.give")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().toLowerCase().contains(args[1].toLowerCase())) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - Quest questToGive; - String name = ""; - if (args.length == 3) { - name = args[2].toLowerCase(); - } else { - for (int i = 2; i < args.length; i++) { - int lastIndex = args.length - 1; - if (i == lastIndex) { - name = name + args[i].toLowerCase(); - } else { - name = name + args[i].toLowerCase() + " "; - } - } - } - questToGive = findQuest(name); - if (questToGive == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("questNotFound")); - } else { - Quester quester = getQuester(target.getUniqueId()); - for (Quest q : quester.currentQuests.keySet()) { - if (q.getName().equalsIgnoreCase(questToGive.getName())) { - String msg = Lang.get("questsPlayerHasQuestAlready"); - msg = msg.replace("", ChatColor.ITALIC + "" + ChatColor.GREEN + target.getName() + ChatColor.RESET + ChatColor.YELLOW); - msg = msg.replace("", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE + questToGive.getName() + ChatColor.RESET + ChatColor.YELLOW); - cs.sendMessage(ChatColor.YELLOW + msg); - return; - } - } - quester.hardQuit(questToGive); - String msg1 = Lang.get("questForceTake"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + questToGive.getName() + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questForcedTake"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + questToGive.getName() + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - quester.takeQuest(questToGive, true); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminPointsAll(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.points.all")) { - final int amount; - try { - amount = Integer.parseInt(args[1]); - if (amount < 0) { - cs.sendMessage(ChatColor.RED + Lang.get("inputPosNum")); - return; - } - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.RED + Lang.get("inputNum")); - return; - } - Thread thread = new Thread(new Runnable() { - - @Override - public void run() { - File questerFolder = new File(getDataFolder(), "data"); - if (questerFolder.exists() && questerFolder.isDirectory()) { - FileConfiguration data = new YamlConfiguration(); - File[] files = questerFolder.listFiles(); - int failCount = 0; - boolean suppressed = false; - if (files != null) { - for (File f : files) { - try { - data.load(f); - data.set("quest-points", amount); - data.save(f); - } catch (IOException e) { - if (failCount < 10) { - String msg = Lang.get("errorReading"); - msg = msg.replace("", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - failCount++; - } else if (suppressed == false) { - String msg = Lang.get("errorReadingSuppress"); - msg = msg.replace("", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - suppressed = true; - } - } catch (InvalidConfigurationException e) { - if (failCount < 10) { - String msg = Lang.get("errorReading"); - msg = msg.replace("", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - failCount++; - } else if (suppressed == false) { - String msg = Lang.get("errorReadingSuppress"); - msg = msg.replace("", ChatColor.DARK_AQUA + f.getName() + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - suppressed = true; - } - } - } - } - cs.sendMessage(ChatColor.GREEN + Lang.get("done")); - String msg = Lang.get("allQuestPointsSet"); - msg = msg.replace("", ChatColor.AQUA + "" + amount + ChatColor.GOLD); - getServer().broadcastMessage(ChatColor.YELLOW + "" + ChatColor.GOLD + msg); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("errorDataFolder")); - } - } - }); - cs.sendMessage(ChatColor.YELLOW + Lang.get("settingAllQuestPoints")); - for (Quester q : questers.values()) { - q.questPoints = amount; - } - thread.start(); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminFinish(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.finish")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().toLowerCase().contains(args[1].toLowerCase())) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - Quester quester = getQuester(target.getUniqueId()); - if (quester.currentQuests.isEmpty()) { - String msg = Lang.get("noCurrentQuest"); - msg = msg.replace("", target.getName()); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - Quest found = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' ')); - if (found == null) { - cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); - return; - } - String msg1 = Lang.get("questForceFinish"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questForcedFinish"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - found.completeQuest(quester); - quester.saveData(); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminSetStage(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.setstage")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - // To ensure the correct player is selected - if (p.getName().equalsIgnoreCase(args[1])) { - target = p; - break; - } - } - if (target == null) { - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().toLowerCase().contains(args[1].toLowerCase())) { - target = p; - break; - } - } - } - int stage = -1; - if (args.length > 3) { - try { - stage = Integer.parseInt(args[2]); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); - } - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_QUESTADMIN_SETSTAGE_USAGE")); - return; - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - Quester quester = getQuester(target.getUniqueId()); - if (quester.currentQuests.isEmpty()) { - String msg = Lang.get("noCurrentQuest"); - msg = msg.replace("", target.getName()); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - Quest found = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' ')); - if (found == null) { - cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); - return; - } - try { - found.setStage(quester, stage); - } catch (InvalidStageException e) { - String msg = Lang.get("invalidStageNum"); - msg = msg.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.RED); - cs.sendMessage(ChatColor.RED + msg); - } - quester.saveData(); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminNextStage(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.nextstage")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().toLowerCase().contains(args[1].toLowerCase())) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - Quester quester = getQuester(target.getUniqueId()); - if (quester.currentQuests.isEmpty()) { - String msg = Lang.get("noCurrentQuest"); - msg = msg.replace("", target.getName()); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - Quest found = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' ')); - if (found == null) { - cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); - return; - } - String msg1 = Lang.get("questForceNextStage"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questForcedNextStage"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - found.nextStage(quester); - quester.saveData(); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminQuit(final CommandSender cs, String[] args) { - try { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.quit")) { - Player target = null; - for (Player p : getServer().getOnlinePlayers()) { - if (p.getName().toLowerCase().contains(args[1].toLowerCase())) { - target = p; - break; - } - } - if (target == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - } else { - Quester quester = getQuester(target.getUniqueId()); - if (quester.currentQuests.isEmpty()) { - String msg = Lang.get("noCurrentQuest"); - msg = msg.replace("", target.getName()); - cs.sendMessage(ChatColor.YELLOW + msg); - } else { - Quest found = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' ')); - if (found == null) { - cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); - return; - } - quester.hardQuit(found); - String msg1 = Lang.get("questForceQuit"); - msg1 = msg1.replace("", ChatColor.GREEN + target.getName() + ChatColor.GOLD); - msg1 = msg1.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg1); - String msg2 = Lang.get(target, "questForcedQuit"); - msg2 = msg2.replace("", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); - msg2 = msg2.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.GOLD); - target.sendMessage(ChatColor.GREEN + msg2); - quester.saveData(); - quester.updateJournal(); - } - } - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } catch (NullPointerException npe) { - npe.printStackTrace(); - } - } - - private void adminReset(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.reset")) { - Quester quester = getQuester(args[1]); - if (quester == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - return; - } - UUID id = quester.getUUID(); - questers.remove(id); - try { - quester.hardClear(); - quester.saveData(); - quester.updateJournal(); - final File dataFolder = new File(this.getDataFolder(), "data" + File.separator); - final File found = new File(dataFolder, id + ".yml"); - found.delete(); - String msg = Lang.get("questReset"); - if (Bukkit.getOfflinePlayer(id).getName() != null) { - msg = msg.replace("", ChatColor.GREEN + Bukkit.getOfflinePlayer(id).getName() + ChatColor.GOLD); - } else { - msg = msg.replace("", ChatColor.GREEN + args[1] + ChatColor.GOLD); - } - cs.sendMessage(ChatColor.GOLD + msg); - cs.sendMessage(ChatColor.DARK_PURPLE + " UUID: " + ChatColor.DARK_AQUA + id); - } catch (Exception e) { - getLogger().info("Data file does not exist for " + id.toString()); - } - quester = new Quester(this); - quester.setUUID(id); - quester.saveData(); - questers.put(id, quester); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminStats(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.stats")) { - questsStats(cs, args); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private void adminRemove(final CommandSender cs, String[] args) { - if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.remove")) { - Quester quester = getQuester(args[1]); - if (quester == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - return; - } - Quest toRemove = findQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' ')); - if (toRemove == null) { - cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); - return; - } - String msg = Lang.get("questRemoved"); - if (Bukkit.getOfflinePlayer(quester.getUUID()).getName() != null) { - msg = msg.replace("", ChatColor.GREEN + Bukkit.getOfflinePlayer(quester.getUUID()).getName() + ChatColor.GOLD); - } else { - msg = msg.replace("", ChatColor.GREEN + args[1] + ChatColor.GOLD); - } - msg = msg.replace("", ChatColor.DARK_PURPLE + toRemove.getName() + ChatColor.AQUA); - cs.sendMessage(ChatColor.GOLD + msg); - cs.sendMessage(ChatColor.DARK_PURPLE + " UUID: " + ChatColor.DARK_AQUA + quester.getUUID().toString()); - quester.hardRemove(toRemove); - quester.saveData(); - quester.updateJournal(); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - } - - private boolean questActionsCommandHandler(final CommandSender cs, String[] args) { - if (cs instanceof Player) { - if (args.length == 0) { - questsHelp(cs); - return true; - } else { - if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_LIST") : "list")) { - questsList(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TAKE") : "take")) { - questsTake((Player) cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUIT") : "quit")) { - questsQuit((Player) cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_STATS") : "stats")) { - questsStats(cs, null); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_JOURNAL") : "journal")) { - questsJournal((Player) cs); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TOP") : "top")) { - questsTop(cs, args); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EDITOR") : "editor")) { - questsEditor(cs); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EVENTS_EDITOR") : "events")) { - questsEvents(cs); - } else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_INFO") : "info")) { - questsInfo(cs); - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownCommand")); - return true; - } - } - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError")); - return true; - } - return true; - } - - private boolean questsInfo(final CommandSender cs) { - if (cs.hasPermission("quests.info")) { - cs.sendMessage(ChatColor.GOLD + Lang.get("quests") + " " + this.getDescription().getVersion()); - cs.sendMessage(ChatColor.GOLD + Lang.get("createdBy") + " " + ChatColor.DARK_RED + "Blackvein" - + ChatColor.GOLD + " " + Lang.get("continuedBy") + " " + ChatColor.DARK_RED + "FlyingPikachu"); - cs.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.UNDERLINE + "https://www.spigotmc.org/resources/quests.3711/"); - } - return true; - } - - private boolean questsEvents(final CommandSender cs) { - if (cs.hasPermission("quests.editor.*") || cs.hasPermission("quests.events.editor")) { - eventFactory.convoCreator.buildConversation((Conversable) cs).begin(); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - return true; - } - - private boolean questsEditor(final CommandSender cs) { - if (cs.hasPermission("quests.editor.*") || cs.hasPermission("quests.editor.editor")) { - questFactory.convoCreator.buildConversation((Conversable) cs).begin(); - } else { - cs.sendMessage(ChatColor.RED + Lang.get("NoPermission")); - } - return true; - } - - private boolean questsTop(final CommandSender cs, String[] args) { - if (args.length > 2) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_TOP_USAGE")); - } else { - int topNumber; - if (args.length == 1) { - topNumber = 5; // default - } else { - try { - topNumber = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); - return true; - } - } - if (topNumber < 1) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputPosNum")); - return true; - } - File folder = new File(this.getDataFolder(), "data"); - File[] playerFiles = folder.listFiles(); - Map questPoints = new HashMap(); - if (playerFiles != null) { - for (File f : playerFiles) { - if (!f.isDirectory()) { - FileConfiguration data = new YamlConfiguration(); - try { - data.load(f); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); - } - String name = f.getName().substring(0, (f.getName().indexOf("."))); - questPoints.put(name, data.getInt("quest-points")); - } - } - } - LinkedHashMap sortedMap = (LinkedHashMap) Quests.sort(questPoints); - int numPrinted = 0; - String msg = Lang.get("topQuestersTitle"); - msg = msg.replace("", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg); - for (String s : sortedMap.keySet()) { - int i = (Integer) sortedMap.get(s); - s = s.trim(); - try { - UUID id = UUID.fromString(s); - s = Bukkit.getOfflinePlayer(id).getName(); - } catch (IllegalArgumentException e) { - getLogger().warning("File name \"" + s + "\"in /data folder is not a valid player UUID!"); - break; - } - numPrinted++; - cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + s + " - " + ChatColor.DARK_PURPLE + i + ChatColor.YELLOW + " " + Lang.get("questPoints")); - if (numPrinted == topNumber) { - break; - } - } - } - return true; - } - - private void questsStats(final CommandSender cs, String[] args) { - Quester quester; - if (args != null) { - quester = getQuester(args[1]); - if (quester == null) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - return; - } else if (Bukkit.getOfflinePlayer(quester.getUUID()).getName() != null) { - cs.sendMessage(ChatColor.GOLD + "- " + Bukkit.getOfflinePlayer(quester.getUUID()).getName() + " -"); - } else { - cs.sendMessage(ChatColor.GOLD + "- " + args[1] + " -"); - } - } else { - quester = getQuester(((Player) cs).getUniqueId()); - cs.sendMessage(ChatColor.GOLD + "- " + ((Player) cs).getName() + " -"); - } - cs.sendMessage(ChatColor.YELLOW + Lang.get("questPointsDisplay") + " " + ChatColor.DARK_PURPLE + quester.questPoints); - if (quester.currentQuests.isEmpty()) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest") + " " + ChatColor.DARK_PURPLE + Lang.get("none")); - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest")); - for (Quest q : quester.currentQuests.keySet()) { - cs.sendMessage(ChatColor.LIGHT_PURPLE + " - " + ChatColor.DARK_PURPLE + q.getName()); - } - } - String completed; - if (quester.completedQuests.isEmpty()) { - completed = ChatColor.DARK_PURPLE + Lang.get("none"); - } else { - completed = ChatColor.DARK_PURPLE + ""; - for (String s : quester.completedQuests) { - completed += s; - if (quester.amountsCompleted.containsKey(s) && quester.amountsCompleted.get(s) > 1) { - completed += ChatColor.LIGHT_PURPLE + " (x" + quester.amountsCompleted.get(s) + ")"; - } - if (quester.completedQuests.indexOf(s) < (quester.completedQuests.size() - 1)) { - completed += ", "; - } - } - } - cs.sendMessage(ChatColor.YELLOW + Lang.get("completedQuestsTitle")); - cs.sendMessage(completed); - } - - @SuppressWarnings("deprecation") - private void questsJournal(final Player player) { - Quester quester = getQuester(player.getUniqueId()); - if (quester.hasJournal) { - Inventory inv = player.getInventory(); - ItemStack[] arr = inv.getContents(); - for (int i = 0; i < arr.length; i++) { - if (arr[i] != null) { - if (ItemUtil.isJournal(arr[i])) { - inv.setItem(i, null); - break; - } - } - } - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalPutAway")); - quester.hasJournal = false; - } else if (player.getItemInHand() == null || player.getItemInHand().getType().equals(Material.AIR)) { - ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - stack.setItemMeta(meta); - player.setItemInHand(stack); - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); - quester.hasJournal = true; - quester.updateJournal(); - } else { - Inventory inv = player.getInventory(); - ItemStack[] arr = inv.getContents(); - boolean given = false; - for (int i = 0; i < arr.length; i++) { - if (arr[i] == null) { - ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - stack.setItemMeta(meta); - inv.setItem(i, stack); - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); - given = true; - break; - } - } - if (given) { - quester.hasJournal = true; - quester.updateJournal(); - } else - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalNoRoom")); - } - } - - private boolean questsQuit(final Player player, String[] args) { - if (allowQuitting == true) { - if (((Player) player).hasPermission("quests.quit")) { - if (args.length == 1) { - player.sendMessage(ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP")); - return true; - } - Quester quester = getQuester(player.getUniqueId()); - if (quester.currentQuests.isEmpty() == false) { - Quest found = findQuest(MiscUtil.concatArgArray(args, 1, args.length - 1, ' ')); - if (found == null) { - player.sendMessage(ChatColor.RED + Lang.get(player, "questNotFound")); - return true; - } - quester.hardQuit(found); - String msg = Lang.get("questQuit"); - msg = msg.replace("", ChatColor.DARK_PURPLE + found.getName() + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + msg); - quester.saveData(); - quester.loadData(); - quester.updateJournal(); - return true; - } else { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "noActiveQuest")); - return true; - } - } else { - player.sendMessage(ChatColor.RED + Lang.get(player, "NoPermission")); - return true; - } - } else { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled")); - return true; - } - } - - private void questsTake(final Player player, String[] args) { - if (allowCommands == true) { - if (((Player) player).hasPermission("quests.take")) { - if (args.length == 1) { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE")); - } else { - String name = null; - if (args.length == 2) { - name = args[1].toLowerCase(); - } else { - boolean first = true; - int lastIndex = (args.length - 1); - int index = 0; - for (String s : args) { - if (index != 0) { - if (first) { - first = false; - if (args.length > 2) { - name = s.toLowerCase() + " "; - } else { - name = s.toLowerCase(); - } - } else if (index == lastIndex) { - name = name + s.toLowerCase(); - } else { - name = name + s.toLowerCase() + " "; - } - } - index++; - } - } - Quest questToFind = findQuest(name); - if (questToFind != null) { - final Quest q = questToFind; - final Quester quester = getQuester(player.getUniqueId()); - if (quester.currentQuests.size() >= maxQuests && maxQuests > 0) { - String msg = Lang.get(player, "questMaxAllowed"); - msg = msg.replace("", String.valueOf(maxQuests)); - player.sendMessage(ChatColor.YELLOW + msg); - } else if (quester.currentQuests.containsKey(q)) { - String msg = Lang.get(player, "questAlreadyOn"); - player.sendMessage(ChatColor.YELLOW + msg); - } else if (quester.completedQuests.contains(q.getName()) && q.getPlanner().getCooldown() < 0) { - String msg = Lang.get(player, "questAlreadyCompleted"); - msg = msg.replace("", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + msg); - } else if (q.npcStart != null && allowCommandsForNpcQuests == false) { - String msg = Lang.get(player, "mustSpeakTo"); - msg = msg.replace("", ChatColor.DARK_PURPLE + q.npcStart.getName() + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + msg); - } else if (q.blockStart != null) { - String msg = Lang.get(player, "noCommandStart"); - msg = msg.replace("", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW); - player.sendMessage(ChatColor.YELLOW + msg); - } else { - boolean takeable = true; - if (quester.completedQuests.contains(q.getName())) { - if (quester.getCooldownDifference(q) > 0) { - String early = Lang.get(player, "questTooEarly"); - early = early.replace("", ChatColor.AQUA + q.getName() + ChatColor.YELLOW); - early = early.replace("