diff --git a/src/main/java/me/blackvein/quests/NpcListener.java b/src/main/java/me/blackvein/quests/NpcListener.java index 48ab8d94d..7fb0e6c65 100644 --- a/src/main/java/me/blackvein/quests/NpcListener.java +++ b/src/main/java/me/blackvein/quests/NpcListener.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import me.blackvein.quests.util.ItemUtil; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.event.NPCDeathEvent; +import net.citizensnpcs.api.event.NPCLeftClickEvent; import net.citizensnpcs.api.event.NPCRightClickEvent; import net.citizensnpcs.api.npc.NPC; import org.bukkit.ChatColor; @@ -32,6 +33,11 @@ public class NpcListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onNPCRightClick(NPCRightClickEvent evt) { + if(plugin.questFactory.selectingNPCs.contains(evt.getClicker())){ + evt.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN + "ID " + evt.getNPC().getId()); + return; + } + if (evt.getClicker().isConversing() == false) { final Player player = evt.getClicker(); @@ -111,11 +117,11 @@ public class NpcListener implements Listener { quester.questToTake = q.name; String s = extracted(quester); - + for (String msg : s.split("
")) { player.sendMessage(msg); } - + plugin.conversationFactory.buildConversation((Conversable) player).begin(); } else if (quester.currentQuest.equals(q) == false) { @@ -135,7 +141,7 @@ public class NpcListener implements Listener { } else { quester.questToTake = q.name; String s = extracted(quester); - + for (String msg : s.split("
")) { player.sendMessage(msg); } @@ -163,6 +169,15 @@ public class NpcListener implements Listener { } } + @EventHandler + public void onNPCLeftClick(NPCLeftClickEvent evt){ + + if(plugin.questFactory.selectingNPCs.contains(evt.getClicker())){ + evt.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN + "ID " + evt.getNPC().getId()); + } + + } + @EventHandler public void onNPCDeath(NPCDeathEvent evt) { diff --git a/src/main/java/me/blackvein/quests/PlayerListener.java b/src/main/java/me/blackvein/quests/PlayerListener.java index d9d3d3d27..387f78928 100644 --- a/src/main/java/me/blackvein/quests/PlayerListener.java +++ b/src/main/java/me/blackvein/quests/PlayerListener.java @@ -653,6 +653,8 @@ public class PlayerListener implements Listener { quester.saveData(); } + if(plugin.questFactory.selectingNPCs.contains(evt.getPlayer())) + plugin.questFactory.selectingNPCs.remove(evt.getPlayer()); plugin.questers.remove(quester.name); } diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index 628e5698b..45cfeeeda 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -4,6 +4,7 @@ import me.blackvein.quests.util.ColorUtil; import java.io.File; import java.io.IOException; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -37,6 +38,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { Map selectedBlockStarts = new HashMap(); public Map selectedKillLocations = new HashMap(); public Map selectedReachLocations = new HashMap(); + public HashSet selectingNPCs = new HashSet(); public List names = new LinkedList(); ConversationFactory convoCreator; File questsFile; @@ -471,7 +473,8 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart"); + selectingNPCs.add((Player) context.getForWhom()); + return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @@ -486,12 +489,15 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { } context.setSessionData(CK.Q_START_NPC, input.intValue()); + selectingNPCs.remove((Player) context.getForWhom()); return new CreateMenuPrompt(); } else if (input.intValue() == -1) { context.setSessionData(CK.Q_START_NPC, null); + selectingNPCs.remove((Player) context.getForWhom()); return new CreateMenuPrompt(); } else if (input.intValue() == -2) { + selectingNPCs.remove((Player) context.getForWhom()); return new CreateMenuPrompt(); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC")); @@ -888,7 +894,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { LinkedList heroesClassRews = null; LinkedList heroesExpRews = null; - + if (cc.getSessionData(CK.Q_REDO_DELAY) != null) { redo = (Long) cc.getSessionData(CK.Q_REDO_DELAY); } @@ -930,11 +936,11 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { mcMMOSkillReqs = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILLS); mcMMOAmountReqs = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); } - + if (cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null) { heroesPrimaryReq = (String) cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS); } - + if (cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null) { heroesSecondaryReq = (String) cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS); } @@ -989,7 +995,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { mcMMOSkillRews = (LinkedList) cc.getSessionData(CK.REW_MCMMO_SKILLS); mcMMOSkillAmounts = (LinkedList) cc.getSessionData(CK.REW_MCMMO_AMOUNTS); } - + if (cc.getSessionData(CK.REW_HEROES_CLASSES) != null) { heroesClassRews = (LinkedList) cc.getSessionData(CK.REW_HEROES_CLASSES); heroesExpRews = (LinkedList) cc.getSessionData(CK.REW_HEROES_AMOUNTS); @@ -1362,11 +1368,11 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { } System.out.println("HERE 1"); - + if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null || RPGItemRews != null || heroesClassRews != null && heroesClassRews.isEmpty() == false) { System.out.println("HERE 2"); - + ConfigurationSection rews = cs.createSection("rewards"); rews.set("items", (itemRews != null && itemRews.isEmpty() == false) ? itemRews : null); @@ -1385,7 +1391,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { } else { cs.set("rewards", null); } - + System.out.println("HERE 3"); } @@ -1482,7 +1488,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { cc.setSessionData(CK.REW_MCMMO_SKILLS, q.mcmmoSkills); cc.setSessionData(CK.REW_MCMMO_AMOUNTS, q.mcmmoAmounts); } - + if (q.heroesClasses.isEmpty() == false) { cc.setSessionData(CK.REW_HEROES_CLASSES, q.heroesClasses); cc.setSessionData(CK.REW_HEROES_AMOUNTS, q.heroesAmounts); @@ -1492,7 +1498,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { cc.setSessionData(CK.REW_RPG_ITEM_IDS, q.rpgItemRewardIDs); cc.setSessionData(CK.REW_RPG_ITEM_AMOUNTS, q.rpgItemRewardAmounts); } - + if(q.heroesClasses.isEmpty() == false) { cc.setSessionData(CK.REW_HEROES_CLASSES, q.heroesClasses); cc.setSessionData(CK.REW_HEROES_AMOUNTS, q.heroesAmounts); @@ -1818,29 +1824,28 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { LinkedList used = new LinkedList(); - for (Quest quest : quests.quests) { + Quest found = quests.findQuest(input); - if (quest.name.equalsIgnoreCase(input) || quest.name.toLowerCase().contains(input.toLowerCase())) { + if (found != null) { - for (Quest q : quests.quests) { - - if (q.neededQuests.contains(q.name) || q.blockQuests.contains(q.name)) { - used.add(q.name); - } + for (Quest q : quests.quests) { + if (q.neededQuests.contains(q.name) || q.blockQuests.contains(q.name)) { + used.add(q.name); } - if (used.isEmpty()) { - context.setSessionData(CK.ED_QUEST_DELETE, quest.name); - return new DeletePrompt(); - } else { - ((Player) context.getForWhom()).sendMessage(RED + Lang.get("questEditorQuestAsRequirement1") + " \"" + PURPLE + context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\" " + Lang.get("questEditorQuestAsRequirement2")); - for (String s : used) { - ((Player) context.getForWhom()).sendMessage(RED + "- " + DARKRED + s); - } - ((Player) context.getForWhom()).sendMessage(RED + Lang.get("questEditorQuestAsRequirement3")); - return new SelectDeletePrompt(); + } + + if (used.isEmpty()) { + context.setSessionData(CK.ED_QUEST_DELETE, found.name); + return new DeletePrompt(); + } else { + ((Player) context.getForWhom()).sendMessage(RED + Lang.get("questEditorQuestAsRequirement1") + " \"" + PURPLE + context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\" " + Lang.get("questEditorQuestAsRequirement2")); + for (String s : used) { + ((Player) context.getForWhom()).sendMessage(RED + "- " + DARKRED + s); } + ((Player) context.getForWhom()).sendMessage(RED + Lang.get("questEditorQuestAsRequirement3")); + return new SelectDeletePrompt(); } } @@ -1862,7 +1867,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { String text = RED + Lang.get("questEditorDeleted") + " \"" + GOLD + (String) context.getSessionData(CK.ED_QUEST_DELETE) + RED + "\"?\n"; - text += YELLOW + Lang.get("yes") + "/" + Lang.get(Lang.get("no")); + text += YELLOW + Lang.get("yes") + "/" + Lang.get("no"); return text; @@ -1874,7 +1879,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { if (input.equalsIgnoreCase(Lang.get("yes"))) { deleteQuest(context); return Prompt.END_OF_CONVERSATION; - } else if (input.equalsIgnoreCase(Lang.get(Lang.get("no")))) { + } else if (input.equalsIgnoreCase(Lang.get("no"))) { return new MenuPrompt(); } else { return new DeletePrompt(); diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index b0cb4eb35..4106a69eb 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -511,16 +511,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } } - Quest quest = null; - - for (Quest q : quests) { - - if (q.name.toLowerCase().contains(name)) { - quest = q; - break; - } - - } + Quest quest = findQuest(name); if (quest != null) { @@ -815,16 +806,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } - Quest questToFind = null; - - for (Quest q : quests) { - - if (q.name.toLowerCase().contains(name)) { - questToFind = q; - break; - } - - } + Quest questToFind = findQuest(name); if (questToFind != null) { @@ -1407,14 +1389,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } - for (Quest q : quests) { - - if (q.name.toLowerCase().contains(name)) { - questToGive = q; - break; - } - - } + questToGive = findQuest(name); if (questToGive == null) { @@ -3409,7 +3384,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, if (Quests.checkList(config.getList("quests." + s + ".rewards.mcmmo-skills"), String.class)) { if (config.contains("quests." + s + ".rewards.mcmmo-levels")) { - + if(Quests.checkList(config.getList("quests." + s + ".rewards.mcmmo-levels"), Integer.class)){ boolean failed = false; @@ -3431,7 +3406,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, quest.mcmmoSkills.addAll(config.getStringList("quests." + s + ".rewards.mcmmo-skills")); quest.mcmmoAmounts.addAll(config.getIntegerList("quests." + s + ".rewards.mcmmo-levels")); - + } else { printSevere("[Quests] mcmmo-levels: Reward in Quest " + quest.name + " is not a list of numbers!"); continue; @@ -3447,13 +3422,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, continue; } } - + if (config.contains("quests." + s + ".rewards.heroes-exp-classes")) { if (Quests.checkList(config.getList("quests." + s + ".rewards.heroes-exp-classes"), String.class)) { if (config.contains("quests." + s + ".rewards.heroes-exp-amounts")) { - + if (Quests.checkList(config.getList("quests." + s + ".rewards.heroes-exp-amounts"), Double.class)) { boolean failed = false; @@ -3475,7 +3450,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, quest.heroesClasses.addAll(config.getStringList("quests." + s + ".rewards.heroes-exp-classes")); quest.heroesAmounts.addAll(config.getDoubleList("quests." + s + ".rewards.heroes-exp-amounts")); - + } else { printSevere("[Quests] heroes-exp-amounts: Reward in Quest " + quest.name + " is not a list of experience amounts (decimal numbers)!"); continue; @@ -4264,6 +4239,22 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, return null; } + public Quest findQuest(String s) { + + for(Quest q : quests) { + if(q.name.equalsIgnoreCase(s)) + return q; + } + + for(Quest q : quests) { + if(q.name.toLowerCase().contains(s.toLowerCase())) + return q; + } + + return null; + + } + public Event getEvent(String s) { for (Event e : events) { diff --git a/src/main/java/me/blackvein/quests/TODO b/src/main/java/me/blackvein/quests/TODO index 0a54a2d85..e69de29bb 100644 --- a/src/main/java/me/blackvein/quests/TODO +++ b/src/main/java/me/blackvein/quests/TODO @@ -1 +0,0 @@ -Add Heroes class requirements to the RequirementsPrompt, saveQuest() and loadQuest() stages etc. etc. \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java index 00dbd5f1f..fac24a730 100644 --- a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java @@ -1769,7 +1769,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { String text = GOLD + "- " + Lang.get("stageEditorDeliverItems") + " -\n"; if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) { text += GRAY + " (" + Lang.get("noneSet") + ")\n"; - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - " + Lang.get("stageEditorAddItem") + "\n"; + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - " + Lang.get("stageEditorDeliveryAddItem") + "\n"; text += GRAY + "2 - " + Lang.get("stageEditorDeliveryNPCs") + " (" + Lang.get("stageEditorNoItemsSet") + ")\n"; if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null) { text += BLUE + "3 - " + Lang.get("stageEditorDeliveryMessages") + " (" + Lang.get("noneSet") + ")\n"; @@ -1792,7 +1792,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - " + Lang.get("stageEditorAddItem") + "\n"; + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - " + Lang.get("stageEditorDeliveryAddItem") + "\n"; if (context.getSessionData(pref + CK.S_DELIVERY_NPCS) == null) { text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - " + Lang.get("stageEditorDeliveryNPCs") + " (" + Lang.get("noneSet") + ")\n"; @@ -1956,7 +1956,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { @Override public Prompt acceptInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("cmdCancel") == false) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { String[] args = input.split(";"); LinkedList messages = new LinkedList(); @@ -1976,7 +1976,8 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { @Override public String getPromptText(ConversationContext context) { - return YELLOW + Lang.get("stageEditorNPCToTalkToPrompt"); + questFactory.selectingNPCs.add((Player) context.getForWhom()); + return YELLOW + Lang.get("stageEditorNPCToTalkToPrompt") + "\n" + GOLD + Lang.get("npcHint"); } @Override @@ -2008,6 +2009,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } + questFactory.selectingNPCs.remove((Player) context.getForWhom()); context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { @@ -2016,6 +2018,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } + return new CreateStagePrompt(stageNum, questFactory, citizens); } @@ -2073,13 +2076,13 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { protected Prompt acceptValidatedInput(ConversationContext context, String input) { if (input.equalsIgnoreCase("1")) { - return new npcIdsToKillPrompt(); + return new NpcIdsToKillPrompt(); } else if (input.equalsIgnoreCase("2")) { if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) { context.getForWhom().sendRawMessage(RED + Lang.get("stageEditorNoNPCs")); return new NPCKillListPrompt(); } else { - return new npcAmountsToKillPrompt(); + return new NpcAmountsToKillPrompt(); } } else if (input.equalsIgnoreCase("3")) { context.getForWhom().sendRawMessage(YELLOW + Lang.get("stageEditorKillNPCsCleared")); @@ -2123,12 +2126,13 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } } - private class npcIdsToKillPrompt extends StringPrompt { + private class NpcIdsToKillPrompt extends StringPrompt { @Override public String getPromptText(ConversationContext context) { - return YELLOW + Lang.get("stageEditorNPCPrompt"); + questFactory.selectingNPCs.add((Player) context.getForWhom()); + return YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + GOLD + Lang.get("npcHint"); } @Override @@ -2148,13 +2152,13 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { npcs.add(i); } else { context.getForWhom().sendRawMessage(PINK + "" + i + RED + " " + Lang.get("stageEditorInvalidNPC")); - return new npcIdsToKillPrompt(); + return new NpcIdsToKillPrompt(); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage( PINK + s + RED + Lang.get("stageEditorNotListofNumbers")); - return new npcIdsToKillPrompt(); + return new NpcIdsToKillPrompt(); } @@ -2164,12 +2168,13 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } + questFactory.selectingNPCs.remove((Player) context.getForWhom()); return new NPCKillListPrompt(); } } - private class npcAmountsToKillPrompt extends StringPrompt { + private class NpcAmountsToKillPrompt extends StringPrompt { @Override public String getPromptText(ConversationContext context) { @@ -2191,12 +2196,12 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { amounts.add(Integer.parseInt(s)); } else { context.getForWhom().sendRawMessage(PINK + s + RED + " " + Lang.get("stageEditorNotGreaterThanZero")); - return new npcAmountsToKillPrompt(); + return new NpcAmountsToKillPrompt(); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage( PINK + s + RED + Lang.get("stageEditorNotListofNumbers")); - return new npcAmountsToKillPrompt(); + return new NpcAmountsToKillPrompt(); } } @@ -2295,7 +2300,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } - text += DARKGRAY + "|--------------------------|"; + text += DARKGRAY + "|--------------------------|\n"; text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - " + Lang.get("clear") + "\n"; text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - " + Lang.get("done"); @@ -2486,7 +2491,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { if (Quests.getMobType(s) != null) { - mobTypes.add(Quester.prettyMobString(Quests.getMobType(s))); + mobTypes.add(s); context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); } else { diff --git a/src/main/java/me/blackvein/quests/util/Lang.java b/src/main/java/me/blackvein/quests/util/Lang.java index 47958b999..3f7c24126 100644 --- a/src/main/java/me/blackvein/quests/util/Lang.java +++ b/src/main/java/me/blackvein/quests/util/Lang.java @@ -174,7 +174,7 @@ public class Lang { en.put("stageEditorItemIDsPrompt", "Enter item IDs, separating each one by a space, or enter \'cancel\' to return."); en.put("stageEditorNPCPrompt", "Enter NPC ids, separating each one by a space, or enter \'cancel\' to return."); en.put("stageEditorNPCToTalkToPrompt", "Enter NPC IDs, separating each one by a space, or enter \'clear\' to clear the NPC ID list, or \'cancel\' to return."); - en.put("stageEditorDeliveryMessagesPrompt", "Enter delivery messages, separating each one by a \"semi-colon\" or enter \'cancel\' to return"); + en.put("stageEditorDeliveryMessagesPrompt", "Enter delivery messages, separating each one by a semi-colon or enter \'cancel\' to return"); en.put("stageEditorKillNPCsPrompt", "Enter kill amounts (numbers), separating each one by a space, or enter \'cancel\' to return."); en.put("stageEditorMobsPrompt", "Enter mob names separating each one by a space, or enter \"cancel\" to return"); en.put("stageEditorMobAmountsPrompt", "Enter mob amounts separating each one by a space, or enter \"cancel\" to return"); @@ -482,6 +482,7 @@ public class Lang { en.put("worlds", "Worlds"); en.put("mobs", "Mobs"); en.put("invalidOption", "Invalid option!"); + en.put("npcHint", "Note: You can left or right click on NPC's to get their ID."); // //