2010-10-11 08:22:47 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-13 01:03:56 +00:00
|
|
|
import com.sk89q.worldedit.Vector;
|
2010-10-14 08:31:05 +00:00
|
|
|
import com.sk89q.worldedit.ServerInterface;
|
2010-10-20 00:10:02 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract class WorldEditPlayer {
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2010-10-14 08:31:05 +00:00
|
|
|
* Server interface.
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 18:59:45 +00:00
|
|
|
protected ServerInterface server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the player.
|
|
|
|
*/
|
|
|
|
public WorldEditPlayer() {
|
|
|
|
server = WorldEdit.getServer();
|
|
|
|
}
|
2010-10-17 00:08:56 +00:00
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the name of the player.
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract String getName();
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block that is being stood upon.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return point
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract Vector getBlockOn();
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block that is being stood in.
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return point
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract Vector getBlockIn();
|
2010-10-20 00:10:02 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
*
|
|
|
|
* @param range
|
|
|
|
* @return point
|
|
|
|
*/
|
|
|
|
public abstract Vector getBlockTrace(int range);
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the player's position.
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return point
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract Vector getPosition();
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the player's view pitch.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return pitch
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract double getPitch();
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Get the player's view yaw.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return yaw
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract double getYaw();
|
2010-10-12 20:51:25 +00:00
|
|
|
/**
|
|
|
|
* Get the ID of the item that the player is holding.
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-12 20:51:25 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract int getItemInHand();
|
2010-10-12 20:51:25 +00:00
|
|
|
|
2010-10-13 18:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the player is holding a pick axe.
|
|
|
|
*
|
|
|
|
* @return whether a pick axe is held
|
|
|
|
*/
|
|
|
|
public boolean isHoldingPickAxe() {
|
|
|
|
int item = getItemInHand();
|
|
|
|
return item == 271 || item == 270 || item == 274 || item == 278
|
|
|
|
|| item == 285;
|
|
|
|
}
|
|
|
|
|
2010-10-13 04:41:06 +00:00
|
|
|
/**
|
|
|
|
* Get the player's cardinal direction (N, W, NW, etc.).
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-13 04:41:06 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract String getCardinalDirection();
|
2010-10-13 04:41:06 +00:00
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Print a WorldEdit message.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract void print(String msg);
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a WorldEdit error.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract void printError(String msg);
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the player.
|
2010-10-13 05:06:46 +00:00
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @param pos
|
|
|
|
* @param pitch
|
|
|
|
* @param yaw
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract void setPosition(Vector pos, float pitch, float yaw);
|
2010-10-11 08:22:47 +00:00
|
|
|
|
2010-10-13 05:06:46 +00:00
|
|
|
/**
|
|
|
|
* Move the player.
|
|
|
|
*
|
|
|
|
* @param pos
|
|
|
|
*/
|
|
|
|
public void setPosition(Vector pos) {
|
2010-10-14 08:31:05 +00:00
|
|
|
setPosition(pos, (float)getPitch(), (float)getYaw());
|
2010-10-13 05:06:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2010-10-20 00:10:02 +00:00
|
|
|
*
|
|
|
|
* @param searchPos search position
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2010-10-20 00:10:02 +00:00
|
|
|
public void findFreePosition(Vector searchPos) {
|
|
|
|
int x = searchPos.getBlockX();
|
|
|
|
int y = searchPos.getBlockY();
|
2010-10-11 08:22:47 +00:00
|
|
|
int origY = y;
|
2010-10-20 00:10:02 +00:00
|
|
|
int z = searchPos.getBlockZ();
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
byte free = 0;
|
|
|
|
|
|
|
|
while (y <= 129) {
|
|
|
|
if (etc.getServer().getBlockIdAt(x, y, z) == 0) {
|
|
|
|
free++;
|
|
|
|
} else {
|
|
|
|
free = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free == 2) {
|
|
|
|
if (y - 1 != origY) {
|
2010-10-14 08:31:05 +00:00
|
|
|
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
2010-10-11 08:22:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-20 00:10:02 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
public void findFreePosition() {
|
|
|
|
findFreePosition(getBlockIn());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass through the wall that you are looking at.
|
|
|
|
*
|
|
|
|
* @param range
|
|
|
|
* @return whether a wall was passed through
|
|
|
|
*/
|
|
|
|
public abstract boolean passThroughForwardWall(int range);
|
|
|
|
|
2010-10-13 05:06:46 +00:00
|
|
|
/**
|
|
|
|
* Go up one level to the next free space above.
|
|
|
|
*
|
|
|
|
* @return true if a spot was found
|
|
|
|
*/
|
|
|
|
public boolean ascendLevel() {
|
2010-10-16 23:56:59 +00:00
|
|
|
Vector pos = getBlockIn();
|
2010-10-14 08:31:05 +00:00
|
|
|
int x = pos.getBlockX();
|
|
|
|
int y = pos.getBlockY();
|
|
|
|
int z = pos.getBlockZ();
|
2010-10-13 05:06:46 +00:00
|
|
|
|
|
|
|
byte free = 0;
|
|
|
|
byte spots = 0;
|
|
|
|
|
|
|
|
while (y <= 129) {
|
2010-10-14 08:31:05 +00:00
|
|
|
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
2010-10-13 05:06:46 +00:00
|
|
|
free++;
|
|
|
|
} else {
|
|
|
|
free = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-16 23:56:59 +00:00
|
|
|
if (free == 2) {
|
2010-10-13 05:06:46 +00:00
|
|
|
spots++;
|
2010-10-16 23:56:59 +00:00
|
|
|
if (spots == 2) {
|
2010-10-17 00:15:17 +00:00
|
|
|
int type = server.getBlockType(new Vector(x, y - 2, z));
|
|
|
|
|
|
|
|
// Don't get put in lava!
|
|
|
|
if (type == 10 || type == 11) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-13 05:06:46 +00:00
|
|
|
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go up one level to the next free space above.
|
|
|
|
*
|
|
|
|
* @return true if a spot was found
|
|
|
|
*/
|
|
|
|
public boolean descendLevel() {
|
2010-10-17 00:08:56 +00:00
|
|
|
Vector pos = getBlockIn();
|
2010-10-14 08:31:05 +00:00
|
|
|
int x = pos.getBlockX();
|
|
|
|
int y = pos.getBlockY() - 1;
|
|
|
|
int z = pos.getBlockZ();
|
2010-10-13 05:06:46 +00:00
|
|
|
|
|
|
|
byte free = 0;
|
|
|
|
|
2010-10-17 00:08:56 +00:00
|
|
|
while (y >= 1) {
|
2010-10-14 08:31:05 +00:00
|
|
|
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
2010-10-13 05:06:46 +00:00
|
|
|
free++;
|
|
|
|
} else {
|
|
|
|
free = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free == 2) {
|
2010-10-17 00:08:56 +00:00
|
|
|
// So we've found a spot, but we have to drop the player
|
|
|
|
// lightly and also check to see if there's something to
|
|
|
|
// stand upon
|
|
|
|
while (y >= 0) {
|
2010-10-17 00:15:17 +00:00
|
|
|
int type = server.getBlockType(new Vector(x, y, z));
|
|
|
|
|
|
|
|
// Don't want to end up in lava
|
|
|
|
if (type != 0 && type != 10 && type != 11) {
|
2010-10-17 00:08:56 +00:00
|
|
|
// Found a block!
|
|
|
|
setPosition(new Vector(x + 0.5, y + 1, z + 0.5));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-10-13 05:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-20 00:10:02 +00:00
|
|
|
/**
|
|
|
|
* Ascend to the ceiling above.
|
|
|
|
*
|
|
|
|
* @param clearance
|
|
|
|
* @return whether the player was moved
|
|
|
|
*/
|
|
|
|
public boolean ascendToCeiling(int clearance) {
|
|
|
|
Vector pos = getBlockIn();
|
|
|
|
int x = pos.getBlockX();
|
|
|
|
int y = pos.getBlockY() + 2;
|
|
|
|
int initialY = y;
|
|
|
|
int z = pos.getBlockZ();
|
|
|
|
|
|
|
|
// Nothing above
|
|
|
|
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (y <= 127) {
|
|
|
|
// Found a ceiling!
|
|
|
|
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
|
|
|
int platformY = Math.max(initialY, y - 3);
|
|
|
|
server.setBlockType(new Vector(x, platformY, z),
|
|
|
|
BlockType.GLASS.getID());
|
|
|
|
setPosition(new Vector(x, platformY + 1, z));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
|
|
|
* Gives the player an item.
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @param type
|
|
|
|
* @param amt
|
|
|
|
*/
|
2010-10-14 08:31:05 +00:00
|
|
|
public abstract void giveItem(int type, int amt);
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if equal.
|
2010-10-17 00:08:56 +00:00
|
|
|
*
|
2010-10-11 08:22:47 +00:00
|
|
|
* @param other
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return whether the other object is equivalent
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
if (!(other instanceof WorldEditPlayer)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
WorldEditPlayer other2 = (WorldEditPlayer)other;
|
2010-10-14 08:31:05 +00:00
|
|
|
return other2.getName().equals(getName());
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the hash code.
|
|
|
|
*
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return hash code
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return getName().hashCode();
|
|
|
|
}
|
|
|
|
}
|