Initial abstraction.

Dieser Commit ist enthalten in:
sk89q 2010-12-31 17:06:42 -08:00
Ursprung 162fd3148d
Commit ecce855db2
11 geänderte Dateien mit 1196 neuen und 749 gelöschten Zeilen

273
src/HMPlayer.java Normale Datei
Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -1,403 +1,394 @@
// $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.*;
import com.sk89q.worldedit.blocks.BaseItemStack;
import java.util.logging.Logger;
import java.util.Random;
/**
*
* @author sk89q
*/
public class ServerInterface {
/**
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* Random generator.
*/
private static Random random = new Random();
/**
* Set block type.
*
* @param pt
* @param type
* @return
*/
public static boolean setBlockType(Vector pt, int type) {
// Can't set colored cloth or crash
if ((type >= 21 && type <= 34) || type == 36) {
return false;
}
return etc.getServer().setBlockAt(type, pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Get block type.
*
* @param pt
* @return
*/
public static int getBlockType(Vector pt) {
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Set block data.
*
* @param pt
* @param data
* @return
*/
public static void setBlockData(Vector pt, int data) {
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data);
}
/**
* Get block data.
*
* @param pt
* @return
*/
public static int getBlockData(Vector pt) {
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Set sign text.
*
* @param pt
* @param text
*/
public static void setSignText(Vector pt, String[] text) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
return;
}
for (byte i = 0; i < 4; i++) {
signData.setText(i, text[i]);
}
signData.update();
}
/**
* Get sign text.
*
* @param pt
* @return
*/
public static String[] getSignText(Vector pt) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
return new String[]{"", "", "", ""};
}
String[] text = new String[4];
for (byte i = 0; i < 4; i++) {
text[i] = signData.getText(i);
}
return text;
}
/**
* 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 static BaseItemStack[] getChestContents(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
BaseItemStack[] items;
Item[] nativeItems;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
nativeItems = chest.getContents();
} else {
return null;
}
items = new BaseItemStack[nativeItems.length];
for (byte i = 0; i < nativeItems.length; i++) {
Item item = nativeItems[i];
if (item != null) {
items[i] = new BaseItemStack((short)item.getItemId(),
item.getAmount(), (short)item.getDamage());
}
}
return items;
}
/**
* Sets a chest slot.
*
* @param pt
* @param contents
* @return
*/
public static boolean setChestContents(Vector pt,
BaseItemStack[] contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
Item[] nativeItems = new Item[contents.length];
for (int i = 0; i < contents.length; i++) {
BaseItemStack item = contents[i];
if (item != null) {
Item nativeItem =
new Item(item.getID(), item.getAmount());
nativeItem.setDamage(item.getDamage());
nativeItems[i] = nativeItem;
}
}
setContents(chest, nativeItems);
}
return false;
}
/**
* Clear a chest's contents.
*
* @param pt
*/
public static boolean clearChest(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
chest.clearContents();
chest.update();
return true;
}
return false;
}
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
private static void setContents(ItemArray<?> itemArray, Item[] contents) {
int size = contents.length;
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i].getItemId(),
contents[i].getAmount(), contents[i].getDamage(), i);
}
}
}
/**
* Checks if a mob type is valid.
*
* @param type
* @return
*/
public static boolean isValidMobType(String type) {
return Mob.isValid(type);
}
/**
* Set mob spawner mob type.
*
* @param pt
* @param mobType
*/
public static void setMobSpawnerType(Vector pt, String mobType) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof MobSpawner)) {
return;
}
MobSpawner mobSpawner = (MobSpawner)cblock;
mobSpawner.setSpawn(mobType);
mobSpawner.update();
}
/**
* Get mob spawner mob type. May return an empty string.
*
* @param pt
* @param mobType
*/
public static String getMobSpawnerType(Vector pt) {
try {
return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) {
logger.severe("Failed to get mob spawner type (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
return "";
}
}
/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
public static boolean generateTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) {
logger.severe("Failed to create tree (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
return false;
}
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public static void dropItem(Vector pt, int type, int count, int times) {
for (int i = 0; i < times; i++) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public static void dropItem(Vector pt, int type, int count) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public static void dropItem(Vector pt, int type) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
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.
*
* @param pt
*/
public static void simulateBlockMine(Vector pt) {
int type = getBlockType(pt);
setBlockType(pt, 0);
if (type == 1) { dropItem(pt, 4); } // Stone
else if (type == 2) { dropItem(pt, 3); } // Grass
else if (type == 7) { } // Bedrock
else if (type == 8) { } // Water
else if (type == 9) { } // Water
else if (type == 10) { } // Lava
else if (type == 11) { } // Lava
else if (type == 13) { // Gravel
dropItem(pt, type);
if (random.nextDouble() >= 0.9) {
dropItem(pt, 318);
}
}
else if (type == 16) { dropItem(pt, 263); } // Coal ore
else if (type == 18) { // Leaves
if (random.nextDouble() > 0.95) {
dropItem(pt, 6);
}
}
else if (type == 20) { } // Glass
else if (type == 43) { dropItem(pt, 44); } // Double step
else if (type == 47) { } // Bookshelves
else if (type == 51) { } // Fire
else if (type == 52) { } // Mob spawner
else if (type == 53) { dropItem(pt, 5); } // Wooden stairs
else if (type == 55) { dropItem(pt, 331); } // Redstone wire
else if (type == 56) { dropItem(pt, 264); } // Diamond ore
else if (type == 59) { dropItem(pt, 295); } // Crops
else if (type == 60) { dropItem(pt, 3); } // Soil
else if (type == 62) { dropItem(pt, 61); } // Furnace
else if (type == 63) { dropItem(pt, 323); } // Sign post
else if (type == 64) { dropItem(pt, 324); } // Wood door
else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs
else if (type == 68) { dropItem(pt, 323); } // Wall sign
else if (type == 71) { dropItem(pt, 330); } // Iron door
else if (type == 73) { dropItem(pt, 331, 1, 4); } // Redstone ore
else if (type == 74) { dropItem(pt, 331, 1, 4); } // Glowing redstone ore
else if (type == 75) { dropItem(pt, 76); } // Redstone torch
else if (type == 78) { } // Snow
else if (type == 79) { } // Ice
else if (type == 82) { dropItem(pt, 337, 1, 4); } // Clay
else if (type == 83) { dropItem(pt, 338); } // Reed
else if (type == 89) { dropItem(pt, 348); } // Lightstone
else if (type == 90) { } // Portal
else if (type != 0) {
dropItem(pt, type);
}
}
}
// $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.*;
import com.sk89q.worldedit.blocks.BaseItemStack;
import java.util.logging.Logger;
import java.util.Random;
/**
*
* @author sk89q
*/
public class HMServerInterface extends ServerInterface {
/**
* Logger.
*/
private final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/**
* Random generator.
*/
private Random random = new Random();
/**
* Set block type.
*
* @param pt
* @param type
* @return
*/
public boolean setBlockType(Vector pt, int type) {
// Can't set colored cloth or crash
if ((type >= 21 && type <= 34) || type == 36) {
return false;
}
return etc.getServer().setBlockAt(type, pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Get block type.
*
* @param pt
* @return
*/
public int getBlockType(Vector pt) {
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Set block data.
*
* @param pt
* @param data
* @return
*/
public void setBlockData(Vector pt, int data) {
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data);
}
/**
* Get block data.
*
* @param pt
* @return
*/
public int getBlockData(Vector pt) {
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ());
}
/**
* Set sign text.
*
* @param pt
* @param text
*/
public void setSignText(Vector pt, String[] text) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
return;
}
for (byte i = 0; i < 4; i++) {
signData.setText(i, text[i]);
}
signData.update();
}
/**
* Get sign text.
*
* @param pt
* @return
*/
public String[] getSignText(Vector pt) {
Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) {
return new String[]{"", "", "", ""};
}
String[] text = new String[4];
for (byte i = 0; i < 4; i++) {
text[i] = signData.getText(i);
}
return text;
}
/**
* 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 BaseItemStack[] getChestContents(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
BaseItemStack[] items;
Item[] nativeItems;
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
nativeItems = chest.getContents();
} else {
return null;
}
items = new BaseItemStack[nativeItems.length];
for (byte i = 0; i < nativeItems.length; i++) {
Item item = nativeItems[i];
if (item != null) {
items[i] = new BaseItemStack((short)item.getItemId(),
item.getAmount(), (short)item.getDamage());
}
}
return items;
}
/**
* Sets a chest slot.
*
* @param pt
* @param contents
* @return
*/
public boolean setChestContents(Vector pt,
BaseItemStack[] contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
Item[] nativeItems = new Item[contents.length];
for (int i = 0; i < contents.length; i++) {
BaseItemStack item = contents[i];
if (item != null) {
Item nativeItem =
new Item(item.getID(), item.getAmount());
nativeItem.setDamage(item.getDamage());
nativeItems[i] = nativeItem;
}
}
setContents(chest, nativeItems);
}
return false;
}
/**
* Clear a chest's contents.
*
* @param pt
*/
public boolean clearChest(Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (cblock instanceof Chest) {
Chest chest = (Chest)cblock;
chest.clearContents();
chest.update();
return true;
}
return false;
}
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
private void setContents(ItemArray<?> itemArray, Item[] contents) {
int size = contents.length;
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i].getItemId(),
contents[i].getAmount(), contents[i].getDamage(), i);
}
}
}
/**
* Checks if a mob type is valid.
*
* @param type
* @return
*/
public boolean isValidMobType(String type) {
return Mob.isValid(type);
}
/**
* Set mob spawner mob type.
*
* @param pt
* @param mobType
*/
public void setMobSpawnerType(Vector pt, String mobType) {
ComplexBlock cblock = etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (!(cblock instanceof MobSpawner)) {
return;
}
MobSpawner mobSpawner = (MobSpawner)cblock;
mobSpawner.setSpawn(mobType);
mobSpawner.update();
}
/**
* Get mob spawner mob type. May return an empty string.
*
* @param pt
* @param mobType
*/
public String getMobSpawnerType(Vector pt) {
try {
return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) {
logger.severe("Failed to get mob spawner type (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
return "";
}
}
/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
public boolean generateTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) {
logger.severe("Failed to create tree (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
return false;
}
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public void dropItem(Vector pt, int type, int count, int times) {
for (int i = 0; i < times; i++) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public void dropItem(Vector pt, int type, int count) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count);
}
/**
* Drop an item.
*
* @param pt
* @param type
* @param count
* @param times
*/
public void dropItem(Vector pt, int type) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, 1);
}
/**
* Simulate a block being mined.
*
* @param pt
*/
public void simulateBlockMine(Vector pt) {
int type = getBlockType(pt);
setBlockType(pt, 0);
if (type == 1) { dropItem(pt, 4); } // Stone
else if (type == 2) { dropItem(pt, 3); } // Grass
else if (type == 7) { } // Bedrock
else if (type == 8) { } // Water
else if (type == 9) { } // Water
else if (type == 10) { } // Lava
else if (type == 11) { } // Lava
else if (type == 13) { // Gravel
dropItem(pt, type);
if (random.nextDouble() >= 0.9) {
dropItem(pt, 318);
}
}
else if (type == 16) { dropItem(pt, 263); } // Coal ore
else if (type == 18) { // Leaves
if (random.nextDouble() > 0.95) {
dropItem(pt, 6);
}
}
else if (type == 20) { } // Glass
else if (type == 43) { dropItem(pt, 44); } // Double step
else if (type == 47) { } // Bookshelves
else if (type == 51) { } // Fire
else if (type == 52) { } // Mob spawner
else if (type == 53) { dropItem(pt, 5); } // Wooden stairs
else if (type == 55) { dropItem(pt, 331); } // Redstone wire
else if (type == 56) { dropItem(pt, 264); } // Diamond ore
else if (type == 59) { dropItem(pt, 295); } // Crops
else if (type == 60) { dropItem(pt, 3); } // Soil
else if (type == 62) { dropItem(pt, 61); } // Furnace
else if (type == 63) { dropItem(pt, 323); } // Sign post
else if (type == 64) { dropItem(pt, 324); } // Wood door
else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs
else if (type == 68) { dropItem(pt, 323); } // Wall sign
else if (type == 71) { dropItem(pt, 330); } // Iron door
else if (type == 73) { dropItem(pt, 331, 1, 4); } // Redstone ore
else if (type == 74) { dropItem(pt, 331, 1, 4); } // Glowing redstone ore
else if (type == 75) { dropItem(pt, 76); } // Redstone torch
else if (type == 78) { } // Snow
else if (type == 79) { } // Ice
else if (type == 82) { dropItem(pt, 337, 1, 4); } // Clay
else if (type == 83) { dropItem(pt, 338); } // Reed
else if (type == 89) { dropItem(pt, 348); } // Lightstone
else if (type == 90) { } // Portal
else if (type != 0) {
dropItem(pt, type);
}
}
}

