aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2022-04-18 13:15:07 +0100
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2022-04-18 13:15:07 +0100
commitc408fdd2697aaa6b7b899880e7f6afdea88836d5 (patch)
tree8c8f0ed61dba5e9fad0de6cf4ebfec9e565f4d53
parente1b86ec1b0ce425d08cea79ec63944c49f1223c5 (diff)
Add partial delivery option (closes #360)
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InventoryTaskType.java33
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensDeliverTaskType.java31
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);
}
}
}