From 32240cd00db8c8ea270a26c39dcd9e45a2ff58b5 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 8 Aug 2012 10:16:06 +0200 Subject: [PATCH 1/6] Fix teleports on beds --- Essentials/src/com/earth2me/essentials/Util.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 4f8f10887..c327c164b 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -376,6 +376,11 @@ public class Util { return true; } + + if (below.getType() == Material.BED) + { + return true; + } if ((!AIR_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId())) || (!AIR_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId()))) From 0319415f1bb3f7d96b5129f00746e54cf5897fba Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 8 Aug 2012 13:13:39 +0200 Subject: [PATCH 2/6] Test the places around the location first, then go up --- .../src/com/earth2me/essentials/Util.java | 86 +++++++++++++------ .../com/earth2me/essentials/UtilTest.java | 29 +++++++ 2 files changed, 88 insertions(+), 27 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index c327c164b..2b0c4f0a5 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -285,6 +285,45 @@ public class Util } return block.getLocation(); } + public final static int RADIUS = 3; + public final static Vector3D[] VOLUME; + + public static class Vector3D + { + public Vector3D(int x, int y, int z) + { + this.x = x; + this.y = y; + this.z = z; + } + public int x; + public int y; + public int z; + } + + static + { + List pos = new ArrayList(); + for (int x = -RADIUS; x <= RADIUS; x++) + { + for (int y = -RADIUS; y <= RADIUS; y++) + { + for (int z = -RADIUS; z <= RADIUS; z++) + { + pos.add(new Vector3D(x, y, z)); + } + } + } + Collections.sort(pos, new Comparator() + { + @Override + public int compare(Vector3D a, Vector3D b) + { + return (a.x * a.x + a.y * a.y + a.z * a.z) - (b.x * b.x + b.y * b.y + b.z * b.z); + } + }); + VOLUME = pos.toArray(new Vector3D[0]); + } public static Location getSafeDestination(final Location loc) throws Exception { @@ -296,7 +335,9 @@ public class Util int x = loc.getBlockX(); int y = (int)Math.round(loc.getY()); int z = loc.getBlockZ(); + final int origX = x; final int origY = y; + final int origZ = z; while (isBlockAboveAir(world, x, y, z)) { @@ -308,38 +349,29 @@ public class Util } } + int i = 0; + while (isBlockUnsafe(world, x, y, z)) + { + i++; + if (i >= VOLUME.length) + { + x = origX; + y = origY + RADIUS; + z = origZ; + break; + } + x = origX + VOLUME[i].x; + y = origY + VOLUME[i].y; + z = origZ + VOLUME[i].z; + } + while (isBlockUnsafe(world, x, y, z)) { y += 1; if (y >= world.getHighestBlockYAt(x, z)) - { - x -= 3; - z -= 3; - y = origY + 4; - break; - } - } - - while (isBlockUnsafe(world, x, y, z)) - { - y -= 1; - if (y + 4 < origY) { x += 1; - if (x - 3 > loc.getBlockX()) - { - x = loc.getBlockX() - 3; - z += 1; - if (z - 3 > loc.getBlockZ()) - { - x = loc.getBlockX() + 4; - z = loc.getBlockZ(); - y = world.getHighestBlockYAt(x, z); - break; - } - } - - y = origY + 4; + break; } } @@ -376,7 +408,7 @@ public class Util { return true; } - + if (below.getType() == Material.BED) { return true; diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index 2efd39e4c..e1edda95e 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -3,6 +3,8 @@ package com.earth2me.essentials; import java.io.IOException; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Set; import junit.framework.TestCase; import org.bukkit.World.Environment; import org.bukkit.plugin.InvalidDescriptionException; @@ -32,6 +34,33 @@ public class UtilTest extends TestCase } } + public void testSafeLocation() + { + Set testSet = new HashSet(); + int count = 0; + int x, y, z, origX, origY, origZ; + x = y = z = origX = origY = origZ = 0; + int i = 0; + while (true) + { + testSet.add(x + ":" + y + ":" + z); + count++; + i++; + if (i >= Util.VOLUME.length) + { + break; + } + x = origX + Util.VOLUME[i].x; + y = origY + Util.VOLUME[i].y; + z = origZ + Util.VOLUME[i].z; + } + assertTrue(testSet.contains("0:0:0")); + assertTrue(testSet.contains("3:3:3")); + assertEquals(testSet.size(), count); + int diameter = Util.RADIUS * 2 + 1; + assertEquals(diameter * diameter * diameter, count); + } + public void testFDDnow() { Calendar c = new GregorianCalendar(); From ee072e844b066da7a06498b9d9ea9c8cc4977333 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 8 Aug 2012 14:11:40 +0200 Subject: [PATCH 3/6] Fix right click on signs --- .../earth2me/essentials/signs/SignPlayerListener.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java index d415ef6a8..7fd563c17 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java @@ -20,14 +20,19 @@ public class SignPlayerListener implements Listener this.ess = ess; } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW) public void onPlayerInteract(final PlayerInteractEvent event) { - if (ess.getSettings().areSignsDisabled() || event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (ess.getSettings().areSignsDisabled() || (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR)) { return; } - final Block block = event.getClickedBlock(); + final Block block; + if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) { + block = event.getPlayer().getTargetBlock(null, 5); + } else { + block = event.getClickedBlock(); + } if (block == null) { return; From 8e50158af82bf72e4ec4995389230a18b1bab510 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 8 Aug 2012 14:21:25 +0200 Subject: [PATCH 4/6] Correct material for beds --- Essentials/src/com/earth2me/essentials/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 2b0c4f0a5..68fb956ef 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -409,7 +409,7 @@ public class Util return true; } - if (below.getType() == Material.BED) + if (below.getType() == Material.BED_BLOCK) { return true; } From dd12e5db66d89dc7310651a9860cf061141e0d67 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 8 Aug 2012 22:50:54 +0100 Subject: [PATCH 5/6] Fix tp permissions check to check player typing command not teleportee. If you don't want players inviting players to other worlds, do not give them essentials.world. --- Essentials/src/com/earth2me/essentials/commands/Commandtp.java | 2 +- .../src/com/earth2me/essentials/commands/Commandtpahere.java | 2 +- .../src/com/earth2me/essentials/commands/Commandtpall.java | 2 +- .../src/com/earth2me/essentials/commands/Commandtphere.java | 2 +- .../src/com/earth2me/essentials/commands/Commandtpohere.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index c1d4347c6..d6d6b76f9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -58,7 +58,7 @@ public class Commandtp extends EssentialsCommand throw new Exception(_("teleportDisabled", toPlayer.getDisplayName())); } if (target.getWorld() != toPlayer.getWorld() && ess.getSettings().isWorldTeleportPermissions() - && !target.isAuthorized("essentials.world." + toPlayer.getWorld().getName())) + && !user.isAuthorized("essentials.world." + toPlayer.getWorld().getName())) { throw new Exception(_("noPerm", "essentials.world." + toPlayer.getWorld().getName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index dba6bdb87..9d389ecac 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -26,7 +26,7 @@ public class Commandtpahere extends EssentialsCommand throw new Exception(_("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() - && !player.isAuthorized("essentials.world." + user.getWorld().getName())) + && !user.isAuthorized("essentials.world." + user.getWorld().getName())) { throw new Exception(_("noPerm", "essentials.world." + user.getWorld().getName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index 98e232609..6335a4a54 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -43,7 +43,7 @@ public class Commandtpall extends EssentialsCommand continue; } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() - && !player.isAuthorized("essentials.world." + user.getWorld().getName())) + && !user.isAuthorized("essentials.world." + user.getWorld().getName())) { continue; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index 804176bd3..92eb87226 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -23,7 +23,7 @@ public class Commandtphere extends EssentialsCommand throw new Exception(_("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() - && !player.isAuthorized("essentials.world." + user.getWorld().getName())) + && !user.isAuthorized("essentials.world." + user.getWorld().getName())) { throw new Exception(_("noPerm", "essentials.world." + user.getWorld().getName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index 3f650f96d..880c4e362 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -31,7 +31,7 @@ public class Commandtpohere extends EssentialsCommand } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() - && !player.isAuthorized("essentials.world." + user.getWorld().getName())) + && !user.isAuthorized("essentials.world." + user.getWorld().getName())) { throw new Exception(_("noPerm", "essentials.world." + user.getWorld().getName())); } From 17adafecf9ed58081c2c45dc8d5045a5d88ce597 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 8 Aug 2012 23:00:09 +0100 Subject: [PATCH 6/6] Fix /top so that glass counts as a real block. --- Essentials/src/com/earth2me/essentials/Util.java | 2 +- .../src/com/earth2me/essentials/commands/Commandtop.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 68fb956ef..0b5c3e426 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -368,7 +368,7 @@ public class Util while (isBlockUnsafe(world, x, y, z)) { y += 1; - if (y >= world.getHighestBlockYAt(x, z)) + if (y >= world.getMaxHeight()) { x += 1; break; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index e91d0984a..fe7690646 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -20,8 +20,8 @@ public class Commandtop extends EssentialsCommand { final int topX = user.getLocation().getBlockX(); final int topZ = user.getLocation().getBlockZ(); - final int topY = user.getWorld().getHighestBlockYAt(topX, topZ); - user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess), TeleportCause.COMMAND); + final Location location = new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ); + user.getTeleport().teleport(location, new Trade(this.getName(), ess), TeleportCause.COMMAND); user.sendMessage(_("teleportTop")); } }