Updated region protection to support chests.

This commit is contained in:
sk89q 2011-01-15 23:47:15 -08:00
parent d19db5f86f
commit 0934a12205
2 changed files with 30 additions and 2 deletions

View File

@ -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")

View File

@ -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);