2011-01-01 01:06:42 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEditLibrary
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-01 18:33:18 +00:00
|
|
|
import com.sk89q.worldedit.LocalWorld;
|
2011-01-01 01:06:42 +00:00
|
|
|
import com.sk89q.worldedit.ServerInterface;
|
|
|
|
import com.sk89q.worldedit.Vector;
|
2011-01-01 18:34:36 +00:00
|
|
|
import com.sk89q.worldedit.LocalPlayer;
|
2011-01-01 18:33:18 +00:00
|
|
|
import com.sk89q.worldedit.WorldVector;
|
2011-01-01 01:06:42 +00:00
|
|
|
import com.sk89q.worldedit.bags.BlockBag;
|
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public class HMPlayer extends LocalPlayer {
|
2011-01-01 01:06:42 +00:00
|
|
|
/**
|
|
|
|
* Stores the player.
|
|
|
|
*/
|
|
|
|
private Player player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the object.
|
|
|
|
*
|
|
|
|
* @param player
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public HMPlayer(ServerInterface server, Player player) {
|
|
|
|
super(server);
|
2011-01-01 01:06:42 +00:00
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the player.
|
|
|
|
*
|
|
|
|
* @param pos
|
|
|
|
*/
|
|
|
|
public void setPosition(Vector pos) {
|
|
|
|
setPosition(pos, (float)getPitch(), (float)getYaw());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
*
|
|
|
|
* @param range
|
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public WorldVector getBlockTrace(int range) {
|
2011-01-01 01:06:42 +00:00
|
|
|
HitBlox hitBlox = new HitBlox(player,range, 0.2);
|
|
|
|
Block block = hitBlox.getTargetBlock();
|
|
|
|
if (block == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
return new WorldVector(null, block.getX(), block.getY(), block.getZ());
|
2011-01-01 01:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
*
|
|
|
|
* @param range
|
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public WorldVector getSolidBlockTrace(int range) {
|
2011-01-01 01:06:42 +00:00
|
|
|
HitBlox hitBlox = new HitBlox(player,range, 0.2);
|
|
|
|
Block block = null;
|
|
|
|
|
|
|
|
while (hitBlox.getNextBlock() != null
|
|
|
|
&& BlockType.canPassThrough(hitBlox.getCurBlock().getType()));
|
|
|
|
|
|
|
|
block = hitBlox.getCurBlock();
|
|
|
|
|
|
|
|
if (block == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
return new WorldVector(null, block.getX(), block.getY(), block.getZ());
|
2011-01-01 01:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public double getPitch() {
|
|
|
|
return player.getPitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's position.
|
|
|
|
*
|
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public WorldVector getPosition() {
|
|
|
|
return new WorldVector(null, player.getX(), player.getY(), player.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's world.
|
|
|
|
*
|
|
|
|
* @return point
|
|
|
|
*/
|
|
|
|
public LocalWorld getWorld() {
|
|
|
|
return null;
|
2011-01-01 01:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's view yaw.
|
|
|
|
*
|
|
|
|
* @return yaw
|
|
|
|
*/
|
|
|
|
public double getYaw() {
|
|
|
|
return player.getRotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2011-01-01 18:33:18 +00:00
|
|
|
LocalWorld world = getPosition().getWorld();
|
2011-01-01 01:06:42 +00:00
|
|
|
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());
|
2011-01-01 18:33:18 +00:00
|
|
|
if (server.getBlockType(world, v) == 0) {
|
2011-01-01 01:06:42 +00:00
|
|
|
setPosition(v.add(0.5, 0, 0.5));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foundNext = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a message.
|
|
|
|
*
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
public void printRaw(String msg) {
|
|
|
|
player.sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a player's list of groups.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String[] getGroups() {
|
|
|
|
return player.getGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a player has permission.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean hasPermission(String perm) {
|
|
|
|
return player.canUseCommand("/" + perm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get this player's block bag.
|
|
|
|
*/
|
|
|
|
public BlockBag getInventoryBlockBag() {
|
2011-01-01 01:40:07 +00:00
|
|
|
return new HMPlayerInventoryBlockBag(player);
|
2011-01-01 01:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the player
|
|
|
|
*/
|
|
|
|
public Player getPlayerObject() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|