From d37101c8bf40395ecbed2f8050abe3ceb0014af6 Mon Sep 17 00:00:00 2001 From: Blackvein Date: Mon, 29 Oct 2012 15:21:22 -0700 Subject: [PATCH] Finished Quest item clicking, starting stage time delays --- src/me/blackvein/quests/PlayerListener.java | 20 ++++++--- src/me/blackvein/quests/Quest.java | 5 ++- src/me/blackvein/quests/Quester.java | 46 +++++++++++++++++++++ src/me/blackvein/quests/Quests.java | 22 +++++++++- src/me/blackvein/quests/Stage.java | 10 ++++- 5 files changed, 95 insertions(+), 8 deletions(-) diff --git a/src/me/blackvein/quests/PlayerListener.java b/src/me/blackvein/quests/PlayerListener.java index af86886aa..cbcfe46ab 100644 --- a/src/me/blackvein/quests/PlayerListener.java +++ b/src/me/blackvein/quests/PlayerListener.java @@ -2,6 +2,7 @@ package me.blackvein.quests; import java.io.File; import java.util.HashMap; +import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.conversations.Conversable; @@ -450,7 +451,7 @@ public class PlayerListener implements Listener { }else{ - if(player != null && evt.getCurrentItem() != null && evt.getResult().equals(org.bukkit.event.Event.Result.ALLOW)){ + if(player != null && evt.getCurrentItem() != null){ Quester quester = plugin.getQuester(evt.getWhoClicked().getName()); Material mat = evt.getCurrentItem().getType(); @@ -459,14 +460,23 @@ public class PlayerListener implements Listener { if(quester.currentQuest.questItems.containsKey(mat)){ - String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot()); - if(s == null){ + List changedSlots = Quester.getChangedSlots(evt.getInventory(), evt.getCurrentItem()); + boolean can = true; + for(int i : changedSlots){ + + String s = Quester.checkPlacement(evt.getInventory(), i); + if(s != null){ + can = false; + break; + } + + } + if(!can){ - player.sendMessage(ChatColor.YELLOW + "You may not store Quest items."); evt.setCancelled(true); player.updateInventory(); - }else{ + }else if(can && Quester.checkPlacement(evt.getInventory(), evt.getRawSlot()) != null){ ItemStack oldStack = evt.getCurrentItem(); Inventory inv = plugin.getServer().createInventory(null, evt.getInventory().getType()); diff --git a/src/me/blackvein/quests/Quest.java b/src/me/blackvein/quests/Quest.java index 88bc95f43..9401cae2b 100644 --- a/src/me/blackvein/quests/Quest.java +++ b/src/me/blackvein/quests/Quest.java @@ -48,6 +48,7 @@ public class Quest { List commands = new LinkedList(); List permissions = new LinkedList(); LinkedList itemRewards = new LinkedList(); + LinkedList itemRewardAmounts = new LinkedList(); //Heroes int heroesExp = 0; String heroesClass = null; @@ -69,6 +70,7 @@ public class Quest { plugin.trigger.parseQuestTaskTrigger(q.currentStage.script, player); if(q.currentStage.event != null) q.currentStage.event.happen(player); + completeQuest(q); }else { @@ -245,7 +247,7 @@ public class Quest { } for(ItemStack i : itemRewards){ - player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount()); + player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + itemRewardAmounts.get(itemRewards.indexOf(i))); none = null; } @@ -284,6 +286,7 @@ public class Quest { q.currentStage = null; q.saveData(); + player.updateInventory(); } diff --git a/src/me/blackvein/quests/Quester.java b/src/me/blackvein/quests/Quester.java index cc7a15ab7..25fe4ae5c 100644 --- a/src/me/blackvein/quests/Quester.java +++ b/src/me/blackvein/quests/Quester.java @@ -40,6 +40,7 @@ public class Quester { Map potionsBrewed = new HashMap(); int fishCaught = 0; int playersKilled = 0; + long stageDelay = 0; Map playerKillTimes = new HashMap(); Map, Integer> itemsEnchanted = new HashMap, Integer>(); LinkedList mobsKilled = new LinkedList(); @@ -2672,4 +2673,49 @@ public class Quester { return null; } + + public static List getChangedSlots(Inventory inInv, ItemStack inNew) + { + List changed = new ArrayList(); + if(inInv.contains(inNew.getType())) + { + int amount = inNew.getAmount(); + HashMap items = inInv.all(inNew.getType()); + for(int i = 0; i < inInv.getSize(); i++) + { + if(!items.containsKey((Integer)i)) + continue; + + ItemStack item = items.get((Integer)i); + int slotamount = item.getMaxStackSize() - item.getAmount(); + if(slotamount > 1) + { + if(amount > slotamount) + { + int toAdd = slotamount - amount; + amount = amount - toAdd; + changed.add(i); + } + else + { + changed.add(i); + amount = 0; + break; + } + } + } + + if(amount > 0) + { + if(inInv.firstEmpty() != -1) + changed.add(inInv.firstEmpty()); + } + } + else + { + if(inInv.firstEmpty() != -1) + changed.add(inInv.firstEmpty()); + } + return changed; + } } diff --git a/src/me/blackvein/quests/Quests.java b/src/me/blackvein/quests/Quests.java index f56f8cfe5..b31c2c87b 100644 --- a/src/me/blackvein/quests/Quests.java +++ b/src/me/blackvein/quests/Quests.java @@ -2685,6 +2685,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } + + if (config.contains("quests." + s + ".stages.ordered." + s2 + ".delay")) { + + if (config.getLong("quests." + s + ".stages.ordered." + s2 + ".delay", -999) != -999){ + stage.delay = config.getLong("quests." + s + ".stages.ordered." + s2 + ".delay"); + }else { + printSevere(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "delay: " + ChatColor.GOLD + "in " + ChatColor.LIGHT_PURPLE + "Stage " + s2 + ChatColor.GOLD + " of Quest " + ChatColor.DARK_PURPLE + quest.name + ChatColor.GOLD + " is not a number!"); + stageFailed = true; + break; + } + + } + + if(config.contains("quests." + s + ".stages.ordered." + s2 + ".delay-message")){ + + stage.delayMessage = config.getString("quests." + s + ".stages.ordered." + s2 + ".delay-message"); + + } stage.citizensToInteract = npcsToTalkTo; @@ -2717,8 +2735,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener failed = true; break; } - ItemStack stack = new ItemStack(m, config.getIntegerList("quests." + s + ".rewards.item-amounts").get(config.getIntegerList("quests." + s + ".rewards.item-ids").indexOf(i))); + int amnt = config.getIntegerList("quests." + s + ".rewards.item-amounts").get(config.getIntegerList("quests." + s + ".rewards.item-ids").indexOf(i)); + ItemStack stack = new ItemStack(m, amnt); quest.itemRewards.add(stack); + quest.itemRewardAmounts.add(amnt); } diff --git a/src/me/blackvein/quests/Stage.java b/src/me/blackvein/quests/Stage.java index e31253468..21c454c93 100644 --- a/src/me/blackvein/quests/Stage.java +++ b/src/me/blackvein/quests/Stage.java @@ -30,7 +30,7 @@ public class Stage { LinkedList radiiToKillWithin = new LinkedList(); LinkedList areaNames = new LinkedList(); LinkedList citizensToInteract = new LinkedList(){ - + @Override public boolean equals(Object o) { @@ -87,6 +87,8 @@ public class Stage { Map itemsToCraft = new EnumMap(Material.class); String script; Event event; + long delay = -1; + String delayMessage = ""; @Override public boolean equals(Object o) { @@ -232,6 +234,12 @@ public class Stage { } else if (other.event == null && event != null) { return false; } + + if(other.delay != delay) + return false; + + if(other.delayMessage.equalsIgnoreCase(delayMessage) == false) + return false; }