fix issues with servers not having worldguard

This commit is contained in:
2021-09-18 00:21:19 +02:00
parent bea0d9c7df
commit a86485a089
2 changed files with 7 additions and 13 deletions
+1 -2
View File
@@ -6,7 +6,7 @@
<groupId>me.youhavetrouble</groupId>
<artifactId>PreventStabby</artifactId>
<version>1.3-pre4</version>
<version>1.3-pre5</version>
<packaging>jar</packaging>
<name>PreventStabby</name>
@@ -47,7 +47,6 @@
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>bstats</shadedPattern>
</relocation>
</relocations>
@@ -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;
}
}