Commit f32f3b02 authored by Amosar's avatar Amosar

Add support for WorldGuard 7

parent 3563d547
name: antiRedstoneClock
version: 1.0
version: 1.0.1
description: Limit the redstoneClock
author: Amosar
website: https://www.spigotmc.org/resources/antiredstoneclock.18557
......
......@@ -4,7 +4,7 @@ import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClock;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClockController;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import com.trafalcraft.antiRedstoneClock.util.WorldGuardLink;
import com.trafalcraft.antiRedstoneClock.util.WorldGuard.WorldGuardHook;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
......@@ -38,7 +38,7 @@ class Util {
return true;
}
}
return WorldGuardLink.checkAllowedRegion(block.getLocation());
return WorldGuardHook.checkAllowedRegion(block.getLocation());
}
static void removeRedstoneClock(Block block) {
......
package com.trafalcraft.antiRedstoneClock.util;
package com.trafalcraft.antiRedstoneClock.util.WorldGuard;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager;
......@@ -10,8 +11,8 @@ import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
public class WorldGuardLink {
private static WorldGuardPlugin getWorldGuard() {
public class WorldGuardHook {
public static WorldGuardPlugin getWorldGuard() {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
// WorldGuard may not be loaded
......@@ -24,12 +25,19 @@ public class WorldGuardLink {
public static boolean checkAllowedRegion(Location loc) {
if (getWorldGuard() == null) {
WorldGuardPlugin worldGuard = getWorldGuard();
if (worldGuard == null) {
return false;
}
if (getWorldGuard().getRegionManager(loc.getWorld()) != null) {
RegionManager worldGuard = getWorldGuard().getRegionManager(loc.getWorld());
ApplicableRegionSet regions = worldGuard.getApplicableRegions(loc);
RegionManager regionManager;
if (worldGuard.getDescription().getVersion().startsWith("6")) {
regionManager = WorldGuard_6.getRegionManager(worldGuard, loc.getWorld());
} else {
regionManager = WorldGuard_7.getRegionManager(worldGuard, loc.getWorld());
}
if (regionManager != null) {
ApplicableRegionSet regions = regionManager.getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ()));
for (String ignoreRegion : Main.getIgnoredRegions()) {
for (ProtectedRegion region : regions.getRegions()) {
if (region.getId().equals(ignoreRegion)) {
......@@ -40,4 +48,6 @@ public class WorldGuardLink {
}
return false;
}
}
package com.trafalcraft.antiRedstoneClock.util.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.World;
import java.lang.reflect.Method;
class WorldGuard_6 {
//TODO need to make it cleaner with maven
static RegionManager getRegionManager(WorldGuardPlugin worldGuard, World world) {
try {
Method method = worldGuard.getClass().getMethod("getRegionContainer");
Object regionContainer = method.invoke(worldGuard);
method = regionContainer.getClass().getMethod("get", World.class);
return (RegionManager) method.invoke(regionContainer, world);
} catch (Exception e) {
return null;
}
}
}
package com.trafalcraft.antiRedstoneClock.util.WorldGuard;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldGuardPlatform;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.World;
class WorldGuard_7 {
static RegionManager getRegionManager(WorldGuardPlugin worldGuard, World world) {
BukkitWorldGuardPlatform wgPlatform = (BukkitWorldGuardPlatform)
WorldGuard.getInstance().getPlatform();
RegionManager regionManager = wgPlatform.getRegionContainer().get(wgPlatform.getWorldByName(world.getName()));
return regionManager;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment