Merge branch 'master' into bukkit

This commit is contained in:
sk89q
2011-01-02 17:09:11 -08:00
86 changed files with 7676 additions and 909 deletions

View File

@ -0,0 +1,101 @@
// $Id$
/*
* 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/>.
*/
package com.sk89q.util;
/**
* String utilities.
*
* @author sk89q
*/
public class StringUtil {
/**
* Trim a string if it is longer than a certain length.
*
* @param str
* @param len
* @return
*/
public static String trimLength(String str, int len) {
if (str.length() > len) {
return str.substring(0, len);
}
return str;
}
/**
* Join an array of strings into a string.
*
* @param str
* @param delimiter
* @param initialIndex
* @return
*/
public static String joinString(String[] str, String delimiter,
int initialIndex) {
if (str.length == 0) {
return "";
}
StringBuilder buffer = new StringBuilder(str[initialIndex]);
for (int i = initialIndex + 1; i < str.length; i++) {
buffer.append(delimiter).append(str[i]);
}
return buffer.toString();
}
/**
* Join an array of strings into a string.
*
* @param str
* @param delimiter
* @param initialIndex
* @return
*/
public static String joinString(Object[] str, String delimiter,
int initialIndex) {
if (str.length == 0) {
return "";
}
StringBuilder buffer = new StringBuilder(str[initialIndex].toString());
for (int i = initialIndex + 1; i < str.length; i++) {
buffer.append(delimiter).append(str[i].toString());
}
return buffer.toString();
}
/**
* Join an array of strings into a string.
*
* @param str
* @param delimiter
* @param initialIndex
* @return
*/
public static String joinString(int[] str, String delimiter,
int initialIndex) {
if (str.length == 0) {
return "";
}
StringBuilder buffer = new StringBuilder(Integer.toString(str[initialIndex]));
for (int i = initialIndex + 1; i < str.length; i++) {
buffer.append(delimiter).append(Integer.toString(str[i]));
}
return buffer.toString();
}
}

View File

@ -0,0 +1,101 @@
// $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/>.
*/
package com.sk89q.worldedit;
/**
* Extension of Vector that supports being compared as ints (for accuracy).
*
* @author sk89q
*/
public class BlockWorldVector extends WorldVector {
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(WorldVector pt) {
super(pt.getWorld(), pt);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, Vector pt) {
super(world, pt);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, int x, int y, int z) {
super(world, x, y, z);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, float x, float y, float z) {
super(world, x, y, z);
}
/**
* Construct the Vector object.
*
* @param pt
*/
public BlockWorldVector(LocalWorld world, double x, double y, double z) {
super(world, x, y, z);
}
/**
* Checks if another object is equivalent.
*
* @param obj
* @return whether the other object is equivalent
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof WorldVector)) {
return false;
}
WorldVector other = (WorldVector)obj;
return (int)other.x == (int)this.x && (int)other.y == (int)this.y
&& (int)other.z == (int)this.z;
}
/**
* Gets the hash code.
*
* @return hash code
*/
@Override
public int hashCode() {
return (Integer.valueOf((int)x).hashCode() >> 13) ^
(Integer.valueOf((int)y).hashCode() >> 7) ^
Integer.valueOf((int)z).hashCode();
}
}

View File

@ -1,4 +1,3 @@
package com.sk89q.worldedit;
// $Id$
/*
* WorldEdit
@ -18,7 +17,8 @@ package com.sk89q.worldedit;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.sk89q.worldedit.*;
package com.sk89q.worldedit;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.data.*;
import org.jnbt.*;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
// $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/>.
*/
package com.sk89q.worldedit;
import java.util.Set;
import com.sk89q.worldedit.snapshots.SnapshotRepository;
/**
* Represents WorldEdit's configuration.
*
* @author sk89q
*/
public abstract class LocalConfiguration {
protected static final int[] defaultDisallowedBlocks = new int[] {
6, 7, 14, 15, 16, 21, 22, 23, 24, 25, 26, 27, 28, 29, 39, 31,
32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74,
75, 76, 77, 81, 83
};
public boolean profile = false;
public Set<Integer> disallowedBlocks = null;
public int defaultChangeLimit = -1;
public int maxChangeLimit = -1;
public String shellSaveType = null;
public SnapshotRepository snapshotRepo = null;
public int maxRadius = -1;
public int maxSuperPickaxeSize = 5;
public boolean logComands = false;
public boolean registerHelp = true;
public int wandItem = 271;
public boolean superPickaxeDrop = true;
public boolean superPickaxeManyDrop = true;
public boolean noDoubleSlash = false;
public boolean useInventory = false;
public boolean useInventoryOverride = false;
/**
* Loads the configuration.
*/
public abstract void load();
}

