mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
fix issues with servers not having worldguard
This commit is contained in:
@@ -18,27 +18,26 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
private static WorldGuardPlugin worldGuardPlugin;
|
||||
private static FlagRegistry flagRegistry;
|
||||
public static StateFlag FORCE_PVP_FLAG;
|
||||
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void init() {
|
||||
PreventStabby plugin = PreventStabby.getPlugin();
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
||||
worldGuardPlugin = WorldGuardPlugin.inst();
|
||||
WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst();
|
||||
if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return;
|
||||
plugin.getLogger().info("Hooking into WorldGuard");
|
||||
flagRegistry = WorldGuard.getInstance().getFlagRegistry();
|
||||
createForcePvpFlag(plugin);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException e) {
|
||||
return;
|
||||
enabled = true;
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createForcePvpFlag(Plugin plugin) {
|
||||
if (!isHooked()) return;
|
||||
if (!enabled) return;
|
||||
if (flagRegistry == null) return;
|
||||
String flagName = "preventstabby-force-pvp";
|
||||
try {
|
||||
@@ -56,7 +55,7 @@ public class WorldGuardHook {
|
||||
}
|
||||
|
||||
public static boolean isPlayerForcedToPvp(Player player) {
|
||||
if (!isHooked()) return false;
|
||||
if (!enabled) return false;
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
org.bukkit.Location loc = player.getLocation();
|
||||
@@ -65,10 +64,6 @@ public class WorldGuardHook {
|
||||
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
||||
}
|
||||
|
||||
public static boolean isHooked() {
|
||||
return worldGuardPlugin != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user