mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Initial abstraction.
This commit is contained in:
parent
162fd3148d
commit
ecce855db2
273
src/HMPlayer.java
Normal file
273
src/HMPlayer.java
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
// $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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.ServerInterface;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.WorldEditPlayer;
|
||||||
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public class HMPlayer extends WorldEditPlayer {
|
||||||
|
/**
|
||||||
|
* Stores the player.
|
||||||
|
*/
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the object.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public HMPlayer(Player player) {
|
||||||
|
super();
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
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 point of the block being looked at. May return null.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public Vector getSolidBlockTrace(int range) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return new Vector(block.getX(), block.getY(), block.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 (server.getBlockType(v) == 0) {
|
||||||
|
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() {
|
||||||
|
return new PlayerInventoryBlockBag(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the player
|
||||||
|
*/
|
||||||
|
public Player getPlayerObject() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
@ -26,15 +26,15 @@ import java.util.Random;
|
|||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class ServerInterface {
|
public class HMServerInterface extends ServerInterface {
|
||||||
/**
|
/**
|
||||||
* Logger.
|
* Logger.
|
||||||
*/
|
*/
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
private final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
/**
|
/**
|
||||||
* Random generator.
|
* Random generator.
|
||||||
*/
|
*/
|
||||||
private static Random random = new Random();
|
private Random random = new Random();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set block type.
|
* Set block type.
|
||||||
@ -43,7 +43,7 @@ public class ServerInterface {
|
|||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean setBlockType(Vector pt, int type) {
|
public boolean setBlockType(Vector pt, int type) {
|
||||||
// Can't set colored cloth or crash
|
// Can't set colored cloth or crash
|
||||||
if ((type >= 21 && type <= 34) || type == 36) {
|
if ((type >= 21 && type <= 34) || type == 36) {
|
||||||
return false;
|
return false;
|
||||||
@ -58,7 +58,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int getBlockType(Vector pt) {
|
public int getBlockType(Vector pt) {
|
||||||
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
|
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
|
||||||
pt.getBlockZ());
|
pt.getBlockZ());
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ public class ServerInterface {
|
|||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void setBlockData(Vector pt, int data) {
|
public void setBlockData(Vector pt, int data) {
|
||||||
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
|
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
|
||||||
pt.getBlockZ(), data);
|
pt.getBlockZ(), data);
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int getBlockData(Vector pt) {
|
public int getBlockData(Vector pt) {
|
||||||
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
|
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
|
||||||
pt.getBlockZ());
|
pt.getBlockZ());
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @param text
|
* @param text
|
||||||
*/
|
*/
|
||||||
public static void setSignText(Vector pt, String[] text) {
|
public void setSignText(Vector pt, String[] text) {
|
||||||
Sign signData = (Sign)etc.getServer().getComplexBlock(
|
Sign signData = (Sign)etc.getServer().getComplexBlock(
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
if (signData == null) {
|
if (signData == null) {
|
||||||
@ -110,7 +110,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String[] getSignText(Vector pt) {
|
public String[] getSignText(Vector pt) {
|
||||||
Sign signData = (Sign)etc.getServer().getComplexBlock(
|
Sign signData = (Sign)etc.getServer().getComplexBlock(
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
if (signData == null) {
|
if (signData == null) {
|
||||||
@ -130,7 +130,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static BaseItemStack[] getChestContents(Vector pt) {
|
public BaseItemStack[] getChestContents(Vector pt) {
|
||||||
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ public class ServerInterface {
|
|||||||
* @param contents
|
* @param contents
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean setChestContents(Vector pt,
|
public boolean setChestContents(Vector pt,
|
||||||
BaseItemStack[] contents) {
|
BaseItemStack[] contents) {
|
||||||
|
|
||||||
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
||||||
@ -197,7 +197,7 @@ public class ServerInterface {
|
|||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
*/
|
*/
|
||||||
public static boolean clearChest(Vector pt) {
|
public boolean clearChest(Vector pt) {
|
||||||
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class ServerInterface {
|
|||||||
* @param itemArray
|
* @param itemArray
|
||||||
* @param contents
|
* @param contents
|
||||||
*/
|
*/
|
||||||
private static void setContents(ItemArray<?> itemArray, Item[] contents) {
|
private void setContents(ItemArray<?> itemArray, Item[] contents) {
|
||||||
int size = contents.length;
|
int size = contents.length;
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@ -237,7 +237,7 @@ public class ServerInterface {
|
|||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isValidMobType(String type) {
|
public boolean isValidMobType(String type) {
|
||||||
return Mob.isValid(type);
|
return Mob.isValid(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @param mobType
|
* @param mobType
|
||||||
*/
|
*/
|
||||||
public static void setMobSpawnerType(Vector pt, String mobType) {
|
public void setMobSpawnerType(Vector pt, String mobType) {
|
||||||
ComplexBlock cblock = etc.getServer().getComplexBlock(
|
ComplexBlock cblock = etc.getServer().getComplexBlock(
|
||||||
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @param mobType
|
* @param mobType
|
||||||
*/
|
*/
|
||||||
public static String getMobSpawnerType(Vector pt) {
|
public String getMobSpawnerType(Vector pt) {
|
||||||
try {
|
try {
|
||||||
return MinecraftServerInterface.getMobSpawnerType(pt);
|
return MinecraftServerInterface.getMobSpawnerType(pt);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@ -282,7 +282,7 @@ public class ServerInterface {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean generateTree(EditSession editSession, Vector pt) {
|
public boolean generateTree(EditSession editSession, Vector pt) {
|
||||||
try {
|
try {
|
||||||
return MinecraftServerInterface.generateTree(editSession, pt);
|
return MinecraftServerInterface.generateTree(editSession, pt);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@ -300,7 +300,7 @@ public class ServerInterface {
|
|||||||
* @param count
|
* @param count
|
||||||
* @param times
|
* @param times
|
||||||
*/
|
*/
|
||||||
public static void dropItem(Vector pt, int type, int count, int times) {
|
public void dropItem(Vector pt, int type, int count, int times) {
|
||||||
for (int i = 0; i < times; i++) {
|
for (int i = 0; i < times; i++) {
|
||||||
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
||||||
type, count);
|
type, count);
|
||||||
@ -315,7 +315,7 @@ public class ServerInterface {
|
|||||||
* @param count
|
* @param count
|
||||||
* @param times
|
* @param times
|
||||||
*/
|
*/
|
||||||
public static void dropItem(Vector pt, int type, int count) {
|
public void dropItem(Vector pt, int type, int count) {
|
||||||
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
||||||
type, count);
|
type, count);
|
||||||
}
|
}
|
||||||
@ -328,26 +328,17 @@ public class ServerInterface {
|
|||||||
* @param count
|
* @param count
|
||||||
* @param times
|
* @param times
|
||||||
*/
|
*/
|
||||||
public static void dropItem(Vector pt, int type) {
|
public void dropItem(Vector pt, int type) {
|
||||||
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
|
||||||
type, 1);
|
type, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a block bag for a player.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
public static PlayerInventoryBlockBag getPlayerBlockBag(WorldEditPlayer player) {
|
|
||||||
return new PlayerInventoryBlockBag(player.getPlayerObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulate a block being mined.
|
* Simulate a block being mined.
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param pt
|
||||||
*/
|
*/
|
||||||
public static void simulateBlockMine(Vector pt) {
|
public void simulateBlockMine(Vector pt) {
|
||||||
int type = getBlockType(pt);
|
int type = getBlockType(pt);
|
||||||
setBlockType(pt, 0);
|
setBlockType(pt, 0);
|
||||||
|
|
@ -17,6 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
@ -56,6 +56,12 @@ public class WorldEditListener extends PluginListener {
|
|||||||
20, 35, 41, 42, 43, 44, 45, 47, 48, 49, 52, 53, 54, 56, 57, 58, 60,
|
20, 35, 41, 42, 43, 44, 45, 47, 48, 49, 52, 53, 54, 56, 57, 58, 60,
|
||||||
61, 62, 67, 73, 78, 79, 80, 82, 85, 86, 87, 88, 89, 91
|
61, 62, 67, 73, 78, 79, 80, 82, 85, 86, 87, 88, 89, 91
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server interface.
|
||||||
|
*/
|
||||||
|
private ServerInterface server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorldEditLibrary's properties file.
|
* WorldEditLibrary's properties file.
|
||||||
*/
|
*/
|
||||||
@ -97,6 +103,8 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* Construct an instance of the plugin.
|
* Construct an instance of the plugin.
|
||||||
*/
|
*/
|
||||||
public WorldEditListener() {
|
public WorldEditListener() {
|
||||||
|
server = ServerInterface.getInstance();
|
||||||
|
|
||||||
// Note: Commands should only have the phrase 'air' at the end
|
// Note: Commands should only have the phrase 'air' at the end
|
||||||
// for now (see SMWorldEditListener.canUseCommand)
|
// for now (see SMWorldEditListener.canUseCommand)
|
||||||
commands.put("//pos1", "Set editing position #1");
|
commands.put("//pos1", "Set editing position #1");
|
||||||
@ -184,7 +192,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
return sessions.get(player);
|
return sessions.get(player);
|
||||||
} else {
|
} else {
|
||||||
WorldEditSession session = new WorldEditSession();
|
WorldEditSession session = new WorldEditSession();
|
||||||
if (!player.getPlayerObject().canUseCommand("/worldeditnomax")
|
if (!player.hasPermission("/worldeditnomax")
|
||||||
&& maxChangeLimit > -1) {
|
&& maxChangeLimit > -1) {
|
||||||
if (defaultChangeLimit < 0) {
|
if (defaultChangeLimit < 0) {
|
||||||
// No infinite!
|
// No infinite!
|
||||||
@ -199,7 +207,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
}
|
}
|
||||||
session.setUseInventory(useInventory
|
session.setUseInventory(useInventory
|
||||||
&& (!useInventoryOverride
|
&& (!useInventoryOverride
|
||||||
|| !player.getPlayerObject().canUseCommand("/worldeditunlimited")));
|
|| !player.hasPermission("/worldeditunlimited")));
|
||||||
sessions.put(player, session);
|
sessions.put(player, session);
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
@ -272,7 +280,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
return new SignBlock(blockType.getID(), data, text);
|
return new SignBlock(blockType.getID(), data, text);
|
||||||
} else if (blockType == BlockType.MOB_SPAWNER) {
|
} else if (blockType == BlockType.MOB_SPAWNER) {
|
||||||
if (args0.length > 1) {
|
if (args0.length > 1) {
|
||||||
if (!ServerInterface.isValidMobType(args0[1])) {
|
if (!server.isValidMobType(args0[1])) {
|
||||||
throw new InvalidItemException(arg, "Unknown mob type '" + args0[1] + "'");
|
throw new InvalidItemException(arg, "Unknown mob type '" + args0[1] + "'");
|
||||||
}
|
}
|
||||||
return new MobSpawnerBlock(data, args0[1]);
|
return new MobSpawnerBlock(data, args0[1]);
|
||||||
@ -599,7 +607,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
} else if (split[0].equalsIgnoreCase("//limit")) {
|
} else if (split[0].equalsIgnoreCase("//limit")) {
|
||||||
checkArgs(split, 1, 1, split[0]);
|
checkArgs(split, 1, 1, split[0]);
|
||||||
int limit = Math.max(-1, Integer.parseInt(split[1]));
|
int limit = Math.max(-1, Integer.parseInt(split[1]));
|
||||||
if (!player.getPlayerObject().canUseCommand("/worldeditnomax")
|
if (!player.hasPermission("/worldeditnomax")
|
||||||
&& maxChangeLimit > -1) {
|
&& maxChangeLimit > -1) {
|
||||||
if (limit > maxChangeLimit) {
|
if (limit > maxChangeLimit) {
|
||||||
player.printError("Your maximum allowable limit is " + maxChangeLimit + ".");
|
player.printError("Your maximum allowable limit is " + maxChangeLimit + ".");
|
||||||
@ -1596,30 +1604,32 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* @param dir
|
* @param dir
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Vector getDirection(WorldEditPlayer player, String dir)
|
public Vector getDirection(WorldEditPlayer player, String dirStr)
|
||||||
throws UnknownDirectionException {
|
throws UnknownDirectionException {
|
||||||
int xm = 0;
|
int xm = 0;
|
||||||
int ym = 0;
|
int ym = 0;
|
||||||
int zm = 0;
|
int zm = 0;
|
||||||
|
|
||||||
if (dir.equals("me")) {
|
WorldEditPlayer.DIRECTION dir = null;
|
||||||
|
|
||||||
|
if (dirStr.equals("me")) {
|
||||||
dir = player.getCardinalDirection();
|
dir = player.getCardinalDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.charAt(0) == 'w') {
|
if (dirStr.charAt(0) == 'u' || dir == WorldEditPlayer.DIRECTION.WEST) {
|
||||||
zm += 1;
|
zm += 1;
|
||||||
} else if (dir.charAt(0) == 'e') {
|
} else if (dirStr.charAt(0) == 'e' || dir == WorldEditPlayer.DIRECTION.EAST) {
|
||||||
zm -= 1;
|
zm -= 1;
|
||||||
} else if (dir.charAt(0) == 's') {
|
} else if (dirStr.charAt(0) == 's' || dir == WorldEditPlayer.DIRECTION.SOUTH) {
|
||||||
xm += 1;
|
xm += 1;
|
||||||
} else if (dir.charAt(0) == 'n') {
|
} else if (dirStr.charAt(0) == 'n' || dir == WorldEditPlayer.DIRECTION.NORTH) {
|
||||||
xm -= 1;
|
xm -= 1;
|
||||||
} else if (dir.charAt(0) == 'u') {
|
} else if (dirStr.charAt(0) == 'u') {
|
||||||
ym += 1;
|
ym += 1;
|
||||||
} else if (dir.charAt(0) == 'd') {
|
} else if (dirStr.charAt(0) == 'd') {
|
||||||
ym -= 1;
|
ym -= 1;
|
||||||
} else {
|
} else {
|
||||||
throw new UnknownDirectionException(dir);
|
throw new UnknownDirectionException(dirStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Vector(xm, ym, zm);
|
return new Vector(xm, ym, zm);
|
||||||
@ -1634,26 +1644,28 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CuboidClipboard.FlipDirection getFlipDirection(
|
public CuboidClipboard.FlipDirection getFlipDirection(
|
||||||
WorldEditPlayer player, String dir)
|
WorldEditPlayer player, String dirStr)
|
||||||
throws UnknownDirectionException {
|
throws UnknownDirectionException {
|
||||||
if (dir.equals("me")) {
|
WorldEditPlayer.DIRECTION dir = null;
|
||||||
|
|
||||||
|
if (dirStr.equals("me")) {
|
||||||
dir = player.getCardinalDirection();
|
dir = player.getCardinalDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.charAt(0) == 'w') {
|
if (dirStr.charAt(0) == 'w' || dir == WorldEditPlayer.DIRECTION.EAST) {
|
||||||
return CuboidClipboard.FlipDirection.WEST_EAST;
|
return CuboidClipboard.FlipDirection.WEST_EAST;
|
||||||
} else if (dir.charAt(0) == 'e') {
|
} else if (dirStr.charAt(0) == 'e' || dir == WorldEditPlayer.DIRECTION.EAST) {
|
||||||
return CuboidClipboard.FlipDirection.WEST_EAST;
|
return CuboidClipboard.FlipDirection.WEST_EAST;
|
||||||
} else if (dir.charAt(0) == 's') {
|
} else if (dirStr.charAt(0) == 's' || dir == WorldEditPlayer.DIRECTION.SOUTH) {
|
||||||
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
|
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
|
||||||
} else if (dir.charAt(0) == 'n') {
|
} else if (dirStr.charAt(0) == 'n' || dir == WorldEditPlayer.DIRECTION.SOUTH) {
|
||||||
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
|
return CuboidClipboard.FlipDirection.NORTH_SOUTH;
|
||||||
} else if (dir.charAt(0) == 'u') {
|
} else if (dirStr.charAt(0) == 'u') {
|
||||||
return CuboidClipboard.FlipDirection.UP_DOWN;
|
return CuboidClipboard.FlipDirection.UP_DOWN;
|
||||||
} else if (dir.charAt(0) == 'd') {
|
} else if (dirStr.charAt(0) == 'd') {
|
||||||
return CuboidClipboard.FlipDirection.UP_DOWN;
|
return CuboidClipboard.FlipDirection.UP_DOWN;
|
||||||
} else {
|
} else {
|
||||||
throw new UnknownDirectionException(dir);
|
throw new UnknownDirectionException(dirStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1691,7 +1703,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(Player player) {
|
public void onDisconnect(Player player) {
|
||||||
removeSession(new WorldEditPlayer(player));
|
removeSession(new HMPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1700,9 +1712,10 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void onArmSwing(Player modPlayer) {
|
public void onArmSwing(Player modPlayer) {
|
||||||
if (!canUseCommand(modPlayer, "//")) { return; }
|
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||||
|
|
||||||
|
if (!canUseCommand(player, "//")) { return; }
|
||||||
|
|
||||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
|
||||||
WorldEditSession session = getSession(player);
|
WorldEditSession session = getSession(player);
|
||||||
|
|
||||||
if (player.isHoldingPickAxe()) {
|
if (player.isHoldingPickAxe()) {
|
||||||
@ -1746,16 +1759,16 @@ public class WorldEditListener extends PluginListener {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
|
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
|
||||||
Block blockClicked, int itemInHand) {
|
Block blockClicked, int itemInHand) {
|
||||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||||
|
|
||||||
// This prevents needless sessions from being created
|
// This prevents needless sessions from being created
|
||||||
if (!hasSession(player) && !(itemInHand == wandItem &&
|
if (!hasSession(player) && !(itemInHand == wandItem &&
|
||||||
canUseCommand(modPlayer, "//pos2"))) { return false; }
|
canUseCommand(player, "//pos2"))) { return false; }
|
||||||
|
|
||||||
WorldEditSession session = getSession(player);
|
WorldEditSession session = getSession(player);
|
||||||
|
|
||||||
if (itemInHand == wandItem && session.isToolControlEnabled()
|
if (itemInHand == wandItem && session.isToolControlEnabled()
|
||||||
&& canUseCommand(modPlayer, "//pos2")) {
|
&& canUseCommand(player, "//pos2")) {
|
||||||
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
|
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
|
||||||
blockClicked.getY(),
|
blockClicked.getY(),
|
||||||
blockClicked.getZ());
|
blockClicked.getZ());
|
||||||
@ -1779,7 +1792,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
new EditSession(session.getBlockChangeLimit());
|
new EditSession(session.getBlockChangeLimit());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!ServerInterface.generateTree(editSession, pos)) {
|
if (!server.generateTree(editSession, pos)) {
|
||||||
player.printError("Notch won't let you put a tree there.");
|
player.printError("Notch won't let you put a tree there.");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -1793,7 +1806,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
blockClicked.getY(),
|
blockClicked.getY(),
|
||||||
blockClicked.getZ());
|
blockClicked.getZ());
|
||||||
|
|
||||||
BaseBlock block = EditSession.rawGetBlock(pos);
|
BaseBlock block = (new EditSession(0)).rawGetBlock(pos);
|
||||||
|
|
||||||
player.printRaw(Colors.LightPurple + "@" + pos + ": " + Colors.Yellow
|
player.printRaw(Colors.LightPurple + "@" + pos + ": " + Colors.Yellow
|
||||||
+ "Type: " + block.getID() + Colors.LightGray + " ("
|
+ "Type: " + block.getID() + Colors.LightGray + " ("
|
||||||
@ -1821,10 +1834,11 @@ public class WorldEditListener extends PluginListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockDestroy(Player modPlayer, Block blockClicked) {
|
public boolean onBlockDestroy(Player modPlayer, Block blockClicked) {
|
||||||
if (!canUseCommand(modPlayer, "//pos1")
|
WorldEditPlayer player = new HMPlayer(modPlayer);
|
||||||
&& !canUseCommand(modPlayer, "//")) { return false; }
|
|
||||||
|
if (!canUseCommand(player, "//pos1")
|
||||||
|
&& !canUseCommand(player, "//")) { return false; }
|
||||||
|
|
||||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
|
||||||
WorldEditSession session = getSession(player);
|
WorldEditSession session = getSession(player);
|
||||||
|
|
||||||
if (player.getItemInHand() == wandItem) {
|
if (player.getItemInHand() == wandItem) {
|
||||||
@ -1858,23 +1872,23 @@ public class WorldEditListener extends PluginListener {
|
|||||||
}
|
}
|
||||||
} else if (player.isHoldingPickAxe()) {
|
} else if (player.isHoldingPickAxe()) {
|
||||||
if (session.hasSuperPickAxe()) {
|
if (session.hasSuperPickAxe()) {
|
||||||
boolean canBedrock = canUseCommand(modPlayer, "/worldeditbedrock");
|
boolean canBedrock = canUseCommand(player, "/worldeditbedrock");
|
||||||
|
|
||||||
// Single block super pickaxe
|
// Single block super pickaxe
|
||||||
if (session.getSuperPickaxeMode() ==
|
if (session.getSuperPickaxeMode() ==
|
||||||
WorldEditSession.SuperPickaxeMode.SINGLE) {
|
WorldEditSession.SuperPickaxeMode.SINGLE) {
|
||||||
Vector pos = new Vector(blockClicked.getX(),
|
Vector pos = new Vector(blockClicked.getX(),
|
||||||
blockClicked.getY(), blockClicked.getZ());
|
blockClicked.getY(), blockClicked.getZ());
|
||||||
if (ServerInterface.getBlockType(pos) == 7 && !canBedrock) {
|
if (server.getBlockType(pos) == 7 && !canBedrock) {
|
||||||
return true;
|
return true;
|
||||||
} else if (ServerInterface.getBlockType(pos) == 46) {
|
} else if (server.getBlockType(pos) == 46) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (superPickaxeDrop) {
|
if (superPickaxeDrop) {
|
||||||
ServerInterface.simulateBlockMine(pos);
|
server.simulateBlockMine(pos);
|
||||||
} else {
|
} else {
|
||||||
ServerInterface.setBlockType(pos, 0);
|
server.setBlockType(pos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Area super pickaxe
|
// Area super pickaxe
|
||||||
@ -1886,7 +1900,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
int oy = blockClicked.getY();
|
int oy = blockClicked.getY();
|
||||||
int oz = blockClicked.getZ();
|
int oz = blockClicked.getZ();
|
||||||
int size = session.getSuperPickaxeRange();
|
int size = session.getSuperPickaxeRange();
|
||||||
int initialType = ServerInterface.getBlockType(origin);
|
int initialType = server.getBlockType(origin);
|
||||||
|
|
||||||
if (initialType == 7 && !canBedrock) {
|
if (initialType == 7 && !canBedrock) {
|
||||||
return true;
|
return true;
|
||||||
@ -1896,11 +1910,11 @@ public class WorldEditListener extends PluginListener {
|
|||||||
for (int y = oy - size; y <= oy + size; y++) {
|
for (int y = oy - size; y <= oy + size; y++) {
|
||||||
for (int z = oz - size; z <= oz + size; z++) {
|
for (int z = oz - size; z <= oz + size; z++) {
|
||||||
Vector pos = new Vector(x, y, z);
|
Vector pos = new Vector(x, y, z);
|
||||||
if (ServerInterface.getBlockType(pos) == initialType) {
|
if (server.getBlockType(pos) == initialType) {
|
||||||
if (superPickaxeManyDrop) {
|
if (superPickaxeManyDrop) {
|
||||||
ServerInterface.simulateBlockMine(pos);
|
server.simulateBlockMine(pos);
|
||||||
} else {
|
} else {
|
||||||
ServerInterface.setBlockType(pos, 0);
|
server.setBlockType(pos, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1915,7 +1929,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
Vector origin = new Vector(blockClicked.getX(),
|
Vector origin = new Vector(blockClicked.getX(),
|
||||||
blockClicked.getY(), blockClicked.getZ());
|
blockClicked.getY(), blockClicked.getZ());
|
||||||
int size = session.getSuperPickaxeRange();
|
int size = session.getSuperPickaxeRange();
|
||||||
int initialType = ServerInterface.getBlockType(origin);
|
int initialType = server.getBlockType(origin);
|
||||||
|
|
||||||
if (initialType == 7 && !canBedrock) {
|
if (initialType == 7 && !canBedrock) {
|
||||||
return true;
|
return true;
|
||||||
@ -1949,11 +1963,11 @@ public class WorldEditListener extends PluginListener {
|
|||||||
|
|
||||||
visited.add(pos);
|
visited.add(pos);
|
||||||
|
|
||||||
if (ServerInterface.getBlockType(pos) == initialType) {
|
if (server.getBlockType(pos) == initialType) {
|
||||||
if (superPickaxeManyDrop) {
|
if (superPickaxeManyDrop) {
|
||||||
ServerInterface.simulateBlockMine(pos);
|
server.simulateBlockMine(pos);
|
||||||
} else {
|
} else {
|
||||||
ServerInterface.setBlockType(pos, 0);
|
server.setBlockType(pos, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -1999,8 +2013,9 @@ public class WorldEditListener extends PluginListener {
|
|||||||
split[0] = split[0].substring(1);
|
split[0] = split[0].substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canUseCommand(ply, split[0])) {
|
WorldEditPlayer player = new HMPlayer(ply);
|
||||||
WorldEditPlayer player = new WorldEditPlayer(ply);
|
|
||||||
|
if (canUseCommand(player, split[0])) {
|
||||||
WorldEditSession session = getSession(player);
|
WorldEditSession session = getSession(player);
|
||||||
BlockBag blockBag = session.getBlockBag(player);
|
BlockBag blockBag = session.getBlockBag(player);
|
||||||
|
|
||||||
@ -2108,30 +2123,19 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* @param command
|
* @param command
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean canUseCommand(Player player, String command) {
|
private boolean canUseCommand(WorldEditPlayer player, String command) {
|
||||||
// Allow the /worldeditselect permission
|
// Allow the /worldeditselect permission
|
||||||
if (command.equalsIgnoreCase("//pos1")
|
if (command.equalsIgnoreCase("//pos1")
|
||||||
|| command.equalsIgnoreCase("//pos2")
|
|| command.equalsIgnoreCase("//pos2")
|
||||||
|| command.equalsIgnoreCase("//hpos1")
|
|| command.equalsIgnoreCase("//hpos1")
|
||||||
|| command.equalsIgnoreCase("//hpos2")) {
|
|| command.equalsIgnoreCase("//hpos2")) {
|
||||||
return player.canUseCommand(command)
|
return player.hasPermission(command)
|
||||||
|| player.canUseCommand("/worldeditselect")
|
|| player.hasPermission("/worldeditselect")
|
||||||
|| player.canUseCommand("/worldedit");
|
|| player.hasPermission("/worldedit");
|
||||||
}
|
}
|
||||||
|
|
||||||
return player.canUseCommand(command.replace("air", ""))
|
return player.hasPermission(command.replace("air", ""))
|
||||||
|| player.canUseCommand("/worldedit");
|
|| player.hasPermission("/worldedit");
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if the player can use a command or /worldedit.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @param command
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean canUseCommand(WorldEditPlayer player, String command) {
|
|
||||||
return canUseCommand(player.getPlayerObject(), command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2228,7 +2232,7 @@ public class WorldEditListener extends PluginListener {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public WorldEditSession _bridgeSession(Player pl) {
|
public WorldEditSession _bridgeSession(Player pl) {
|
||||||
WorldEditPlayer player = new WorldEditPlayer(pl);
|
WorldEditPlayer player = new HMPlayer(pl);
|
||||||
|
|
||||||
if (sessions.containsKey(player)) {
|
if (sessions.containsKey(player)) {
|
||||||
return sessions.get(player);
|
return sessions.get(player);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
package com.sk89q.worldedit;
|
||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldEdit
|
* WorldEdit
|
@ -17,6 +17,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -49,6 +51,11 @@ public class EditSession {
|
|||||||
*/
|
*/
|
||||||
private static Random prng = new Random();
|
private static Random prng = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server interface.
|
||||||
|
*/
|
||||||
|
private ServerInterface server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the original blocks before modification.
|
* Stores the original blocks before modification.
|
||||||
*/
|
*/
|
||||||
@ -97,6 +104,7 @@ public class EditSession {
|
|||||||
throw new IllegalArgumentException("Max blocks must be >= -1");
|
throw new IllegalArgumentException("Max blocks must be >= -1");
|
||||||
}
|
}
|
||||||
this.maxBlocks = maxBlocks;
|
this.maxBlocks = maxBlocks;
|
||||||
|
server = ServerInterface.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,6 +116,7 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
this.maxBlocks = maxBlocks;
|
this.maxBlocks = maxBlocks;
|
||||||
this.blockBag = blockBag;
|
this.blockBag = blockBag;
|
||||||
|
server = ServerInterface.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,14 +133,14 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear the chest so that it doesn't drop items
|
// Clear the chest so that it doesn't drop items
|
||||||
if (ServerInterface.getBlockType(pt) == 54 && blockBag == null) {
|
if (server.getBlockType(pt) == 54 && blockBag == null) {
|
||||||
ServerInterface.clearChest(pt);
|
server.clearChest(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = block.getID();
|
int id = block.getID();
|
||||||
|
|
||||||
if (blockBag != null) {
|
if (blockBag != null) {
|
||||||
int existing = ServerInterface.getBlockType(pt);
|
int existing = server.getBlockType(pt);
|
||||||
|
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
try {
|
try {
|
||||||
@ -152,25 +161,25 @@ public class EditSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = ServerInterface.setBlockType(pt, id);
|
boolean result = server.setBlockType(pt, id);
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
if (BlockType.usesData(id)) {
|
if (BlockType.usesData(id)) {
|
||||||
ServerInterface.setBlockData(pt, block.getData());
|
server.setBlockData(pt, block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signs
|
// Signs
|
||||||
if (block instanceof SignBlock) {
|
if (block instanceof SignBlock) {
|
||||||
SignBlock signBlock = (SignBlock)block;
|
SignBlock signBlock = (SignBlock)block;
|
||||||
String[] text = signBlock.getText();
|
String[] text = signBlock.getText();
|
||||||
ServerInterface.setSignText(pt, text);
|
server.setSignText(pt, text);
|
||||||
// Chests
|
// Chests
|
||||||
} else if (block instanceof ChestBlock && blockBag == null) {
|
} else if (block instanceof ChestBlock && blockBag == null) {
|
||||||
ChestBlock chestBlock = (ChestBlock)block;
|
ChestBlock chestBlock = (ChestBlock)block;
|
||||||
ServerInterface.setChestContents(pt, chestBlock.getItems());
|
server.setChestContents(pt, chestBlock.getItems());
|
||||||
// Mob spawners
|
// Mob spawners
|
||||||
} else if (block instanceof MobSpawnerBlock) {
|
} else if (block instanceof MobSpawnerBlock) {
|
||||||
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block;
|
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block;
|
||||||
ServerInterface.setMobSpawnerType(pt, mobSpawnerblock.getMobType());
|
server.setMobSpawnerType(pt, mobSpawnerblock.getMobType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,22 +280,22 @@ public class EditSession {
|
|||||||
* @param pt
|
* @param pt
|
||||||
* @return BaseBlock
|
* @return BaseBlock
|
||||||
*/
|
*/
|
||||||
public static BaseBlock rawGetBlock(Vector pt) {
|
public BaseBlock rawGetBlock(Vector pt) {
|
||||||
int type = ServerInterface.getBlockType(pt);
|
int type = server.getBlockType(pt);
|
||||||
int data = ServerInterface.getBlockData(pt);
|
int data = server.getBlockData(pt);
|
||||||
|
|
||||||
// Sign
|
// Sign
|
||||||
if (type == 63 || type == 68) {
|
if (type == 63 || type == 68) {
|
||||||
String[] text = ServerInterface.getSignText(pt);
|
String[] text = server.getSignText(pt);
|
||||||
return new SignBlock(type, data, text);
|
return new SignBlock(type, data, text);
|
||||||
// Chest
|
// Chest
|
||||||
} else if (type == 54) {
|
} else if (type == 54) {
|
||||||
BaseItemStack[] items =
|
BaseItemStack[] items =
|
||||||
ServerInterface.getChestContents(pt);
|
server.getChestContents(pt);
|
||||||
return new ChestBlock(data, items);
|
return new ChestBlock(data, items);
|
||||||
// Mob spawner
|
// Mob spawner
|
||||||
} else if (type == 52) {
|
} else if (type == 52) {
|
||||||
return new MobSpawnerBlock(data, ServerInterface.getMobSpawnerType(pt));
|
return new MobSpawnerBlock(data, server.getMobSpawnerType(pt));
|
||||||
} else {
|
} else {
|
||||||
return new BaseBlock(type, data);
|
return new BaseBlock(type, data);
|
||||||
}
|
}
|
||||||
@ -1728,7 +1737,7 @@ public class EditSession {
|
|||||||
if (pineTree) {
|
if (pineTree) {
|
||||||
makePineTree(new Vector(x, y + 1, z));
|
makePineTree(new Vector(x, y + 1, z));
|
||||||
} else {
|
} else {
|
||||||
ServerInterface.generateTree(this, new Vector(x, y + 1, z));
|
server.generateTree(this, new Vector(x, y + 1, z));
|
||||||
}
|
}
|
||||||
affected++;
|
affected++;
|
||||||
break;
|
break;
|
194
src/com/sk89q/worldedit/ServerInterface.java
Normal file
194
src/com/sk89q/worldedit/ServerInterface.java
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
package com.sk89q.worldedit;
|
||||||
|
// $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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public abstract class ServerInterface {
|
||||||
|
/**
|
||||||
|
* Instance.
|
||||||
|
*/
|
||||||
|
private static ServerInterface instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current instance.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ServerInterface getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up an instance.
|
||||||
|
* @param instance
|
||||||
|
*/
|
||||||
|
public static void setup(ServerInterface instance) {
|
||||||
|
ServerInterface.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set block type.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean setBlockType(Vector pt, int type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get block type.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract int getBlockType(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set block data.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract void setBlockData(Vector pt, int data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get block data.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract int getBlockData(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set sign text.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
|
public abstract void setSignText(Vector pt, String[] text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get sign text.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String[] getSignText(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the contents of chests. Will return null if the chest does not
|
||||||
|
* really exist or it is the second block for a double chest.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract BaseItemStack[] getChestContents(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a chest slot.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param contents
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean setChestContents(Vector pt, BaseItemStack[] contents);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear a chest's contents.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
*/
|
||||||
|
public abstract boolean clearChest(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a mob type is valid.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean isValidMobType(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set mob spawner mob type.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param mobType
|
||||||
|
*/
|
||||||
|
public abstract void setMobSpawnerType(Vector pt, String mobType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mob spawner mob type. May return an empty string.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param mobType
|
||||||
|
*/
|
||||||
|
public abstract String getMobSpawnerType(Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a tree at a location.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean generateTree(EditSession editSession, Vector pt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop an item.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param type
|
||||||
|
* @param count
|
||||||
|
* @param times
|
||||||
|
*/
|
||||||
|
public abstract void dropItem(Vector pt, int type, int count, int times);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop an item.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param type
|
||||||
|
* @param count
|
||||||
|
* @param times
|
||||||
|
*/
|
||||||
|
public abstract void dropItem(Vector pt, int type, int count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop an item.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
* @param type
|
||||||
|
* @param count
|
||||||
|
* @param times
|
||||||
|
*/
|
||||||
|
public abstract void dropItem(Vector pt, int type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate a block being mined.
|
||||||
|
*
|
||||||
|
* @param pt
|
||||||
|
*/
|
||||||
|
public abstract void simulateBlockMine(Vector pt);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldEditLibrary
|
* WorldEdit
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -17,26 +17,40 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldEditPlayer {
|
public abstract class WorldEditPlayer {
|
||||||
/**
|
/**
|
||||||
* Stores the player.
|
* Directions.
|
||||||
*/
|
*/
|
||||||
private Player player;
|
public enum DIRECTION {
|
||||||
|
NORTH,
|
||||||
|
NORTH_EAST,
|
||||||
|
EAST,
|
||||||
|
SOUTH_EAST,
|
||||||
|
SOUTH,
|
||||||
|
SOUTH_WEST,
|
||||||
|
WEST,
|
||||||
|
NORTH_WEST
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server.
|
||||||
|
*/
|
||||||
|
protected ServerInterface server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
*/
|
||||||
public WorldEditPlayer(Player player) {
|
protected WorldEditPlayer() {
|
||||||
this.player = player;
|
server = ServerInterface.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,15 +64,6 @@ public class WorldEditPlayer {
|
|||||||
|| item == 285;
|
|| item == 285;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Move the player.
|
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
*/
|
|
||||||
public void setPosition(Vector pos) {
|
|
||||||
setPosition(pos, (float)getPitch(), (float)getYaw());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a position for the player to stand that is not inside a block.
|
* 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
|
* Blocks above the player will be iteratively tested until there is
|
||||||
@ -76,7 +81,7 @@ public class WorldEditPlayer {
|
|||||||
byte free = 0;
|
byte free = 0;
|
||||||
|
|
||||||
while (y <= 129) {
|
while (y <= 129) {
|
||||||
if (BlockType.canPassThrough(etc.getServer().getBlockIdAt(x, y, z))) {
|
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||||
free++;
|
free++;
|
||||||
} else {
|
} else {
|
||||||
free = 0;
|
free = 0;
|
||||||
@ -119,7 +124,7 @@ public class WorldEditPlayer {
|
|||||||
byte spots = 0;
|
byte spots = 0;
|
||||||
|
|
||||||
while (y <= 129) {
|
while (y <= 129) {
|
||||||
if (BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
|
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||||
free++;
|
free++;
|
||||||
} else {
|
} else {
|
||||||
free = 0;
|
free = 0;
|
||||||
@ -128,7 +133,7 @@ public class WorldEditPlayer {
|
|||||||
if (free == 2) {
|
if (free == 2) {
|
||||||
spots++;
|
spots++;
|
||||||
if (spots == 2) {
|
if (spots == 2) {
|
||||||
int type = ServerInterface.getBlockType(new Vector(x, y - 2, z));
|
int type = server.getBlockType(new Vector(x, y - 2, z));
|
||||||
|
|
||||||
// Don't get put in lava!
|
// Don't get put in lava!
|
||||||
if (type == 10 || type == 11) {
|
if (type == 10 || type == 11) {
|
||||||
@ -160,7 +165,7 @@ public class WorldEditPlayer {
|
|||||||
byte free = 0;
|
byte free = 0;
|
||||||
|
|
||||||
while (y >= 1) {
|
while (y >= 1) {
|
||||||
if (BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
|
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||||
free++;
|
free++;
|
||||||
} else {
|
} else {
|
||||||
free = 0;
|
free = 0;
|
||||||
@ -171,7 +176,7 @@ public class WorldEditPlayer {
|
|||||||
// lightly and also check to see if there's something to
|
// lightly and also check to see if there's something to
|
||||||
// stand upon
|
// stand upon
|
||||||
while (y >= 0) {
|
while (y >= 0) {
|
||||||
int type = ServerInterface.getBlockType(new Vector(x, y, z));
|
int type = server.getBlockType(new Vector(x, y, z));
|
||||||
|
|
||||||
// Don't want to end up in lava
|
// Don't want to end up in lava
|
||||||
if (type != 0 && type != 10 && type != 11) {
|
if (type != 0 && type != 10 && type != 11) {
|
||||||
@ -206,15 +211,15 @@ public class WorldEditPlayer {
|
|||||||
int z = pos.getBlockZ();
|
int z = pos.getBlockZ();
|
||||||
|
|
||||||
// No free space above
|
// No free space above
|
||||||
if (ServerInterface.getBlockType(new Vector(x, y, z)) != 0) {
|
if (server.getBlockType(new Vector(x, y, z)) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (y <= 127) {
|
while (y <= 127) {
|
||||||
// Found a ceiling!
|
// Found a ceiling!
|
||||||
if (!BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
|
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||||
int platformY = Math.max(initialY, y - 3 - clearance);
|
int platformY = Math.max(initialY, y - 3 - clearance);
|
||||||
ServerInterface.setBlockType(new Vector(x, platformY, z),
|
server.setBlockType(new Vector(x, platformY, z),
|
||||||
BlockType.GLASS.getID());
|
BlockType.GLASS.getID());
|
||||||
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
|
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
|
||||||
return true;
|
return true;
|
||||||
@ -241,12 +246,12 @@ public class WorldEditPlayer {
|
|||||||
int maxY = Math.min(128, initialY + distance);
|
int maxY = Math.min(128, initialY + distance);
|
||||||
|
|
||||||
while (y <= 129) {
|
while (y <= 129) {
|
||||||
if (!BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
|
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
|
||||||
break; // Hit something
|
break; // Hit something
|
||||||
} else if (y > maxY + 1) {
|
} else if (y > maxY + 1) {
|
||||||
break;
|
break;
|
||||||
} else if (y == maxY + 1) {
|
} else if (y == maxY + 1) {
|
||||||
ServerInterface.setBlockType(new Vector(x, y - 2, z),
|
server.setBlockType(new Vector(x, y - 2, z),
|
||||||
BlockType.GLASS.getID());
|
BlockType.GLASS.getID());
|
||||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||||
return true;
|
return true;
|
||||||
@ -258,6 +263,206 @@ public class WorldEditPlayer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the point of the block that is being stood in.
|
||||||
|
*
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public Vector getBlockIn() {
|
||||||
|
return getPosition().toBlockVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the point of the block that is being stood upon.
|
||||||
|
*
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public Vector getBlockOn() {
|
||||||
|
return getPosition().subtract(0, 1, 0).toBlockVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the point of the block being looked at. May return null.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public abstract Vector getBlockTrace(int range);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the point of the block being looked at. May return null.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public abstract Vector getSolidBlockTrace(int range);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WorldEditPlayer.DIRECTION getCardinalDirection() {
|
||||||
|
// From hey0's code
|
||||||
|
double rot = (getYaw() - 90) % 360;
|
||||||
|
if (rot < 0) {
|
||||||
|
rot += 360.0;
|
||||||
|
}
|
||||||
|
return getDirection(rot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns direction according to rotation. May return null.
|
||||||
|
*
|
||||||
|
* @param rot
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static WorldEditPlayer.DIRECTION getDirection(double rot) {
|
||||||
|
if (0 <= rot && rot < 22.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.NORTH;
|
||||||
|
} else if (22.5 <= rot && rot < 67.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.NORTH_EAST;
|
||||||
|
} else if (67.5 <= rot && rot < 112.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.EAST;
|
||||||
|
} else if (112.5 <= rot && rot < 157.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.SOUTH_EAST;
|
||||||
|
} else if (157.5 <= rot && rot < 202.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.SOUTH;
|
||||||
|
} else if (202.5 <= rot && rot < 247.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.SOUTH_WEST;
|
||||||
|
} else if (247.5 <= rot && rot < 292.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.WEST;
|
||||||
|
} else if (292.5 <= rot && rot < 337.5) {
|
||||||
|
return WorldEditPlayer.DIRECTION.NORTH_WEST;
|
||||||
|
} else if (337.5 <= rot && rot < 360.0) {
|
||||||
|
return WorldEditPlayer.DIRECTION.NORTH;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the item that the player is holding.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract int getItemInHand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the player.
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's position.
|
||||||
|
*
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
|
public abstract Vector getPosition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's view pitch.
|
||||||
|
*
|
||||||
|
* @return pitch
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Get the player's view pitch.
|
||||||
|
*
|
||||||
|
* @return pitch
|
||||||
|
*/
|
||||||
|
public abstract double getPitch();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's view yaw.
|
||||||
|
*
|
||||||
|
* @return yaw
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Get the player's view yaw.
|
||||||
|
*
|
||||||
|
* @return yaw
|
||||||
|
*/
|
||||||
|
public abstract double getYaw();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives the player an item.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param amt
|
||||||
|
*/
|
||||||
|
public abstract void giveItem(int type, int amt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass through the wall that you are looking at.
|
||||||
|
*
|
||||||
|
* @param range
|
||||||
|
* @return whether the player was pass through
|
||||||
|
*/
|
||||||
|
public abstract boolean passThroughForwardWall(int range);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a message.
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public abstract void printRaw(String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a WorldEdit message.
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public abstract void print(String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a WorldEdit 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.
|
||||||
|
*
|
||||||
|
* @param pos
|
||||||
|
*/
|
||||||
|
public void setPosition(Vector pos) {
|
||||||
|
setPosition(pos, (float)getPitch(), (float)getYaw());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a player's list of groups.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String[] getGroups();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get this player's block bag.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract BlockBag getInventoryBlockBag();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a player has permission.
|
||||||
|
*
|
||||||
|
* @param perm
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean hasPermission(String perm);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if equal.
|
* Returns true if equal.
|
||||||
*
|
*
|
||||||
@ -282,239 +487,4 @@ public class WorldEditPlayer {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getName().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 point of the block being looked at. May return null.
|
|
||||||
*
|
|
||||||
* @param range
|
|
||||||
* @return point
|
|
||||||
*/
|
|
||||||
public Vector getSolidBlockTrace(int range) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the player
|
|
||||||
*/
|
|
||||||
public Player getPlayerObject() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
package com.sk89q.worldedit;
|
||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldEdit
|
* WorldEdit
|
||||||
@ -22,6 +23,7 @@ import com.sk89q.worldedit.bags.BlockBag;
|
|||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +355,7 @@ public class WorldEditSession {
|
|||||||
if (!useInventory) {
|
if (!useInventory) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ServerInterface.getPlayerBlockBag(player);
|
return player.getInventoryBlockBag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,3 +1,4 @@
|
|||||||
|
package com.sk89q.worldedit.snapshots;
|
||||||
// $Id$
|
// $Id$
|
||||||
/*
|
/*
|
||||||
* WorldEdit
|
* WorldEdit
|
Loading…
Reference in New Issue
Block a user