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