From d7f1c29552659f3647c3a1d43e8575c6d0913d13 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Mon, 4 Dec 2023 02:10:40 +0100 Subject: Nullable block interact task type support --- .../quests/bukkit/tasktype/type/InteractTaskType.java | 17 ++++++----------- .../leonardobishop/quests/bukkit/util/TaskUtils.java | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'bukkit/src') diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InteractTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InteractTaskType.java index bad80afb..ebea3150 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InteractTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/InteractTaskType.java @@ -42,11 +42,6 @@ public final class InteractTaskType extends BukkitTaskType { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { - Block block = event.getClickedBlock(); - if (block == null) { - return; - } - Player player = event.getPlayer(); if (player.hasMetadata("NPC")) { return; @@ -57,6 +52,7 @@ public final class InteractTaskType extends BukkitTaskType { return; } + Block block = event.getClickedBlock(); ItemStack item = event.getItem(); for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) { @@ -66,6 +62,11 @@ public final class InteractTaskType extends BukkitTaskType { super.debug("Player interacted", quest.getId(), task.getId(), player.getUniqueId()); + if (!TaskUtils.matchBlock(this, pendingTask, block, player.getUniqueId())) { + super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId()); + continue; + } + if (task.hasConfigKey("item")) { if (item == null) { super.debug("Specific item is required, player has no item in hand; continuing...", quest.getId(), task.getId(), player.getUniqueId()); @@ -90,12 +91,6 @@ public final class InteractTaskType extends BukkitTaskType { } } - super.debug("Player clicked block " + 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()); diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java index 93b7506c..015c994d 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java @@ -266,18 +266,18 @@ public class TaskUtils { public record PendingTask(Quest quest, Task task, QuestProgress questProgress, TaskProgress taskProgress) { } - public static boolean matchBlock(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @NotNull Block block, @NotNull UUID player) { - return matchBlock(type, pendingTask, block.getState(), player); + public static boolean matchBlock(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @Nullable Block block, @NotNull UUID player) { + return matchBlock(type, pendingTask, block != null ? block.getState() : null, player); } - public static boolean matchBlock(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @NotNull BlockState state, @NotNull UUID player) { + public static boolean matchBlock(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @Nullable BlockState state, @NotNull UUID player) { Task task = pendingTask.task; List checkBlocks = TaskUtils.getConfigStringList(task, task.getConfigValues().containsKey("block") ? "block" : "blocks"); if (checkBlocks == null) { return true; } else if (checkBlocks.isEmpty()) { - return false; + return state == null; } Object configData = task.getConfigValue("data"); -- cgit v1.2.3-70-g09d2