mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 18:45:34 +01:00
fix worldguard flag injection for WG7
This commit is contained in:
parent
62a5dfbd90
commit
247b84c040
@ -6,19 +6,15 @@ import org.bukkit.Location;
|
||||
|
||||
public class WorldGuardHook {
|
||||
|
||||
static boolean canHook, checkedCanHook = false;
|
||||
|
||||
private static void init() {
|
||||
if(checkedCanHook) return;
|
||||
static boolean canHook = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
// if this class exists, we're good to use WG classes
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.Flag");
|
||||
canHook = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
}
|
||||
|
||||
checkedCanHook = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,7 +25,6 @@ public class WorldGuardHook {
|
||||
* @param state default value of the flag
|
||||
*/
|
||||
public static void addHook(String flag, boolean state) {
|
||||
init();
|
||||
if(canHook) {
|
||||
WorldGuardFlagHandler.addHook(flag, state);
|
||||
}
|
||||
@ -42,7 +37,6 @@ public class WorldGuardHook {
|
||||
* called and added successfully
|
||||
*/
|
||||
public static boolean isEnabled() {
|
||||
init();
|
||||
return canHook && WorldGuardFlagHandler.isEnabled();
|
||||
}
|
||||
|
||||
@ -54,7 +48,6 @@ public class WorldGuardHook {
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
public static Boolean getBooleanFlag(Location l, String flag) {
|
||||
init();
|
||||
return canHook ? WorldGuardFlagHandler.getBooleanFlag(l, flag) : null;
|
||||
}
|
||||
|
||||
@ -66,7 +59,6 @@ public class WorldGuardHook {
|
||||
* @return flag state, or null if undefined
|
||||
*/
|
||||
public static Boolean getBooleanFlag(Chunk c, String flag) {
|
||||
init();
|
||||
return canHook ? WorldGuardFlagHandler.getBooleanFlag(c, flag) : null;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class WorldGuardFlagHandler {
|
||||
|
||||
static Boolean wgPlugin = null;
|
||||
static Object worldGuardPlugin;
|
||||
static boolean wg_v7 = false;
|
||||
static boolean legacy_v6 = false;
|
||||
static boolean legacy_v5 = false;
|
||||
static boolean hooksInstalled = false;
|
||||
@ -47,18 +48,24 @@ public class WorldGuardFlagHandler {
|
||||
*/
|
||||
public static void addHook(String flag, boolean state) {
|
||||
if (wgPlugin == null && (wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) {
|
||||
// a number of flags were introduced in 7.x that aren't in 5 or 6
|
||||
try {
|
||||
// if this class exists, we're on 7.x
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag");
|
||||
wg_v7 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
try {
|
||||
// if this class exists, we're on 6.0
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry");
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.FlagContextCreateEvent");
|
||||
legacy_v6 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
}
|
||||
if(!legacy_v6) {
|
||||
} catch (ClassNotFoundException ex2) {
|
||||
try {
|
||||
// if this class exists, we're on 5.x
|
||||
Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag");
|
||||
legacy_v5 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (ClassNotFoundException ex3) {
|
||||
// ¯\_(ツ)_/¯
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,7 +137,7 @@ public class WorldGuardFlagHandler {
|
||||
flags.put(flag, wgFlag);
|
||||
} catch (Exception ex) {
|
||||
//Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", flag);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard " + (legacy_v6 ? "6" : "5"), flag);
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard");
|
||||
wgPlugin = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user