mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 20:16:13 +01:00
Merge pull request #1743 from flo0s/master
Add compatibility with BlockTracker
This commit is contained in:
commit
054a162b7b
@ -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();
|
||||
|
@ -11,6 +11,7 @@ public enum JobsHook {
|
||||
WorldGuard,
|
||||
MythicMobs,
|
||||
mcMMO,
|
||||
BlockTracker;
|
||||
PyroFishingPro;
|
||||
|
||||
private Boolean enabled;
|
||||
|
@ -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<? extends Plugin> pluginClazz = (Class<? extends Plugin>) 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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user