From ab318d18222bfde83055a1d9cfe2302eca809d20 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Sun, 19 Mar 2023 16:51:12 +0100 Subject: PlayerBlockTracker support Closes https://github.com/LMBishop/Quests/issues/499 --- .../quests/bukkit/BukkitQuestsPlugin.java | 10 +++++++++ .../AbstractPlayerBlockTrackerHook.java | 15 +++++++++++++ .../playerblocktracker/PlayerBlockTrackerHook.java | 13 +++++++++++ .../bukkit/tasktype/type/MiningTaskType.java | 25 ++++++++++++++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/AbstractPlayerBlockTrackerHook.java create mode 100644 bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/PlayerBlockTrackerHook.java (limited to 'bukkit/src/main/java/com') 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 5d4f1c32..633509a5 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -13,6 +13,8 @@ import com.leonardobishop.quests.bukkit.hook.itemgetter.ItemGetter_1_13; import com.leonardobishop.quests.bukkit.hook.itemgetter.ItemGetter_Late_1_8; import com.leonardobishop.quests.bukkit.hook.papi.AbstractPlaceholderAPIHook; import com.leonardobishop.quests.bukkit.hook.papi.PlaceholderAPIHook; +import com.leonardobishop.quests.bukkit.hook.playerblocktracker.AbstractPlayerBlockTrackerHook; +import com.leonardobishop.quests.bukkit.hook.playerblocktracker.PlayerBlockTrackerHook; import com.leonardobishop.quests.bukkit.hook.title.Title; import com.leonardobishop.quests.bukkit.hook.title.Title_Bukkit; import com.leonardobishop.quests.bukkit.hook.title.Title_BukkitNoTimings; @@ -89,6 +91,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { private AbstractPlaceholderAPIHook placeholderAPIHook; private AbstractCoreProtectHook coreProtectHook; private AbstractEssentialsHook essentialsHook; + private AbstractPlayerBlockTrackerHook playerBlockTrackerHook; private ItemGetter itemGetter; private Title titleHandle; private VersionSpecificHandler versionSpecificHandler; @@ -277,6 +280,9 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { this.essentialsHook = new EssentialsHook(); } + if (Bukkit.getPluginManager().isPluginEnabled("PlayerBlockTracker")) { + this.playerBlockTrackerHook = new PlayerBlockTrackerHook(); + } taskTypeManager.registerTaskType(new MiningTaskType(this)); taskTypeManager.registerTaskType(new BuildingTaskType(this)); @@ -569,6 +575,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { return essentialsHook; } + public @Nullable AbstractPlayerBlockTrackerHook getPlayerBlockTrackerHook() { + return playerBlockTrackerHook; + } + public ItemGetter getItemGetter() { return itemGetter; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/AbstractPlayerBlockTrackerHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/AbstractPlayerBlockTrackerHook.java new file mode 100644 index 00000000..2e07316b --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/AbstractPlayerBlockTrackerHook.java @@ -0,0 +1,15 @@ +package com.leonardobishop.quests.bukkit.hook.playerblocktracker; + +import org.bukkit.block.Block; + +public interface AbstractPlayerBlockTrackerHook { + + /** + * Check whether or not the most recent edit to a block was the result of a player. + * + * @param block the block + * @return true if from a player + */ + boolean checkBlock(Block block); + +} diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/PlayerBlockTrackerHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/PlayerBlockTrackerHook.java new file mode 100644 index 00000000..34bf95af --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/playerblocktracker/PlayerBlockTrackerHook.java @@ -0,0 +1,13 @@ +package com.leonardobishop.quests.bukkit.hook.playerblocktracker; + +import com.gestankbratwurst.playerblocktracker.PlayerBlockTracker; +import org.bukkit.block.Block; + +public class PlayerBlockTrackerHook implements AbstractPlayerBlockTrackerHook { + + @Override + public boolean checkBlock(Block block) { + return PlayerBlockTracker.isTracked(block); + } + +} diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java index 4249600e..e0395d83 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java @@ -2,6 +2,7 @@ package com.leonardobishop.quests.bukkit.tasktype.type; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import com.leonardobishop.quests.bukkit.hook.coreprotect.AbstractCoreProtectHook; +import com.leonardobishop.quests.bukkit.hook.playerblocktracker.AbstractPlayerBlockTrackerHook; import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType; import com.leonardobishop.quests.bukkit.util.TaskUtils; import com.leonardobishop.quests.common.player.QPlayer; @@ -30,6 +31,7 @@ public final class MiningTaskType extends BukkitTaskType { super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, TaskUtils.MaterialListConfigValidatorMode.BLOCK, "block", "blocks")); super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data")); + super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "check-playerblocktracker")); super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "check-coreprotect")); super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "check-coreprotect-time")); super.addConfigValidator(TaskUtils.useBooleanConfigValidator(this, "reverse-if-placed")); @@ -68,8 +70,24 @@ public final class MiningTaskType extends BukkitTaskType { super.debug("allow-silk-touch is disabled, checking block", quest.getId(), task.getId(), player.getUniqueId()); if (TaskUtils.matchBlock(this, pendingTask, block, player.getUniqueId())) { - boolean coreProtectEnabled = (boolean) task.getConfigValue("check-coreprotect", false); - int coreProtectTime = (int) task.getConfigValue("check-coreprotect-time", 3600); + boolean playerBlockTrackerEnabled = (boolean) task.getConfigValue("check-playerblocktracker", false); + + if (playerBlockTrackerEnabled) { + AbstractPlayerBlockTrackerHook playerBlockTrackerHook = plugin.getPlayerBlockTrackerHook(); + if (playerBlockTrackerHook != null) { + super.debug("Running PlayerBlockTracker lookup", quest.getId(), task.getId(), player.getUniqueId()); + + boolean result = playerBlockTrackerHook.checkBlock(block); + if (result) { + super.debug("PlayerBlockTracker lookup indicates this is a player placed block, continuing...", quest.getId(), task.getId(), player.getUniqueId()); + continue; + } + + super.debug("PlayerBlockTracker lookup OK", quest.getId(), task.getId(), player.getUniqueId()); + } else { + super.debug("check-playerblocktracker is enabled, but PlayerBlockTracker is not detected on the server", quest.getId(), task.getId(), player.getUniqueId()); + } + } Runnable increment = () -> { int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress); @@ -82,6 +100,9 @@ public final class MiningTaskType extends BukkitTaskType { } }; + boolean coreProtectEnabled = (boolean) task.getConfigValue("check-coreprotect", false); + int coreProtectTime = (int) task.getConfigValue("check-coreprotect-time", 3600); + if (coreProtectEnabled) { AbstractCoreProtectHook coreProtectHook = plugin.getCoreProtectHook(); if (coreProtectHook != null) { -- cgit v1.2.3-70-g09d2