From 7d2c41646ef41e2f7df9ce8de54dae964945b315 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Sun, 26 Mar 2023 03:09:07 +0200 Subject: [PATCH] make worldguard hook register on load --- pom.xml | 4 ++-- .../preventstabby/PreventStabby.java | 19 ++++++++++++------- .../preventstabby/hooks/WorldGuardHook.java | 12 +++++------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index c9d5bcd..358e45e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.youhavetrouble PreventStabby - 1.8.0 + 1.8.1 jar PreventStabby @@ -100,7 +100,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.26 provided diff --git a/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java b/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java index 42d75ff..a8d4d11 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java +++ b/src/main/java/me/youhavetrouble/preventstabby/PreventStabby.java @@ -76,13 +76,6 @@ public final class PreventStabby extends JavaPlugin { pvpCommand.setExecutor(mainCommand); pvpCommand.setTabCompleter(mainCommand); - try { - WorldGuardHook.init(); - worldGuardHook = true; - } catch (NoClassDefFoundError e) { - worldGuardHook = false; - } - if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { new PlacoholderApiHook(this).register(); } @@ -90,6 +83,18 @@ public final class PreventStabby extends JavaPlugin { Metrics metrics = new Metrics(this, 14074); } + @Override + public void onLoad() { + if (getServer().getPluginManager().getPlugin("WorldGuard") != null) { + try { + WorldGuardHook.init(); + worldGuardHook = true; + } catch (NoClassDefFoundError e) { + worldGuardHook = false; + } + } + } + public static boolean worldGuardHookEnabled() { return worldGuardHook; } diff --git a/src/main/java/me/youhavetrouble/preventstabby/hooks/WorldGuardHook.java b/src/main/java/me/youhavetrouble/preventstabby/hooks/WorldGuardHook.java index 8cf614d..a01e90c 100644 --- a/src/main/java/me/youhavetrouble/preventstabby/hooks/WorldGuardHook.java +++ b/src/main/java/me/youhavetrouble/preventstabby/hooks/WorldGuardHook.java @@ -12,9 +12,8 @@ import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; -import me.youhavetrouble.preventstabby.PreventStabby; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; public class WorldGuardHook { @@ -22,19 +21,18 @@ public class WorldGuardHook { public static StateFlag FORCE_PVP_FLAG; public static void init() { - PreventStabby plugin = PreventStabby.getPlugin(); try { Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry"); WorldGuardPlugin worldGuardPlugin = WorldGuardPlugin.inst(); if (WorldGuard.getInstance() == null || worldGuardPlugin == null) return; - plugin.getLogger().info("Hooking into WorldGuard"); + Bukkit.getLogger().info("[PreventStabby] Hooking into WorldGuard"); flagRegistry = WorldGuard.getInstance().getFlagRegistry(); - createForcePvpFlag(plugin); + createForcePvpFlag(); } catch (NoClassDefFoundError | ClassNotFoundException ignored) { } } - private static void createForcePvpFlag(Plugin plugin) { + private static void createForcePvpFlag() { if (flagRegistry == null) return; String flagName = "preventstabby-force-pvp"; try { @@ -46,7 +44,7 @@ public class WorldGuardHook { if (existing instanceof StateFlag) { FORCE_PVP_FLAG = (StateFlag) existing; } else { - plugin.getLogger().severe("There is a conflict between flag names!"); + Bukkit.getLogger().severe("[PreventStabby] There is a conflict between flag names!"); } } }