diff options
| author | Krakenied <Krakenied1@gmail.com> | 2024-02-23 10:30:41 +0100 |
|---|---|---|
| committer | Leonardo Bishop <13875753+LMBishop@users.noreply.github.com> | 2024-03-09 16:17:14 +0000 |
| commit | 80b9c51c020c59b1091c1db3eb0976dbb222e661 (patch) | |
| tree | bf78e7c62ad529982efcff54a1ba8aca725cf710 /bukkit/src/main/java/com | |
| parent | 57b3b3dd1f5e06007f0be081dc86019effd2d14f (diff) | |
Add allow negative progress option to building task type
Diffstat (limited to 'bukkit/src/main/java/com')
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingTaskType.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingTaskType.java index 5bd3c40a..75681db8 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingTaskType.java @@ -28,6 +28,7 @@ public final class BuildingTaskType extends BukkitTaskType { super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, TaskUtils.MaterialListConfigValidatorMode.BLOCK, "block", "blocks")); super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data")); super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "reverse-if-broken")); + super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "allow-negative-progress")); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -42,7 +43,7 @@ public final class BuildingTaskType extends BukkitTaskType { return; } - final Block block = event.getBlock(); + Block block = event.getBlock(); for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) { Quest quest = pendingTask.quest(); @@ -60,7 +61,6 @@ public final class BuildingTaskType extends BukkitTaskType { super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId()); int amount = (int) task.getConfigValue("amount"); - if (progress >= amount) { super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId()); taskProgress.setCompleted(true); @@ -83,7 +83,7 @@ public final class BuildingTaskType extends BukkitTaskType { return; } - final Block block = event.getBlock(); + Block block = event.getBlock(); for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) { Quest quest = pendingTask.quest(); @@ -104,6 +104,13 @@ public final class BuildingTaskType extends BukkitTaskType { continue; } + boolean allowNegativeProgress = TaskUtils.getConfigBoolean(task, "allow-negative-progress", true); + int currentProgress = TaskUtils.getIntegerTaskProgress(taskProgress); + if (currentProgress <= 0 && !allowNegativeProgress) { + super.debug("Task progress is already at zero and negative progress is disabled, skipping decrement", quest.getId(), task.getId(), player.getUniqueId()); + continue; + } + int progress = TaskUtils.decrementIntegerTaskProgress(taskProgress); super.debug("Decrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId()); |
