Compare commits

..

3 Commits

Author SHA1 Message Date
YouHaveTrouble 9a707b34a3 bump version 2023-03-26 03:17:46 +02:00
YouHaveTrouble d52648b4ff Merge pull request #13 from YouHaveTrouble/api-changes
Api changes + worldguard flag fix for 1.19.4
2023-03-26 03:15:42 +02:00
YouHaveTrouble 7d2c41646e make worldguard hook register on load 2023-03-26 03:09:07 +02:00
3 changed files with 19 additions and 16 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
<groupId>me.youhavetrouble</groupId> <groupId>me.youhavetrouble</groupId>
<artifactId>PreventStabby</artifactId> <artifactId>PreventStabby</artifactId>
<version>1.8.0</version> <version>1.9.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>PreventStabby</name> <name>PreventStabby</name>
@@ -100,7 +100,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.24</version> <version>1.18.26</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -76,13 +76,6 @@ public final class PreventStabby extends JavaPlugin {
pvpCommand.setExecutor(mainCommand); pvpCommand.setExecutor(mainCommand);
pvpCommand.setTabCompleter(mainCommand); pvpCommand.setTabCompleter(mainCommand);
try {
WorldGuardHook.init();
worldGuardHook = true;
} catch (NoClassDefFoundError e) {
worldGuardHook = false;
}
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlacoholderApiHook(this).register(); new PlacoholderApiHook(this).register();
} }
@@ -90,6 +83,18 @@ public final class PreventStabby extends JavaPlugin {
Metrics metrics = new Metrics(this, 14074); 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() { public static boolean worldGuardHookEnabled() {
return worldGuardHook; return worldGuardHook;
} }
@@ -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.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery; import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.youhavetrouble.preventstabby.PreventStabby; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class WorldGuardHook { public class WorldGuardHook {
@@ -22,19 +21,18 @@ public class WorldGuardHook {
public static StateFlag FORCE_PVP_FLAG; public static StateFlag FORCE_PVP_FLAG;
public static void init() { public static void init() {
PreventStabby plugin = PreventStabby.getPlugin();
try { try {
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry"); Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
WorldGuardPlugin 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"); Bukkit.getLogger().info("[PreventStabby] Hooking into WorldGuard");
flagRegistry = WorldGuard.getInstance().getFlagRegistry(); flagRegistry = WorldGuard.getInstance().getFlagRegistry();
createForcePvpFlag(plugin); createForcePvpFlag();
} catch (NoClassDefFoundError | ClassNotFoundException ignored) { } catch (NoClassDefFoundError | ClassNotFoundException ignored) {
} }
} }
private static void createForcePvpFlag(Plugin plugin) { private static void createForcePvpFlag() {
if (flagRegistry == null) return; if (flagRegistry == null) return;
String flagName = "preventstabby-force-pvp"; String flagName = "preventstabby-force-pvp";
try { try {
@@ -46,7 +44,7 @@ public class WorldGuardHook {
if (existing instanceof StateFlag) { if (existing instanceof StateFlag) {
FORCE_PVP_FLAG = (StateFlag) existing; FORCE_PVP_FLAG = (StateFlag) existing;
} else { } else {
plugin.getLogger().severe("There is a conflict between flag names!"); Bukkit.getLogger().severe("[PreventStabby] There is a conflict between flag names!");
} }
} }
} }