From 7eb820c688b872f5284ae9374c3c35fc771a4ffc Mon Sep 17 00:00:00 2001 From: Wizjany Date: Wed, 30 Jan 2013 13:47:48 -0500 Subject: [PATCH] Fixed bug where players could place beds on the borders of regions without permissions --- .../bukkit/WorldGuardPlayerListener.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index b9607d2d..b16f3604 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -720,6 +720,37 @@ private void handleBlockRightClick(PlayerInteractEvent event) { } } + if (item.getTypeId() == ItemID.BED_ITEM) { + // this is mojang-level code, it had better give us the right direction + double yaw = (player.getLocation().getYaw() * 4.0F / 360.0F) + 0.5D; + int i = (int) yaw; + int i1 = (yaw < i ? i - 1 : i) & 3; + byte b0 = 0; + byte b1 = 0; + if (i1 == 0) { + b1 = 1; + } + if (i1 == 1) { + b0 = -1; + } + if (i1 == 2) { + b1 = -1; + } + if (i1 == 3) { + b0 = 1; + } + // end mojang-level code + Block headLoc = placedOn.getRelative(b0, 0, b1); + if (!plugin.getGlobalRegionManager().hasBypass(localPlayer, world) + && !(plugin.canBuild(player, block) && plugin.canBuild(player, headLoc))) { + // note that normal block placement is handled later, this is just a workaround + // for the location of the head block of the bed + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); + event.setCancelled(true); + return; + } + } + if (item.getTypeId() == ItemID.INK_SACK && item.getData() != null) { if (item.getData().getData() == 15 // bonemeal