2010-10-11 08:22:47 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
2011-01-01 01:06:42 +00:00
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2010-10-11 08:22:47 +00:00
|
|
|
*
|
|
|
|
* 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 01:06:42 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
import java.io.File;
|
2013-01-20 00:06:55 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2013-06-23 19:04:23 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2011-09-03 16:54:20 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
2010-10-20 00:10:02 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
2011-09-19 06:38:30 +00:00
|
|
|
import com.sk89q.worldedit.blocks.ItemID;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
2011-01-19 09:12:05 +00:00
|
|
|
import com.sk89q.worldedit.util.TargetBlock;
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2011-12-15 10:27:22 +00:00
|
|
|
public abstract class LocalPlayer {
|
|
|
|
/**
|
|
|
|
* Server.
|
|
|
|
*/
|
|
|
|
protected ServerInterface server;
|
|
|
|
|
2010-10-14 18:59:45 +00:00
|
|
|
/**
|
2010-11-05 23:42:16 +00:00
|
|
|
* Construct the object.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param server A reference to the server this player is on
|
2010-10-14 18:59:45 +00:00
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
protected LocalPlayer(ServerInterface server) {
|
2011-12-15 10:27:22 +00:00
|
|
|
this.server = server;
|
2010-10-14 18:59:45 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +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();
|
2011-09-19 06:38:30 +00:00
|
|
|
return item == ItemID.IRON_PICK
|
|
|
|
|| item == ItemID.WOOD_PICKAXE
|
|
|
|
|| item == ItemID.STONE_PICKAXE
|
|
|
|
|| item == ItemID.DIAMOND_PICKAXE
|
|
|
|
|| item == ItemID.GOLD_PICKAXE;
|
2010-10-13 18:26:07 +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
|
|
|
*/
|
2011-01-09 17:25:24 +00:00
|
|
|
public void findFreePosition(WorldVector searchPos) {
|
|
|
|
LocalWorld world = searchPos.getWorld();
|
2010-10-20 00:10:02 +00:00
|
|
|
int x = searchPos.getBlockX();
|
2010-11-06 08:28:45 +00:00
|
|
|
int y = Math.max(0, 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;
|
|
|
|
|
2012-03-02 04:47:19 +00:00
|
|
|
while (y <= world.getMaxY() + 2) {
|
2013-06-23 19:04:23 +00:00
|
|
|
if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++free;
|
2010-10-11 08:22:47 +00:00
|
|
|
} else {
|
|
|
|
free = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free == 2) {
|
|
|
|
if (y - 1 != origY) {
|
2012-08-12 13:43:16 +00:00
|
|
|
final Vector pos = new Vector(x, y - 2, z);
|
|
|
|
final int id = world.getBlockType(pos);
|
|
|
|
final int data = world.getBlockData(pos);
|
|
|
|
setPosition(new Vector(x + 0.5, y - 2 + BlockType.centralTopLimit(id, data), z + 0.5));
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2010-11-17 06:17:50 +00:00
|
|
|
|
|
|
|
return;
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++y;
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
/**
|
|
|
|
* Set the player on the ground.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param searchPos The location to start searching from
|
2011-01-26 19:23:24 +00:00
|
|
|
*/
|
|
|
|
public void setOnGround(WorldVector searchPos) {
|
|
|
|
LocalWorld world = searchPos.getWorld();
|
|
|
|
int x = searchPos.getBlockX();
|
|
|
|
int y = Math.max(0, searchPos.getBlockY());
|
|
|
|
int z = searchPos.getBlockZ();
|
|
|
|
|
|
|
|
while (y >= 0) {
|
2012-08-12 13:43:16 +00:00
|
|
|
final Vector pos = new Vector(x, y, z);
|
|
|
|
final int id = world.getBlockType(pos);
|
2013-06-23 19:04:23 +00:00
|
|
|
final int data = world.getBlockData(pos);
|
|
|
|
if (!BlockType.canPassThrough(id, data)) {
|
2012-08-12 13:43:16 +00:00
|
|
|
setPosition(new Vector(x + 0.5, y + BlockType.centralTopLimit(id, data), z + 0.5));
|
2011-01-26 19:23:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
--y;
|
2011-01-26 19:23:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-11 08:22:47 +00:00
|
|
|
|
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() {
|
2011-01-09 17:25:24 +00:00
|
|
|
findFreePosition(getBlockIn());
|
2010-10-20 00:10:02 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2013-06-24 15:58:57 +00:00
|
|
|
final WorldVector pos = getBlockIn();
|
|
|
|
final int x = pos.getBlockX();
|
2010-11-06 08:28:45 +00:00
|
|
|
int y = Math.max(0, pos.getBlockY());
|
2013-06-24 15:58:57 +00:00
|
|
|
final int z = pos.getBlockZ();
|
|
|
|
final LocalWorld world = pos.getWorld();
|
2010-10-13 05:06:46 +00:00
|
|
|
|
|
|
|
byte free = 0;
|
|
|
|
byte spots = 0;
|
|
|
|
|
2012-03-02 04:47:19 +00:00
|
|
|
while (y <= world.getMaxY() + 2) {
|
2013-06-23 19:04:23 +00:00
|
|
|
if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++free;
|
2010-10-13 05:06:46 +00:00
|
|
|
} else {
|
|
|
|
free = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-16 23:56:59 +00:00
|
|
|
if (free == 2) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++spots;
|
2010-10-16 23:56:59 +00:00
|
|
|
if (spots == 2) {
|
2013-06-24 15:58:57 +00:00
|
|
|
final Vector platform = new Vector(x, y - 2, z);
|
|
|
|
final BaseBlock block = world.getBlock(platform);
|
|
|
|
final int type = block.getId();
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2010-10-17 00:15:17 +00:00
|
|
|
// Don't get put in lava!
|
2011-09-03 16:54:20 +00:00
|
|
|
if (type == BlockID.LAVA || type == BlockID.STATIONARY_LAVA) {
|
2010-10-17 00:15:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-24 15:58:57 +00:00
|
|
|
setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5));
|
2010-10-13 05:06:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++y;
|
2010-10-13 05:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go up one level to the next free space above.
|
|
|
|
*
|
|
|
|
* @return true if a spot was found
|
|
|
|
*/
|
|
|
|
public boolean descendLevel() {
|
2013-06-24 15:58:57 +00:00
|
|
|
final WorldVector pos = getBlockIn();
|
|
|
|
final int x = pos.getBlockX();
|
2010-11-06 08:28:45 +00:00
|
|
|
int y = Math.max(0, pos.getBlockY() - 1);
|
2013-06-24 15:58:57 +00:00
|
|
|
final int z = pos.getBlockZ();
|
|
|
|
final LocalWorld world = pos.getWorld();
|
2010-10-13 05:06:46 +00:00
|
|
|
|
|
|
|
byte free = 0;
|
|
|
|
|
2010-10-17 00:08:56 +00:00
|
|
|
while (y >= 1) {
|
2013-06-23 19:04:23 +00:00
|
|
|
if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++free;
|
2010-10-13 05:06:46 +00:00
|
|
|
} 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) {
|
2013-06-24 15:58:57 +00:00
|
|
|
final Vector platform = new Vector(x, y, z);
|
|
|
|
final BaseBlock block = world.getBlock(platform);
|
|
|
|
final int type = block.getId();
|
2010-10-17 00:15:17 +00:00
|
|
|
|
|
|
|
// Don't want to end up in lava
|
2011-09-03 16:54:20 +00:00
|
|
|
if (type != BlockID.AIR && type != BlockID.LAVA && type != BlockID.STATIONARY_LAVA) {
|
2010-10-17 00:08:56 +00:00
|
|
|
// Found a block!
|
2013-06-24 15:58:57 +00:00
|
|
|
setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5));
|
2010-10-17 00:08:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
--y;
|
2010-10-17 00:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-10-13 05:06:46 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
--y;
|
2010-10-13 05:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-20 00:10:02 +00:00
|
|
|
/**
|
|
|
|
* Ascend to the ceiling above.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param clearance How many blocks to leave above the player's head
|
2010-10-20 00:10:02 +00:00
|
|
|
* @return whether the player was moved
|
|
|
|
*/
|
|
|
|
public boolean ascendToCeiling(int clearance) {
|
2013-10-23 17:03:09 +00:00
|
|
|
return ascendToCeiling(clearance, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ascend to the ceiling above.
|
|
|
|
*
|
|
|
|
* @param clearance How many blocks to leave above the player's head
|
|
|
|
* @param alwaysGlass Always put glass under the player
|
|
|
|
* @return whether the player was moved
|
|
|
|
*/
|
|
|
|
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
|
2010-10-20 00:10:02 +00:00
|
|
|
Vector pos = getBlockIn();
|
|
|
|
int x = pos.getBlockX();
|
2010-11-06 08:28:45 +00:00
|
|
|
int initialY = Math.max(0, pos.getBlockY());
|
|
|
|
int y = Math.max(0, pos.getBlockY() + 2);
|
2010-10-20 00:10:02 +00:00
|
|
|
int z = pos.getBlockZ();
|
2011-01-01 18:33:18 +00:00
|
|
|
LocalWorld world = getPosition().getWorld();
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2010-10-20 03:36:57 +00:00
|
|
|
// No free space above
|
2011-01-08 19:26:27 +00:00
|
|
|
if (world.getBlockType(new Vector(x, y, z)) != 0) {
|
2010-10-20 00:10:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
while (y <= world.getMaxY()) {
|
2010-10-20 00:10:02 +00:00
|
|
|
// Found a ceiling!
|
2013-06-23 19:04:23 +00:00
|
|
|
if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
|
2010-10-20 03:36:57 +00:00
|
|
|
int platformY = Math.max(initialY, y - 3 - clearance);
|
2013-10-23 17:03:09 +00:00
|
|
|
floatAt(x, platformY + 1, z, alwaysGlass);
|
2010-10-20 00:10:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++y;
|
2010-10-20 00:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-07 04:47:50 +00:00
|
|
|
/**
|
|
|
|
* Just go up.
|
|
|
|
*
|
2013-10-19 09:31:31 +00:00
|
|
|
* @param distance How far up to teleport
|
2010-11-07 04:47:50 +00:00
|
|
|
* @return whether the player was moved
|
|
|
|
*/
|
|
|
|
public boolean ascendUpwards(int distance) {
|
2013-10-23 17:03:09 +00:00
|
|
|
return ascendUpwards(distance, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Just go up.
|
|
|
|
*
|
|
|
|
* @param distance How far up to teleport
|
|
|
|
* @param alwaysGlass Always put glass under the player
|
|
|
|
* @return whether the player was moved
|
|
|
|
*/
|
|
|
|
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
|
2013-10-19 09:31:31 +00:00
|
|
|
final Vector pos = getBlockIn();
|
|
|
|
final int x = pos.getBlockX();
|
|
|
|
final int initialY = Math.max(0, pos.getBlockY());
|
2010-11-07 04:47:50 +00:00
|
|
|
int y = Math.max(0, pos.getBlockY() + 1);
|
2013-10-19 09:31:31 +00:00
|
|
|
final int z = pos.getBlockZ();
|
|
|
|
final int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance);
|
|
|
|
final LocalWorld world = getPosition().getWorld();
|
2010-11-07 04:47:50 +00:00
|
|
|
|
2012-03-02 04:47:19 +00:00
|
|
|
while (y <= world.getMaxY() + 2) {
|
2013-06-23 19:04:23 +00:00
|
|
|
if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
|
2010-11-07 04:47:50 +00:00
|
|
|
break; // Hit something
|
|
|
|
} else if (y > maxY + 1) {
|
|
|
|
break;
|
|
|
|
} else if (y == maxY + 1) {
|
2013-10-23 17:03:09 +00:00
|
|
|
floatAt(x, y - 1, z, alwaysGlass);
|
2010-11-07 04:47:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++y;
|
2010-11-07 04:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-23 17:02:47 +00:00
|
|
|
/**
|
|
|
|
* Make the player float in the given blocks.
|
|
|
|
*
|
|
|
|
* @param x The X coordinate of the block to float in
|
|
|
|
* @param y The Y coordinate of the block to float in
|
|
|
|
* @param z The Z coordinate of the block to float in
|
|
|
|
*/
|
2013-10-23 17:03:09 +00:00
|
|
|
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
2013-10-23 17:02:47 +00:00
|
|
|
getPosition().getWorld().setBlockType(new Vector(x, y - 1, z), BlockID.GLASS);
|
|
|
|
setPosition(new Vector(x + 0.5, y, z + 0.5));
|
|
|
|
}
|
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block that is being stood in.
|
|
|
|
*
|
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public WorldVector getBlockIn() {
|
2011-01-08 18:52:48 +00:00
|
|
|
WorldVector pos = getPosition();
|
|
|
|
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
|
|
|
|
pos.getY(), pos.getZ());
|
2010-11-05 23:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the point of the block that is being stood upon.
|
|
|
|
*
|
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public WorldVector getBlockOn() {
|
|
|
|
WorldVector pos = getPosition();
|
2011-01-08 18:52:48 +00:00
|
|
|
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
|
|
|
|
pos.getY() - 1, pos.getZ());
|
2010-11-05 23:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-06-22 22:28:56 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
* Will return the farthest away air block if useLastBlock is true and no other block is found.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param range How far to checks for blocks
|
|
|
|
* @param useLastBlock Try to return the last valid air block found.
|
2011-06-22 22:28:56 +00:00
|
|
|
* @return point
|
|
|
|
*/
|
|
|
|
public WorldVector getBlockTrace(int range, boolean useLastBlock) {
|
|
|
|
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
|
|
|
return (useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock());
|
|
|
|
}
|
2011-09-19 01:49:45 +00:00
|
|
|
|
|
|
|
public WorldVectorFace getBlockTraceFace(int range, boolean useLastBlock) {
|
|
|
|
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
|
|
|
return (useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace());
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param range How far to checks for blocks
|
2010-11-05 23:42:16 +00:00
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-19 09:12:05 +00:00
|
|
|
public WorldVector getBlockTrace(int range) {
|
2011-06-22 22:28:56 +00:00
|
|
|
return getBlockTrace(range, false);
|
2011-01-19 09:12:05 +00:00
|
|
|
}
|
2010-11-05 23:42:16 +00:00
|
|
|
|
2010-11-10 09:54:07 +00:00
|
|
|
/**
|
|
|
|
* Get the point of the block being looked at. May return null.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param range How far to checks for blocks
|
2010-11-10 09:54:07 +00:00
|
|
|
* @return point
|
|
|
|
*/
|
2011-01-19 09:12:05 +00:00
|
|
|
public WorldVector getSolidBlockTrace(int range) {
|
|
|
|
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
|
|
|
return tb.getSolidTargetBlock();
|
|
|
|
}
|
2010-11-10 09:54:07 +00:00
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
2011-01-01 01:06:42 +00:00
|
|
|
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
|
2010-11-05 23:42:16 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the direction
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-23 10:03:49 +00:00
|
|
|
public PlayerDirection getCardinalDirection() {
|
2011-10-24 23:02:50 +00:00
|
|
|
return getCardinalDirection(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's cardinal direction (N, W, NW, etc.) with an offset. May return null.
|
|
|
|
* @param yawOffset offset that is added to the player's yaw before determining the cardinal direction
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the direction
|
2011-10-24 23:02:50 +00:00
|
|
|
*/
|
|
|
|
public PlayerDirection getCardinalDirection(int yawOffset) {
|
2011-09-24 19:24:10 +00:00
|
|
|
if (getPitch() > 67.5) {
|
2011-08-15 12:05:21 +00:00
|
|
|
return PlayerDirection.DOWN;
|
2011-09-24 19:24:10 +00:00
|
|
|
}
|
|
|
|
if (getPitch() < -67.5) {
|
2011-08-15 12:05:21 +00:00
|
|
|
return PlayerDirection.UP;
|
2011-09-24 19:24:10 +00:00
|
|
|
}
|
2011-08-15 12:05:21 +00:00
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
// From hey0's code
|
2012-11-20 08:28:41 +00:00
|
|
|
double rot = (getYaw() + yawOffset) % 360; //let's use real yaw now
|
2010-11-05 23:42:16 +00:00
|
|
|
if (rot < 0) {
|
|
|
|
rot += 360.0;
|
|
|
|
}
|
2011-01-01 01:06:42 +00:00
|
|
|
return getDirection(rot);
|
2010-11-05 23:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-01 01:06:42 +00:00
|
|
|
* Returns direction according to rotation. May return null.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param rot yaw
|
|
|
|
* @return the direction
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-23 10:03:49 +00:00
|
|
|
private static PlayerDirection getDirection(double rot) {
|
2011-01-01 01:06:42 +00:00
|
|
|
if (0 <= rot && rot < 22.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.SOUTH;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (22.5 <= rot && rot < 67.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.SOUTH_WEST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (67.5 <= rot && rot < 112.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.WEST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (112.5 <= rot && rot < 157.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.NORTH_WEST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (157.5 <= rot && rot < 202.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.NORTH;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (202.5 <= rot && rot < 247.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.NORTH_EAST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (247.5 <= rot && rot < 292.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.EAST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (292.5 <= rot && rot < 337.5) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.SOUTH_EAST;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else if (337.5 <= rot && rot < 360.0) {
|
2012-11-20 08:28:41 +00:00
|
|
|
return PlayerDirection.SOUTH;
|
2011-01-01 01:06:42 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
|
|
|
* Get the ID of the item that the player is holding.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the item id of the item the player is holding
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-01 01:06:42 +00:00
|
|
|
public abstract int getItemInHand();
|
2010-11-05 23:42:16 +00:00
|
|
|
|
2013-11-10 12:53:17 +00:00
|
|
|
/**
|
|
|
|
* Get the Block that the player is holding.
|
|
|
|
*
|
|
|
|
* @return the item id of the item the player is holding
|
|
|
|
*/
|
|
|
|
public BaseBlock getBlockInHand() throws WorldEditException {
|
|
|
|
final int typeId = getItemInHand();
|
|
|
|
if (!getWorld().isValidBlockType(typeId)) {
|
|
|
|
throw new NotABlockException(typeId);
|
|
|
|
}
|
|
|
|
return new BaseBlock(typeId);
|
|
|
|
}
|
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
/**
|
|
|
|
* Get the name of the player.
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public abstract String getName();
|
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
2011-01-01 01:06:42 +00:00
|
|
|
* Get the player's position.
|
2010-11-05 23:42:16 +00:00
|
|
|
*
|
2011-01-01 01:06:42 +00:00
|
|
|
* @return point
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-01 18:33:18 +00:00
|
|
|
public abstract WorldVector getPosition();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's world.
|
|
|
|
*
|
|
|
|
* @return point
|
|
|
|
*/
|
|
|
|
public abstract LocalWorld getWorld();
|
2011-01-01 01:06:42 +00:00
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
|
|
|
* Get the player's view pitch.
|
|
|
|
*
|
|
|
|
* @return pitch
|
|
|
|
*/
|
|
|
|
/**
|
2011-01-01 01:06:42 +00:00
|
|
|
* Get the player's view pitch.
|
2010-11-05 23:42:16 +00:00
|
|
|
*
|
2011-01-01 01:06:42 +00:00
|
|
|
* @return pitch
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-01 01:06:42 +00:00
|
|
|
public abstract double getPitch();
|
2010-11-05 23:42:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player's view yaw.
|
|
|
|
*
|
|
|
|
* @return yaw
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Get the player's view yaw.
|
|
|
|
*
|
|
|
|
* @return yaw
|
|
|
|
*/
|
2011-01-01 01:06:42 +00:00
|
|
|
public abstract double getYaw();
|
2010-11-05 23:42:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gives the player an item.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param type The item id of the item to be given to the player
|
|
|
|
* @param amount How many items in the stack
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2013-10-24 18:36:44 +00:00
|
|
|
public abstract void giveItem(int type, int amount);
|
2010-11-05 23:42:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass through the wall that you are looking at.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param range How far to checks for blocks
|
2010-11-05 23:42:16 +00:00
|
|
|
* @return whether the player was pass through
|
|
|
|
*/
|
2011-01-19 09:12:05 +00:00
|
|
|
public boolean passThroughForwardWall(int range) {
|
|
|
|
int searchDist = 0;
|
|
|
|
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
|
|
|
|
LocalWorld world = getPosition().getWorld();
|
|
|
|
BlockWorldVector block;
|
2011-01-26 19:23:24 +00:00
|
|
|
boolean firstBlock = true;
|
|
|
|
int freeToFind = 2;
|
|
|
|
boolean inFree = false;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-19 09:12:05 +00:00
|
|
|
while ((block = hitBlox.getNextBlock()) != null) {
|
2013-06-23 19:04:23 +00:00
|
|
|
boolean free = BlockType.canPassThrough(world.getBlock(block));
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
if (firstBlock) {
|
|
|
|
firstBlock = false;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
if (!free) {
|
2011-07-15 07:00:48 +00:00
|
|
|
--freeToFind;
|
2011-01-26 19:23:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++searchDist;
|
2011-01-19 09:12:05 +00:00
|
|
|
if (searchDist > 20) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
if (inFree != free) {
|
|
|
|
if (free) {
|
2011-07-15 07:00:48 +00:00
|
|
|
--freeToFind;
|
2011-01-19 09:12:05 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
if (freeToFind == 0) {
|
|
|
|
setOnGround(block);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-26 19:23:24 +00:00
|
|
|
inFree = free;
|
2011-01-19 09:12:05 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-19 09:12:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-05 23:42:16 +00:00
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
/**
|
|
|
|
* Print a message.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param msg The message text
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract void printRaw(String msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a WorldEdit message.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param msg The message text
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract void printDebug(String msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a WorldEdit message.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param msg The message text
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract void print(String msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a WorldEdit error.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param msg The error message text
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract void printError(String msg);
|
|
|
|
|
2010-11-05 23:42:16 +00:00
|
|
|
/**
|
|
|
|
* Move the player.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param pos Where to move them
|
|
|
|
* @param pitch The pitch (up/down) of the player's view
|
|
|
|
* @param yaw The yaw (left/right) of the player's view
|
2010-11-05 23:42:16 +00:00
|
|
|
*/
|
2011-01-01 01:06:42 +00:00
|
|
|
public abstract void setPosition(Vector pos, float pitch, float yaw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the player.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param pos Where to move them
|
2011-01-01 01:06:42 +00:00
|
|
|
*/
|
|
|
|
public void setPosition(Vector pos) {
|
2011-11-23 01:29:48 +00:00
|
|
|
setPosition(pos, (float) getPitch(), (float) getYaw());
|
2010-11-05 23:42:16 +00:00
|
|
|
}
|
2010-11-06 07:51:35 +00:00
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
/**
|
|
|
|
* Get a player's list of groups.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return an array containing a group name per entry
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract String[] getGroups();
|
|
|
|
|
2011-01-01 01:06:42 +00:00
|
|
|
/**
|
|
|
|
* Get this player's block bag.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the player's block bag
|
2011-01-01 01:06:42 +00:00
|
|
|
*/
|
|
|
|
public abstract BlockBag getInventoryBlockBag();
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
/**
|
|
|
|
* Checks if a player has permission.
|
|
|
|
*
|
2013-10-24 18:36:44 +00:00
|
|
|
* @param perm The permission to check
|
|
|
|
* @return true if the player has that permission
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public abstract boolean hasPermission(String perm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a file open dialog.
|
|
|
|
*
|
|
|
|
* @param extensions null to allow all
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the selected file or null if something went wrong
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public File openFileOpenDialog(String[] extensions) {
|
|
|
|
printError("File dialogs are not supported in your environment.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a file save dialog.
|
|
|
|
*
|
|
|
|
* @param extensions null to allow all
|
2013-10-24 18:36:44 +00:00
|
|
|
* @return the selected file or null if something went wrong
|
2011-12-15 10:27:22 +00:00
|
|
|
*/
|
|
|
|
public File openFileSaveDialog(String[] extensions) {
|
|
|
|
printError("File dialogs are not supported in your environment.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-01-02 05:50:31 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the player can destroy bedrock.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-02 05:50:31 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean canDestroyBedrock() {
|
2011-01-30 06:10:22 +00:00
|
|
|
return hasPermission("worldedit.override.bedrock");
|
2011-01-02 05:50:31 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
|
|
|
* Send a CUI event.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-03-12 06:43:02 +00:00
|
|
|
* @param event
|
|
|
|
*/
|
|
|
|
public void dispatchCUIEvent(CUIEvent event) {
|
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-03-12 06:43:02 +00:00
|
|
|
/**
|
|
|
|
* Send the CUI handshake.
|
2012-08-05 03:22:55 +00:00
|
|
|
* @deprecated Not used anymore; The CUI begins the handshake
|
2011-03-12 06:43:02 +00:00
|
|
|
*/
|
2012-08-05 03:22:55 +00:00
|
|
|
@Deprecated
|
2011-03-12 06:43:02 +00:00
|
|
|
public void dispatchCUIHandshake() {
|
|
|
|
}
|
2011-01-01 01:06:42 +00:00
|
|
|
|
2011-12-15 10:27:22 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
if (!(other instanceof LocalPlayer)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
LocalPlayer other2 = (LocalPlayer) other;
|
|
|
|
return other2.getName().equals(getName());
|
|
|
|
}
|
|
|
|
|
2011-12-13 02:43:26 +00:00
|
|
|
@Override
|
2011-12-15 10:27:22 +00:00
|
|
|
public int hashCode() {
|
|
|
|
return getName().hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void checkPermission(String permission) throws WorldEditPermissionException {
|
|
|
|
if (!hasPermission(permission)) {
|
|
|
|
throw new WorldEditPermissionException();
|
|
|
|
}
|
2011-12-13 02:43:26 +00:00
|
|
|
}
|
2011-12-15 11:02:00 +00:00
|
|
|
|
|
|
|
public boolean isPlayer() {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-20 00:06:55 +00:00
|
|
|
|
|
|
|
public boolean hasCreativeMode() {
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|