diff options
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java | 48 |
1 files changed, 29 insertions, 19 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 9d934a33..949616f7 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 @@ -56,6 +56,7 @@ public final class InventoryTaskType extends BukkitTaskType { TaskUtils.configValidateInt(root + ".data", config.get("data"), problems, true, false, "data"); TaskUtils.configValidateBoolean(root + ".remove-items-when-complete", config.get("remove-items-when-complete"), problems, true, "remove-items-when-complete", super.getType()); TaskUtils.configValidateBoolean(root + ".update-progress", config.get("update-progress"), problems, true, "update-progress", super.getType()); + TaskUtils.configValidateBoolean(root + ".allow-partial-completion", config.get("allow-partial-completion"), problems, true, "allow-partial-completion", super.getType()); return problems; } @@ -118,33 +119,37 @@ public final class InventoryTaskType extends BukkitTaskType { continue; } - Material material; int amount = (int) task.getConfigValue("amount"); Object configBlock = task.getConfigValue("item"); Object configData = task.getConfigValue("data"); boolean remove = (boolean) task.getConfigValue("remove-items-when-complete", false); boolean allowPartial = (boolean) task.getConfigValue("allow-partial-completion", false); - + QuestItem qi; if ((qi = fixedQuestItemCache.get(quest.getId(), task.getId())) == null) { if (configBlock instanceof ConfigurationSection) { qi = plugin.getConfiguredQuestItem("", (ConfigurationSection) configBlock); } else { - material = Material.getMaterial(String.valueOf(configBlock)); - ItemStack is; + Material material = Material.getMaterial(String.valueOf(configBlock)); if (material == null) { continue; } + + ItemStack is; if (configData != null) { is = new ItemStack(material, 1, ((Integer) configData).shortValue()); } else { is = new ItemStack(material, 1); } + qi = new ParsedQuestItem("parsed", null, is); } 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; @@ -152,25 +157,30 @@ public final class InventoryTaskType extends BukkitTaskType { progress = (int) taskProgress.getProgress(); } - int deficit = amount - progress; + if (allowPartial) { + if (total == 0) { + continue; + } - int[] amountPerSlot = getAmountsPerSlot(player, qi); - int total = Math.min(amountPerSlot[36], deficit); + progress += total; - if (total == 0) { - continue; - } + // 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); + taskProgress.setProgress(progress); + if (progress >= amount) { + taskProgress.setCompleted(true); + } + } else { + taskProgress.setProgress(total); + if (total >= amount) { + taskProgress.setCompleted(true); - if (progress >= amount) { - taskProgress.setCompleted(true); - if (remove) { - removeItemsInSlots(player, amountPerSlot, total); + if (remove) { + removeItemsInSlots(player, amountPerSlot, total); + } } - } else if (remove && allowPartial) { - removeItemsInSlots(player, amountPerSlot, total); } } } @@ -204,4 +214,4 @@ public final class InventoryTaskType extends BukkitTaskType { if (amountToRemove <= 0) break; } } -} +}
\ No newline at end of file |
