mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-20 22:01:20 +01:00
Check WorldGuard's chest protection too
This commit is contained in:
parent
584a2bd51c
commit
d4bb775086
@ -2,9 +2,11 @@ package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||
@ -38,23 +40,34 @@ public class WorldGuardProtection implements Listener {
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
|
||||
Location location = BukkitAdapter.adapt(block.getLocation());
|
||||
|
||||
BlockVector3 blockPos = BukkitAdapter.adapt(block.getLocation()).toVector().toBlockPoint();
|
||||
RegionManager manager = worldGuardPlatform.getRegionContainer().get(BukkitAdapter.adapt(block.getWorld()));
|
||||
if (!canAccess(localPlayer, block, location)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
return;
|
||||
}
|
||||
|
||||
RegionManager manager = worldGuardPlatform.getRegionContainer().get((World) location.getExtent());
|
||||
if (manager == null) {
|
||||
return;
|
||||
}
|
||||
ApplicableRegionSet set = manager.getApplicableRegions(blockPos);
|
||||
ApplicableRegionSet set = manager.getApplicableRegions(location.toVector().toBlockPoint());
|
||||
|
||||
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
|
||||
|
||||
if (!canAccess(localPlayer, block, set)) {
|
||||
if (!canAccess(localPlayer, (World) location.getExtent(), set)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canAccess(LocalPlayer player, Block block, ApplicableRegionSet set) {
|
||||
return new RegionPermissionModel(player).mayIgnoreRegionProtection(BukkitAdapter.adapt(block.getWorld()))
|
||||
private boolean canAccess(LocalPlayer player, Block block, Location location) {
|
||||
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) worldGuardPlatform.getGlobalStateManager().get((World) location.getExtent());
|
||||
return !wcfg.signChestProtection
|
||||
|| !wcfg.getChestProtection().isChest(BukkitAdapter.asBlockType(block.getType()))
|
||||
|| !wcfg.getChestProtection().isProtected(location, player);
|
||||
}
|
||||
|
||||
private boolean canAccess(LocalPlayer player, World world, ApplicableRegionSet set) {
|
||||
return new RegionPermissionModel(player).mayIgnoreRegionProtection(world)
|
||||
|| set.testState(player, Flags.BUILD)
|
||||
|| set.testState(player, Flags.CHEST_ACCESS);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user