mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Moved all the classes around again (re-coupled with Hmod).
This commit is contained in:
@ -18,76 +18,27 @@
|
||||
*/
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class WorldEditPlayer {
|
||||
public class WorldEditPlayer {
|
||||
/**
|
||||
* Server interface.
|
||||
* Stores the player.
|
||||
*/
|
||||
protected ServerInterface server;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Construct the player.
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public WorldEditPlayer() {
|
||||
server = WorldEditController.getServer();
|
||||
public WorldEditPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the player.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public abstract String getName();
|
||||
/**
|
||||
* Get the point of the block that is being stood upon.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getBlockOn();
|
||||
/**
|
||||
* Get the point of the block that is being stood in.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getBlockIn();
|
||||
/**
|
||||
* Get the point of the block being looked at. May return null.
|
||||
*
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getBlockTrace(int range);
|
||||
/**
|
||||
* Get the player's position.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract Vector getPosition();
|
||||
/**
|
||||
* Get the player's view pitch.
|
||||
*
|
||||
* @return pitch
|
||||
*/
|
||||
public abstract double getPitch();
|
||||
/**
|
||||
* Get the player's view yaw.
|
||||
*
|
||||
* @return yaw
|
||||
*/
|
||||
public abstract double getYaw();
|
||||
/**
|
||||
* Get the ID of the item that the player is holding.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getItemInHand();
|
||||
|
||||
/**
|
||||
* Returns true if the player is holding a pick axe.
|
||||
*
|
||||
@ -99,36 +50,6 @@ public abstract class WorldEditPlayer {
|
||||
|| item == 285;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's cardinal direction (N, W, NW, etc.).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String getCardinalDirection();
|
||||
|
||||
/**
|
||||
* Print a WorldEditLibrary message.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void print(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEditLibrary error.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void printError(String msg);
|
||||
|
||||
/**
|
||||
* Move the player.
|
||||
*
|
||||
* @param pos
|
||||
* @param pitch
|
||||
* @param yaw
|
||||
*/
|
||||
public abstract void setPosition(Vector pos, float pitch, float yaw);
|
||||
|
||||
/**
|
||||
* Move the player.
|
||||
*
|
||||
@ -182,14 +103,6 @@ public abstract class WorldEditPlayer {
|
||||
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);
|
||||
|
||||
/**
|
||||
* Go up one level to the next free space above.
|
||||
*
|
||||
@ -205,7 +118,7 @@ public abstract class WorldEditPlayer {
|
||||
byte spots = 0;
|
||||
|
||||
while (y <= 129) {
|
||||
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
if (ServerInterface.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@ -214,7 +127,7 @@ public abstract class WorldEditPlayer {
|
||||
if (free == 2) {
|
||||
spots++;
|
||||
if (spots == 2) {
|
||||
int type = server.getBlockType(new Vector(x, y - 2, z));
|
||||
int type = ServerInterface.getBlockType(new Vector(x, y - 2, z));
|
||||
|
||||
// Don't get put in lava!
|
||||
if (type == 10 || type == 11) {
|
||||
@ -246,7 +159,7 @@ public abstract class WorldEditPlayer {
|
||||
byte free = 0;
|
||||
|
||||
while (y >= 1) {
|
||||
if (server.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
if (ServerInterface.getBlockType(new Vector(x, y, z)) == 0) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
@ -257,7 +170,7 @@ public abstract class WorldEditPlayer {
|
||||
// lightly and also check to see if there's something to
|
||||
// stand upon
|
||||
while (y >= 0) {
|
||||
int type = server.getBlockType(new Vector(x, y, z));
|
||||
int type = ServerInterface.getBlockType(new Vector(x, y, z));
|
||||
|
||||
// Don't want to end up in lava
|
||||
if (type != 0 && type != 10 && type != 11) {
|
||||
@ -292,15 +205,15 @@ public abstract class WorldEditPlayer {
|
||||
int z = pos.getBlockZ();
|
||||
|
||||
// No free space above
|
||||
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
if (ServerInterface.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (y <= 127) {
|
||||
// Found a ceiling!
|
||||
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
if (ServerInterface.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
int platformY = Math.max(initialY, y - 3 - clearance);
|
||||
server.setBlockType(new Vector(x, platformY, z),
|
||||
ServerInterface.setBlockType(new Vector(x, platformY, z),
|
||||
BlockType.GLASS.getID());
|
||||
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
|
||||
return true;
|
||||
@ -312,14 +225,6 @@ public abstract class WorldEditPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the player an item.
|
||||
*
|
||||
* @param type
|
||||
* @param amt
|
||||
*/
|
||||
public abstract void giveItem(int type, int amt);
|
||||
|
||||
/**
|
||||
* Returns true if equal.
|
||||
*
|
||||
@ -344,4 +249,193 @@ public abstract class WorldEditPlayer {
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block that is being stood in.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getBlockIn() {
|
||||
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block that is being stood upon.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getBlockOn() {
|
||||
return Vector.toBlockPoint(player.getX(), player.getY() - 1, player.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block being looked at. May return null.
|
||||
*
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public Vector getBlockTrace(int range) {
|
||||
HitBlox hitBlox = new HitBlox(player, range, 0.2);
|
||||
Block block = hitBlox.getTargetBlock();
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
return new Vector(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's cardinal direction (N, W, NW, etc.).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getCardinalDirection() {
|
||||
// From hey0's code
|
||||
double rot = (getYaw() - 90) % 360;
|
||||
if (rot < 0) {
|
||||
rot += 360.0;
|
||||
}
|
||||
return etc.getCompassPointForDirection(rot).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the item that the player is holding.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* Get the ID of the item that the player is holding.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getItemInHand() {
|
||||
return player.getItemInHand();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the player.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's view pitch.
|
||||
*
|
||||
* @return pitch
|
||||
*/
|
||||
/**
|
||||
* Get the player's view pitch.
|
||||
*
|
||||
* @return pitch
|
||||
*/
|
||||
public double getPitch() {
|
||||
return player.getPitch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's position.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return new Vector(player.getX(), player.getY(), player.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's view yaw.
|
||||
*
|
||||
* @return yaw
|
||||
*/
|
||||
/**
|
||||
* Get the player's view yaw.
|
||||
*
|
||||
* @return yaw
|
||||
*/
|
||||
public double getYaw() {
|
||||
return player.getRotation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the player an item.
|
||||
*
|
||||
* @param type
|
||||
* @param amt
|
||||
*/
|
||||
/**
|
||||
* Gives the player an item.
|
||||
*
|
||||
* @param type
|
||||
* @param amt
|
||||
*/
|
||||
public void giveItem(int type, int amt) {
|
||||
player.giveItem(type, amt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass through the wall that you are looking at.
|
||||
*
|
||||
* @param range
|
||||
* @return whether the player was pass through
|
||||
*/
|
||||
public boolean passThroughForwardWall(int range) {
|
||||
boolean foundNext = false;
|
||||
int searchDist = 0;
|
||||
HitBlox hitBlox = new HitBlox(player, range, 0.2);
|
||||
Block block;
|
||||
while ((block = hitBlox.getNextBlock()) != null) {
|
||||
searchDist++;
|
||||
if (searchDist > 20) {
|
||||
return false;
|
||||
}
|
||||
if (block.getType() == 0) {
|
||||
if (foundNext) {
|
||||
Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ());
|
||||
if (ServerInterface.getBlockType(v) == 0) {
|
||||
setPosition(v.add(0.5, 0, 0.5));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foundNext = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a WorldEdit message.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void print(String msg) {
|
||||
player.sendMessage(Colors.LightPurple + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a WorldEdit error.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void printError(String msg) {
|
||||
player.sendMessage(Colors.Rose + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the player.
|
||||
*
|
||||
* @param pos
|
||||
* @param pitch
|
||||
* @param yaw
|
||||
*/
|
||||
public void setPosition(Vector pos, float pitch, float yaw) {
|
||||
Location loc = new Location();
|
||||
loc.x = pos.getX();
|
||||
loc.y = pos.getY();
|
||||
loc.z = pos.getZ();
|
||||
loc.rotX = (float) yaw;
|
||||
loc.rotY = (float) pitch;
|
||||
player.teleportTo(loc);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user