diff --git a/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java b/src/main/java/com/gamingmesh/jobs/hooks/HookManager.java index 36df65de..7be2b307 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 com.gamingmesh.jobs.hooks.pyroFishingPro.PyroFishingProManager; 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 PyroFishingProManager pyroFishingProManager; private static final Jobs PLUGIN = JavaPlugin.getPlugin(Jobs.class); @@ -39,6 +41,7 @@ public class HookManager { setMythicManager(); setStackMobHandler(); setWildStackerHandler(); + setBlockTrackerManager(); setPyroFishingProManager(); } @@ -96,6 +99,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(); @@ -149,6 +160,11 @@ public class HookManager { } } + private static void setBlockTrackerManager() { + if (JobsHook.BlockTracker.isEnabled()) { + blockTrackerManager = new BlockTrackerManager(); + } + private static void setPyroFishingProManager() { if (JobsHook.PyroFishingPro.isEnabled()) { pyroFishingProManager = new PyroFishingProManager(); diff --git a/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java b/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java index 17d76a21..fbb4d3ed 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/JobsHook.java @@ -11,6 +11,7 @@ public enum JobsHook { WorldGuard, MythicMobs, mcMMO, + BlockTracker; PyroFishingPro; private Boolean enabled; 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..ae3f3ef9 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/hooks/blockTracker/BlockTrackerManager.java @@ -0,0 +1,30 @@ +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 06ab0c62..5afb2086 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -410,13 +410,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 @@ -433,6 +438,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 352cccee..cbf880e0 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, PyroFishingPro] +softdepend: [Vault, Essentials, MythicMobs, WorldGuard, MyPet, PlaceholderAPI, EcoEnchants, WildStacker, StackMob, PyroFishingPro, BlockTracker] commands: jobs: description: Jobs