On paste, you will now be placed on top of the paste if you ended up inside some blocks.

This commit is contained in:
sk89q 2010-10-05 01:43:23 -07:00
parent a61c62f46d
commit f896acc662

View File

@ -407,6 +407,7 @@ public class WorldEdit extends Plugin {
(int)Math.floor(player.getZ())); (int)Math.floor(player.getZ()));
session.getClipboard().paste(editSession, pos, session.getClipboard().paste(editSession, pos,
split[0].equalsIgnoreCase("/editpaste")); split[0].equalsIgnoreCase("/editpaste"));
teleportToStandPosition(player);
logger.log(Level.INFO, player.getName() + " used " + split[0]); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + "Pasted. Undo with /editundo"); player.sendMessage(Colors.LightPurple + "Pasted. Undo with /editundo");
} }
@ -754,6 +755,46 @@ public class WorldEdit extends Plugin {
return affected; 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. * Execute a script.
* *
@ -834,4 +875,17 @@ public class WorldEdit extends Plugin {
return false; 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);
}
} }