diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index c0d4070b..b3990f88 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -24,6 +24,8 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockDamageLevel; import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.World; import org.bukkit.event.block.*; @@ -227,6 +229,32 @@ public void onBlockPhysics(BlockPhysicsEvent event) { return; } } + + /** + * Called when a block is interacted with + * + * @param event Relevant event details + */ + public void onBlockInteract(BlockInteractEvent event) { + Block block = event.getBlock(); + LivingEntity entity = event.getEntity(); + + if (entity instanceof Player && block.getType() == Material.CHEST) { + Player player = (Player)entity; + + if (plugin.useRegions) { + Vector pt = toVector(block); + LocalPlayer localPlayer = plugin.wrapPlayer(player); + + if (!plugin.hasPermission(player, "/regionbypass") + && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) { + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + event.setCancelled(true); + return; + } + } + } + } /** * Called when a player places a block @@ -240,8 +268,7 @@ public void onBlockPlace(BlockPlaceEvent event) { World world = blockPlaced.getWorld(); if (plugin.useRegions) { - Vector pt = new Vector(blockPlaced.getX(), - blockPlaced.getY(), blockPlaced.getZ()); + Vector pt = toVector(blockPlaced); LocalPlayer localPlayer = plugin.wrapPlayer(player); if (!plugin.hasPermission(player, "/regionbypass") diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index fb2a126a..8fe7c29a 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -125,6 +125,7 @@ private void registerEvents() { registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal); registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Priority.Normal); registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal); + registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.Normal); registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal); registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Normal);