diff options
Diffstat (limited to 'bukkit')
3 files changed, 66 insertions, 33 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CraftingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CraftingTaskType.java index 2fdd54f5..7b028ef9 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CraftingTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/CraftingTaskType.java @@ -1,5 +1,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType; import com.leonardobishop.quests.bukkit.util.TaskUtils; @@ -27,6 +29,7 @@ import java.util.List; public final class CraftingTaskType extends BukkitTaskType { private final BukkitQuestsPlugin plugin; + private final Table<String, String, ItemStack> fixedItemStackCache = HashBasedTable.create(); public CraftingTaskType(BukkitQuestsPlugin plugin) { super("crafting", TaskUtils.TASK_ATTRIBUTION_STRING, "Craft a specific item."); @@ -67,6 +70,11 @@ public final class CraftingTaskType extends BukkitTaskType { return problems; } + @Override + public void onReady() { + fixedItemStackCache.clear(); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onItemCraft(CraftItemEvent event) { if (event.getClickedInventory() == null @@ -104,19 +112,22 @@ public final class CraftingTaskType extends BukkitTaskType { Object configData = task.getConfigValue("data"); ItemStack is; - if (configBlock instanceof ConfigurationSection) { - is = plugin.getItemStack("", (ConfigurationSection) configBlock); - } else { - material = Material.getMaterial(String.valueOf(configBlock)); - - if (material == null) { - continue; - } - if (configData != null) { - is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + if ((is = fixedItemStackCache.get(quest.getId(), task.getId())) == null) { + if (configBlock instanceof ConfigurationSection) { + is = plugin.getItemStack("", (ConfigurationSection) configBlock); } else { - is = new ItemStack(material, 1); + material = Material.getMaterial(String.valueOf(configBlock)); + + if (material == null) { + continue; + } + if (configData != null) { + is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + } else { + is = new ItemStack(material, 1); + } } + fixedItemStackCache.put(quest.getId(), task.getId(), is); } if (!clickedItem.isSimilar(is)) continue; diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java index b57aabcd..af001f4d 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java @@ -1,5 +1,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType; import com.leonardobishop.quests.bukkit.util.TaskUtils; @@ -28,6 +30,7 @@ import java.util.List; public final class InventoryTaskType extends BukkitTaskType { private final BukkitQuestsPlugin plugin; + private final Table<String, String, ItemStack> fixedItemStackCache = HashBasedTable.create(); public InventoryTaskType(BukkitQuestsPlugin plugin) { super("inventory", TaskUtils.TASK_ATTRIBUTION_STRING, "Obtain a set of items."); @@ -70,6 +73,11 @@ public final class InventoryTaskType extends BukkitTaskType { return problems; } + @Override + public void onReady() { + fixedItemStackCache.clear(); + } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onItemPickup(PlayerPickupItemEvent event) { @@ -114,19 +122,22 @@ public final class InventoryTaskType extends BukkitTaskType { Object remove = task.getConfigValue("remove-items-when-complete"); ItemStack is; - if (configBlock instanceof ConfigurationSection) { - is = plugin.getItemStack("", (ConfigurationSection) configBlock); - } else { - material = Material.getMaterial(String.valueOf(configBlock)); - - if (material == null) { - continue; - } - if (configData != null) { - is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + if ((is = fixedItemStackCache.get(quest.getId(), task.getId())) == null) { + if (configBlock instanceof ConfigurationSection) { + is = plugin.getItemStack("", (ConfigurationSection) configBlock); } else { - is = new ItemStack(material, 1); + material = Material.getMaterial(String.valueOf(configBlock)); + + if (material == null) { + continue; + } + if (configData != null) { + is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + } else { + is = new ItemStack(material, 1); + } } + fixedItemStackCache.put(quest.getId(), task.getId(), is); } if (task.getConfigValue("update-progress") != null diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensDeliverTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensDeliverTaskType.java index ee40878c..4c87a743 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensDeliverTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensDeliverTaskType.java @@ -1,5 +1,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type.dependent; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType; import com.leonardobishop.quests.bukkit.util.TaskUtils; @@ -28,6 +30,7 @@ import java.util.List; public final class CitizensDeliverTaskType extends BukkitTaskType { private final BukkitQuestsPlugin plugin; + private final Table<String, String, ItemStack> fixedItemStackCache = HashBasedTable.create(); public CitizensDeliverTaskType(BukkitQuestsPlugin plugin) { super("citizens_deliver", TaskUtils.TASK_ATTRIBUTION_STRING, "Deliver a set of items to a NPC."); @@ -69,6 +72,11 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { return problems; } + @Override + public void onReady() { + fixedItemStackCache.clear(); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onNPCClick(NPCRightClickEvent event) { Bukkit.getScheduler().runTaskLater(plugin, () -> checkInventory(event.getClicker(), event.getNPC().getName()), 1L); @@ -108,19 +116,22 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { Object remove = task.getConfigValue("remove-items-when-complete"); ItemStack is; - if (configBlock instanceof ConfigurationSection) { - is = plugin.getItemStack("", (ConfigurationSection) configBlock); - } else { - material = Material.getMaterial(String.valueOf(configBlock)); - - if (material == null) { - continue; - } - if (configData != null) { - is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + if ((is = fixedItemStackCache.get(quest.getId(), task.getId())) == null) { + if (configBlock instanceof ConfigurationSection) { + is = plugin.getItemStack("", (ConfigurationSection) configBlock); } else { - is = new ItemStack(material, 1); + material = Material.getMaterial(String.valueOf(configBlock)); + + if (material == null) { + continue; + } + if (configData != null) { + is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + } else { + is = new ItemStack(material, 1); + } } + fixedItemStackCache.put(quest.getId(), task.getId(), is); } if (player.getInventory().containsAtLeast(is, amount)) { |
