diff options
| author | Krakenied <Krakenied1@gmail.com> | 2022-05-02 04:05:13 +0200 |
|---|---|---|
| committer | Krakenied <Krakenied1@gmail.com> | 2022-05-05 06:58:03 +0200 |
| commit | af8470a228352a89cc084dede1a895b3905febaf (patch) | |
| tree | 10b676452beb26f6a87a69cba20b0ed51c9ae6e2 /bukkit | |
| parent | 8068d1efc179e60e5b01a1733c392f5b3de21549 (diff) | |
Fix inventory and citizens deliver task types taking too many items
Diffstat (limited to 'bukkit')
2 files changed, 25 insertions, 16 deletions
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 949616f7..5d6f757b 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 @@ -119,7 +119,7 @@ public final class InventoryTaskType extends BukkitTaskType { continue; } - int amount = (int) task.getConfigValue("amount"); + int itemsNeeded = (int) task.getConfigValue("amount"); Object configBlock = task.getConfigValue("item"); Object configData = task.getConfigValue("data"); boolean remove = (boolean) task.getConfigValue("remove-items-when-complete", false); @@ -147,9 +147,6 @@ public final class InventoryTaskType extends BukkitTaskType { fixedQuestItemCache.put(quest.getId(), task.getId(), qi); } - int[] amountPerSlot = getAmountsPerSlot(player, qi); - int total = Math.min(amountPerSlot[36], amount); - int progress; if (taskProgress.getProgress() == null) { progress = 0; @@ -157,24 +154,31 @@ public final class InventoryTaskType extends BukkitTaskType { progress = (int) taskProgress.getProgress(); } + int total; + int[] amountPerSlot = getAmountsPerSlot(player, qi); + if (allowPartial) { + total = Math.min(amountPerSlot[36], itemsNeeded - progress); + if (total == 0) { continue; } - progress += total; - // We must ALWAYS remove items if partial completion is allowed // https://github.com/LMBishop/Quests/issues/375 removeItemsInSlots(player, amountPerSlot, total); + progress += total; taskProgress.setProgress(progress); - if (progress >= amount) { + + if (progress >= itemsNeeded) { taskProgress.setCompleted(true); } } else { + total = Math.min(amountPerSlot[36], itemsNeeded); + taskProgress.setProgress(total); - if (total >= amount) { + if (total >= itemsNeeded) { taskProgress.setCompleted(true); if (remove) { 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 7f9c4b62..da4df740 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 @@ -52,6 +52,7 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { TaskUtils.configValidateExists(root + ".npc-name", config.get("npc-name"), problems, "npc-name", super.getType()); } TaskUtils.configValidateBoolean(root + ".remove-items-when-complete", config.get("remove-items-when-complete"), problems, true, "remove-items-when-complete", super.getType()); + TaskUtils.configValidateBoolean(root + ".allow-partial-completion", config.get("allow-partial-completion"), problems, true, "allow-partial-completion", super.getType()); return problems; } @@ -97,7 +98,7 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { } Material material; - int amount = (int) task.getConfigValue("amount"); + int itemsNeeded = (int) task.getConfigValue("amount"); Object configBlock = task.getConfigValue("item"); Object configData = task.getConfigValue("data"); boolean remove = (boolean) task.getConfigValue("remove-items-when-complete", false); @@ -123,9 +124,6 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { fixedQuestItemCache.put(quest.getId(), task.getId(), qi); } - int[] amountPerSlot = getAmountsPerSlot(player, qi); - int total = Math.min(amountPerSlot[36], amount); - int progress; if (taskProgress.getProgress() == null) { progress = 0; @@ -133,24 +131,31 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { progress = (int) taskProgress.getProgress(); } + int total; + int[] amountPerSlot = getAmountsPerSlot(player, qi); + if (allowPartial) { + total = Math.min(amountPerSlot[36], itemsNeeded - progress); + if (total == 0) { continue; } - progress += total; - // We must ALWAYS remove items if partial completion is allowed // https://github.com/LMBishop/Quests/issues/375 removeItemsInSlots(player, amountPerSlot, total); + progress += total; taskProgress.setProgress(progress); - if (progress >= amount) { + + if (progress >= itemsNeeded) { taskProgress.setCompleted(true); } } else { + total = Math.min(amountPerSlot[36], itemsNeeded); + taskProgress.setProgress(total); - if (total >= amount) { + if (total >= itemsNeeded) { taskProgress.setCompleted(true); if (remove) { |
