Fix WorldGuard integration (#1630)
This commit is contained in:
parent
a7cb4a0c78
commit
137a951448
|
|
@ -201,8 +201,7 @@ public abstract class DataStore
|
||||||
GriefPrevention.AddLogEntry("Successfully hooked into WorldGuard.");
|
GriefPrevention.AddLogEntry("Successfully hooked into WorldGuard.");
|
||||||
}
|
}
|
||||||
//if failed, world guard compat features will just be disabled.
|
//if failed, world guard compat features will just be disabled.
|
||||||
catch (ClassNotFoundException exception) { }
|
catch (IllegalStateException | IllegalArgumentException | ClassCastException | NoClassDefFoundError ignored) { }
|
||||||
catch (NoClassDefFoundError exception) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSoftMutes()
|
private void loadSoftMutes()
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,59 @@
|
||||||
package me.ryanhamshire.GriefPrevention;
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
class WorldGuardWrapper
|
class WorldGuardWrapper
|
||||||
{
|
{
|
||||||
private WorldGuardPlugin worldGuard = null;
|
private final WorldGuardPlugin worldGuard;
|
||||||
|
|
||||||
public WorldGuardWrapper() throws ClassNotFoundException
|
public WorldGuardWrapper() throws IllegalArgumentException, IllegalStateException, ClassCastException
|
||||||
{
|
{
|
||||||
this.worldGuard = (WorldGuardPlugin) GriefPrevention.instance.getServer().getPluginManager().getPlugin("WorldGuard");
|
this.worldGuard = JavaPlugin.getPlugin(WorldGuardPlugin.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBuild(Location lesserCorner, Location greaterCorner, Player creatingPlayer)
|
public boolean canBuild(Location lesserCorner, Location greaterCorner, Player creatingPlayer)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BukkitPlayer localPlayer = new BukkitPlayer(this.worldGuard, creatingPlayer);
|
if (lesserCorner.getWorld() == null)
|
||||||
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
{
|
||||||
World world = platform.getMatcher().getWorldByName(lesserCorner.getWorld().getName());
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (platform.getSessionManager().hasBypass(localPlayer, world)) return true;
|
LocalPlayer localPlayer = this.worldGuard.wrapPlayer(creatingPlayer);
|
||||||
|
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||||
|
World world = BukkitAdapter.adapt(lesserCorner.getWorld());
|
||||||
|
|
||||||
|
if (platform.getSessionManager().hasBypass(localPlayer, world))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
RegionManager manager = platform.getRegionContainer().get(world);
|
RegionManager manager = platform.getRegionContainer().get(world);
|
||||||
|
if (manager == null)
|
||||||
if (manager != null)
|
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
ProtectedCuboidRegion tempRegion = new ProtectedCuboidRegion(
|
ProtectedCuboidRegion tempRegion = new ProtectedCuboidRegion(
|
||||||
"GP_TEMP",
|
"GP_TEMP",
|
||||||
BlockVector3.at(lesserCorner.getX(), 0, lesserCorner.getZ()),
|
BlockVector3.at(lesserCorner.getX(), 0, lesserCorner.getZ()),
|
||||||
BlockVector3.at(greaterCorner.getX(), world.getMaxY(), greaterCorner.getZ()));
|
BlockVector3.at(greaterCorner.getX(), world.getMaxY(), greaterCorner.getZ()));
|
||||||
|
|
||||||
ApplicableRegionSet overlaps = manager.getApplicableRegions(tempRegion);
|
return manager.getApplicableRegions(tempRegion).queryState(localPlayer, Flags.BUILD) == StateFlag.State.ALLOW;
|
||||||
for (ProtectedRegion r : overlaps.getRegions())
|
|
||||||
{
|
|
||||||
if (!manager.getApplicableRegions(r).testState(localPlayer, Flags.BUILD))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Throwable rock)
|
catch (Throwable rock)
|
||||||
{
|
{
|
||||||
|
|
@ -62,8 +62,8 @@ class WorldGuardWrapper
|
||||||
"Consider updating/downgrading/removing WorldGuard or disable WorldGuard integration in GP's config " +
|
"Consider updating/downgrading/removing WorldGuard or disable WorldGuard integration in GP's config " +
|
||||||
"(CreationRequiresWorldGuardBuildPermission). If you're going to report this please be kind because " +
|
"(CreationRequiresWorldGuardBuildPermission). If you're going to report this please be kind because " +
|
||||||
"WorldEdit's API hasn't been :c", CustomLogEntryTypes.Debug, false);
|
"WorldEdit's API hasn't been :c", CustomLogEntryTypes.Debug, false);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user