From 51e545e26a51195a4902e0414193292664ac2f35 Mon Sep 17 00:00:00 2001 From: Blackvein Date: Wed, 7 Nov 2012 15:26:58 -0800 Subject: [PATCH] Finished Crafting Quest Items --- src/me/blackvein/quests/PlayerListener.java | 17 +++++++++-------- src/me/blackvein/quests/Quester.java | 15 +++++++++------ src/me/blackvein/quests/Quests.java | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/me/blackvein/quests/PlayerListener.java b/src/me/blackvein/quests/PlayerListener.java index ec2891615..15eeff2ba 100644 --- a/src/me/blackvein/quests/PlayerListener.java +++ b/src/me/blackvein/quests/PlayerListener.java @@ -274,9 +274,10 @@ public class PlayerListener implements Listener { }else if(quester.hasObjective("craftItem")){ - final int amntBefore = Quests.countInv(evt.getInventory(), evt.getCurrentItem().getType()); + final int amntBefore = Quests.countInv(evt.getInventory(), evt.getCurrentItem().getType(), evt.getCurrentItem().getAmount()); + System.out.println("Amount before: " + amntBefore); final Material mat = evt.getCurrentItem().getType(); - final Inventory inv = evt.getInventory(); + final Inventory inv = evt.getWhoClicked().getInventory(); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ @Override @@ -284,7 +285,8 @@ public class PlayerListener implements Listener { if(evt.isCancelled() == false){ - int amntAfter = Quests.countInv(inv, mat); + int amntAfter = Quests.countInv(inv, mat, 0); + System.out.println("Amount after: " + amntAfter); quester.craftItem(new ItemStack(mat, amntAfter - amntBefore)); } @@ -392,7 +394,7 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(InventoryClickEvent evt) { - + System.out.println("Click fired."); Player player = null; if (evt.getWhoClicked() instanceof Player) { player = (Player) evt.getWhoClicked(); @@ -516,16 +518,15 @@ public class PlayerListener implements Listener { } else { if (evt.getCurrentItem() != null) { - Quester quester = plugin.getQuester(evt.getWhoClicked().getName()); Material mat = evt.getCurrentItem().getType(); if (quester.currentQuest != null) { - if (quester.currentQuest.questItems.containsKey(mat)) { - - if(evt.getInventory().getType().equals(InventoryType.CRAFTING) && evt.getRawSlot() == 0) + System.out.println(evt.getInventory().getType()); + if((evt.getInventory().getType().equals(InventoryType.WORKBENCH) && evt.getRawSlot() == 0) || (evt.getInventory().getType().equals(InventoryType.CRAFTING) && evt.getRawSlot() == 0)){ return; + } List changedSlots = Quester.getChangedSlots(evt.getInventory(), evt.getCurrentItem()); boolean can = true; diff --git a/src/me/blackvein/quests/Quester.java b/src/me/blackvein/quests/Quester.java index dfc75a3db..47e0e8108 100644 --- a/src/me/blackvein/quests/Quester.java +++ b/src/me/blackvein/quests/Quester.java @@ -444,18 +444,21 @@ public class Quester { for (Entry e : currentStage.itemsToCraft.entrySet()) { - System.out.println("Entry."); + Entry entry = null; + for(Object o : ((Map) e.getKey()).entrySet()) + entry = (Entry) o; + for (Entry e2 : itemsCrafted.entrySet()) { - if (e.getKey().equals(e2.getKey())) { + if (entry.getKey().equals(e2.getKey())) { - if ((Integer) e2.getValue() < (Integer) e.getValue()) { + if ((Integer) e2.getValue() < (Integer) entry.getValue()) { - unfinishedObjectives.add(ChatColor.GREEN + "Craft " + prettyItemString(((Material) e.getKey()).getId()) + ": " + ((Integer) e2.getValue()) + "/" + ((Integer) e.getValue())); + unfinishedObjectives.add(ChatColor.GREEN + "Craft " + prettyItemString(((Material) entry.getKey()).getId()) + ": " + ((Integer) e2.getValue()) + "/" + ((Integer) entry.getValue())); } else { - finishedObjectives.add(ChatColor.GRAY + "Craft " + prettyItemString(((Material) e.getKey()).getId()) + ": " + ((Integer) e2.getValue()) + "/" + ((Integer) e.getValue())); + finishedObjectives.add(ChatColor.GRAY + "Craft " + prettyItemString(((Material) entry.getKey()).getId()) + ": " + ((Integer) e2.getValue()) + "/" + ((Integer) entry.getValue())); } @@ -976,7 +979,7 @@ public class Quester { } if (itemsCrafted.get(i.getType()).equals((Integer) m.get(i.getType()))) { - finishObjective("craftItem", null, i, null, null, null, null, null, null, 0); + finishObjective("craftItem", i.getType(), null, null, null, null, null, null, null, 0); } } diff --git a/src/me/blackvein/quests/Quests.java b/src/me/blackvein/quests/Quests.java index 64d454e30..f7f3722e5 100644 --- a/src/me/blackvein/quests/Quests.java +++ b/src/me/blackvein/quests/Quests.java @@ -3802,7 +3802,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return null; } - public static int countInv(Inventory inv, Material m){ + public static int countInv(Inventory inv, Material m, int subtract){ int count = 0; @@ -3815,7 +3815,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } - return count; + return count - subtract; } }