aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java23
2 files changed, 23 insertions, 2 deletions
diff --git a/pom.xml b/pom.xml
index bb78e79c..4d0fe9cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
<groupId>com.leonardobishop</groupId>
<artifactId>quests</artifactId>
- <version>2.9.4</version>
+ <version>2.9.5</version>
<name>Quests</name>
<properties>
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
index 73dd82d6..f5b941cd 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java
@@ -15,6 +15,8 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
@@ -32,6 +34,7 @@ public final class InventoryTaskType extends TaskType {
this.creatorConfigValues.add(new ConfigValue("item", true, "Name or ID of item."));
this.creatorConfigValues.add(new ConfigValue("remove-items-when-complete", false, "Take the items away from the player on completion (true/false, " +
"default = false)."));
+ this.creatorConfigValues.add(new ConfigValue("update-progress", false, "Update the displayed progress (if this causes lag then disable it)."));
}
@Override
@@ -46,7 +49,7 @@ public final class InventoryTaskType extends TaskType {
}
@EventHandler(priority = EventPriority.MONITOR/*, ignoreCancelled = true*/)
- public void onInventoryClick(InventoryInteractEvent event) {
+ public void onInventoryClick(InventoryClickEvent event) {
Bukkit.getScheduler().runTaskLater(Quests.get(), () -> checkInventory((Player) event.getWhoClicked()), 1L); //Still some work to do as it doesn't really work
}
@@ -89,6 +92,10 @@ public final class InventoryTaskType extends TaskType {
is = new ItemStack(material, 1);
}
+ if (task.getConfigValue("update-progress") != null && (Boolean) task.getConfigValue("update-progress")) {
+ taskProgress.setProgress(getAmount(player, is, amount));
+ }
+
if (player.getInventory().containsAtLeast(is, amount)) {
is.setAmount(amount);
taskProgress.setCompleted(true);
@@ -102,4 +109,18 @@ public final class InventoryTaskType extends TaskType {
}
}
+ private int getAmount(Player player, ItemStack is, int max) {
+ if (is == null) {
+ return 0;
+ }
+ int amount = 0;
+ for (int i = 0; i < 36; i++) {
+ ItemStack slot = player.getInventory().getItem(i);
+ if (slot == null || !slot.isSimilar(is))
+ continue;
+ amount += slot.getAmount();
+ }
+ return Math.min(amount, max);
+ }
+
}