Datei anzeigen

@ -17,6 +17,7 @@
* 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.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;

Datei anzeigen

@ -17,6 +17,7 @@
* 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.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;

Datei anzeigen

@ -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,
61, 62, 67, 73, 78, 79, 80, 82, 85, 86, 87, 88, 89, 91
};
/**
* Server interface.
*/
private ServerInterface server;
/**
* WorldEditLibrary's properties file.
*/
@ -97,6 +103,8 @@ public class WorldEditListener extends PluginListener {
* Construct an instance of the plugin.
*/
public WorldEditListener() {
server = ServerInterface.getInstance();
// Note: Commands should only have the phrase 'air' at the end
// for now (see SMWorldEditListener.canUseCommand)
commands.put("//pos1", "Set editing position #1");
@ -184,7 +192,7 @@ public class WorldEditListener extends PluginListener {
return sessions.get(player);
} else {
WorldEditSession session = new WorldEditSession();
if (!player.getPlayerObject().canUseCommand("/worldeditnomax")
if (!player.hasPermission("/worldeditnomax")
&& maxChangeLimit > -1) {
if (defaultChangeLimit < 0) {
// No infinite!
@ -199,7 +207,7 @@ public class WorldEditListener extends PluginListener {
}
session.setUseInventory(useInventory
&& (!useInventoryOverride
|| !player.getPlayerObject().canUseCommand("/worldeditunlimited")));
|| !player.hasPermission("/worldeditunlimited")));
sessions.put(player, session);
return session;
}
@ -272,7 +280,7 @@ public class WorldEditListener extends PluginListener {
return new SignBlock(blockType.getID(), data, text);
} else if (blockType == BlockType.MOB_SPAWNER) {
if (args0.length > 1) {
if (!ServerInterface.isValidMobType(args0[1])) {
if (!server.isValidMobType(args0[1])) {
throw new InvalidItemException(arg, "Unknown mob type '" + args0[1] + "'");
}
return new MobSpawnerBlock(data, args0[1]);
@ -599,7 +607,7 @@ public class WorldEditListener extends PluginListener {
} else if (split[0].equalsIgnoreCase("//limit")) {
checkArgs(split, 1, 1, split[0]);
int limit = Math.max(-1, Integer.parseInt(split[1]));
if (!player.getPlayerObject().canUseCommand("/worldeditnomax")
if (!player.hasPermission("/worldeditnomax")
&& maxChangeLimit > -1) {
if (limit > maxChangeLimit) {
player.printError("Your maximum allowable limit is " + maxChangeLimit + ".");
@ -1596,30 +1604,32 @@ public class WorldEditListener extends PluginListener {
* @param dir
* @return
*/
public Vector getDirection(WorldEditPlayer player, String dir)
public Vector getDirection(WorldEditPlayer player, String dirStr)
throws UnknownDirectionException {
int xm = 0;
int ym = 0;
int zm = 0;
WorldEditPlayer.DIRECTION dir = null;
if (dir.equals("me")) {
if (dirStr.equals("me")) {
dir = player.getCardinalDirection();
}
if (dir.charAt(0) == 'w') {
if (dirStr.charAt(0) == 'u' || dir == WorldEditPlayer.DIRECTION.WEST) {
zm += 1;
} else if (dir.charAt(0) == 'e') {
} else if (dirStr.charAt(0) == 'e' || dir == WorldEditPlayer.DIRECTION.EAST) {
zm -= 1;
} else if (dir.charAt(0) == 's') {
} else if (dirStr.charAt(0) == 's' || dir == WorldEditPlayer.DIRECTION.SOUTH) {
xm += 1;
} else if (dir.charAt(0) == 'n') {
} else if (dirStr.charAt(0) == 'n' || dir == WorldEditPlayer.DIRECTION.NORTH) {
xm -= 1;
} else if (dir.charAt(0) == 'u') {
} else if (dirStr.charAt(0) == 'u') {
ym += 1;
} else if (dir.charAt(0) == 'd') {
} else if (dirStr.charAt(0) == 'd') {
ym -= 1;
} else {
throw new UnknownDirectionException(dir);
throw new UnknownDirectionException(dirStr);
}
return new Vector(xm, ym, zm);
@ -1634,26 +1644,28 @@ public class WorldEditListener extends PluginListener {
* @return
*/
public CuboidClipboard.FlipDirection getFlipDirection(
WorldEditPlayer player, String dir)
WorldEditPlayer player, String dirStr)
throws UnknownDirectionException {
if (dir.equals("me")) {
WorldEditPlayer.DIRECTION dir = null;
if (dirStr.equals("me")) {
dir = player.getCardinalDirection();
}
if (dir.charAt(0) == 'w') {
if (dirStr.charAt(0) == 'w' || dir == WorldEditPlayer.DIRECTION.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;
} else if (dir.charAt(0) == 's') {
} else if (dirStr.charAt(0) == 's' || dir == WorldEditPlayer.DIRECTION.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;
} else if (dir.charAt(0) == 'u') {
} else if (dirStr.charAt(0) == 'u') {
return CuboidClipboard.FlipDirection.UP_DOWN;
} else if (dir.charAt(0) == 'd') {
} else if (dirStr.charAt(0) == 'd') {
return CuboidClipboard.FlipDirection.UP_DOWN;
} else {
throw new UnknownDirectionException(dir);
throw new UnknownDirectionException(dirStr);
}
}
@ -1691,7 +1703,7 @@ public class WorldEditListener extends PluginListener {
*/
@Override
public void onDisconnect(Player player) {
removeSession(new WorldEditPlayer(player));
removeSession(new HMPlayer(player));
}
/**
@ -1700,9 +1712,10 @@ public class WorldEditListener extends PluginListener {
* @param player
*/
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);
if (player.isHoldingPickAxe()) {
@ -1746,16 +1759,16 @@ public class WorldEditListener extends PluginListener {
@SuppressWarnings("deprecation")
public boolean onBlockCreate(Player modPlayer, Block blockPlaced,
Block blockClicked, int itemInHand) {
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
WorldEditPlayer player = new HMPlayer(modPlayer);
// This prevents needless sessions from being created
if (!hasSession(player) && !(itemInHand == wandItem &&
canUseCommand(modPlayer, "//pos2"))) { return false; }
canUseCommand(player, "//pos2"))) { return false; }
WorldEditSession session = getSession(player);
if (itemInHand == wandItem && session.isToolControlEnabled()
&& canUseCommand(modPlayer, "//pos2")) {
&& canUseCommand(player, "//pos2")) {
Vector cur = Vector.toBlockPoint(blockClicked.getX(),
blockClicked.getY(),
blockClicked.getZ());
@ -1779,7 +1792,7 @@ public class WorldEditListener extends PluginListener {
new EditSession(session.getBlockChangeLimit());
try {
if (!ServerInterface.generateTree(editSession, pos)) {
if (!server.generateTree(editSession, pos)) {
player.printError("Notch won't let you put a tree there.");
}
} finally {
@ -1793,7 +1806,7 @@ public class WorldEditListener extends PluginListener {
blockClicked.getY(),
blockClicked.getZ());
BaseBlock block = EditSession.rawGetBlock(pos);
BaseBlock block = (new EditSession(0)).rawGetBlock(pos);
player.printRaw(Colors.LightPurple + "@" + pos + ": " + Colors.Yellow
+ "Type: " + block.getID() + Colors.LightGray + " ("
@ -1821,10 +1834,11 @@ public class WorldEditListener extends PluginListener {
*/
@Override
public boolean onBlockDestroy(Player modPlayer, Block blockClicked) {
if (!canUseCommand(modPlayer, "//pos1")
&& !canUseCommand(modPlayer, "//")) { return false; }
WorldEditPlayer player = new HMPlayer(modPlayer);
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
if (!canUseCommand(player, "//pos1")
&& !canUseCommand(player, "//")) { return false; }
WorldEditSession session = getSession(player);
if (player.getItemInHand() == wandItem) {
@ -1858,23 +1872,23 @@ public class WorldEditListener extends PluginListener {
}
} else if (player.isHoldingPickAxe()) {
if (session.hasSuperPickAxe()) {
boolean canBedrock = canUseCommand(modPlayer, "/worldeditbedrock");
boolean canBedrock = canUseCommand(player, "/worldeditbedrock");
// Single block super pickaxe
if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SINGLE) {
Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(), blockClicked.getZ());
if (ServerInterface.getBlockType(pos) == 7 && !canBedrock) {
if (server.getBlockType(pos) == 7 && !canBedrock) {
return true;
} else if (ServerInterface.getBlockType(pos) == 46) {
} else if (server.getBlockType(pos) == 46) {
return false;
}
if (superPickaxeDrop) {
ServerInterface.simulateBlockMine(pos);
server.simulateBlockMine(pos);
} else {
ServerInterface.setBlockType(pos, 0);
server.setBlockType(pos, 0);
}
// Area super pickaxe
@ -1886,7 +1900,7 @@ public class WorldEditListener extends PluginListener {
int oy = blockClicked.getY();
int oz = blockClicked.getZ();
int size = session.getSuperPickaxeRange();
int initialType = ServerInterface.getBlockType(origin);
int initialType = server.getBlockType(origin);
if (initialType == 7 && !canBedrock) {
return true;
@ -1896,11 +1910,11 @@ public class WorldEditListener extends PluginListener {
for (int y = oy - size; y <= oy + size; y++) {
for (int z = oz - size; z <= oz + size; z++) {
Vector pos = new Vector(x, y, z);
if (ServerInterface.getBlockType(pos) == initialType) {
if (server.getBlockType(pos) == initialType) {
if (superPickaxeManyDrop) {
ServerInterface.simulateBlockMine(pos);
server.simulateBlockMine(pos);
} else {
ServerInterface.setBlockType(pos, 0);
server.setBlockType(pos, 0);
}
}
}
@ -1915,7 +1929,7 @@ public class WorldEditListener extends PluginListener {
Vector origin = new Vector(blockClicked.getX(),
blockClicked.getY(), blockClicked.getZ());
int size = session.getSuperPickaxeRange();
int initialType = ServerInterface.getBlockType(origin);
int initialType = server.getBlockType(origin);
if (initialType == 7 && !canBedrock) {
return true;
@ -1949,11 +1963,11 @@ public class WorldEditListener extends PluginListener {
visited.add(pos);
if (ServerInterface.getBlockType(pos) == initialType) {
if (server.getBlockType(pos) == initialType) {
if (superPickaxeManyDrop) {
ServerInterface.simulateBlockMine(pos);
server.simulateBlockMine(pos);
} else {
ServerInterface.setBlockType(pos, 0);
server.setBlockType(pos, 0);
}
} else {
return;
@ -1998,9 +2012,10 @@ public class WorldEditListener extends PluginListener {
} else if (commands.containsKey(searchCmd.substring(1))) {
split[0] = split[0].substring(1);
}
WorldEditPlayer player = new HMPlayer(ply);
if (canUseCommand(ply, split[0])) {
WorldEditPlayer player = new WorldEditPlayer(ply);
if (canUseCommand(player, split[0])) {
WorldEditSession session = getSession(player);
BlockBag blockBag = session.getBlockBag(player);
@ -2108,30 +2123,19 @@ public class WorldEditListener extends PluginListener {
* @param command
* @return
*/
private boolean canUseCommand(Player player, String command) {
private boolean canUseCommand(WorldEditPlayer player, String command) {
// Allow the /worldeditselect permission
if (command.equalsIgnoreCase("//pos1")
|| command.equalsIgnoreCase("//pos2")
|| command.equalsIgnoreCase("//hpos1")
|| command.equalsIgnoreCase("//hpos2")) {
return player.canUseCommand(command)
|| player.canUseCommand("/worldeditselect")
|| player.canUseCommand("/worldedit");
return player.hasPermission(command)
|| player.hasPermission("/worldeditselect")
|| player.hasPermission("/worldedit");
}
return player.canUseCommand(command.replace("air", ""))
|| player.canUseCommand("/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);
return player.hasPermission(command.replace("air", ""))
|| player.hasPermission("/worldedit");
}
/**
@ -2228,7 +2232,7 @@ public class WorldEditListener extends PluginListener {
* @return
*/
public WorldEditSession _bridgeSession(Player pl) {
WorldEditPlayer player = new WorldEditPlayer(pl);
WorldEditPlayer player = new HMPlayer(pl);
if (sessions.containsKey(player)) {
return sessions.get(player);

Datei anzeigen

@ -1,3 +1,4 @@
package com.sk89q.worldedit;
// $Id$
/*
* WorldEdit

Datei anzeigen

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
import java.util.Map;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -49,6 +51,11 @@ public class EditSession {
*/
private static Random prng = new Random();
/**
* Server interface.
*/
private ServerInterface server;
/**
* Stores the original blocks before modification.
*/
@ -97,6 +104,7 @@ public class EditSession {
throw new IllegalArgumentException("Max blocks must be >= -1");
}
this.maxBlocks = maxBlocks;
server = ServerInterface.getInstance();
}
/**
@ -108,6 +116,7 @@ public class EditSession {
}
this.maxBlocks = maxBlocks;
this.blockBag = blockBag;
server = ServerInterface.getInstance();
}
/**
@ -124,14 +133,14 @@ public class EditSession {
}
// Clear the chest so that it doesn't drop items
if (ServerInterface.getBlockType(pt) == 54 && blockBag == null) {
ServerInterface.clearChest(pt);
if (server.getBlockType(pt) == 54 && blockBag == null) {
server.clearChest(pt);
}
int id = block.getID();
if (blockBag != null) {
int existing = ServerInterface.getBlockType(pt);
int existing = server.getBlockType(pt);
if (id > 0) {
try {
@ -152,25 +161,25 @@ public class EditSession {
}
}
boolean result = ServerInterface.setBlockType(pt, id);
boolean result = server.setBlockType(pt, id);
if (id != 0) {
if (BlockType.usesData(id)) {
ServerInterface.setBlockData(pt, block.getData());
server.setBlockData(pt, block.getData());
}
// Signs
if (block instanceof SignBlock) {
SignBlock signBlock = (SignBlock)block;
String[] text = signBlock.getText();
ServerInterface.setSignText(pt, text);
server.setSignText(pt, text);
// Chests
} else if (block instanceof ChestBlock && blockBag == null) {
ChestBlock chestBlock = (ChestBlock)block;
ServerInterface.setChestContents(pt, chestBlock.getItems());
server.setChestContents(pt, chestBlock.getItems());
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block;
ServerInterface.setMobSpawnerType(pt, mobSpawnerblock.getMobType());
server.setMobSpawnerType(pt, mobSpawnerblock.getMobType());
}
}
@ -271,22 +280,22 @@ public class EditSession {
* @param pt
* @return BaseBlock
*/
public static BaseBlock rawGetBlock(Vector pt) {
int type = ServerInterface.getBlockType(pt);
int data = ServerInterface.getBlockData(pt);
public BaseBlock rawGetBlock(Vector pt) {
int type = server.getBlockType(pt);
int data = server.getBlockData(pt);
// Sign
if (type == 63 || type == 68) {
String[] text = ServerInterface.getSignText(pt);
String[] text = server.getSignText(pt);
return new SignBlock(type, data, text);
// Chest
} else if (type == 54) {
BaseItemStack[] items =
ServerInterface.getChestContents(pt);
server.getChestContents(pt);
return new ChestBlock(data, items);
// Mob spawner
} else if (type == 52) {
return new MobSpawnerBlock(data, ServerInterface.getMobSpawnerType(pt));
return new MobSpawnerBlock(data, server.getMobSpawnerType(pt));
} else {
return new BaseBlock(type, data);
}
@ -1728,7 +1737,7 @@ public class EditSession {
if (pineTree) {
makePineTree(new Vector(x, y + 1, z));
} else {
ServerInterface.generateTree(this, new Vector(x, y + 1, z));
server.generateTree(this, new Vector(x, y + 1, z));
}
affected++;
break;

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -1,6 +1,6 @@
// $Id$
/*
* WorldEditLibrary
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
@ -17,28 +17,42 @@
* 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;
/**
*
* @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.
*
* @param player
*/
public WorldEditPlayer(Player player) {
this.player = player;
protected WorldEditPlayer() {
server = ServerInterface.getInstance();
}
/**
* Returns true if the player is holding a pick axe.
*
@ -50,15 +64,6 @@ public class WorldEditPlayer {
|| 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.
* Blocks above the player will be iteratively tested until there is
@ -76,7 +81,7 @@ public class WorldEditPlayer {
byte free = 0;
while (y <= 129) {
if (BlockType.canPassThrough(etc.getServer().getBlockIdAt(x, y, z))) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -119,7 +124,7 @@ public class WorldEditPlayer {
byte spots = 0;
while (y <= 129) {
if (BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -128,7 +133,7 @@ public class WorldEditPlayer {
if (free == 2) {
spots++;
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!
if (type == 10 || type == 11) {
@ -160,7 +165,7 @@ public class WorldEditPlayer {
byte free = 0;
while (y >= 1) {
if (BlockType.canPassThrough(ServerInterface.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -171,7 +176,7 @@ public class WorldEditPlayer {
// lightly and also check to see if there's something to
// stand upon
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
if (type != 0 && type != 10 && type != 11) {
@ -206,15 +211,15 @@ public class WorldEditPlayer {
int z = pos.getBlockZ();
// No free space above
if (ServerInterface.getBlockType(new Vector(x, y, z)) != 0) {
if (server.getBlockType(new Vector(x, y, z)) != 0) {
return false;
}
while (y <= 127) {
// 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);
ServerInterface.setBlockType(new Vector(x, platformY, z),
server.setBlockType(new Vector(x, platformY, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
return true;
@ -241,12 +246,12 @@ public class WorldEditPlayer {
int maxY = Math.min(128, initialY + distance);
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
} else if (y > maxY + 1) {
break;
} else if (y == maxY + 1) {
ServerInterface.setBlockType(new Vector(x, y - 2, z),
server.setBlockType(new Vector(x, y - 2, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
return true;
@ -258,6 +263,206 @@ public class WorldEditPlayer {
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.
*
@ -282,239 +487,4 @@ public class WorldEditPlayer {
public int hashCode() {
return getName().hashCode();
}
/**
* Get the point of the block that is being stood in.
*
* @return point
*/
public Vector getBlockIn() {
return Vector.toBlockPoint(player.getX(), player.getY(), player.getZ());
}
/**
* Get the point of the block that is being stood upon.
*
* @return point
*/
public Vector getBlockOn() {
return Vector.toBlockPoint(player.getX(), player.getY() - 1, player.getZ());
}
/**
* Get the point of the block being looked at. May return null.
*
* @param range
* @return point
*/
public Vector getBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = hitBlox.getTargetBlock();
if (block == null) {
return null;
}
return new Vector(block.getX(), block.getY(), block.getZ());
}
/**
* Get the 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;
}
}

Datei anzeigen

@ -1,3 +1,4 @@
package com.sk89q.worldedit;
// $Id$
/*
* WorldEdit
@ -22,6 +23,7 @@ import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.*;
import java.util.LinkedList;
/**
@ -353,7 +355,7 @@ public class WorldEditSession {
if (!useInventory) {
return null;
}
return ServerInterface.getPlayerBlockBag(player);
return player.getInventoryBlockBag();
}
/**

Datei anzeigen

@ -1,3 +1,4 @@
package com.sk89q.worldedit.snapshots;
// $Id$
/*
* WorldEdit