From ed4472a5b3b14b9db0e5f8af89e1bf2351c646bc Mon Sep 17 00:00:00 2001 From: Blackvein Date: Mon, 22 Oct 2012 15:24:36 -0700 Subject: [PATCH] Unstable --- src/me/blackvein/quests/NpcListener.java | 80 +++-- src/me/blackvein/quests/PlayerListener.java | 376 +++++++++++--------- src/me/blackvein/quests/Quester.java | 64 +++- src/me/blackvein/quests/Quests.java | 191 +++++----- src/me/blackvein/quests/Stage.java | 195 ++++++---- 5 files changed, 535 insertions(+), 371 deletions(-) diff --git a/src/me/blackvein/quests/NpcListener.java b/src/me/blackvein/quests/NpcListener.java index 1c299c4fa..ac7bf5785 100644 --- a/src/me/blackvein/quests/NpcListener.java +++ b/src/me/blackvein/quests/NpcListener.java @@ -2,7 +2,6 @@ package me.blackvein.quests; import net.citizensnpcs.api.event.NPCDespawnEvent; import net.citizensnpcs.api.event.NPCRightClickEvent; -import net.citizensnpcs.api.npc.NPC; import org.bukkit.ChatColor; import org.bukkit.conversations.Conversable; import org.bukkit.entity.Player; @@ -10,55 +9,84 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -public class NpcListener implements Listener{ +public class NpcListener implements Listener { Quests plugin; - public NpcListener(Quests newPlugin){ + public NpcListener(Quests newPlugin) { plugin = newPlugin; } @EventHandler(priority = EventPriority.LOWEST) - public void onNPCRightClick(NPCRightClickEvent evt){ + public void onNPCRightClick(NPCRightClickEvent evt) { - if(plugin.questNPCs.contains(evt.getNPC())){ + if (plugin.questNPCs.contains(evt.getNPC())) { final Player player = evt.getClicker(); - final NPC npc = evt.getNPC(); final Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("talkToNPC")){ + if (quester.hasObjective("talkToNPC")) { quester.interactWithNPC(evt.getNPC()); - }else { + } else { - for(final Quest q : plugin.quests){ + for (final Quest q : plugin.quests) { - if(q.npcStart != null && player.hasPermission("quests.quest")){ + if (q.npcStart != null && player.hasPermission("quests.quest")) { - if(q.npcStart.equals(evt.getNPC()) && quester.completedQuests.contains(q.name) == false){ + if (q.npcStart.equals(evt.getNPC()) && quester.completedQuests.contains(q.name) == false) { - if(quester.currentQuest == null){ + if (quester.currentQuest == null) { quester.questToTake = q.name; - - String s = - ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" - + "\n" - + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; - player.sendMessage(s); - plugin.conversationFactory.buildConversation((Conversable)player).begin(); - }else { + String s = + ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" + + "\n" + + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; + player.sendMessage(s); + plugin.conversationFactory.buildConversation((Conversable) player).begin(); + + } else if (quester.currentQuest.equals(q) == false) { player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest."); } break; + + } else if (q.npcStart.equals(evt.getNPC()) && quester.completedQuests.contains(q.name) == true) { + + if (quester.currentQuest == null) { + + if (quester.getDifference(q) > 0) { + 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 + "."); + } else { + + quester.questToTake = q.name; + + String s = + ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" + + "\n" + + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; + player.sendMessage(s); + plugin.conversationFactory.buildConversation((Conversable) player).begin(); + + } + + } else if (quester.currentQuest.equals(q) == false) { + + player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest."); + + } + + + + break; + } } @@ -70,14 +98,8 @@ public class NpcListener implements Listener{ } } - - @EventHandler - public void onNPCDespawn(NPCDespawnEvent evt){ - - - - } - - + @EventHandler + public void onNPCDespawn(NPCDespawnEvent evt) { + } } diff --git a/src/me/blackvein/quests/PlayerListener.java b/src/me/blackvein/quests/PlayerListener.java index 69801d2aa..9504f636f 100644 --- a/src/me/blackvein/quests/PlayerListener.java +++ b/src/me/blackvein/quests/PlayerListener.java @@ -35,60 +35,72 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerInteract(PlayerInteractEvent evt){ + public void onPlayerInteract(PlayerInteractEvent evt) { - if(evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ + if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { - final Quester quester = plugin.getQuester(evt.getPlayer().getName()); - final Player player = evt.getPlayer(); + final Quester quester = plugin.getQuester(evt.getPlayer().getName()); + final Player player = evt.getPlayer(); - if(quester.hasObjective("useBlock")){ + if (quester.hasObjective("useBlock")) { - quester.useBlock(evt.getClickedBlock().getType()); + quester.useBlock(evt.getClickedBlock().getType()); - }else { + } else { - for(final Quest q : plugin.quests){ + for (final Quest q : plugin.quests) { - if(q.blockStart != null){ + if (q.blockStart != null) { - if(q.blockStart.equals(evt.getClickedBlock().getLocation())){ + if (q.blockStart.equals(evt.getClickedBlock().getLocation())) { - if(quester.currentQuest != null){ + if (quester.currentQuest != null) { - player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest."); + player.sendMessage(ChatColor.YELLOW + "You may only have one active Quest."); - }else { + } else { - quester.questToTake = q.name; + if (quester.completedQuests.contains(q.name)) { - String s = - ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" - + "\n" - + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; + if (q.redoDelay < 0 || q.redoDelay > -1 && (quester.getDifference(q)) > 0) { - player.sendMessage(s); - plugin.conversationFactory.buildConversation((Conversable)player).begin(); + 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; + + } } + quester.questToTake = q.name; + + String s = + ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" + + "\n" + + ChatColor.RESET + plugin.getQuest(quester.questToTake).description + "\n"; + + player.sendMessage(s); + plugin.conversationFactory.buildConversation((Conversable) player).begin(); + } + break; } } } + } + } } @EventHandler - public void onBlockDamage(BlockDamageEvent evt){ + public void onBlockDamage(BlockDamageEvent evt) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.hasObjective("damageBlock")){ + if (quester.hasObjective("damageBlock")) { quester.damageBlock(evt.getBlock().getType()); @@ -96,16 +108,17 @@ public class PlayerListener implements Listener { } - @EventHandler (priority = EventPriority.HIGHEST) - public void onBlockPlace(BlockPlaceEvent evt){ + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockPlace(BlockPlaceEvent evt) { - if(evt.getPlayer().getName().toLowerCase().contains("_computercraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_redpower_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("(buildcraft)") == false){ + if (evt.getPlayer().getName().toLowerCase().contains("_computercraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("_redpower_") == false && evt.getPlayer().getName().toLowerCase().contains("_buildcraft_") == false && evt.getPlayer().getName().toLowerCase().contains("(buildcraft)") == false) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.hasObjective("placeBlock")){ + if (quester.hasObjective("placeBlock")) { - if(evt.isCancelled() == false) + if (evt.isCancelled() == false) { quester.placeBlock(evt.getBlock().getType()); + } } @@ -113,51 +126,53 @@ public class PlayerListener implements Listener { } - @EventHandler (priority = EventPriority.HIGHEST) - public void onBlockBreak(BlockBreakEvent evt){ + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockBreak(BlockBreakEvent evt) { boolean canOpen = true; - if(canOpen == true){ + if (canOpen == true) { - Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.hasObjective("breakBlock")){ - - if(evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) - quester.breakBlock(evt.getBlock().getType()); + Quester quester = plugin.getQuester(evt.getPlayer().getName()); + if (quester.hasObjective("breakBlock")) { + if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) { + quester.breakBlock(evt.getBlock().getType()); } - if(quester.hasObjective("placeBlock")){ + } - if(quester.blocksPlaced.containsKey(evt.getBlock().getType())){ + if (quester.hasObjective("placeBlock")) { - if(quester.blocksPlaced.get(evt.getBlock().getType()) > 0){ + if (quester.blocksPlaced.containsKey(evt.getBlock().getType())) { - if(evt.isCancelled() == false) - quester.blocksPlaced.put(evt.getBlock().getType(), quester.blocksPlaced.get(evt.getBlock().getType()) - 1); + if (quester.blocksPlaced.get(evt.getBlock().getType()) > 0) { + if (evt.isCancelled() == false) { + quester.blocksPlaced.put(evt.getBlock().getType(), quester.blocksPlaced.get(evt.getBlock().getType()) - 1); } } } - if(evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && quester.hasObjective("cutBlock")){ + } - quester.cutBlock(evt.getBlock().getType()); + if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && quester.hasObjective("cutBlock")) { - } + quester.cutBlock(evt.getBlock().getType()); } + } + } @EventHandler - public void onPlayerPickupItem(PlayerPickupItemEvent evt){ + public void onPlayerPickupItem(PlayerPickupItemEvent evt) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.hasObjective("collectItem")){ + if (quester.hasObjective("collectItem")) { quester.collectItem(evt.getItem().getItemStack()); @@ -166,10 +181,10 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerShearEntity(PlayerShearEntityEvent evt){ + public void onPlayerShearEntity(PlayerShearEntityEvent evt) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(evt.getEntity().getType().equals(EntityType.SHEEP) && quester.hasObjective("shearSheep")){ + if (evt.getEntity().getType().equals(EntityType.SHEEP) && quester.hasObjective("shearSheep")) { Sheep sheep = (Sheep) evt.getEntity(); quester.shearSheep(sheep.getColor()); @@ -179,13 +194,13 @@ public class PlayerListener implements Listener { } @EventHandler - public void onEntityTame(EntityTameEvent evt){ + public void onEntityTame(EntityTameEvent evt) { - if(evt.getOwner() instanceof Player){ + if (evt.getOwner() instanceof Player) { Player p = (Player) evt.getOwner(); Quester quester = plugin.getQuester(p.getName()); - if(quester.hasObjective("tameMob")){ + if (quester.hasObjective("tameMob")) { quester.tameMob(evt.getEntityType()); @@ -196,12 +211,12 @@ public class PlayerListener implements Listener { } @EventHandler - public void onEnchantItem(EnchantItemEvent evt){ + public void onEnchantItem(EnchantItemEvent evt) { Quester quester = plugin.getQuester(evt.getEnchanter().getName()); - if(quester.hasObjective("enchantItem")){ + if (quester.hasObjective("enchantItem")) { - for(Enchantment e : evt.getEnchantsToAdd().keySet()){ + for (Enchantment e : evt.getEnchantsToAdd().keySet()) { quester.enchantItem(e, evt.getItem().getType()); @@ -212,13 +227,13 @@ public class PlayerListener implements Listener { } @EventHandler - public void onCraftItem(CraftItemEvent evt){ + public void onCraftItem(CraftItemEvent evt) { - if(evt.getWhoClicked() instanceof Player){ + if (evt.getWhoClicked() instanceof Player) { Player p = (Player) evt.getWhoClicked(); Quester quester = plugin.getQuester(p.getName()); - if(quester.hasObjective("craftItem")){ + if (quester.hasObjective("craftItem")) { quester.craftItem(evt.getCurrentItem()); @@ -229,16 +244,16 @@ public class PlayerListener implements Listener { } @EventHandler - public void onInventoryClick(InventoryClickEvent evt){ + public void onInventoryClick(InventoryClickEvent evt) { - if(evt.getWhoClicked() instanceof Player && evt.getCursor() != null){ + if (evt.getWhoClicked() instanceof Player && evt.getCursor() != null) { Quester quester = plugin.getQuester(evt.getWhoClicked().getName()); - if(quester.currentQuest != null){ + if (quester.currentQuest != null) { - if(quester.currentQuest.questItems.containsKey(evt.getCursor().getType())){ + if (quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) { - if(evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52){ + if (evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52) { quester.collectItem(evt.getCursor()); } @@ -248,79 +263,19 @@ public class PlayerListener implements Listener { } - if(evt.getWhoClicked() instanceof Player && evt.getCurrentItem() != null){ + if (evt.getWhoClicked() instanceof Player && evt.getCurrentItem() != null) { Quester quester = plugin.getQuester(evt.getWhoClicked().getName()); - if(quester.currentQuest != null){ + if (quester.currentQuest != null) { - if(quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType())){ + if (quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType())) { - if(evt.getInventory().getType().equals(InventoryType.CHEST) == false || evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52){ + if (evt.getInventory().getType().equals(InventoryType.CHEST) == false || evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52) { ((Player) evt.getWhoClicked()).sendMessage(ChatColor.YELLOW + "You may not modify Quest items in your inventory."); evt.setCancelled(true); ((Player) evt.getWhoClicked()).updateInventory(); - }else if(evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() < 53) + } else if (evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() < 53) { quester.collectItem(evt.getCurrentItem()); - - } - - } - - } - - } - - @EventHandler - public void onEntityDeath(EntityDeathEvent evt){ - - if(evt.getEntity() instanceof Player == false){ - - if(evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent){ - - EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause(); - Entity damager = damageEvent.getDamager(); - - if(damager != null){ - - if(damager instanceof Projectile){ - - Projectile p = (Projectile) damager; - if(p.getShooter() instanceof Player){ - - Player player = (Player) p.getShooter(); - boolean okay = true; - - if(plugin.citizens != null){ - if(plugin.citizens.getNPCRegistry().isNPC(player)) - okay = false; - } - - if(okay){ - - Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("killMob")) - quester.killMob(evt.getEntity().getLocation(), evt.getEntity().getType()); - - } - } - - }else if(damager instanceof Player){ - - boolean okay = true; - - if(plugin.citizens != null){ - if(plugin.citizens.getNPCRegistry().isNPC(damager)) - okay = false; - } - - if(okay){ - - Player player = (Player) damager; - Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("killMob")) - quester.killMob(evt.getEntity().getLocation(), evt.getEntity().getType()); - - } } } @@ -332,55 +287,58 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerDeath(PlayerDeathEvent evt){ + public void onEntityDeath(EntityDeathEvent evt) { - if(evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent){ + if (evt.getEntity() instanceof Player == false) { + + if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause(); Entity damager = damageEvent.getDamager(); - if(damager != null){ + if (damager != null) { - if(damager instanceof Projectile){ + if (damager instanceof Projectile) { Projectile p = (Projectile) damager; - if(p.getShooter() instanceof Player){ + if (p.getShooter() instanceof Player) { Player player = (Player) p.getShooter(); boolean okay = true; - if(plugin.citizens != null){ - if(plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) + if (plugin.citizens != null) { + if (plugin.citizens.getNPCRegistry().isNPC(player)) { okay = false; + } } - if(okay){ + if (okay) { Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("killPlayer")) - quester.killPlayer(evt.getEntity().getName()); + if (quester.hasObjective("killMob")) { + quester.killMob(evt.getEntity().getLocation(), evt.getEntity().getType()); + } } - } - }else if(damager instanceof Player){ + } else if (damager instanceof Player) { - Player player = (Player) damager; boolean okay = true; - if(plugin.citizens != null){ - - if(plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) + if (plugin.citizens != null) { + if (plugin.citizens.getNPCRegistry().isNPC(damager)) { okay = false; - + } } - if(okay){ + if (okay) { + Player player = (Player) damager; Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("killPlayer")) - quester.killPlayer(evt.getEntity().getName()); + if (quester.hasObjective("killMob")) { + quester.killMob(evt.getEntity().getLocation(), evt.getEntity().getType()); + } } } @@ -389,28 +347,67 @@ public class PlayerListener implements Listener { } - } - - @EventHandler - public void onPlayerFish(PlayerFishEvent evt){ - - Player player = evt.getPlayer(); - Quester quester = plugin.getQuester(player.getName()); - if(quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) - quester.catchFish(); + } } @EventHandler - public void onPlayerDropItem(PlayerDropItemEvent evt){ + public void onPlayerDeath(PlayerDeathEvent evt) { - Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.currentQuest != null){ + if (evt.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { - if(quester.currentQuest.questItems.containsKey(evt.getItemDrop().getItemStack().getType())){ + EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) evt.getEntity().getLastDamageCause(); + Entity damager = damageEvent.getDamager(); - evt.getPlayer().sendMessage(ChatColor.YELLOW + "You may not discard Quest items."); - evt.setCancelled(true); + if (damager != null) { + + if (damager instanceof Projectile) { + + Projectile p = (Projectile) damager; + if (p.getShooter() instanceof Player) { + + Player player = (Player) p.getShooter(); + boolean okay = true; + + if (plugin.citizens != null) { + if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) { + okay = false; + } + } + + if (okay) { + + Quester quester = plugin.getQuester(player.getName()); + if (quester.hasObjective("killPlayer")) { + quester.killPlayer(evt.getEntity().getName()); + } + + } + + } + + } else if (damager instanceof Player) { + + Player player = (Player) damager; + boolean okay = true; + + if (plugin.citizens != null) { + + if (plugin.citizens.getNPCRegistry().isNPC(player) || plugin.citizens.getNPCRegistry().isNPC(evt.getEntity())) { + okay = false; + } + + } + + if (okay) { + + Quester quester = plugin.getQuester(player.getName()); + if (quester.hasObjective("killPlayer")) { + quester.killPlayer(evt.getEntity().getName()); + } + + } + } } @@ -419,25 +416,54 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerJoin(PlayerJoinEvent evt){ + public void onPlayerFish(PlayerFishEvent evt) { + + Player player = evt.getPlayer(); + Quester quester = plugin.getQuester(player.getName()); + if (quester.hasObjective("catchFish") && evt.getState().equals(State.CAUGHT_FISH)) { + quester.catchFish(); + } + + } + + @EventHandler + public void onPlayerDropItem(PlayerDropItemEvent evt) { + + Quester quester = plugin.getQuester(evt.getPlayer().getName()); + if (quester.currentQuest != null) { + + if (quester.currentQuest.questItems.containsKey(evt.getItemDrop().getItemStack().getType())) { + + evt.getPlayer().sendMessage(ChatColor.YELLOW + "You may not discard Quest items."); + evt.setCancelled(true); + + } + + } + + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent evt) { Quester quester = new Quester(plugin); quester.name = evt.getPlayer().getName(); - if(new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()){ + if (new File(plugin.getDataFolder(), "data/" + quester.name + ".yml").exists()) { quester.loadData(); - }else { + } else { quester.saveData(); } plugin.questers.put(evt.getPlayer().getName(), quester); - for(String s : quester.completedQuests){ + for (String s : quester.completedQuests) { - for(Quest q : plugin.quests){ + for (Quest q : plugin.quests) { - if(q.name.equalsIgnoreCase(s)){ + if (q.name.equalsIgnoreCase(s)) { - 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()); + } } @@ -451,7 +477,7 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerQuit(PlayerQuitEvent evt){ + public void onPlayerQuit(PlayerQuitEvent evt) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); quester.saveData(); @@ -460,19 +486,20 @@ public class PlayerListener implements Listener { } @EventHandler - public void onPlayerMove(PlayerMoveEvent evt){ + public void onPlayerMove(PlayerMoveEvent evt) { boolean isPlayer = true; - if(plugin.getServer().getPluginManager().getPlugin("Citizens") != null){ - if(plugin.citizens.getNPCRegistry().isNPC(evt.getPlayer())) + if (plugin.getServer().getPluginManager().getPlugin("Citizens") != null) { + if (plugin.citizens.getNPCRegistry().isNPC(evt.getPlayer())) { isPlayer = false; + } } - if(isPlayer){ + if (isPlayer) { Quester quester = plugin.getQuester(evt.getPlayer().getName()); - if(quester.hasObjective("reachLocation")){ + if (quester.hasObjective("reachLocation")) { quester.reachLocation(evt.getTo()); @@ -481,5 +508,4 @@ public class PlayerListener implements Listener { } } - } diff --git a/src/me/blackvein/quests/Quester.java b/src/me/blackvein/quests/Quester.java index e1b0e70cc..4a129c59f 100644 --- a/src/me/blackvein/quests/Quester.java +++ b/src/me/blackvein/quests/Quester.java @@ -44,6 +44,8 @@ public class Quester { LinkedList locationsToKillWithin = new LinkedList(); LinkedList radiiToKillWithin = new LinkedList(); Map citizensInteracted = new HashMap(); + LinkedList citizensKilled = new LinkedList(); + LinkedList citizenNumKilled = new LinkedList(); LinkedList locationsReached = new LinkedList(); LinkedList hasReached = new LinkedList(); LinkedList radiiToReachWithin = new LinkedList(); @@ -358,7 +360,7 @@ public class Quester { if (((Boolean) e.getValue()) == false) { - unfinishedObjectives.add(ChatColor.GREEN + "Talk to " + n.getName()); + unfinishedObjectives.add(ChatColor.GREEN + "Talk to " + n.getFullName()); } else { @@ -371,6 +373,24 @@ public class Quester { } } + + for (NPC n : currentStage.citizensToKill) { + + for (NPC n2 : citizensKilled) { + + if (citizenNumKilled.get(citizensKilled.indexOf(n2)) < currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(n))) { + + unfinishedObjectives.add(ChatColor.GREEN + "Kill " + n.getFullName() + ChatColor.GREEN); + + } else {a + + finishedObjectives.add(ChatColor.GRAY + "Kill " + n.getFullName()); + + } + + } + + } for (Entry e : currentStage.mobsToTame.entrySet()) { @@ -1056,7 +1076,7 @@ public class Quester { } else if (objective.equalsIgnoreCase("killNPC")) { String message = ChatColor.GREEN + "(Completed) Kill " + npc.getName(); - message = message + " " + currentStage.citizenNumToKill. + message = message + " " + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)) + "/" + currentStage.citizenNumToKill.get(currentStage.citizensToKill.indexOf(npc)); p.sendMessage(message); if (testComplete()) { currentQuest.nextStage(this); @@ -1203,6 +1223,15 @@ public class Quester { } } + + if (currentStage.citizensToKill.isEmpty() == false) { + for (NPC n : currentStage.citizensToKill) { + + citizensKilled.add(n); + citizenNumKilled.add(0); + + } + } if (currentStage.blocksToCut.isEmpty() == false) { for (Material m : currentStage.blocksToCut.keySet()) { @@ -1264,6 +1293,8 @@ public class Quester { radiiToKillWithin.clear(); playersKilled = 0; citizensInteracted.clear(); + citizensKilled.clear(); + citizenNumKilled.clear(); locationsReached.clear(); hasReached.clear(); radiiToReachWithin.clear(); @@ -1725,6 +1756,21 @@ public class Quester { data.set("has-talked-to", hasTalked); } + + if(citizensKilled.isEmpty() == false) { + + LinkedList npcIds = new LinkedList(); + + for (NPC n : citizensKilled) { + + npcIds.add(n.getId()); + + } + + data.set("citizen-ids-killed", npcIds); + data.set("citizen-amounts-killed", citizenNumKilled); + + } if (locationsReached.isEmpty() == false) { @@ -2303,6 +2349,20 @@ public class Quester { } } + + if (data.contains("citizen-ids-killed")) { + + List ids = data.getIntegerList("citizen-ids-killed"); + List num = data.getIntegerList("citizen-amounts-killed"); + + for (int i : ids) { + + citizensKilled.add(plugin.citizens.getNPCRegistry().getById(i)); + citizenNumKilled.add(num.get(ids.indexOf(i))); + + } + + } if (data.contains("locations-to-reach")) { diff --git a/src/me/blackvein/quests/Quests.java b/src/me/blackvein/quests/Quests.java index 2b5ef1500..3475f59eb 100644 --- a/src/me/blackvein/quests/Quests.java +++ b/src/me/blackvein/quests/Quests.java @@ -32,7 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -public class Quests extends JavaPlugin implements ConversationAbandonedListener{ +public class Quests extends JavaPlugin implements ConversationAbandonedListener { public static Economy economy = null; public static Permission permission = null; @@ -64,13 +64,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ pListener = new PlayerListener(this); npcListener = new NpcListener(this); - this.conversationFactory = new ConversationFactory(this) - .withModality(false) - .withPrefix(new SummoningConversationPrefix()) - .withFirstPrompt(new QuestPrompt()) - .withTimeout(20) - .thatExcludesNonPlayersWithMessage("Console may not perform this conversation!") - .addConversationAbandonedListener(this); + this.conversationFactory = new ConversationFactory(this).withModality(false).withPrefix(new SummoningConversationPrefix()).withFirstPrompt(new QuestPrompt()).withTimeout(20).thatExcludesNonPlayersWithMessage("Console may not perform this conversation!").addConversationAbandonedListener(this); questFactory = new QuestFactory(this); @@ -181,18 +175,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - public LinkedList getQuests(){ + public LinkedList getQuests() { return quests; } - + @Override public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { - } private class QuestPrompt extends FixedSetPrompt { + public QuestPrompt() { - super("Yes","No"); + super("Yes", "No"); } @Override @@ -229,10 +223,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ return ChatColor.GREEN + "Quests: " + ChatColor.GRAY; } - } - public void loadConfig() { FileConfiguration config = getConfig(); @@ -281,13 +273,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ @Override public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { - if(cmd.getName().equalsIgnoreCase("editor")){ + if (cmd.getName().equalsIgnoreCase("editor")) { questFactory.convoCreator.buildConversation((Conversable) cs).begin(); - } - - else if (cmd.getName().equalsIgnoreCase("quest")) { + } else if (cmd.getName().equalsIgnoreCase("quest")) { if (cs instanceof Player) { @@ -631,14 +621,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ quester.questToTake = quest.name; String s = - ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" - + "\n" - + ChatColor.RESET + getQuest(quester.questToTake).description + "\n"; + ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quester.questToTake + ChatColor.GOLD + " -\n" + + "\n" + + ChatColor.RESET + getQuest(quester.questToTake).description + "\n"; cs.sendMessage(s); - conversationFactory.buildConversation((Conversable)cs).begin(); + conversationFactory.buildConversation((Conversable) cs).begin(); return true; - }else{ + } else { return false; } @@ -1340,16 +1330,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ printSevere(ChatColor.GOLD + "[Quests] Quest block \'" + ChatColor.DARK_PURPLE + s + ChatColor.GOLD + "\' is missing " + ChatColor.RED + "name:"); continue; } - + if (config.contains("quests." + s + ".npc-giver-id")) { - if(citizens.getNPCRegistry().getById(config.getInt("quests." + s + ".npc-giver-id")) != null){ + if (citizens.getNPCRegistry().getById(config.getInt("quests." + s + ".npc-giver-id")) != null) { quest.npcStart = citizens.getNPCRegistry().getById(config.getInt("quests." + s + ".npc-giver-id")); questNPCs.add(citizens.getNPCRegistry().getById(config.getInt("quests." + s + ".npc-giver-id"))); - }else{ - printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "npc-giver-id: " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid NPC id!"); + } else { + printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "npc-giver-id: " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid NPC id!"); continue; } @@ -1358,10 +1348,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".block-start")) { Location location = getLocation(config.getString("quests." + s + ".block-start")); - if(location != null) + if (location != null) { quest.blockStart = location; - else{ - printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "block-start: " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not in proper location format!"); + } else { + printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "block-start: " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not in proper location format!"); printSevere(ChatColor.GOLD + "[Quests] Proper location format is: \"WorldName x y z\""); continue; } @@ -2021,7 +2011,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } } - + List npcIdsToKill; List npcKillAmounts; @@ -2029,9 +2019,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".npc-ids-to-kill"), Integer.class)) { - if(config.contains("quests." + s + ".stages.ordered." + s2 + ".npc-kill-amounts")){ - - if(checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".npc-kill-amounts"), Integer.class)) { + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".npc-kill-amounts")) { + + if (checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".npc-kill-amounts"), Integer.class)) { npcIdsToKill = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".npc-ids-to-kill"); npcKillAmounts = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".npc-kill-amounts"); @@ -2039,11 +2029,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (citizens.getNPCRegistry().getById(i) != null) { - if(npcKillAmounts.get(npcIdsToKill.indexOf(i)) > 0){ + if (npcKillAmounts.get(npcIdsToKill.indexOf(i)) > 0) { stage.citizensToKill.add(citizens.getNPCRegistry().getById(i)); stage.citizenNumToKill.add(npcKillAmounts.get(npcIdsToKill.indexOf(i))); questNPCs.add(citizens.getNPCRegistry().getById(i)); - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + npcKillAmounts.get(npcIdsToKill.indexOf(i)) + ChatColor.GOLD + " inside " + ChatColor.GREEN + "npc-kill-amounts: " + ChatColor.GOLD + "inside " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a positive number!"); stageFailed = true; break; @@ -2062,13 +2052,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ stageFailed = true; break; } - + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "npc-kill-amounts:"); stageFailed = true; break; } - + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "npc-ids-to-kill: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); stageFailed = true; @@ -2539,7 +2529,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".sheep-to-shear"), String.class)) { - if(config.contains("quests." + s + ".stages.ordered." + s2 + ".sheep-amounts")){ + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".sheep-amounts")) { if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".sheep-amounts"), Integer.class)) { @@ -2612,7 +2602,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ stage.sheepToShear.put(DyeColor.YELLOW, shearAmounts.get(sheep.indexOf(color))); - } else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + color + ChatColor.GOLD + " inside " + ChatColor.GREEN + "sheep-to-shear: " + ChatColor.GOLD + "inside " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid color!"); stageFailed = true; @@ -2622,19 +2612,19 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - }else { + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "sheep-amounts: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); stageFailed = true; break; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "sheep-amounts:"); stageFailed = true; break; } - }else { + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "sheep-to-shear: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of colors!"); stageFailed = true; break; @@ -2644,11 +2634,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids")) { - if(Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids"), Integer.class)){ + if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids"), Integer.class)) { - if(config.contains("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts")){ + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts")) { - if(Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"), Integer.class)){ + if (Quests.checkList(config.getList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"), Integer.class)) { List craftIds = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-ids"); List craftAmounts = config.getIntegerList("quests." + s + ".stages.ordered." + s2 + ".craft-item-amounts"); @@ -2659,19 +2649,19 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "craft-item-amounts: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); stageFailed = true; break; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "craft-item-amounts:"); stageFailed = true; break; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "craft-item-ids: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of item ids!"); stageFailed = true; break; @@ -2683,9 +2673,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ Event evt = Event.getEvent(config.getString("quests." + s + ".stages.ordered." + s2 + ".event"), this, quest); - if( evt != null) + if (evt != null) { stage.event = evt; - else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "Event " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " failed to load."); stageFailed = true; break; @@ -2695,32 +2685,32 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ stage.citizensToInteract = npcsToTalkTo; - if(stageFailed){ + if (stageFailed) { break; } quest.stages.add(stage); } - if(stageFailed){ + if (stageFailed) { continue; } //Load rewards if (config.contains("quests." + s + ".rewards.item-ids")) { - if(Quests.checkList(config.getList("quests." + s + ".rewards.item-ids"), Integer.class)){ + if (Quests.checkList(config.getList("quests." + s + ".rewards.item-ids"), Integer.class)) { - if(config.contains("quests." + s + ".rewards.item-amounts")){ + if (config.contains("quests." + s + ".rewards.item-amounts")) { - if(Quests.checkList(config.getList("quests." + s + ".rewards.item-amounts"), Integer.class)) { + if (Quests.checkList(config.getList("quests." + s + ".rewards.item-amounts"), Integer.class)) { boolean failed = false; for (int i : config.getIntegerList("quests." + s + ".rewards.item-ids")) { Material m = Material.getMaterial(i); - if(m == null){ - printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + i + ChatColor.GOLD + " in " + ChatColor.GREEN + "item-amounts: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); + if (m == null) { + printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + i + ChatColor.GOLD + " in " + ChatColor.GREEN + "item-amounts: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); failed = true; break; } @@ -2729,20 +2719,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - if(failed) + if (failed) { continue; + } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "item-amounts: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of numbers!"); continue; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.AQUA + "Rewards " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "item-amounts:"); continue; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "item-ids: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of item ids!"); continue; } @@ -2773,9 +2764,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".rewards.commands")) { - if(Quests.checkList(config.getList("quests." + s + ".rewards.commands"), String.class)) + if (Quests.checkList(config.getList("quests." + s + ".rewards.commands"), String.class)) { quest.commands = config.getStringList("quests." + s + ".rewards.commands"); - else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "commands: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of commands!"); continue; } @@ -2784,9 +2775,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".rewards.permissions")) { - if(Quests.checkList(config.getList("quests." + s + ".rewards.permissions"), String.class)) + if (Quests.checkList(config.getList("quests." + s + ".rewards.permissions"), String.class)) { quest.permissions = config.getStringList("quests." + s + ".rewards.permissions"); - else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "permissions: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of permissions!"); continue; } @@ -2817,9 +2808,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".rewards.heroes-class")) { - if(heroes.getClassManager().getClass("quests." + s + ".rewards.heroes-class") != null) + if (heroes.getClassManager().getClass("quests." + s + ".rewards.heroes-class") != null) { quest.heroesClass = config.getString("quests." + s + ".rewards.heroes-class"); - else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "heroes-class: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid Heroes class name!"); continue; } @@ -2828,9 +2819,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".rewards.heroes-secondary-class")) { - if(heroes.getClassManager().getClass("quests." + s + ".rewards.heroes-secondary-class") != null) + if (heroes.getClassManager().getClass("quests." + s + ".rewards.heroes-secondary-class") != null) { quest.heroesSecClass = config.getString("quests." + s + ".rewards.heroes-secondary-class"); - else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "heroes-secondary-class: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid Heroes secondary class name!"); continue; } @@ -2839,32 +2830,33 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ if (config.contains("quests." + s + ".rewards.mcmmo-skills")) { - if(Quests.checkList(config.getList("quests." + s + ".rewards.mcmmo-skills"), String.class)){ + if (Quests.checkList(config.getList("quests." + s + ".rewards.mcmmo-skills"), String.class)) { - if(config.contains("quests." + s + ".rewards.mcmmo-levels")){ + if (config.contains("quests." + s + ".rewards.mcmmo-levels")) { boolean failed = false; - for(String skill : config.getStringList("quests." + s + ".rewards.mcmmo-skills")){ + for (String skill : config.getStringList("quests." + s + ".rewards.mcmmo-skills")) { - if(Quests.getMcMMOSkill(skill) == null){ - printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + skill + ChatColor.GOLD + " in " + ChatColor.GREEN + "mcmmo-skills: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid mcMMO skill name!"); + if (Quests.getMcMMOSkill(skill) == null) { + printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + skill + ChatColor.GOLD + " in " + ChatColor.GREEN + "mcmmo-skills: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a valid mcMMO skill name!"); failed = true; break; } } - if(failed) + if (failed) { continue; + } quest.mcmmoSkills = config.getStringList("quests." + s + ".rewards.mcmmo-skills"); quest.mcmmoAmounts = config.getIntegerList("quests." + s + ".rewards.mcmmo-levels"); - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.AQUA + "Rewards " + ChatColor.GOLD + "for Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is missing " + ChatColor.RED + "mcmmo-levels:"); continue; } - }else{ + } else { printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "mcmmo-skills: " + ChatColor.AQUA + "Reward " + ChatColor.GOLD + "in Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a list of mcMMO skill names!"); continue; } @@ -2976,21 +2968,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ return sortedMap; } - public static void printSevere(String s){ + public static void printSevere(String s) { s = ChatColor.stripColor(s); log.severe(s); } - public static void printWarning(String s){ + public static void printWarning(String s) { s = ChatColor.stripColor(s); log.warning(s); } - public static void printInfo(String s){ + public static void printInfo(String s) { s = ChatColor.stripColor(s); log.info(s); @@ -3218,23 +3210,25 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ public static Location getLocation(String arg) { String[] info = arg.split(" "); - if(info.length != 4) + if (info.length != 4) { return null; + } double x; double y; double z; - try{ + try { x = Double.parseDouble(info[1]); y = Double.parseDouble(info[2]); z = Double.parseDouble(info[3]); - }catch (Exception e){ + } catch (Exception e) { return null; } - if(Bukkit.getServer().getWorld(info[0]) == null) + if (Bukkit.getServer().getWorld(info[0]) == null) { return null; + } Location finalLocation = new Location(Bukkit.getServer().getWorld(info[0]), x, y, z); @@ -3264,9 +3258,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ return Effect.ZOMBIE_CHEW_IRON_DOOR; } else if (eff.equalsIgnoreCase("ZOMBIE_CHEW_WOODEN_DOOR")) { return Effect.ZOMBIE_CHEW_WOODEN_DOOR; - } else if (eff.equalsIgnoreCase("ZOMBIE_DESTROY_DOOR")){ + } else if (eff.equalsIgnoreCase("ZOMBIE_DESTROY_DOOR")) { return Effect.ZOMBIE_DESTROY_DOOR; - } else{ + } else { return null; } } @@ -3550,18 +3544,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - public static String getCurrency(boolean plural){ + public static String getCurrency(boolean plural) { - if(plural){ - if(Quests.economy.currencyNamePlural().trim().isEmpty()) + if (plural) { + if (Quests.economy.currencyNamePlural().trim().isEmpty()) { return "Money"; - else + } else { return Quests.economy.currencyNamePlural(); - }else{ - if(Quests.economy.currencyNameSingular().trim().isEmpty()) + } + } else { + if (Quests.economy.currencyNameSingular().trim().isEmpty()) { return "Money"; - else + } else { return Quests.economy.currencyNameSingular(); + } } } @@ -3623,11 +3619,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener{ } - public Quest getQuest(String s){ + public Quest getQuest(String s) { - for(Quest q : quests){ - if(q.name.equalsIgnoreCase(s)) + for (Quest q : quests) { + if (q.name.equalsIgnoreCase(s)) { return q; + } } return null; diff --git a/src/me/blackvein/quests/Stage.java b/src/me/blackvein/quests/Stage.java index 72dd4324e..e31253468 100644 --- a/src/me/blackvein/quests/Stage.java +++ b/src/me/blackvein/quests/Stage.java @@ -15,168 +15,227 @@ import org.bukkit.entity.EntityType; public class Stage { public String finished; - Map blocksToDamage = new EnumMap(Material.class); - Map blocksToBreak = new EnumMap(Material.class); - Map blocksToPlace = new EnumMap(Material.class); - Map, Boolean> itemsToCollect = new HashMap, Boolean>(); - Map blocksToUse = new EnumMap(Material.class); - Map blocksToCut = new EnumMap(Material.class); - Integer fishToCatch; Integer playersToKill; - Map, Integer> itemsToEnchant = new HashMap, Integer>(); - LinkedList mobsToKill = new LinkedList(); LinkedList mobNumToKill = new LinkedList(); LinkedList locationsToKillWithin = new LinkedList(); LinkedList radiiToKillWithin = new LinkedList(); LinkedList areaNames = new LinkedList(); + LinkedList citizensToInteract = new LinkedList(){ + + @Override + public boolean equals(Object o) { - LinkedList citizensToInteract = new LinkedList(); - - LinkedList citizensToKill = new LinkedList(); + if (o instanceof LinkedList) { + + LinkedList otherList = (LinkedList) o; + + for (NPC n : this) { + + NPC other = otherList.get(this.indexOf(n)); + if (other.getId() != n.getId()) { + return false; + } + } + + } + + return true; + + } + + }; + LinkedList citizensToKill = new LinkedList() { + + @Override + public boolean equals(Object o) { + + if (o instanceof LinkedList) { + + LinkedList otherList = (LinkedList) o; + + for (NPC n : this) { + + NPC other = otherList.get(this.indexOf(n)); + if (other.getId() != n.getId()) { + return false; + } + } + + } + + return true; + + } + + }; LinkedList citizenNumToKill = new LinkedList(); - LinkedList locationsToReach = new LinkedList(); LinkedList radiiToReachWithin = new LinkedList(); LinkedList worldsToReachWithin = new LinkedList(); LinkedList locationNames = new LinkedList(); - Map mobsToTame = new EnumMap(EntityType.class); - Map sheepToShear = new EnumMap(DyeColor.class); - Map itemsToCraft = new EnumMap(Material.class); - String script; - Event event; @Override - public boolean equals(Object o){ + public boolean equals(Object o) { - if(o instanceof Stage){ + if (o instanceof Stage) { Stage other = (Stage) o; - if(other.finished != null && finished != null){ - if(other.finished.equals(finished) == false) + if (other.finished != null && finished != null) { + if (other.finished.equals(finished) == false) { return false; - }else if(other.finished != null && finished == null){ + } + } else if (other.finished != null && finished == null) { return false; - }else if(other.finished == null && finished != null) + } else if (other.finished == null && finished != null) { return false; + } - if(other.blocksToDamage.equals(blocksToDamage) == false) + if (other.blocksToDamage.equals(blocksToDamage) == false) { return false; + } - if(other.blocksToBreak.equals(blocksToBreak) == false) + if (other.blocksToBreak.equals(blocksToBreak) == false) { return false; + } - if(other.blocksToPlace.equals(blocksToPlace) == false) + if (other.blocksToPlace.equals(blocksToPlace) == false) { return false; + } - if(other.itemsToCollect.equals(itemsToCollect) == false) + if (other.itemsToCollect.equals(itemsToCollect) == false) { return false; + } - if(other.blocksToUse.equals(blocksToUse) == false) + if (other.blocksToUse.equals(blocksToUse) == false) { return false; + } - if(other.blocksToCut.equals(blocksToCut) == false) + if (other.blocksToCut.equals(blocksToCut) == false) { return false; + } - if(other.fishToCatch != null && fishToCatch != null){ - if(other.fishToCatch.equals(fishToCatch) == false) + if (other.fishToCatch != null && fishToCatch != null) { + if (other.fishToCatch.equals(fishToCatch) == false) { return false; - }else if(other.fishToCatch != null && fishToCatch == null){ + } + } else if (other.fishToCatch != null && fishToCatch == null) { return false; - }else if(other.fishToCatch == null && fishToCatch != null) + } else if (other.fishToCatch == null && fishToCatch != null) { return false; + } - if(other.playersToKill != null && playersToKill != null){ - if(other.playersToKill.equals(playersToKill) == false) + if (other.playersToKill != null && playersToKill != null) { + if (other.playersToKill.equals(playersToKill) == false) { return false; - }else if(other.playersToKill != null && playersToKill == null){ + } + } else if (other.playersToKill != null && playersToKill == null) { return false; - }else if(other.playersToKill == null && playersToKill != null) + } else if (other.playersToKill == null && playersToKill != null) { return false; + } - if(other.itemsToEnchant.equals(itemsToEnchant) == false) + if (other.itemsToEnchant.equals(itemsToEnchant) == false) { return false; + } - if(other.mobsToKill.equals(mobsToKill) == false) + if (other.mobsToKill.equals(mobsToKill) == false) { return false; + } - if(other.mobNumToKill.equals(mobNumToKill) == false) + if (other.mobNumToKill.equals(mobNumToKill) == false) { return false; + } - if(other.locationsToKillWithin.equals(locationsToKillWithin) == false) + if (other.locationsToKillWithin.equals(locationsToKillWithin) == false) { return false; + } - if(other.radiiToKillWithin.equals(radiiToKillWithin) == false) + if (other.radiiToKillWithin.equals(radiiToKillWithin) == false) { return false; + } - if(other.areaNames.equals(areaNames) == false) + if (other.areaNames.equals(areaNames) == false) { return false; + } - if(other.citizensToInteract.equals(citizensToInteract) == false) - return false; - - if(other.citizensToKill.equals(citizensToKill) == false) - return false; - - if(other.citizenNumToKill.equals(citizenNumToKill) == false) + if (other.citizensToInteract.equals(citizensToInteract) == false) { return false; + } - if(other.locationsToReach.equals(locationsToReach) == false) + if (other.citizensToKill.equals(citizensToKill) == false) { return false; + } - if(other.radiiToReachWithin.equals(radiiToReachWithin) == false) + if (other.citizenNumToKill.equals(citizenNumToKill) == false) { return false; + } - if(other.worldsToReachWithin.equals(worldsToReachWithin) == false) + if (other.locationsToReach.equals(locationsToReach) == false) { return false; + } - if(other.locationNames.equals(locationNames) == false) + if (other.radiiToReachWithin.equals(radiiToReachWithin) == false) { return false; + } - if(other.mobsToTame.equals(mobsToTame) == false) + if (other.worldsToReachWithin.equals(worldsToReachWithin) == false) { return false; + } - if(other.sheepToShear.equals(sheepToShear) == false) + if (other.locationNames.equals(locationNames) == false) { return false; + } - if(other.itemsToCraft.equals(itemsToCraft) == false) + if (other.mobsToTame.equals(mobsToTame) == false) { return false; + } - if(other.script != null && script != null){ - if(other.script.equals(script) == false) + if (other.sheepToShear.equals(sheepToShear) == false) { + return false; + } + + if (other.itemsToCraft.equals(itemsToCraft) == false) { + return false; + } + + if (other.script != null && script != null) { + if (other.script.equals(script) == false) { return false; - }else if(other.script != null && script == null){ + } + } else if (other.script != null && script == null) { return false; - }else if(other.script == null && script != null) + } else if (other.script == null && script != null) { return false; + } - if(other.event != null && event != null){ - if(other.event.equals(event) == false) + if (other.event != null && event != null) { + if (other.event.equals(event) == false) { return false; - }else if(other.event != null && event == null){ + } + } else if (other.event != null && event == null) { return false; - }else if(other.event == null && event != null) + } else if (other.event == null && event != null) { return false; + } } return true; } - } -