From f896acc662f6d5d5d39adcb2442d882c3c9b29cf Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 5 Oct 2010 01:43:23 -0700 Subject: [PATCH] On paste, you will now be placed on top of the paste if you ended up inside some blocks. --- src/WorldEdit.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/WorldEdit.java b/src/WorldEdit.java index e94c5ec2b..a746cb9dc 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -407,6 +407,7 @@ public class WorldEdit extends Plugin { (int)Math.floor(player.getZ())); session.getClipboard().paste(editSession, pos, split[0].equalsIgnoreCase("/editpaste")); + teleportToStandPosition(player); logger.log(Level.INFO, player.getName() + " used " + split[0]); player.sendMessage(Colors.LightPurple + "Pasted. Undo with /editundo"); } @@ -754,6 +755,46 @@ public class WorldEdit extends Plugin { return affected; } + /** + * Find a position for the player to stand that is not inside a block. + * Blocks above the player will be iteratively tested until there is + * a series of two free blocks. The player will be teleported to + * that free position. + * + * @param player + */ + private void teleportToStandPosition(Player player) { + int x = (int)Math.floor(player.getX()); + int y = (int)Math.floor(player.getY()); + int origY = y; + int z = (int)Math.floor(player.getZ()); + + byte free = 0; + + while (y <= 129) { + if (getBlock(x, y, z) == 0) { + free++; + } else { + free = 0; + } + + if (free == 2) { + if (y - 1 != origY) { + Location loc = new Location(); + loc.x = x + 0.5; + loc.y = y - 1; + loc.z = z + 0.5; + loc.rotX = player.getRotation(); + loc.rotY = player.getPitch(); + player.teleportTo(loc); + return; + } + } + + y++; + } + } + /** * Execute a script. * @@ -834,4 +875,17 @@ public class WorldEdit extends Plugin { return false; } + + /** + * Gets the block type at a position x, y, z. Use an instance of + * EditSession if possible. + * + * @param x + * @param y + * @param z + * @return Block type + */ + public int getBlock(int x, int y, int z) { + return etc.getMCServer().e.a(x, y, z); + } }