View File

@ -26,7 +26,7 @@ import com.sk89q.worldedit.blocks.BlockType;
*
* @author sk89q
*/
public abstract class WorldEditPlayer {
public abstract class LocalPlayer {
/**
* Directions.
*/
@ -48,9 +48,11 @@ public abstract class WorldEditPlayer {
/**
* Construct the object.
*
* @param server
*/
protected WorldEditPlayer() {
server = ServerInterface.getInstance();
protected LocalPlayer(ServerInterface server) {
this.server = server;
}
/**
@ -72,7 +74,7 @@ public abstract class WorldEditPlayer {
*
* @param searchPos search position
*/
public void findFreePosition(Vector searchPos) {
public void findFreePosition(LocalWorld world, Vector searchPos) {
int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY());
int origY = y;
@ -81,7 +83,8 @@ public abstract class WorldEditPlayer {
byte free = 0;
while (y <= 129) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world,
new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -106,7 +109,7 @@ public abstract class WorldEditPlayer {
* that free position.
*/
public void findFreePosition() {
findFreePosition(getBlockIn());
findFreePosition(getPosition().getWorld(), getBlockIn());
}
/**
@ -119,12 +122,13 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0;
byte spots = 0;
while (y <= 129) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -133,7 +137,7 @@ public abstract class WorldEditPlayer {
if (free == 2) {
spots++;
if (spots == 2) {
int type = server.getBlockType(new Vector(x, y - 2, z));
int type = server.getBlockType(world, new Vector(x, y - 2, z));
// Don't get put in lava!
if (type == 10 || type == 11) {
@ -161,11 +165,12 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY() - 1);
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0;
while (y >= 1) {
if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
free++;
} else {
free = 0;
@ -176,7 +181,7 @@ public abstract class WorldEditPlayer {
// lightly and also check to see if there's something to
// stand upon
while (y >= 0) {
int type = server.getBlockType(new Vector(x, y, z));
int type = server.getBlockType(world, new Vector(x, y, z));
// Don't want to end up in lava
if (type != 0 && type != 10 && type != 11) {
@ -209,17 +214,18 @@ public abstract class WorldEditPlayer {
int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2);
int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
// No free space above
if (server.getBlockType(new Vector(x, y, z)) != 0) {
if (server.getBlockType(world, new Vector(x, y, z)) != 0) {
return false;
}
while (y <= 127) {
// Found a ceiling!
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
int platformY = Math.max(initialY, y - 3 - clearance);
server.setBlockType(new Vector(x, platformY, z),
server.setBlockType(world, new Vector(x, platformY, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
return true;
@ -244,14 +250,15 @@ public abstract class WorldEditPlayer {
int y = Math.max(0, pos.getBlockY() + 1);
int z = pos.getBlockZ();
int maxY = Math.min(128, initialY + distance);
LocalWorld world = getPosition().getWorld();
while (y <= 129) {
if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) {
if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) {
break; // Hit something
} else if (y > maxY + 1) {
break;
} else if (y == maxY + 1) {
server.setBlockType(new Vector(x, y - 2, z),
server.setBlockType(world, new Vector(x, y - 2, z),
BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
return true;
@ -268,8 +275,8 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public Vector getBlockIn() {
return getPosition().toBlockVector();
public WorldVector getBlockIn() {
return getPosition();
}
/**
@ -277,8 +284,9 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public Vector getBlockOn() {
return getPosition().subtract(0, 1, 0).toBlockVector();
public WorldVector getBlockOn() {
WorldVector pos = getPosition();
return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0));
}
/**
@ -287,7 +295,7 @@ public abstract class WorldEditPlayer {
* @param range
* @return point
*/
public abstract Vector getBlockTrace(int range);
public abstract WorldVector getBlockTrace(int range);
/**
* Get the point of the block being looked at. May return null.
@ -295,14 +303,14 @@ public abstract class WorldEditPlayer {
* @param range
* @return point
*/
public abstract Vector getSolidBlockTrace(int range);
public abstract WorldVector getSolidBlockTrace(int range);
/**
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
*
* @return
*/
public WorldEditPlayer.DIRECTION getCardinalDirection() {
public LocalPlayer.DIRECTION getCardinalDirection() {
// From hey0's code
double rot = (getYaw() - 90) % 360;
if (rot < 0) {
@ -317,25 +325,25 @@ public abstract class WorldEditPlayer {
* @param rot
* @return
*/
private static WorldEditPlayer.DIRECTION getDirection(double rot) {
private static LocalPlayer.DIRECTION getDirection(double rot) {
if (0 <= rot && rot < 22.5) {
return WorldEditPlayer.DIRECTION.NORTH;
return LocalPlayer.DIRECTION.NORTH;
} else if (22.5 <= rot && rot < 67.5) {
return WorldEditPlayer.DIRECTION.NORTH_EAST;
return LocalPlayer.DIRECTION.NORTH_EAST;
} else if (67.5 <= rot && rot < 112.5) {
return WorldEditPlayer.DIRECTION.EAST;
return LocalPlayer.DIRECTION.EAST;
} else if (112.5 <= rot && rot < 157.5) {
return WorldEditPlayer.DIRECTION.SOUTH_EAST;
return LocalPlayer.DIRECTION.SOUTH_EAST;
} else if (157.5 <= rot && rot < 202.5) {
return WorldEditPlayer.DIRECTION.SOUTH;
return LocalPlayer.DIRECTION.SOUTH;
} else if (202.5 <= rot && rot < 247.5) {
return WorldEditPlayer.DIRECTION.SOUTH_WEST;
return LocalPlayer.DIRECTION.SOUTH_WEST;
} else if (247.5 <= rot && rot < 292.5) {
return WorldEditPlayer.DIRECTION.WEST;
return LocalPlayer.DIRECTION.WEST;
} else if (292.5 <= rot && rot < 337.5) {
return WorldEditPlayer.DIRECTION.NORTH_WEST;
return LocalPlayer.DIRECTION.NORTH_WEST;
} else if (337.5 <= rot && rot < 360.0) {
return WorldEditPlayer.DIRECTION.NORTH;
return LocalPlayer.DIRECTION.NORTH;
} else {
return null;
}
@ -360,7 +368,14 @@ public abstract class WorldEditPlayer {
*
* @return point
*/
public abstract Vector getPosition();
public abstract WorldVector getPosition();
/**
* Get the player's world.
*
* @return point
*/
public abstract LocalWorld getWorld();
/**
* Get the player's view pitch.
@ -462,6 +477,15 @@ public abstract class WorldEditPlayer {
* @return
*/
public abstract boolean hasPermission(String perm);
/**
* Returns true if the player can destroy bedrock.
*
* @return
*/
public boolean canDestroyBedrock() {
return hasPermission("worldeditbedrock");
}
/**
* Returns true if equal.
@ -471,10 +495,10 @@ public abstract class WorldEditPlayer {
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof WorldEditPlayer)) {
if (!(other instanceof LocalPlayer)) {
return false;
}
WorldEditPlayer other2 = (WorldEditPlayer)other;
LocalPlayer other2 = (LocalPlayer)other;
return other2.getName().equals(getName());
}

View File

@ -21,6 +21,8 @@ package com.sk89q.worldedit;
import java.util.LinkedList;
import com.sk89q.worldedit.snapshots.Snapshot;
import com.sk89q.worldedit.superpickaxe.SinglePickaxe;
import com.sk89q.worldedit.superpickaxe.SuperPickaxeMode;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -29,25 +31,9 @@ import com.sk89q.worldedit.regions.CuboidRegion;
*
* @author sk89q
*/
public class WorldEditSession {
/**
* List of super pick axe modes.
*/
public static enum SuperPickaxeMode {
SINGLE,
SAME_TYPE_RECURSIVE,
SAME_TYPE_AREA
};
/**
* List of tools.
*/
public static enum Tool {
NONE,
INFO,
TREE,
}
public class LocalSession {
public static final int MAX_HISTORY_SIZE = 15;
private boolean placeAtPos1 = false;
private Vector pos1, pos2;
private Region region;
@ -55,10 +41,9 @@ public class WorldEditSession {
private int historyPointer = 0;
private CuboidClipboard clipboard;
private boolean toolControl = true;
private boolean superPickAxe = false;
private SuperPickaxeMode superPickaxeMode = SuperPickaxeMode.SINGLE;
private Tool tool = Tool.NONE;
private int superPickaxeRange = 3;
private boolean superPickaxe = false;
private SuperPickaxeMode superPickaxeMode = new SinglePickaxe();
private SuperPickaxeMode tool;
private int maxBlocksChanged = -1;
private boolean useInventory;
private Snapshot snapshot;
@ -291,25 +276,25 @@ public class WorldEditSession {
* @return status
*/
public boolean hasSuperPickAxe() {
return superPickAxe;
return superPickaxe;
}
/**
* Enable super pick axe.
*
* @param superPickAxe
* @param superPickaxe
*/
public void enableSuperPickAxe() {
superPickAxe = true;
superPickaxe = true;
}
/**
* Disable super pick axe.
*
* @param superPickAxe
* @param superPickaxe
*/
public void disableSuperPickAxe() {
superPickAxe = false;
superPickaxe = false;
}
/**
@ -318,15 +303,15 @@ public class WorldEditSession {
* @return status
*/
public boolean toggleSuperPickAxe() {
superPickAxe = !superPickAxe;
return superPickAxe;
superPickaxe = !superPickaxe;
return superPickaxe;
}
/**
* @return position
* @throws IncompleteRegionException
*/
public Vector getPlacementPosition(WorldEditPlayer player)
public Vector getPlacementPosition(LocalPlayer player)
throws IncompleteRegionException {
if (!placeAtPos1) {
return player.getBlockIn();
@ -350,7 +335,7 @@ public class WorldEditSession {
* @param player
* @return
*/
public BlockBag getBlockBag(WorldEditPlayer player) {
public BlockBag getBlockBag(LocalPlayer player) {
if (!useInventory) {
return null;
}
@ -385,31 +370,17 @@ public class WorldEditSession {
this.superPickaxeMode = superPickaxeMode;
}
/**
* @return the superPickaxeRange
*/
public int getSuperPickaxeRange() {
return superPickaxeRange;
}
/**
* @param superPickaxeRange the superPickaxeRange to set
*/
public void setSuperPickaxeRange(int superPickaxeRange) {
this.superPickaxeRange = superPickaxeRange;
}
/**
* @return the tool
*/
public Tool getTool() {
public SuperPickaxeMode getTool() {
return tool;
}
/**
* @param tool the tool to set
*/
public void setTool(Tool tool) {
public void setTool(SuperPickaxeMode tool) {
this.tool = tool;
}

View File

@ -0,0 +1,41 @@
// $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/>.
*/
package com.sk89q.worldedit;
/**
* Represents a world.
*
* @author sk89q
*/
public abstract class LocalWorld {
/**
* Compare if the other world is equal.
*
* @param other
* @return
*/
public abstract boolean equals(Object other);
/**
* Hash code.
*
* @return
*/
public abstract int hashCode();
}

View File

@ -15,113 +15,92 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package com.sk89q.worldedit;
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);
public abstract boolean setBlockType(LocalWorld world, Vector pt, int type);
/**
* Get block type.
*
*
* @param pt
* @return
*/
public abstract int getBlockType(Vector pt);
public abstract int getBlockType(LocalWorld world, Vector pt);
/**
* Set block data.
*
*
* @param pt
* @param data
* @return
*/
public abstract void setBlockData(Vector pt, int data);
public abstract void setBlockData(LocalWorld world, Vector pt, int data);
/**
* Get block data.
*
*
* @param pt
* @return
*/
public abstract int getBlockData(Vector pt);
public abstract int getBlockData(LocalWorld world, Vector pt);
/**
* Set sign text.
*
*
* @param pt
* @param text
*/
public abstract void setSignText(Vector pt, String[] text);
public abstract void setSignText(LocalWorld world, Vector pt, String[] text);
/**
* Get sign text.
*
*
* @param pt
* @return
*/
public abstract String[] getSignText(Vector pt);
public abstract String[] getSignText(LocalWorld world, 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);
public abstract BaseItemStack[] getChestContents(LocalWorld world, Vector pt);
/**
* Sets a chest slot.
*
*
* @param pt
* @param contents
* @return
*/
public abstract boolean setChestContents(Vector pt, BaseItemStack[] contents);
public abstract boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents);
/**
* Clear a chest's contents.
*
* @param pt
*/
public abstract boolean clearChest(Vector pt);
public abstract boolean clearChest(LocalWorld world, Vector pt);
/**
* Checks if a mob type is valid.
@ -133,19 +112,20 @@ public abstract class ServerInterface {
/**
* Set mob spawner mob type.
*
*
* @param pt
* @param mobType
*/
public abstract void setMobSpawnerType(Vector pt, String mobType);
public abstract void setMobSpawnerType(LocalWorld world, Vector pt,
String mobType);
/**
* Get mob spawner mob type. May return an empty string.
*
*
* @param pt
* @param mobType
*/
public abstract String getMobSpawnerType(Vector pt);
public abstract String getMobSpawnerType(LocalWorld world, Vector pt);
/**
* Generate a tree at a location.
@ -153,45 +133,48 @@ public abstract class ServerInterface {
* @param pt
* @return
*/
public abstract boolean generateTree(EditSession editSession, Vector pt);
public abstract boolean generateTree(EditSession editSession,
LocalWorld world, 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);
public abstract void dropItem(LocalWorld world, 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);
public abstract void dropItem(LocalWorld world, 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);
public abstract void dropItem(LocalWorld world, Vector pt, int type);
/**
* Simulate a block being mined.
*
* @param pt
*/
public abstract void simulateBlockMine(Vector pt);
public abstract void simulateBlockMine(LocalWorld world, Vector pt);
/**
* Resolves an item name to its ID.
*
@ -207,5 +190,5 @@ public abstract class ServerInterface {
* @param radius
* @return
*/
public abstract int killMobs(Vector origin, int radius);
public abstract int killMobs(LocalWorld world, Vector origin, int radius);
}

View File

@ -21,7 +21,7 @@ package com.sk89q.worldedit;
/**
*
* @author Albert
* @author sk89q
*/
public class Vector {
protected final double x, y, z;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
// $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/>.
*/
package com.sk89q.worldedit;
/**
* A vector with a world component.
*
* @author sk89q
*/
public class WorldVector extends Vector {
/**
* Represents the world.
*/
private LocalWorld world;
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, double x, double y, double z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, int x, int y, int z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param x
* @param y
* @param z
*/
public WorldVector(LocalWorld world, float x, float y, float z) {
super(x, y, z);
this.world = world;
}
/**
* Construct the Vector object.
*
* @param pt
*/
public WorldVector(LocalWorld world, Vector pt) {
super(pt);
this.world = world;
}
/**
* Construct the Vector object.
*/
public WorldVector(LocalWorld world) {
super();
this.world = world;
}
/**
* Get the world.
*
* @return
*/
public LocalWorld getWorld() {
return world;
}
/**
* Gets a BlockVector version.
*
* @return BlockWorldVector
*/
public BlockWorldVector toWorldBlockVector() {
return new BlockWorldVector(this);
}
}

View File

@ -0,0 +1,94 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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/>.
*/
package com.sk89q.worldedit.cli;
import static java.util.Arrays.*;
import java.util.List;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
/**
*
* @author sk89q
*/
public class Main {
/**
* @param args
*/
public static void main(String[] _args) throws Throwable {
OptionParser parser = new OptionParser();
OptionSpec<String> world =
parser.accepts("world").withRequiredArg().ofType(String.class)
.describedAs("world directory").defaultsTo("world");
parser.acceptsAll(asList("?", "h"), "show help");
OptionSet options = parser.parse(_args);
List<String> args = options.nonOptionArguments();
if (args.size() != 1 || options.has("?")) {
System.err.println("worldedit <action>");
System.err.println();
parser.printHelpOn(System.err);
return;
}
System.err.println("WorldEdit v" + getVersion());
System.err.println("Copyright (c) 2010-2011 sk89q <http://www.sk89q.com>");
System.err.println();
String act = args.get(0);
String worldPath = options.valueOf(world);
if (act.equalsIgnoreCase("check")) {
new WorldChecker(worldPath);
} else {
System.err.println("Only valid action is 'check'.");
}
}
/**
* Get the version.
*
* @return
*/
public static String getVersion() {
Package p = com.sk89q.worldedit.cli.Main.class.getPackage();
if (p == null) {
p = Package.getPackage("com.sk89q.worldedit");
}
String version;
if (p == null) {
return "(unknown)";
} else {
version = p.getImplementationVersion();
if (version == null) {
return "(unknown)";
}
}
return version;
}
}

View File

@ -0,0 +1,92 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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/>.
*/
package com.sk89q.worldedit.cli;
import java.io.*;
import java.nio.*;
import java.util.regex.Pattern;
import org.jnbt.NBTInputStream;
import org.jnbt.Tag;
public class WorldChecker {
private File worldPath;
public WorldChecker(String path) {
worldPath = new File(path);
checkLevelDat();
checkFiles();
System.out.println("Done.");
}
public void checkLevelDat() {
try {
checkNBT(new File(worldPath, "level.dat"));
} catch (IOException e) {
System.out.println("BAD: level.dat: " + e.getMessage());
}
}
public void checkFiles() {
final Pattern chunkFilePattern = Pattern.compile("^c\\..*\\.dat$");
FileFilter folderFilter = new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory();
}
};
FileFilter chunkFilter = new FileFilter() {
@Override
public boolean accept(File f) {
return f.isFile()
&& chunkFilePattern.matcher(f.getName()).matches();
}
};
for (File l1 : worldPath.listFiles(folderFilter)) {
for (File l2 : l1.listFiles(folderFilter)) {
for (File chunkFile : l2.listFiles(chunkFilter)) {
checkChunkFile(chunkFile,
l1.getName(), l2.getName(), chunkFile.getName());
}
}
}
}
public void checkChunkFile(File f, String a, String b, String c) {
String id = a + "/" + b + "/" + c;
try {
checkNBT(f);
} catch (IOException e) {
System.out.println("BAD: " + id);
}
}
public void checkNBT(File file) throws IOException {
FileInputStream stream = new FileInputStream(file);
NBTInputStream nbt = new NBTInputStream(stream);
Tag tag = nbt.readTag();
}
}

View File

@ -0,0 +1,82 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
/**
* A super pickaxe mode that will remove blocks in an area.
*
* @author sk89q
*/
public class AreaPickaxe implements SuperPickaxeMode {
private static final BaseBlock air = new BaseBlock(0);
private int range;
public AreaPickaxe(int range) {
this.range = range;
}
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
int initialType = server.getBlockType(world, clicked);
if (initialType == 0) {
return true;
}
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
EditSession editSession = new EditSession(server, world,
session.getBlockChangeLimit());
try {
for (int x = ox - range; x <= ox + range; x++) {
for (int y = oy - range; y <= oy + range; y++) {
for (int z = oz - range; z <= oz + range; z++) {
Vector pos = new Vector(x, y, z);
if (server.getBlockType(world, pos) == initialType) {
if (config.superPickaxeManyDrop) {
server.simulateBlockMine(world, pos);
}
editSession.setBlock(pos, air);
}
}
}
}
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
return true;
}
}

View File

@ -0,0 +1,54 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* A smode that replaces one block.
*
* @author sk89q
*/
public class BlockReplacer implements SuperPickaxeMode {
private BaseBlock targetBlock;
public BlockReplacer(BaseBlock targetBlock) {
this.targetBlock = targetBlock;
}
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
EditSession editSession = new EditSession(server, world, -1);
try {
editSession.setBlock(clicked, targetBlock);
} catch (MaxChangedBlocksException e) {
} finally {
session.remember(editSession);
}
return true;
}
}

View File

@ -0,0 +1,52 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.*;
/**
* Plants a tree.
*
* @author sk89q
*/
public class QueryTool implements SuperPickaxeMode {
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
BaseBlock block = (new EditSession(server, world, 0)).rawGetBlock(clicked);
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ "Type: " + block.getID() + "\u00A77" + " ("
+ BlockType.fromID(block.getID()).getName() + ") "
+ "\u00A7f"
+ "[" + block.getData() + "]");
if (block instanceof MobSpawnerBlock) {
player.printRaw("\u00A7e" + "Mob Type: "
+ ((MobSpawnerBlock)block).getMobType());
}
return true;
}
}

View File

@ -0,0 +1,119 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
/**
* A pickaxe mode that recursively finds adjacent blocks within range of
* an initial block and of the same type.
*
* @author sk89q
*/
public class RecursivePickaxe implements SuperPickaxeMode {
private static final BaseBlock air = new BaseBlock(0);
private int range;
public RecursivePickaxe(int range) {
this.range = range;
}
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
int initialType = server.getBlockType(world, clicked);
if (initialType == 0) {
return true;
}
if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
EditSession editSession = new EditSession(server, world,
session.getBlockChangeLimit());
try {
recurse(server, editSession, world, clicked.toBlockVector(),
clicked, range, initialType, new HashSet<BlockVector>(),
config.superPickaxeManyDrop);
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
return true;
}
/**
* Helper method.
*
* @param server
* @param superPickaxeManyDrop
* @param world
* @param pos
* @param origin
* @param size
* @param initialType
* @param visited
*/
private void recurse(ServerInterface server, EditSession editSession,
LocalWorld world, BlockVector pos,
Vector origin, int size, int initialType,
Set<BlockVector> visited, boolean drop)
throws MaxChangedBlocksException {
if (origin.distance(pos) > size || visited.contains(pos)) {
return;
}
visited.add(pos);
if (editSession.getBlock(pos).getID() == initialType) {
if (drop) {
server.simulateBlockMine(world, pos);
}
editSession.setBlock(pos, air);
} else {
return;
}
recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(),
origin, size, initialType, visited, drop);
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
origin, size, initialType, visited, drop);
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
origin, size, initialType, visited, drop);
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
origin, size, initialType, visited, drop);
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
origin, size, initialType, visited, drop);
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
origin, size, initialType, visited, drop);
}
}

View File

@ -0,0 +1,52 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID;
/**
* A super pickaxe mode that removes one block.
*
* @author sk89q
*/
public class SinglePickaxe implements SuperPickaxeMode {
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
if (server.getBlockType(world, clicked) == BlockID.BEDROCK
&& !player.canDestroyBedrock()) {
return true;
} else if (server.getBlockType(world, clicked) == BlockID.TNT) {
return false;
}
if (config.superPickaxeDrop) {
server.simulateBlockMine(world, clicked);
}
server.setBlockType(world, clicked, 0);
return true;
}
}

View File

@ -0,0 +1,42 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
/**
* Represents a super pickaxe mode.
*
* @author sk89q
*/
public interface SuperPickaxeMode {
/**
* Perform the action. Should return true to deny the default
* action.
*
* @param player
* @param session
* @param clicked
* @return true to deny
*/
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked);
}

View File

@ -0,0 +1,49 @@
// $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/>.
*/
package com.sk89q.worldedit.superpickaxe;
import com.sk89q.worldedit.*;
/**
* Plants a tree.
*
* @author sk89q
*/
public class TreePlanter implements SuperPickaxeMode {
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, LocalWorld world,
Vector clicked) {
EditSession editSession =
new EditSession(server, world, session.getBlockChangeLimit());
try {
if (!server.generateTree(editSession, player.getWorld(), clicked)) {
player.printError("Notch won't let you put a tree there.");
}
} finally {
session.remember(editSession);
}
return true;
}
}