From ba8514691b8e26f4285673a475f045597b0e84b5 Mon Sep 17 00:00:00 2001 From: Blackvein Date: Wed, 18 Sep 2013 23:28:54 -0700 Subject: [PATCH] More bugfixes (unfinished) --- pom.xml | 8 +- src/main/java/me/blackvein/quests/Event.java | 68 +++++++---- .../me/blackvein/quests/EventFactory.java | 96 +++++++-------- .../me/blackvein/quests/PlayerListener.java | 106 ++++++++++++----- src/main/java/me/blackvein/quests/Quest.java | 35 +++++- .../me/blackvein/quests/QuestFactory.java | 16 +-- .../java/me/blackvein/quests/Quester.java | 83 +++++++++++-- src/main/java/me/blackvein/quests/Quests.java | 109 ++++++++++++++++-- src/main/java/me/blackvein/quests/Stage.java | 48 ++++++-- .../java/me/blackvein/quests/StageTimer.java | 11 +- src/main/java/me/blackvein/quests/TODO | 0 src/main/java/me/blackvein/quests/languages | 12 -- src/main/java/me/blackvein/quests/notes | 5 - .../java/me/blackvein/quests/objective names | 16 --- src/main/java/me/blackvein/quests/particles | 12 -- .../quests/prompts/CreateStagePrompt.java | 63 +++++++++- .../me/blackvein/quests/stageDataNames.txt | 62 ---------- .../java/me/blackvein/quests/util/Lang.java | 3 + .../me/blackvein/quests/util/QuestMob.java | 77 +++++++------ src/main/resources/events.yml | 11 +- src/main/resources/quests.yml | 29 ++++- 21 files changed, 573 insertions(+), 297 deletions(-) delete mode 100644 src/main/java/me/blackvein/quests/TODO delete mode 100644 src/main/java/me/blackvein/quests/languages delete mode 100644 src/main/java/me/blackvein/quests/notes delete mode 100644 src/main/java/me/blackvein/quests/objective names delete mode 100644 src/main/java/me/blackvein/quests/particles delete mode 100644 src/main/java/me/blackvein/quests/stageDataNames.txt diff --git a/pom.xml b/pom.xml index e6620e441..e6df0de3e 100644 --- a/pom.xml +++ b/pom.xml @@ -30,10 +30,6 @@ vault-repo http://ci.herocraftonline.com/plugin/repository/everything - - mcMMO-repo - http://repo.mcmmo.org - @@ -61,7 +57,9 @@ com.gmail.nossr50.mcMMO mcMMO - LATEST + 1.0 + system + ${project.basedir}/lib/mcMMO.jar me.ThaH3lper diff --git a/src/main/java/me/blackvein/quests/Event.java b/src/main/java/me/blackvein/quests/Event.java index cec440be5..b303e166e 100644 --- a/src/main/java/me/blackvein/quests/Event.java +++ b/src/main/java/me/blackvein/quests/Event.java @@ -5,10 +5,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; - import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.QuestMob; - import org.bukkit.ChatColor; import org.bukkit.Effect; import org.bukkit.Location; @@ -26,6 +24,7 @@ public class Event { String name = ""; String message = null; boolean clearInv = false; + boolean failQuest = false; LinkedList explosions = new LinkedList(); Map effects = new HashMap(); LinkedList items = new LinkedList(); @@ -34,15 +33,15 @@ public class Event { World thunderWorld = null; int thunderDuration = 0; public LinkedList mobSpawns = new LinkedList() { - + @Override public boolean equals(Object o) { if (o instanceof LinkedList) { - + LinkedList other = (LinkedList) o; - + if (size() != other.size()) return false; - + for (int i = 0; i < size(); i++) { if (get(i).equals(other.get(i)) == false) return false; } @@ -83,6 +82,10 @@ public class Event { return false; } + if(other.failQuest != failQuest) { + return false; + } + if (other.explosions.equals(explosions) == false) { return false; } @@ -122,9 +125,13 @@ public class Event { if (other.thunderDuration != thunderDuration) { return false; } - - if (other.mobSpawns.equals(mobSpawns) == false) - return false; + + for(QuestMob qm : mobSpawns){ + + if(qm.equals(other.mobSpawns.get(mobSpawns.indexOf(qm))) == false) + return false; + + } if (other.lightningStrikes.equals(lightningStrikes) == false) { return false; @@ -171,7 +178,7 @@ public class Event { } - public void happen(Quester quester) { + public void fire(Quester quester) { Player player = quester.getPlayer(); @@ -220,9 +227,9 @@ public class Event { thunderWorld.setThundering(true); thunderWorld.setThunderDuration(thunderDuration); } - + if (mobSpawns.isEmpty() == false) { - + for (QuestMob questMob : mobSpawns) { questMob.spawn(); } @@ -281,6 +288,12 @@ public class Event { } + if(failQuest == true) { + + quester.currentQuest.failQuest(quester); + + } + } public static Event loadEvent(String name, Quests plugin) { @@ -316,6 +329,17 @@ public class Event { } + if (data.contains(eventKey + "fail-quest")) { + + if (data.isBoolean(eventKey + "fail-quest")) { + event.failQuest = data.getBoolean(eventKey + "fail-quest"); + } else { + Quests.printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "fail-quest: " + ChatColor.GOLD + "inside Event " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a true/false value!"); + return null; + } + + } + if (data.contains(eventKey + "explosions")) { if (Quests.checkList(data.getList(eventKey + "explosions"), String.class)) { @@ -465,32 +489,32 @@ public class Event { } } - + if (data.contains(eventKey + "mob-spawns")) { ConfigurationSection section = data.getConfigurationSection(eventKey + "mob-spawns"); - + //is a mob, the keys are just a number or something. for (String s : section.getKeys(false)) { String mobName = section.getString(s + ".name"); Location spawnLocation = Quests.getLocation(section.getString(s + ".spawn-location")); EntityType type = Quests.getMobType(section.getString(s + ".mob-type")); Integer mobAmount = section.getInt(s + ".spawn-amounts"); - - + + if (spawnLocation == null) { Quests.printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD + " inside " + ChatColor.GREEN + " mob-spawn-locations: " + ChatColor.GOLD + "inside Event " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not in proper location format!"); Quests.printSevere(ChatColor.GOLD + "[Quests] Proper location format is: \"WorldName x y z\""); return null; } - + if (type == null) { Quests.printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + section.getString(s + ".mob-type") + ChatColor.GOLD + " inside " + ChatColor.GREEN + " mob-spawn-types: " + ChatColor.GOLD + "inside Event " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a valid mob name!"); return null; } - + ItemStack[] inventory = new ItemStack[5]; Float[] dropChances = new Float[5]; - + inventory[0] = ItemUtil.readItemStack(section.getString(s + ".held-item")); dropChances[0] = (float) section.getDouble(s + ".held-item-drop-chance"); @@ -504,13 +528,13 @@ public class Event { dropChances[3] = (float) section.getDouble(s + ".chest-plate-drop-chance"); inventory[4] = ItemUtil.readItemStack(section.getString(s + ".helmet")); - dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance"); - + dropChances[4] = (float) section.getDouble(s + ".helmet-drop-chance"); + QuestMob questMob = new QuestMob(type, spawnLocation, mobAmount); questMob.inventory = inventory; questMob.dropChances = dropChances; questMob.setName(mobName); - + event.mobSpawns.add(questMob); } } diff --git a/src/main/java/me/blackvein/quests/EventFactory.java b/src/main/java/me/blackvein/quests/EventFactory.java index 1d599c0b4..1b5a62654 100644 --- a/src/main/java/me/blackvein/quests/EventFactory.java +++ b/src/main/java/me/blackvein/quests/EventFactory.java @@ -268,13 +268,13 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ } if (event.mobSpawns != null && event.mobSpawns.isEmpty() == false) { - + LinkedList questMobs = new LinkedList(); - + for (QuestMob questMob : event.mobSpawns) { questMobs.add(questMob.serialize()); } - + context.setSessionData(CK.E_MOB_TYPES, questMobs); } @@ -415,7 +415,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ for(Stage stage : quest.stages){ - if(stage.event != null && stage.event.name.equalsIgnoreCase(evt.name)){ + if(stage.finishEvent != null && stage.finishEvent.name.equalsIgnoreCase(evt.name)){ used.add(quest.name); break; } @@ -802,9 +802,9 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ for(Stage s : q.stages){ - if(s.event != null && s.event.name != null){ + if(s.finishEvent != null && s.finishEvent.name != null){ - if(s.event.name.equalsIgnoreCase(modifiedName)){ + if(s.finishEvent.name.equalsIgnoreCase(modifiedName)){ modified.add(q.getName()); break; } @@ -1010,16 +1010,16 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ try { if (context.getSessionData(CK.E_MOB_TYPES) != null) { int count = 0; - + for (String s : getCStringList(context, CK.E_MOB_TYPES)) { ConfigurationSection ss = section.getConfigurationSection("mob-spawns." + count); if (ss == null) { ss = section.createSection("mob-spawns." + count); } QuestMob questMob = QuestMob.fromString(s); - + if (questMob == null) continue; - + ss.set("name", questMob.getName()); ss.set("spawn-location", Quests.getLocationInfo(questMob.getSpawnLocation())); ss.set("mob-type", questMob.getType().getName()); @@ -1036,7 +1036,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ ss.set("helmet-drop-chance", questMob.dropChances[4]); count++; } - + } } catch (Exception e) { e.printStackTrace(); @@ -1891,7 +1891,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - " + Lang.get("done"); } else { LinkedList types = (LinkedList) context.getSessionData(CK.E_MOB_TYPES); - + for (int i = 0; i < types.size(); i++) { QuestMob qm = QuestMob.fromString(types.get(i)); text += GOLD + " " + (i + 1) + " - Edit: " + AQUA + qm.getType().getName() + ((qm.getName() != null) ? ": " + qm.getName() : "") + GRAY + " x " + DARKAQUA + qm.getSpawnAmounts() + GRAY + " -> " + GREEN + Quests.getLocationInfo(qm.getSpawnLocation()) + "\n"; @@ -1909,7 +1909,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ @Override public Prompt acceptInput(ConversationContext context, String input) { - + if (context.getSessionData(CK.E_MOB_TYPES) == null) { if (input.equalsIgnoreCase("1")) { return new QuestMobPrompt(0, null); @@ -1929,8 +1929,8 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ context.getForWhom().sendRawMessage(RED + Lang.get("eventEditorNotANumber")); return new MobPrompt(); } - - if (inp == types.size() + 1) { + + if (inp == types.size() + 1) { return new QuestMobPrompt(inp - 1, null); } else if (inp == types.size() + 2) { context.getForWhom().sendRawMessage(YELLOW + Lang.get("eventEditorMobSpawnsCleared")); @@ -1944,7 +1944,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ return new QuestMobPrompt(inp - 1, QuestMob.fromString(types.get(inp - 1))); } } - + return new MobPrompt(); } } @@ -1954,7 +1954,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ private QuestMob questMob; private Integer itemIndex = -1; private Integer mobIndex; - + public QuestMobPrompt(int mobIndex, QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; @@ -1964,13 +1964,13 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ public String getPromptText(ConversationContext context) { String text = GOLD + "- " + Lang.get("eventEditorAddMobTypes") + " - \n"; - + if (questMob == null) { - questMob = new QuestMob(); + questMob = new QuestMob(); } - + // Check/add newly made item - + if(context.getSessionData("newItem") != null){ if(itemIndex >= 0){ questMob.inventory[itemIndex] = ((ItemStack) context.getSessionData("tempStack")); @@ -1981,7 +1981,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ context.setSessionData("tempStack", null); } - + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - " + Lang.get("eventEditorSetMobName") + GRAY + " (" + ((questMob.getName() == null) ? Lang.get("noneSet") : AQUA + questMob.getName()) + ")\n"; text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - " + Lang.get("eventEditorSetMobType") + GRAY + " (" + ((questMob.getType() == null) ? Lang.get("eventEditorNoTypesSet") : AQUA + questMob.getType().getName()) + GRAY + ")\n"; text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - " + Lang.get("eventEditorAddSpawnLocation") + GRAY + " (" + ((questMob.getSpawnLocation() == null) ? GRAY + Lang.get("noneSet") : AQUA + Quests.getLocationInfo(questMob.getSpawnLocation()) ) + GRAY + ")\n"; @@ -1996,11 +1996,11 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ text += BLUE + "" + BOLD + "12" + RESET + YELLOW + " - " + Lang.get("eventEditorSetMobChestPlateDrop") + GRAY + " (" + ((questMob.dropChances[3] == null) ? GRAY + Lang.get("noneSet") : AQUA + "" + questMob.dropChances[3]) + GRAY + ")\n"; text += BLUE + "" + BOLD + "13" + RESET + YELLOW + " - " + Lang.get("eventEditorSetMobHelmet") + GRAY + " (" + ((questMob.inventory[4] == null) ? GRAY + Lang.get("noneSet") : AQUA + ItemUtil.getDisplayString(questMob.inventory[4])) + GRAY + ")\n"; text += BLUE + "" + BOLD + "14" + RESET + YELLOW + " - " + Lang.get("eventEditorSetMobHelmetDrop") + GRAY + " (" + ((questMob.dropChances[4] == null) ? GRAY + Lang.get("noneSet") : AQUA + "" + questMob.dropChances[4]) + GRAY + ")\n"; - - + + text += GREEN + "" + BOLD + "15" + RESET + YELLOW + " - " + Lang.get("done") + "\n"; text += RED + "" + BOLD + "16" + RESET + YELLOW + " - " + Lang.get("cancel"); - + return text; } @@ -2008,7 +2008,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ @SuppressWarnings("unchecked") @Override public Prompt acceptInput(ConversationContext context, String input) { - + if (input.equalsIgnoreCase("1")) { return new MobNamePrompt(mobIndex, questMob); } else if (input.equalsIgnoreCase("2")) { @@ -2075,31 +2075,31 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ } else { return new QuestMobPrompt(mobIndex, questMob); } - + } } - + private class MobNamePrompt extends StringPrompt { private QuestMob questMob; private Integer mobIndex; - + public MobNamePrompt (int mobIndex, QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; } - + @Override public String getPromptText(ConversationContext context) { String text = YELLOW + Lang.get("eventEditorSetMobNamePrompt"); return text; } - + @Override public Prompt acceptInput(ConversationContext context, String input) { - + if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { - return new QuestMobPrompt(mobIndex, questMob); + return new QuestMobPrompt(mobIndex, questMob); } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { questMob.setName(null); return new QuestMobPrompt(mobIndex, questMob); @@ -2110,12 +2110,12 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ } } } - + private class MobTypePrompt extends StringPrompt { - + private QuestMob questMob; private Integer mobIndex; - + public MobTypePrompt (int mobIndex, QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; @@ -2155,7 +2155,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ return mobs + YELLOW + Lang.get("eventEditorSetMobTypesPrompt"); } - + @Override public Prompt acceptInput(ConversationContext context, String input) { Player player = (Player) context.getForWhom(); @@ -2165,7 +2165,7 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ if (Quests.getMobType(input) != null) { questMob.setType(Quests.getMobType(input)); - + } else { player.sendMessage(PINK + input + " " + RED + Lang.get("eventEditorInvalidMob")); return new MobTypePrompt(mobIndex, questMob); @@ -2180,12 +2180,12 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ private QuestMob questMob; private Integer mobIndex; - + public MobAmountPrompt (int mobIndex, QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; } - + @Override public String getPromptText(ConversationContext context) { @@ -2224,10 +2224,10 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ } private class MobLocationPrompt extends StringPrompt { - + private QuestMob questMob; private Integer mobIndex; - + public MobLocationPrompt (int mobIndex, QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; @@ -2275,11 +2275,11 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ } private class MobDropPrompt extends StringPrompt { - + private QuestMob questMob; private Integer mobIndex; private Integer invIndex; - + public MobDropPrompt (int invIndex, int mobIndex ,QuestMob questMob) { this.questMob = questMob; this.mobIndex = mobIndex; @@ -2291,15 +2291,15 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ String text = YELLOW + Lang.get("eventEditorSetDropChance"); return text; } - + @Override public Prompt acceptInput(ConversationContext context, String input) { float chance = 0.0F; - + if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new QuestMobPrompt(mobIndex, questMob); } - + try { chance = Float.parseFloat(input); } catch (Exception e) { @@ -2310,9 +2310,9 @@ public class EventFactory implements ConversationAbandonedListener, ColorUtil{ context.getForWhom().sendRawMessage(RED + Lang.get("eventEditorInvalidDropChance")); return new MobDropPrompt(invIndex, mobIndex, questMob); } - + questMob.dropChances[invIndex] = chance; - + return new QuestMobPrompt(mobIndex, questMob); } } diff --git a/src/main/java/me/blackvein/quests/PlayerListener.java b/src/main/java/me/blackvein/quests/PlayerListener.java index 24616ca07..4f251dd25 100644 --- a/src/main/java/me/blackvein/quests/PlayerListener.java +++ b/src/main/java/me/blackvein/quests/PlayerListener.java @@ -1,9 +1,7 @@ package me.blackvein.quests; import java.io.File; - import net.citizensnpcs.api.CitizensAPI; - import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -50,63 +48,63 @@ public class PlayerListener implements Listener { quester.useBlock(evt.getClickedBlock().getType()); - }else if (plugin.questFactory.selectedBlockStarts.containsKey(evt.getPlayer())){ + } else if (plugin.questFactory.selectedBlockStarts.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.questFactory.selectedBlockStarts.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.eventFactory.selectedExplosionLocations.containsKey(evt.getPlayer())){ + } else if (plugin.eventFactory.selectedExplosionLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.eventFactory.selectedExplosionLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.eventFactory.selectedEffectLocations.containsKey(evt.getPlayer())){ + } else if (plugin.eventFactory.selectedEffectLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.eventFactory.selectedEffectLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.eventFactory.selectedMobLocations.containsKey(evt.getPlayer())){ + } else if (plugin.eventFactory.selectedMobLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.eventFactory.selectedMobLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.eventFactory.selectedLightningLocations.containsKey(evt.getPlayer())){ + } else if (plugin.eventFactory.selectedLightningLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.eventFactory.selectedLightningLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.eventFactory.selectedTeleportLocations.containsKey(evt.getPlayer())){ + } else if (plugin.eventFactory.selectedTeleportLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.eventFactory.selectedTeleportLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.questFactory.selectedKillLocations.containsKey(evt.getPlayer())){ + } else if (plugin.questFactory.selectedKillLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.questFactory.selectedKillLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if (plugin.questFactory.selectedReachLocations.containsKey(evt.getPlayer())){ + } else if (plugin.questFactory.selectedReachLocations.containsKey(evt.getPlayer())) { Block block = evt.getClickedBlock(); Location loc = block.getLocation(); plugin.questFactory.selectedReachLocations.put(evt.getPlayer(), block); evt.getPlayer().sendMessage(ChatColor.GOLD + "Selected location " + ChatColor.AQUA + loc.getWorld().getName() + ": " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ChatColor.GOLD + " (" + ChatColor.GREEN + Quester.prettyItemString(block.getType().getId()) + ChatColor.GOLD + ")"); - }else if(player.isConversing() == false){ + } else if (player.isConversing() == false) { for (final Quest q : plugin.quests) { @@ -127,7 +125,7 @@ public class PlayerListener implements Listener { player.sendMessage(ChatColor.YELLOW + "You may not take " + ChatColor.AQUA + q.name + ChatColor.YELLOW + " again for another " + ChatColor.DARK_PURPLE + Quests.getTime(quester.getDifference(q)) + ChatColor.YELLOW + "."); return; - }else if (quester.completedQuests.contains(q.name) && q.redoDelay < 0) { + } else if (quester.completedQuests.contains(q.name) && q.redoDelay < 0) { player.sendMessage(ChatColor.YELLOW + "You have already completed " + ChatColor.AQUA + q.name + ChatColor.YELLOW + "."); return; @@ -144,9 +142,9 @@ public class PlayerListener implements Listener { + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; for (String msg : s.split("
")) { - player.sendMessage(msg); + player.sendMessage(msg); } - + plugin.conversationFactory.buildConversation((Conversable) player).begin(); } @@ -166,6 +164,40 @@ public class PlayerListener implements Listener { } + @EventHandler + public void onPlayerChat(AsyncPlayerChatEvent evt) { + + if (plugin.checkQuester(evt.getPlayer().getName()) == false) { + + Quester quester = plugin.getQuester(evt.getPlayer().getName()); + if (quester.currentStage != null) { + + if (quester.currentStage.chatEvents.isEmpty() == false) { + + String chat = evt.getMessage(); + for (String s : quester.currentStage.chatEvents.keySet()) { + + if (s.equalsIgnoreCase(chat)) { + + if (quester.eventFired.get(s) == false) { + + quester.currentStage.chatEvents.get(s).fire(quester); + quester.eventFired.put(s, true); + + } + + } + + } + + } + + } + + } + + } + @EventHandler public void onBlockDamage(BlockDamageEvent evt) { @@ -374,7 +406,6 @@ public class PlayerListener implements Listener { * hotbar slots * */ - @EventHandler public void onEntityDeath(EntityDeathEvent evt) { @@ -404,7 +435,7 @@ public class PlayerListener implements Listener { if (okay) { Quester quester = plugin.getQuester(player.getName()); - + if (quester.hasObjective("killMob")) { quester.killMob(evt.getEntity().getLocation(), evt.getEntity().getType()); } @@ -471,7 +502,7 @@ public class PlayerListener implements Listener { if (okay) { Quester quester = plugin.getQuester(player.getName()); - + if (quester.hasObjective("killPlayer")) { quester.killPlayer(evt.getEntity().getName()); } @@ -514,13 +545,25 @@ public class PlayerListener implements Listener { } + Player player = evt.getEntity(); + if (plugin.checkQuester(player.getName()) == false) { + + Quester quester = plugin.getQuester(player.getName()); + if(quester.currentStage != null){ + if(quester.currentStage.deathEvent != null){ + quester.currentStage.deathEvent.fire(quester); + } + } + + } + } @EventHandler public void onPlayerFish(PlayerFishEvent evt) { Player player = evt.getPlayer(); - if(plugin.checkQuester(player.getName()) == false){ + if (plugin.checkQuester(player.getName()) == false) { Quester quester = plugin.getQuester(player.getName()); if (quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { @@ -534,15 +577,17 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent evt) { - if(plugin.checkQuester(evt.getPlayer().getName()) == false){ + if (plugin.checkQuester(evt.getPlayer().getName()) == false) { Quester quester = new Quester(plugin); quester.name = evt.getPlayer().getName(); if (new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()) { quester.loadData(); + } else { quester.saveData(); } + plugin.questers.put(evt.getPlayer().getName(), quester); for (String s : quester.completedQuests) { @@ -551,8 +596,9 @@ public class PlayerListener implements Listener { if (q != null) { - if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1) + if (quester.completedTimes.containsKey(q.name) == false && q.redoDelay > -1) { quester.completedTimes.put(q.name, System.currentTimeMillis()); + } } @@ -560,9 +606,9 @@ public class PlayerListener implements Listener { quester.checkQuest(); - if(quester.currentQuest != null){ + if (quester.currentQuest != null) { - if(quester.currentStage.delay > -1){ + if (quester.currentStage.delay > -1) { quester.startStageTimer(); @@ -577,12 +623,19 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent evt) { - if(plugin.checkQuester(evt.getPlayer().getName()) == false){ + if (plugin.checkQuester(evt.getPlayer().getName()) == false) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.currentQuest != null){ - if(quester.currentStage.delay > -1) + if (quester.currentQuest != null) { + + if (quester.currentStage.delay > -1) { quester.stopStageTimer(); + } + + if(quester.currentStage.disconnectEvent != null){ + quester.currentStage.disconnectEvent.fire(quester); + } + } quester.saveData(); @@ -595,7 +648,7 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent evt) { - if(plugin.checkQuester(evt.getPlayer().getName()) == false){ + if (plugin.checkQuester(evt.getPlayer().getName()) == false) { boolean isPlayer = true; if (plugin.citizens != null) { @@ -619,5 +672,4 @@ public class PlayerListener implements Listener { } } - } diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index 2d8be85a1..3159ac180 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import com.gmail.nossr50.util.player.UserManager; +import me.blackvein.quests.util.Lang; public class Quest { @@ -70,8 +71,8 @@ public class Quest { if(q.currentStage.script != null) plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); - if(q.currentStage.event != null) - q.currentStage.event.happen(q); + if(q.currentStage.finishEvent != null) + q.currentStage.finishEvent.fire(q); completeQuest(q); @@ -98,15 +99,19 @@ public class Quest { return; } - q.reset(); + q.resetObjectives(); if(q.currentStage.script != null) plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, q.getPlayer()); - if(q.currentStage.event != null) - q.currentStage.event.happen(q); + if(q.currentStage.finishEvent != null) + q.currentStage.finishEvent.fire(q); q.currentStage = stages.get(stage); + + if(q.currentStage.startEvent != null) + q.currentStage.startEvent.fire(q); + q.addEmpties(); q.getPlayer().sendMessage(ChatColor.GOLD + "---(Objectives)---"); @@ -185,7 +190,7 @@ public class Quest { public void completeQuest(Quester q){ Player player = plugin.getServer().getPlayerExact(q.name); - q.reset(); + q.resetObjectives(); q.completedQuests.add(name); String none = ChatColor.GRAY + "- (None)"; @@ -287,6 +292,24 @@ public class Quest { } + public void failQuest(Quester q){ + + Player player = plugin.getServer().getPlayerExact(q.name); + q.resetObjectives(); + + player.sendMessage(ChatColor.AQUA + "-- " + ChatColor.DARK_PURPLE + q.currentQuest.name + ChatColor.AQUA + " -- "); + player.sendMessage(ChatColor.RED + Lang.get("questFailed")); + + q.currentQuest = null; + + q.currentStage = null; + q.currentStageIndex = 0; + + q.saveData(); + player.updateInventory(); + + } + @Override public boolean equals(Object o){ diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index d9333592f..4e315d3c7 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -387,25 +387,25 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { loadQuest(context, q); return new CreateMenuPrompt(); } - + } - + for (Quest q : quests.getQuests()) { if (q.getName().toLowerCase().startsWith(input.toLowerCase())) { loadQuest(context, q); return new CreateMenuPrompt(); } - + } - + for (Quest q : quests.getQuests()) { if (q.getName().toLowerCase().contains(input.toLowerCase())) { loadQuest(context, q); return new CreateMenuPrompt(); } - + } return new SelectEditPrompt(); @@ -1195,7 +1195,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { mobLocNames = (LinkedList) cc.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES); } } - + if (cc.getSessionData(pref + CK.S_REACH_LOCATIONS) != null) { reachLocs = (LinkedList) cc.getSessionData(pref + CK.S_REACH_LOCATIONS); reachRadii = (LinkedList) cc.getSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS); @@ -1651,8 +1651,8 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil { } - if (stage.event != null) { - cc.setSessionData(pref + CK.S_EVENT, stage.event.getName()); + if (stage.finishEvent != null) { + cc.setSessionData(pref + CK.S_EVENT, stage.finishEvent.getName()); } diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index 08b00f1e6..81f57f242 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -4,7 +4,6 @@ import java.io.File; import java.util.*; import java.util.Map.Entry; import java.util.logging.Level; - import me.blackvein.quests.util.ItemUtil; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; @@ -63,6 +62,7 @@ public class Quester { LinkedList radiiToReachWithin = new LinkedList(); Map mobsTamed = new EnumMap(EntityType.class); Map sheepSheared = new EnumMap(DyeColor.class); + public Map eventFired = new HashMap(); final Random random = new Random(); public Quester(Quests newPlugin) { @@ -107,8 +107,21 @@ public class Quester { if (stageStartMessage != null) { getPlayer().sendMessage(Quests.parseString(stageStartMessage, currentQuest)); } + + if(currentStage.chatEvents.isEmpty() == false){ + + for(String chatTrigger : currentStage.chatEvents.keySet()){ + + eventFired.put(chatTrigger, false); + + } + + } + if(q.initialEvent != null) - q.initialEvent.happen(this); + q.initialEvent.fire(this); + if(currentStage.startEvent != null) + currentStage.startEvent.fire(this); } else { @@ -365,7 +378,6 @@ public class Quester { } - } for (NPC n : currentStage.citizensToInteract) { @@ -394,13 +406,17 @@ public class Quester { for (NPC n2 : citizensKilled) { - if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) { + if(n.getId() == n2.getId()){ - unfinishedObjectives.add(ChatColor.GREEN + "Kill " + n.getName() + ChatColor.GREEN + " " + citizenNumKilled.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); + if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) { - } else { + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + n.getName() + ChatColor.GREEN + " " + citizenNumKilled.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); - finishedObjectives.add(ChatColor.GRAY + "Kill " + n.getName() + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); + } else { + + finishedObjectives.add(ChatColor.GRAY + "Kill " + n.getName() + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))); + + } } @@ -1192,6 +1208,9 @@ public class Quester { public void addEmpties() { + System.out.println("Adding empties."); + System.out.println("Citizens to kill: " + currentStage.citizensToKill.size()); + if (currentStage.blocksToDamage.isEmpty() == false) { for (Material m : currentStage.blocksToDamage.keySet()) { @@ -1279,6 +1298,7 @@ public class Quester { if (currentStage.citizensToKill.isEmpty() == false) { for (NPC n : currentStage.citizensToKill) { + System.out.println("Adding.."); citizensKilled.add(n); citizenNumKilled.add(0); @@ -1330,7 +1350,7 @@ public class Quester { } - public void reset() { + public void resetObjectives() { blocksDamaged.clear(); blocksBroken.clear(); @@ -1963,6 +1983,21 @@ public class Quester { data.set("stage-delay", delayTimeLeft); } + if(eventFired.isEmpty() == false){ + + LinkedList triggers = new LinkedList(); + for(String trigger : eventFired.keySet()){ + + if(eventFired.get(trigger) == true) + triggers.add(trigger); + + } + + if(triggers.isEmpty() == false) + data.set("chat-triggers", triggers); + + } + } else { @@ -2071,14 +2106,14 @@ public class Quester { } } - + if (stage == null) { currentQuest = quest; currentQuest.completeQuest(this); Quests.log.log(Level.SEVERE, "[Quests] Invalid stage for player: \"" + name + "\". Quest ended."); return true; } - + currentQuest = quest; currentStage = stage; @@ -2360,6 +2395,9 @@ public class Quester { List ids = data.getIntegerList("citizen-ids-killed"); List num = data.getIntegerList("citizen-amounts-killed"); + citizensKilled.clear(); + citizenNumKilled.clear(); + for (int i : ids) { citizensKilled.add(CitizensAPI.getNPCRegistry().getById(i)); @@ -2545,6 +2583,27 @@ public class Quester { } + if(currentStage.chatEvents.isEmpty() == false){ + + for(String trig : currentStage.chatEvents.keySet()){ + + eventFired.put(trig, false); + + } + + } + + if(data.contains("chat-triggers")){ + + List triggers = data.getStringList("chat-triggers"); + for(String s : triggers){ + + eventFired.put(s, true); + + } + + } + } return true; @@ -2601,7 +2660,7 @@ public class Quester { if (q.equals(currentQuest) == false) { currentStage = null; - reset(); + resetObjectives(); if (plugin.getServer().getPlayer(name) != null) { plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " has been modified. You have been forced to quit the Quest."); } @@ -2618,7 +2677,7 @@ public class Quester { if (exists == false) { currentStage = null; - reset(); + resetObjectives(); if (plugin.getServer().getPlayer(name) != null) { plugin.getServer().getPlayer(name).sendMessage(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Your active Quest " + ChatColor.DARK_PURPLE + currentQuest.name + ChatColor.RED + " no longer exists. You have been forced to quit the Quest."); } diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index fbf5b140c..87bbb94cd 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -847,10 +847,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, Quester quester = getQuester(cs.getName()); if (quester.currentQuest != null) { - quester.reset(); + quester.resetObjectives(); quester.currentStage = null; cs.sendMessage(YELLOW + "You have quit " + PURPLE + quester.currentQuest.name + YELLOW + "."); quester.currentQuest = null; + quester.saveData(); + quester.loadData(); return true; } else { @@ -1090,7 +1092,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } else { - quester.reset(); + quester.resetObjectives(); quester.currentStage = null; player.sendMessage(GREEN + target.getName() + GOLD + " has forcibly quit the Quest " + PURPLE + quester.currentQuest.name + GOLD + "."); target.sendMessage(GREEN + player.getName() + GOLD + " has forced you to quit the Quest " + PURPLE + quester.currentQuest.name + GOLD + "."); @@ -1357,7 +1359,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, Quester quester = getQuester(target.getName()); - quester.reset(); + quester.resetObjectives(); quester.currentQuest = questToGive; quester.currentStage = questToGive.stages.getFirst(); @@ -2961,14 +2963,107 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } - if (config.contains("quests." + s + ".stages.ordered." + s2 + ".event")) { + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".start-event")) { - Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".event"), this); + Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".start-event"), this); if (evt != null) { - stage.event = evt; + stage.startEvent = evt; } else { - printSevere("[Quests] Event in Stage " + s2 + " of Quest " + quest.name + " failed to load."); + printSevere("[Quests] start-event in Stage " + s2 + " of Quest " + quest.name + " failed to load."); + stageFailed = true; + break; + } + + } + + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".death-event")) { + + Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".death-event"), this); + + if (evt != null) { + stage.deathEvent = evt; + } else { + printSevere("[Quests] death-event in Stage " + s2 + " of Quest " + quest.name + " failed to load."); + stageFailed = true; + break; + } + + } + + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".disconnect-event")) { + + Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".disconnect-event"), this); + + if (evt != null) { + stage.disconnectEvent = evt; + } else { + printSevere("[Quests] disconnect-event in Stage " + s2 + " of Quest " + quest.name + " failed to load."); + stageFailed = true; + break; + } + + } + + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".chat-events")) { + + if(config.isList("quests." + s + ".stages.ordered." + s2 + ".chat-events")){ + + if(config.contains("quests." + s + ".stages.ordered." + s2 + ".chat-event-triggers")){ + + if (config.isList("quests." + s + ".stages.ordered." + s2 + ".chat-event-triggers")) { + + List chatEvents = config.getStringList("quests." + s + ".stages.ordered." + s2 + ".chat-events"); + List chatEventTriggers = config.getStringList("quests." + s + ".stages.ordered." + s2 + ".chat-event-triggers"); + boolean loadEventFailed = false; + + for (int i = 0; i < chatEvents.size(); i++) { + + Event evt = Event.loadEvent(chatEvents.get(i), this); + + if (evt != null) { + stage.chatEvents.put(chatEventTriggers.get(i), evt); + } else { + printSevere("[Quests] " + chatEvents.get(i) + " inside of chat-events: in Stage " + s2 + " of Quest " + quest.name + " failed to load."); + stageFailed = true; + loadEventFailed = true; + break; + } + + } + + if (loadEventFailed) { + break; + } + + } else { + printSevere("[Quests] chat-event-triggers in Stage " + s2 + " of Quest " + quest.name + " is not in list format!"); + stageFailed = true; + break; + } + + }else{ + printSevere("[Quests] Stage " + s2 + " of Quest " + quest.name + " is missing chat-event-triggers!"); + stageFailed = true; + break; + } + + }else{ + printSevere("[Quests] chat-events in Stage " + s2 + " of Quest " + quest.name + " is not in list format!"); + stageFailed = true; + break; + } + + } + + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".finish-event")) { + + Event evt = Event.loadEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".finish-event"), this); + + if (evt != null) { + stage.finishEvent = evt; + } else { + printSevere("[Quests] finish-event in Stage " + s2 + " of Quest " + quest.name + " failed to load."); stageFailed = true; break; } diff --git a/src/main/java/me/blackvein/quests/Stage.java b/src/main/java/me/blackvein/quests/Stage.java index 43c1b48bb..374a383cb 100644 --- a/src/main/java/me/blackvein/quests/Stage.java +++ b/src/main/java/me/blackvein/quests/Stage.java @@ -3,11 +3,8 @@ package me.blackvein.quests; import java.util.EnumMap; import java.util.HashMap; import java.util.LinkedList; -import java.util.List; import java.util.Map; - import net.citizensnpcs.api.npc.NPC; - import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; @@ -26,7 +23,7 @@ public class Stage { Integer fishToCatch; Integer playersToKill; Map, Integer> itemsToEnchant = new HashMap, Integer>(); - + LinkedList mobsToKill = new LinkedList(); LinkedList mobNumToKill = new LinkedList(); LinkedList locationsToKillWithin = new LinkedList(); @@ -92,7 +89,7 @@ public class Stage { if (o instanceof LinkedList) { LinkedList otherList = (LinkedList) o; - + if (this.size() != otherList.size()) return false; for (int i = 0; i < this.size(); i++) { @@ -118,12 +115,16 @@ public class Stage { public Map sheepToShear = new EnumMap(DyeColor.class); public Map, Boolean> itemsToCraft = new HashMap, Boolean>(); public String script; - public Event event; + public Event startEvent = null; + public Event deathEvent = null; + public Map chatEvents = new HashMap(); + public Event disconnectEvent = null; + public Event finishEvent = null; public long delay = -1; public String delayMessage = null; public String completeMessage = null; public String startMessage = null; - + @Override public boolean equals(Object o) { @@ -265,16 +266,39 @@ public class Stage { return false; } - if (other.event != null && event != null) { - if (other.event.equals(event) == false) { + if (other.startEvent != null && startEvent != null) { + if (other.startEvent.equals(startEvent) == false) { return false; } - } else if (other.event != null && event == null) { + } else if (other.startEvent != null && startEvent == null) { return false; - } else if (other.event == null && event != null) { + } else if (other.startEvent == null && startEvent != null) { return false; } + if (other.deathEvent != null && deathEvent != null) { + if (other.deathEvent.equals(deathEvent) == false) { + return false; + } + } else if (other.deathEvent != null && deathEvent == null) { + return false; + } else if (other.deathEvent == null && deathEvent != null) { + return false; + } + + if (other.finishEvent != null && finishEvent != null) { + if (other.finishEvent.equals(finishEvent) == false) { + return false; + } + } else if (other.finishEvent != null && finishEvent == null) { + return false; + } else if (other.finishEvent == null && finishEvent != null) { + return false; + } + + if(other.chatEvents.equals(chatEvents) == false) + return false; + if(other.delay != delay) return false; @@ -314,5 +338,5 @@ public class Stage { } - + } diff --git a/src/main/java/me/blackvein/quests/StageTimer.java b/src/main/java/me/blackvein/quests/StageTimer.java index d23bb4835..46b42a87d 100644 --- a/src/main/java/me/blackvein/quests/StageTimer.java +++ b/src/main/java/me/blackvein/quests/StageTimer.java @@ -28,20 +28,21 @@ public class StageTimer implements Runnable{ if(quester.currentStage.script != null) plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player); - if(quester.currentStage.event != null) - quester.currentStage.event.happen(quester); + if(quester.currentStage.finishEvent != null) + quester.currentStage.finishEvent.fire(quester); quester.currentQuest.completeQuest(quester); }else { - quester.reset(); + quester.resetObjectives(); if(quester.currentStage.script != null) plugin.trigger.parseQuestTaskTrigger(quester.currentStage.script, player); - if(quester.currentStage.event != null) - quester.currentStage.event.happen(quester); + if(quester.currentStage.finishEvent != null) + quester.currentStage.finishEvent.fire(quester); quester.currentStage = quester.currentQuest.stages.get(quester.currentStageIndex + 1); quester.currentStageIndex++; + System.out.println("Adding empties from stage timer"); quester.addEmpties(); quester.delayStartTime = 0; quester.delayTimeLeft = -1; diff --git a/src/main/java/me/blackvein/quests/TODO b/src/main/java/me/blackvein/quests/TODO deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/java/me/blackvein/quests/languages b/src/main/java/me/blackvein/quests/languages deleted file mode 100644 index 05712d8a5..000000000 --- a/src/main/java/me/blackvein/quests/languages +++ /dev/null @@ -1,12 +0,0 @@ -Languages - -en - English -fr - French -es - Spanish -de - German -sv - Swedish -nl - Dutch -pl - Polish -da - Danish -zh - Chinese [Simplified] -no - Norwegian \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/notes b/src/main/java/me/blackvein/quests/notes deleted file mode 100644 index 218714a50..000000000 --- a/src/main/java/me/blackvein/quests/notes +++ /dev/null @@ -1,5 +0,0 @@ -Parties - --1 : No parties -0 : Parties allowed -1+ : Only parties of x size or greater \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/objective names b/src/main/java/me/blackvein/quests/objective names deleted file mode 100644 index 213191133..000000000 --- a/src/main/java/me/blackvein/quests/objective names +++ /dev/null @@ -1,16 +0,0 @@ -damageBlock -breakBlock -placeBlock -useBlock -cutBlock -catchFish -enchantItem -killMob -deliverItem -killPlayer -talkToNPC -killNPC -tameMob -shearSheep -craftItem -reachLocation \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/particles b/src/main/java/me/blackvein/quests/particles deleted file mode 100644 index e866a85e5..000000000 --- a/src/main/java/me/blackvein/quests/particles +++ /dev/null @@ -1,12 +0,0 @@ -enchant -crit -spell -magiccrit -mobspell -note -portal -dust -witch -snowball -splash -smoke \ 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 2af226f47..11187fd93 100644 --- a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java @@ -418,7 +418,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } else if (input.equalsIgnoreCase("16")) { return new ShearListPrompt(); } else if (input.equalsIgnoreCase("17")) { - return new EventPrompt(); + return new EventsPrompt(); } else if (input.equalsIgnoreCase("18")) { return new DelayPrompt(); } else if (input.equalsIgnoreCase("19")) { @@ -3367,6 +3367,67 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil { } } + private class EventsPrompt extends FixedSetPrompt { + + public EventsPrompt(){ + + super("1", "2", "3", "4"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = DARKGREEN + "- " + Lang.get("stageEditorEvents") + " -\n"; + if (questFactory.quests.events.isEmpty()) { + text += RED + "- None"; + } else { + for (Event e : questFactory.quests.events) { + text += GREEN + "- " + e.getName() + "\n"; + } + } + + return text + YELLOW + Lang.get("stageEditorEventsPrompt"); + + } + + @Override + public Prompt acceptValidatedInput(ConversationContext context, String input) { + + Player player = (Player) context.getForWhom(); + + if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + + Event found = null; + + for (Event e : questFactory.quests.events) { + + if (e.getName().equalsIgnoreCase(input)) { + found = e; + break; + } + + } + + if (found == null) { + player.sendMessage(RED + input + YELLOW + " " + Lang.get("stageEditorInvalidEvent")); + return new EventsPrompt(); + } else { + context.setSessionData(pref + CK.S_EVENT, found.getName()); + return new CreateStagePrompt(stageNum, questFactory, citizens); + } + + } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(pref + CK.S_EVENT, null); + player.sendMessage(YELLOW + "Event cleared."); + return new CreateStagePrompt(stageNum, questFactory, citizens); + } else { + return new CreateStagePrompt(stageNum, questFactory, citizens); + } + + } + } + private class EventPrompt extends StringPrompt { @Override diff --git a/src/main/java/me/blackvein/quests/stageDataNames.txt b/src/main/java/me/blackvein/quests/stageDataNames.txt deleted file mode 100644 index 0addd757a..000000000 --- a/src/main/java/me/blackvein/quests/stageDataNames.txt +++ /dev/null @@ -1,62 +0,0 @@ -stage#breakIds -stage#breakAmounts - -stage#damageIds -stage#damageAmounts - -stage#placeIds -stage#placeAmounts - -stage#useIds -stage#useAmounts - -stage#cutIds -stage#cutAmounts - -stage#fish - -stage#playerKill - -stage#enchantTypes -stage#enchantIds -stage#enchantAmounts - -stage#deliveryIds -stage#deliveryAmounts -stage#deliveryNPCs -stage#deliveryMessages - -stage#npcIdsToTalkTo - -stage#npcIdsToKill -stage#npcAmountsToKill - -stage#mobTypes -stage#mobAmounts -stage#killLocations -stage#killLocationRadii -stage#killLocationNames - -stage#bossIds -stage#bossAmounts -^^^^ -boss-ids-to-kill -boss-amounts-to-kill -^^^^ - -stage#reachLocations -stage#reachLocationRadii -stage#reachLocationNames - -stage#tameTypes -stage#tameAmounts - -stage#shearColors -stage#shearAmounts - -stage#event - -stage#delay -stage#delayMessage - -stage#denizen \ No newline at end of file diff --git a/src/main/java/me/blackvein/quests/util/Lang.java b/src/main/java/me/blackvein/quests/util/Lang.java index 82b7795d2..f813c0efa 100644 --- a/src/main/java/me/blackvein/quests/util/Lang.java +++ b/src/main/java/me/blackvein/quests/util/Lang.java @@ -31,6 +31,9 @@ public class Lang { //English //TODO: If finished, completely check everything. //Quests + + en.put("questFailed", "*QUEST FAILED*"); + //Quest create menu en.put("questEditorHeader", "Create Quest"); en.put("questEditorCreate", "Create new Quest"); diff --git a/src/main/java/me/blackvein/quests/util/QuestMob.java b/src/main/java/me/blackvein/quests/util/QuestMob.java index cf7129acf..1e1bbea1e 100644 --- a/src/main/java/me/blackvein/quests/util/QuestMob.java +++ b/src/main/java/me/blackvein/quests/util/QuestMob.java @@ -1,7 +1,6 @@ package me.blackvein.quests.util; import me.blackvein.quests.Quests; - import org.bukkit.Location; import org.bukkit.World; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity; @@ -27,31 +26,31 @@ public class QuestMob { this.spawnLocation = spawnLocation; this.spawnAmounts = spawnAmounts; } - + public QuestMob() { - + } - + public void setSpawnLocation(Location spawnLocation) { this.spawnLocation = spawnLocation; } - + public Location getSpawnLocation() { return spawnLocation; } - + public void setType(EntityType entityType) { this.entityType = entityType; } - + public EntityType getType() { return entityType; } - + public void setSpawnAmounts(int spawnAmounts) { this.spawnAmounts = spawnAmounts; } - + public Integer getSpawnAmounts() { return spawnAmounts; } @@ -60,7 +59,7 @@ public class QuestMob { public void setName(String name) { this.name = name; } - + public String getName() { return name; @@ -97,9 +96,9 @@ public class QuestMob { World world = spawnLocation.getWorld(); for (int i = 0; i < spawnAmounts; i++) { - + Entity entity = world.spawnEntity(spawnLocation, entityType); - + if (name != null) { ((LivingEntity) entity).setCustomName(name); ((LivingEntity) entity).setCustomNameVisible(true); @@ -120,51 +119,51 @@ public class QuestMob { } } - + public String serialize() { String string = ""; string += "type-" + entityType.getName(); if (name != null) string += "::name-" + name; if (spawnLocation != null) string += "::spawn-" + Quests.getLocationInfo(spawnLocation); if (spawnAmounts != null) string += "::amounts-" + spawnAmounts; - + if (inventory[0] != null) { string += "::hand-" + ItemUtil.serialize(inventory[0]); string += "::hand_drop-" + dropChances[0]; } - + if (inventory[1] != null) { string += "::boots-" + ItemUtil.serialize(inventory[1]); string += "::boots_drop-" + dropChances[1]; } - + if (inventory[2] != null) { string += "::leggings-" + ItemUtil.serialize(inventory[2]); string += "::leggings_drop-" + dropChances[2]; } - + if (inventory[3] != null) { string += "::chest-" + ItemUtil.serialize(inventory[3]); string += "::chest_drop-" + dropChances[3]; } - + if (inventory[4] != null) { string += "::helmet-" + ItemUtil.serialize(inventory[4]); string += "::helmet_drop-" + dropChances[4]; } - + return string; } - + public static QuestMob fromString(String str) { - + String name = null; EntityType entityType = null; Location loc = null; Integer amounts = null; ItemStack[] inventory = new ItemStack[5]; Float[] dropChances = new Float[5]; - + String[] args = str.split("::"); for (String string : args) { if (string.startsWith("type-")) { @@ -196,32 +195,38 @@ public class QuestMob { } else if (string.startsWith("helmet_drop-")) { dropChances[4] = Float.parseFloat(string.substring(12)); } - + } - + QuestMob qm = new QuestMob(entityType, loc, amounts); qm.setName(name); qm.inventory = inventory; qm.dropChances = dropChances; return qm; } - + @Override public boolean equals(Object o) { if ((o instanceof QuestMob) == false) { return false; } + + System.out.println("1"); QuestMob other = (QuestMob) o; - - if (name.equalsIgnoreCase(other.name) == false) + + if (name.equalsIgnoreCase(other.name) == false) return false; - - if (entityType != other.entityType) + + if (entityType != other.entityType) return false; - - if (dropChances != other.dropChances) + + System.out.println("2"); + + if (dropChances != other.dropChances) return false; - + + System.out.println("3"); + if (inventory.length == other.inventory.length) { for (int i = 0; i < inventory.length; i++) { if (ItemUtil.compareItems(inventory[i], other.inventory[i], false) != 0) @@ -230,10 +235,12 @@ public class QuestMob { } else { return false; } - - if (spawnAmounts != other.spawnAmounts) + + System.out.println("4"); + + if (spawnAmounts != other.spawnAmounts) return false; - + if (spawnLocation != other.spawnLocation) return false; diff --git a/src/main/resources/events.yml b/src/main/resources/events.yml index e7b554ba7..53315ce3b 100644 --- a/src/main/resources/events.yml +++ b/src/main/resources/events.yml @@ -10,4 +10,13 @@ events: potion-effect-amplifiers: - 3 - 2 - + GoodJob: + message: "Good job!" + DeathFail: + fail-quest: true + FishingStart: + message: "Type 'rod' in chat to get a fishing rod!" + RodEvent: + message: "Here you go!" + items: + - id-346:amount-1 \ No newline at end of file diff --git a/src/main/resources/quests.yml b/src/main/resources/quests.yml index 095b17169..2279888e0 100644 --- a/src/main/resources/quests.yml +++ b/src/main/resources/quests.yml @@ -36,16 +36,21 @@ quests: stages: ordered: 1: + death-event: DeathFail mobs-to-kill: - Pig mob-amounts: - 3 + finish-event: GoodJob 2: + death-event: DeathFail mobs-to-kill: - Zombie mob-amounts: - 2 + finish-event: GoodJob 3: + death-event: DeathFail mobs-to-kill: - Skeleton mob-amounts: @@ -55,4 +60,26 @@ quests: items: - id-276:amount-1 exp: 100 - quest-points: 1 \ No newline at end of file + quest-points: 1 + CatchFish: + name: 'Catch Fish' + ask-message: 'Catch some fish!' + finish-message: 'Excellent. Here is some experience.' + parties: 2 + requirements: + quests: + - Stone Miner + fail-requirement-message: 'Complete Stone Miner first.' + stages: + ordered: + 1: + start-event: FishingStart + death-event: DeathFail + chat-events: + - "RodEvent" + chat-event-triggers: + - "rod" + fish-to-catch: 5 + + rewards: + exp: 250 \ No newline at end of file