diff options
| author | Krakenied <krakenied1@gmail.com> | 2025-03-01 04:46:19 +0100 |
|---|---|---|
| committer | Krakenied <46192742+Krakenied@users.noreply.github.com> | 2025-05-13 20:34:15 +0200 |
| commit | 8f5308bdb71ea95c2420e9e22e0ce7057e05a05c (patch) | |
| tree | 4f38a9fe403348f83d4f1b2def6c59c4b8959c08 | |
| parent | cdecd05fe4a41c032eb78a311d3a73ceea52b296 (diff) | |
Add blockfertilizing task type
3 files changed, 107 insertions, 1 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java index df7f6e81..a3bdf14d 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -64,6 +64,7 @@ import com.leonardobishop.quests.bukkit.storage.ModernYAMLStorageProvider; import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskTypeManager; import com.leonardobishop.quests.bukkit.tasktype.type.BarteringTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.BlockItemdroppingTaskType; +import com.leonardobishop.quests.bukkit.tasktype.type.BlockfertilizingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.BlockshearingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.BreedingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.BrewingTaskType; @@ -164,7 +165,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -466,6 +466,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { // Register task types with class/method compatibility requirement taskTypeManager.registerTaskType(() -> new BarteringTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.entity.PiglinBarterEvent")); taskTypeManager.registerTaskType(() -> new BlockItemdroppingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.block.BlockDropItemEvent")); + taskTypeManager.registerTaskType(() -> new BlockfertilizingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.block.BlockFertilizeEvent")); taskTypeManager.registerTaskType(() -> new BlockshearingTaskType(this), () -> CompatUtils.classExists("io.papermc.paper.event.block.PlayerShearBlockEvent")); taskTypeManager.registerTaskType(() -> new BrewingTaskType(this), () -> CompatUtils.classWithMethodExists("org.bukkit.event.inventory.BrewEvent", "getResults")); taskTypeManager.registerTaskType(() -> new BucketEntityTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.player.PlayerBucketEntityEvent")); diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockfertilizingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockfertilizingTaskType.java new file mode 100644 index 00000000..5e750fc5 --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockfertilizingTaskType.java @@ -0,0 +1,69 @@ +package com.leonardobishop.quests.bukkit.tasktype.type; + +import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; +import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType; +import com.leonardobishop.quests.bukkit.util.TaskUtils; +import com.leonardobishop.quests.bukkit.util.constraint.TaskConstraintSet; +import com.leonardobishop.quests.common.player.QPlayer; +import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress; +import com.leonardobishop.quests.common.quest.Quest; +import com.leonardobishop.quests.common.quest.Task; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockFertilizeEvent; +import org.jetbrains.annotations.NotNull; + +public final class BlockfertilizingTaskType extends BukkitTaskType { + + private final BukkitQuestsPlugin plugin; + + public BlockfertilizingTaskType(final @NotNull BukkitQuestsPlugin plugin) { + super("blockfertilizing", TaskUtils.TASK_ATTRIBUTION_STRING, "Fertilize a set amount of a block."); + this.plugin = plugin; + + super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); + super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); + super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, TaskUtils.MaterialListConfigValidatorMode.BLOCK, "block", "blocks")); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBlockFertilize(final @NotNull BlockFertilizeEvent event) { + Player player = event.getPlayer(); + if (player == null || player.hasMetadata("NPC")) { + return; + } + + QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId()); + if (qPlayer == null) { + return; + } + + Block block = event.getBlock(); + + for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) { + Quest quest = pendingTask.quest(); + Task task = pendingTask.task(); + TaskProgress taskProgress = pendingTask.taskProgress(); + + super.debug("Player fertilized a block, current block is " + block.getType(), quest.getId(), task.getId(), player.getUniqueId()); + + if (!TaskUtils.matchBlock(this, pendingTask, block, player.getUniqueId())) { + super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId()); + continue; + } + + int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress); + 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); + } + + TaskUtils.sendTrackAdvancement(player, quest, task, pendingTask, amount); + } + } +} diff --git a/docs/task-types/blockfertilizing-(task-type).md b/docs/task-types/blockfertilizing-(task-type).md new file mode 100644 index 00000000..7b5833f6 --- /dev/null +++ b/docs/task-types/blockfertilizing-(task-type).md @@ -0,0 +1,36 @@ +--- +title: blockfertilizing +parent: Built-in task types +grand_parent: Task types +--- + +# blockfertilizing (task type) + +Not released yet (dev builds) +{: .label .label-green } + +Minecraft 1.13+ required +{: .label .label-purple } + +Fertilize a set amount of blocks. + +## Options + +| Key | Description | Type | Required | Default | Notes | +|----------|-------------------------------------------------|-------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `amount` | The number of blocks to fertilize. | Integer | Yes | \- | \- | +| `block` | The specific block(s) to fertilize. | Material, or list of material | No | \- | Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. Note that some items are confusingly named, they may refer to the held item or block instead of the crop block. | +| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- | + +## Examples + +Fertilize beetroots in world_nether: + +``` yaml +infernalbeetroots: + type: "blockfertilizing" + amount: 1 # amount of blocks to be fertilized + block: "BEETROOTS" # name of block + worlds: # (OPTIONAL) restrict to certain worlds + - "world_nether" +``` |
