aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src
diff options
context:
space:
mode:
authorKrakenied <krakenied1@gmail.com>2026-02-14 09:02:50 +0100
committerKrakenied <krakenied1@gmail.com>2026-02-14 09:43:40 +0100
commit03f899de659047448c5648fa8f75bbe8f8cd28f1 (patch)
tree3b83344c0aa58ed8909bef650b8aa483ec095b49 /bukkit/src
parente3d434f1db1f04bba3425cf12dce0a4affbad2c2 (diff)
Add blocklootdispensing task typefeature/block-loot-dispensing
Allows for making trial chambers vaults tasks
Diffstat (limited to 'bukkit/src')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java2
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockItemdroppingTaskType.java60
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockLootdispensingTaskType.java133
3 files changed, 174 insertions, 21 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 fe361ebf..c6d9257d 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -58,6 +58,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.BlockLootdispensingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.BlockchangingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.BlockfertilizingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.BlockshearingTaskType;
@@ -476,6 +477,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 BlockLootdispensingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.block.BlockDispenseLootEvent"));
taskTypeManager.registerTaskType(() -> new BlockchangingTaskType(this), () -> CompatUtils.classWithMethodExists("org.bukkit.event.entity.EntityChangeBlockEvent", "getBlockData"));
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"));
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockItemdroppingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockItemdroppingTaskType.java
index 21b9c0ea..e1c93acd 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockItemdroppingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockItemdroppingTaskType.java
@@ -36,6 +36,7 @@ public final class BlockItemdroppingTaskType extends BukkitTaskType {
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data"));
super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "exact-match"));
super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, TaskUtils.MaterialListConfigValidatorMode.BLOCK, "block", "blocks"));
+ super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "count-drops"));
}
@Override
@@ -56,14 +57,18 @@ public final class BlockItemdroppingTaskType extends BukkitTaskType {
}
BlockState state = event.getBlockState();
-
List<Item> drops = event.getItems();
- for (Item drop : drops) {
- handle(player, qPlayer, state, drop.getItemStack());
+
+ if (drops.isEmpty()) {
+ handle(player, qPlayer, state, null, 0);
+ }
+
+ for (int i = 0; i < drops.size(); i++) {
+ handle(player, qPlayer, state, drops.get(i).getItemStack(), i);
}
}
- private void handle(Player player, QPlayer qPlayer, BlockState state, ItemStack item) {
+ private void handle(Player player, QPlayer qPlayer, BlockState state, ItemStack item, int i) {
for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
@@ -71,28 +76,41 @@ public final class BlockItemdroppingTaskType extends BukkitTaskType {
super.debug("Player dropped item from block", quest.getId(), task.getId(), player.getUniqueId());
- if (task.hasConfigKey("item")) {
- if (item == null) {
- super.debug("Specific item is required, dropped item is null; continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ Boolean countDrops = (Boolean) task.getConfigValue("count-drops");
+ final int amountToIncrease;
+
+ if (Boolean.TRUE.equals(countDrops)) {
+ if (i != 0) {
continue;
}
- super.debug("Specific item is required; dropped item is of type '" + item.getType() + "'", quest.getId(), task.getId(), player.getUniqueId());
+ amountToIncrease = 1;
+ } else {
+ if (task.hasConfigKey("item")) {
+ if (item == null) {
+ super.debug("Specific item is required, dropped item is null; continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
- QuestItem qi;
- if ((qi = fixedQuestItemCache.get(quest.getId(), task.getId())) == null) {
- QuestItem fetchedItem = TaskUtils.getConfigQuestItem(task, "item", "data");
- fixedQuestItemCache.put(quest.getId(), task.getId(), fetchedItem);
- qi = fetchedItem;
- }
+ super.debug("Specific item is required; dropped item is of type '" + item.getType() + "'", quest.getId(), task.getId(), player.getUniqueId());
- boolean exactMatch = TaskUtils.getConfigBoolean(task, "exact-match", true);
- if (!qi.compareItemStack(item, exactMatch)) {
- super.debug("Item does not match required item, continuing...", quest.getId(), task.getId(), player.getUniqueId());
- continue;
- } else {
- super.debug("Item matches required item", quest.getId(), task.getId(), player.getUniqueId());
+ QuestItem qi;
+ if ((qi = fixedQuestItemCache.get(quest.getId(), task.getId())) == null) {
+ QuestItem fetchedItem = TaskUtils.getConfigQuestItem(task, "item", "data");
+ fixedQuestItemCache.put(quest.getId(), task.getId(), fetchedItem);
+ qi = fetchedItem;
+ }
+
+ boolean exactMatch = TaskUtils.getConfigBoolean(task, "exact-match", true);
+ if (!qi.compareItemStack(item, exactMatch)) {
+ super.debug("Item does not match required item, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ } else {
+ super.debug("Item matches required item", quest.getId(), task.getId(), player.getUniqueId());
+ }
}
+
+ amountToIncrease = item != null ? item.getAmount() : 0;
}
if (!TaskUtils.matchBlock(this, pendingTask, state, player.getUniqueId())) {
@@ -100,7 +118,7 @@ public final class BlockItemdroppingTaskType extends BukkitTaskType {
continue;
}
- int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
+ int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress, amountToIncrease);
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());
int amount = (int) task.getConfigValue("amount");
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockLootdispensingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockLootdispensingTaskType.java
new file mode 100644
index 00000000..dfab6231
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockLootdispensingTaskType.java
@@ -0,0 +1,133 @@
+package com.leonardobishop.quests.bukkit.tasktype.type;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.item.QuestItem;
+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.BlockDispenseLootEvent;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.List;
+
+public final class BlockLootdispensingTaskType extends BukkitTaskType {
+
+ private final BukkitQuestsPlugin plugin;
+ private final Table<String, String, QuestItem> fixedQuestItemCache = HashBasedTable.create();
+
+ public BlockLootdispensingTaskType(BukkitQuestsPlugin plugin) {
+ super("blocklootdispensing", TaskUtils.TASK_ATTRIBUTION_STRING, "Dispense certain amount of loot from a block.");
+ this.plugin = plugin;
+
+ super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount"));
+ super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount"));
+ super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "item"));
+ super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data"));
+ super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "exact-match"));
+ super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, TaskUtils.MaterialListConfigValidatorMode.BLOCK, "block", "blocks"));
+ super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "count-dispenses"));
+ }
+
+ @Override
+ public void onReady() {
+ fixedQuestItemCache.clear();
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onBlockDispenseLoot(BlockDispenseLootEvent 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();
+ List<ItemStack> loots = event.getDispensedLoot();
+
+ if (loots.isEmpty()) {
+ handle(player, qPlayer, block, null, 0);
+ }
+
+ for (int i = 0; i < loots.size(); i++) {
+ handle(player, qPlayer, block, loots.get(i), i);
+ }
+ }
+
+ private void handle(Player player, QPlayer qPlayer, Block block, ItemStack item, int i) {
+ 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 dispensed loot from block", quest.getId(), task.getId(), player.getUniqueId());
+
+ Boolean countDispenses = (Boolean) task.getConfigValue("count-dispenses");
+ final int amountToIncrease;
+
+ if (Boolean.TRUE.equals(countDispenses)) {
+ if (i != 0) {
+ continue;
+ }
+
+ amountToIncrease = 1;
+ } else {
+ if (task.hasConfigKey("item")) {
+ if (item == null) {
+ super.debug("Specific item is required, dropped item is null; continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+
+ super.debug("Specific item is required; dropped item is of type '" + item.getType() + "'", quest.getId(), task.getId(), player.getUniqueId());
+
+ QuestItem qi;
+ if ((qi = fixedQuestItemCache.get(quest.getId(), task.getId())) == null) {
+ QuestItem fetchedItem = TaskUtils.getConfigQuestItem(task, "item", "data");
+ fixedQuestItemCache.put(quest.getId(), task.getId(), fetchedItem);
+ qi = fetchedItem;
+ }
+
+ boolean exactMatch = TaskUtils.getConfigBoolean(task, "exact-match", true);
+ if (!qi.compareItemStack(item, exactMatch)) {
+ super.debug("Item does not match required item, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ } else {
+ super.debug("Item matches required item", quest.getId(), task.getId(), player.getUniqueId());
+ }
+ }
+
+ amountToIncrease = item != null ? item.getAmount() : 0;
+ }
+
+ if (!TaskUtils.matchBlock(this, pendingTask, block, player.getUniqueId())) {
+ super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+
+ int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress, amountToIncrease);
+ 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);
+ }
+ }
+}