summaryrefslogtreecommitdiffstats
path: root/bukkit/src
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2022-04-21 18:06:12 +0200
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2022-04-21 19:38:10 +0100
commit23aeb212cc556e1e4315ddf2dcfa0c15c3875429 (patch)
tree1cc348f66f333e23ecbe50ba68b1d99482894017 /bukkit/src
parent8110d8e29f1d8b659e323425e8d8466be794e516 (diff)
Fix partial inventory task type completion
Fixes https://github.com/LMBishop/Quests/issues/375
Diffstat (limited to 'bukkit/src')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java48
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