Fix older Builds of WorldGuard 7.0

Created a Brewery maven repo, use that for some of the dependencies
This commit is contained in:
Sn0wStorm
2019-01-17 12:30:12 +01:00
parent e1d68a03dc
commit 213ef13c0e
7 changed files with 85 additions and 50 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ public class Barrel implements InventoryHolder {
}
} catch (Throwable e) {
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
P.p.errorLog("Brewery was tested with version 5.8, 6.1 to 7.0 of WorldGuard!");
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
@@ -143,7 +143,7 @@ public class Barrel implements InventoryHolder {
}
} catch (Throwable e) {
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.4");
P.p.errorLog("Brewery was tested with GriefPrevention v14.5 - v16.9");
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
+26 -1
View File
@@ -17,13 +17,38 @@ import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class WGBarrel7 implements WGBarrel {
private Method getWorldByName;
public WGBarrel7() {
try {
getWorldByName = WorldGuardPlatform.class.getDeclaredMethod("getWorldByName", String.class);
} catch (NoSuchMethodException e) {
getWorldByName = null;
}
}
public boolean checkAccess(Player player, Block spigot, Plugin plugin) {
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
World world = platform.getMatcher().getWorldByName(spigot.getWorld().getName());
World world;
if (getWorldByName == null) {
world = platform.getMatcher().getWorldByName(spigot.getWorld().getName());
} else {
// Workaround for an older Beta Version of WorldGuard 7.0
try {
world = ((World) getWorldByName.invoke(platform, spigot.getWorld().getName()));
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
P.p.msg(player, "Error in WorldGuard");
return false;
}
}
if (!platform.getGlobalStateManager().get(world).useRegions) return true; // Region support disabled
WorldEditPlugin we = JavaPlugin.getPlugin(WorldEditPlugin.class);
if (new RegionPermissionModel(we.wrapPlayer(player)).mayIgnoreRegionProtection(world)) return true; // Whitelisted cause
@@ -30,7 +30,7 @@ public class WGBarrelOld implements WGBarrel {
getApplicableRegions = RegionManager.class.getMethod("getApplicableRegions", Location.class);
} catch (NoSuchMethodException e) {
P.p.errorLog("Failed to Hook WorldGuard for Barrel Open Permissions! Opening Barrels will NOT work!");
P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
P.p.errorLog("Brewery was tested with version 5.8, 6.1 to 7.0 of WorldGuard!");
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
e.printStackTrace();
}