From 49b8e5cb570f2cb08b225a8a75fcfe629a95e834 Mon Sep 17 00:00:00 2001 From: flo0s Date: Thu, 25 Apr 2024 19:49:26 +0200 Subject: [PATCH 1/2] Adds compatibility with BlockTracker --- .../gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java diff --git a/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java b/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java new file mode 100644 index 00000000..69d982c8 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java @@ -0,0 +1,2 @@ +package com.gamingmesh.jobs.hooks.blockTracker;public class BlockTrackerManager { +} From dc2d3405393ffd7ee7f35bb31bca49b369c88d89 Mon Sep 17 00:00:00 2001 From: flo0s Date: Thu, 25 Apr 2024 19:52:36 +0200 Subject: [PATCH 2/2] Add BlockTracker to softdepend --- .../gamingmesh/jobs/hooks/HookManager.java | 17 +++++++++++ .../com/gamingmesh/jobs/hooks/JobsHook.java | 3 +- .../blockTracker/BlockTrackerManager.java | 30 ++++++++++++++++++- .../jobs/listeners/JobsPaymentListener.java | 8 ++++- src/main/resources/plugin.yml | 2 +- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java b/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java index 7f5c65c1..97bc6518 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java @@ -1,5 +1,6 @@ package com.gamingmesh.jobs.hooks; +import com.gamingmesh.jobs.hooks.blockTracker.BlockTrackerManager; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -25,6 +26,7 @@ public class HookManager { private static WorldGuardManager worldGuardManager; private static StackMobHandler stackMobHandler; private static WildStackerHandler wildStackerHandler; + private static BlockTrackerManager blockTrackerManager; private static final Jobs PLUGIN = JavaPlugin.getPlugin(Jobs.class); @@ -38,6 +40,7 @@ public class HookManager { setMythicManager(); setStackMobHandler(); setWildStackerHandler(); + setBlockTrackerManager(); } public static StackMobHandler getStackMobHandler() { @@ -87,6 +90,14 @@ public class HookManager { return Jobs.getGCManager().MythicMobsEnabled && MythicManager != null && MythicManager.check(); } + public static BlockTrackerManager getBlockTrackerManager() { + if (blockTrackerManager == null) { + blockTrackerManager = new BlockTrackerManager(); + } + + return blockTrackerManager; + } + private static boolean setWorldGuard() { if (JobsHook.WorldGuard.isEnabled()) { worldGuardManager = new WorldGuardManager(); @@ -145,4 +156,10 @@ public class HookManager { wildStackerHandler = new WildStackerHandler(); } } + + private static void setBlockTrackerManager() { + if (JobsHook.BlockTracker.isEnabled()) { + blockTrackerManager = new BlockTrackerManager(); + } + } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java b/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java index 11640804..5699799b 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java @@ -10,7 +10,8 @@ public enum JobsHook { WildStacker, WorldGuard, MythicMobs, - mcMMO; + mcMMO, + BlockTracker; private Boolean enabled; private Boolean present; diff --git a/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java b/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java index 69d982c8..ae3f3ef9 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java @@ -1,2 +1,30 @@ -package com.gamingmesh.jobs.hooks.blockTracker;public class BlockTrackerManager { +package com.gamingmesh.jobs.hooks.blockTracker; + +import org.bukkit.block.Block; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.Method; + +public class BlockTrackerManager { + private final Method isTrackedMethod; + public BlockTrackerManager() { + try { + Class pluginClazz = (Class) Class.forName("dev.krakenied.blocktracker.bukkit.BukkitBlockTrackerPlugin"); + this.isTrackedMethod = pluginClazz.getMethod("isTracked", Block.class); + } catch (ClassCastException | ClassNotFoundException | NoSuchMethodException ignored) { + throw new IllegalStateException("BlockTracker plugin not found"); + } + } + + public boolean isTracked(Block block) { + try { + return (boolean) this.isTrackedMethod.invoke(null, block); + } catch (Throwable e) { + return false; + } + } + + public Method getIsTrackedMethod() { + return isTrackedMethod; + } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index b71b0f9d..303098d4 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -417,13 +417,18 @@ public final class JobsPaymentListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { final Block block = event.getBlock(); if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) return; + // Checks whether the broken block has been tracked by BlockTracker + if (JobsHook.BlockTracker.isEnabled()) { + if (HookManager.getBlockTrackerManager().isTracked(block)) return; + } + Player player = event.getPlayer(); // Remove block owner ships @@ -440,6 +445,7 @@ public final class JobsPaymentListener implements Listener { if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) return; + BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK); FastPayment fp = Jobs.FASTPAYMENT.get(player.getUniqueId()); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4c90794d..8ecfb1b0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,7 +8,7 @@ website: https://www.spigotmc.org/resources/4216/ authors: [Zrips] contributors: [montlikadani] depend: [CMILib] -softdepend: [Vault, Essentials, MythicMobs, WorldGuard, MyPet, PlaceholderAPI, EcoEnchants, WildStacker, StackMob] +softdepend: [Vault, Essentials, MythicMobs, WorldGuard, MyPet, PlaceholderAPI, EcoEnchants, WildStacker, StackMob, BlockTracker] commands: jobs: description: Jobs