diff options
Diffstat (limited to 'bukkit/src')
2 files changed, 51 insertions, 13 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 22aec162..9d934a33 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 @@ -122,8 +122,9 @@ public final class InventoryTaskType extends BukkitTaskType { int amount = (int) task.getConfigValue("amount"); Object configBlock = task.getConfigValue("item"); Object configData = task.getConfigValue("data"); - Object remove = task.getConfigValue("remove-items-when-complete"); - + 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) { @@ -144,14 +145,32 @@ public final class InventoryTaskType extends BukkitTaskType { fixedQuestItemCache.put(quest.getId(), task.getId(), qi); } + int progress; + if (taskProgress.getProgress() == null) { + progress = 0; + } else { + progress = (int) taskProgress.getProgress(); + } + + int deficit = amount - progress; + int[] amountPerSlot = getAmountsPerSlot(player, qi); - int total = Math.min(amountPerSlot[36], amount); - taskProgress.setProgress(total); + int total = Math.min(amountPerSlot[36], deficit); - if (total >= amount) { - taskProgress.setCompleted(true); + if (total == 0) { + continue; + } + + progress += total; + taskProgress.setProgress(progress); - if (remove != null && ((Boolean) remove)) removeItemsInSlots(player, amountPerSlot, total); + if (progress >= amount) { + taskProgress.setCompleted(true); + if (remove) { + removeItemsInSlots(player, amountPerSlot, total); + } + } else if (remove && allowPartial) { + removeItemsInSlots(player, amountPerSlot, total); } } } 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 256216b0..e876b5be 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 @@ -100,7 +100,8 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { int amount = (int) task.getConfigValue("amount"); Object configBlock = task.getConfigValue("item"); Object configData = task.getConfigValue("data"); - Object remove = task.getConfigValue("remove-items-when-complete"); + 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) { @@ -122,14 +123,32 @@ public final class CitizensDeliverTaskType extends BukkitTaskType { fixedQuestItemCache.put(quest.getId(), task.getId(), qi); } + int progress; + if (taskProgress.getProgress() == null) { + progress = 0; + } else { + progress = (int) taskProgress.getProgress(); + } + + int deficit = amount - progress; + int[] amountPerSlot = getAmountsPerSlot(player, qi); - int total = Math.min(amountPerSlot[36], amount); - taskProgress.setProgress(total); + int total = Math.min(amountPerSlot[36], deficit); - if (total >= amount) { - taskProgress.setCompleted(true); + if (total == 0) { + continue; + } + + progress += total; + taskProgress.setProgress(progress); - if (remove != null && ((Boolean) remove)) removeItemsInSlots(player, amountPerSlot, total); + if (progress >= amount) { + taskProgress.setCompleted(true); + if (remove) { + removeItemsInSlots(player, amountPerSlot, total); + } + } else if (remove && allowPartial) { + removeItemsInSlots(player, amountPerSlot, total); } } } |
