mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 04:23:54 +00:00
More file moving.
This commit is contained in:
100
src/main/java/com/sk89q/worldedit/BlockVector.java
Normal file
100
src/main/java/com/sk89q/worldedit/BlockVector.java
Normal file
@ -0,0 +1,100 @@
|
||||
// $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 BlockVector extends Vector {
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public BlockVector(Vector pt) {
|
||||
super(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector(float x, float y, float z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector(double x, double y, double z) {
|
||||
super(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 Vector)) {
|
||||
return false;
|
||||
}
|
||||
Vector other = (Vector)obj;
|
||||
return (int)other.getX() == (int)this.x && (int)other.getY() == (int)this.y
|
||||
&& (int)other.getZ() == (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();
|
||||
}
|
||||
}
|
93
src/main/java/com/sk89q/worldedit/BlockVector2D.java
Normal file
93
src/main/java/com/sk89q/worldedit/BlockVector2D.java
Normal file
@ -0,0 +1,93 @@
|
||||
// $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 Vector2D that supports being compared as ints (for accuracy).
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlockVector2D extends Vector2D {
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public BlockVector2D(Vector2D pt) {
|
||||
super(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector2D(int x, int z) {
|
||||
super(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector2D(float x, float z) {
|
||||
super(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public BlockVector2D(double x, double z) {
|
||||
super(x, 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 Vector2D)) {
|
||||
return false;
|
||||
}
|
||||
Vector2D other = (Vector2D)obj;
|
||||
return (int)other.x == (int)this.x && (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)z).hashCode();
|
||||
}
|
||||
}
|
111
src/main/java/com/sk89q/worldedit/BlockWorldVector.java
Normal file
111
src/main/java/com/sk89q/worldedit/BlockWorldVector.java
Normal file
@ -0,0 +1,111 @@
|
||||
// $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 world
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public BlockWorldVector(LocalWorld world, Vector pt) {
|
||||
super(world, pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public BlockWorldVector(LocalWorld world, int x, int y, int z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public BlockWorldVector(LocalWorld world, float x, float y, float z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
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.getX() == (int)this.x && (int)other.getY() == (int)this.y
|
||||
&& (int)other.getZ() == (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();
|
||||
}
|
||||
}
|
105
src/main/java/com/sk89q/worldedit/Countable.java
Normal file
105
src/main/java/com/sk89q/worldedit/Countable.java
Normal file
@ -0,0 +1,105 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
* @param <T>
|
||||
*/
|
||||
public class Countable<T> implements Comparable<Countable<T>> {
|
||||
/**
|
||||
* ID.
|
||||
*/
|
||||
private T id;
|
||||
/**
|
||||
* Amount.
|
||||
*/
|
||||
private int amount;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param amount
|
||||
*/
|
||||
public Countable(T id, int amount) {
|
||||
this.id = id;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public T getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setID(T id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the amount.
|
||||
*/
|
||||
public void decrement() {
|
||||
this.amount--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the amount.
|
||||
*/
|
||||
public void increment() {
|
||||
this.amount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
public int compareTo(Countable<T> other) {
|
||||
if (amount > other.amount) {
|
||||
return 1;
|
||||
} else if (amount == other.amount) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
566
src/main/java/com/sk89q/worldedit/CuboidClipboard.java
Normal file
566
src/main/java/com/sk89q/worldedit/CuboidClipboard.java
Normal file
@ -0,0 +1,566 @@
|
||||
// $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 com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* The clipboard remembers the state of a cuboid region.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CuboidClipboard {
|
||||
/**
|
||||
* Flip direction.
|
||||
*/
|
||||
public enum FlipDirection {
|
||||
NORTH_SOUTH,
|
||||
WEST_EAST,
|
||||
UP_DOWN
|
||||
}
|
||||
|
||||
private BaseBlock[][][] data;
|
||||
private Vector offset;
|
||||
private Vector origin;
|
||||
private Vector size;
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
public CuboidClipboard(Vector size) {
|
||||
this.size = size;
|
||||
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
origin = new Vector();
|
||||
offset = new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size
|
||||
* @param origin
|
||||
*/
|
||||
public CuboidClipboard(Vector size, Vector origin) {
|
||||
this.size = size;
|
||||
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.origin = origin;
|
||||
offset = new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size
|
||||
* @param origin
|
||||
* @param offset
|
||||
*/
|
||||
public CuboidClipboard(Vector size, Vector origin, Vector offset) {
|
||||
this.size = size;
|
||||
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
||||
this.origin = origin;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width (X-direction) of the clipboard.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
public int getWidth() {
|
||||
return size.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length (Z-direction) of the clipboard.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public int getLength() {
|
||||
return size.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height (Y-direction) of the clipboard.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
public int getHeight() {
|
||||
return size.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
|
||||
*
|
||||
* @param angle in degrees
|
||||
*/
|
||||
public void rotate2D(int angle) {
|
||||
angle = angle % 360;
|
||||
if (angle % 90 != 0) { // Can only rotate 90 degrees at the moment
|
||||
return;
|
||||
}
|
||||
boolean reverse = angle < 0;
|
||||
int numRotations = (int)Math.floor(angle / 90.0);
|
||||
|
||||
int width = getWidth();
|
||||
int length = getLength();
|
||||
int height = getHeight();
|
||||
Vector sizeRotated = size.transform2D(angle, 0, 0, 0, 0);
|
||||
int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
|
||||
int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;
|
||||
|
||||
BaseBlock newData[][][] = new BaseBlock
|
||||
[Math.abs(sizeRotated.getBlockX())]
|
||||
[Math.abs(sizeRotated.getBlockY())]
|
||||
[Math.abs(sizeRotated.getBlockZ())];
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
Vector v = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0);
|
||||
int newX = v.getBlockX();
|
||||
int newZ = v.getBlockZ();
|
||||
for (int y = 0; y < height; y++) {
|
||||
BaseBlock block = data[x][y][z];
|
||||
newData[shiftX + newX][y][shiftZ + newZ] = block;
|
||||
|
||||
if (reverse) {
|
||||
for (int i = 0; i < numRotations; i++) {
|
||||
block.rotate90Reverse();
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < numRotations; i++) {
|
||||
block.rotate90();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data = newData;
|
||||
size = new Vector(Math.abs(sizeRotated.getBlockX()),
|
||||
Math.abs(sizeRotated.getBlockY()),
|
||||
Math.abs(sizeRotated.getBlockZ()));
|
||||
offset = offset.transform2D(angle, 0, 0, 0, 0)
|
||||
.subtract(shiftX, 0, shiftZ);;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the clipboard.
|
||||
*
|
||||
* @param dir
|
||||
*/
|
||||
public void flip(FlipDirection dir) {
|
||||
int width = getWidth();
|
||||
int length = getLength();
|
||||
int height = getHeight();
|
||||
|
||||
if (dir == FlipDirection.NORTH_SOUTH) {
|
||||
int len = (int)Math.floor(width / 2);
|
||||
for (int xs = 0; xs < len; xs++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
BaseBlock old = data[xs][y][z];
|
||||
old.flip();
|
||||
data[xs][y][z] = data[width - xs - 1][y][z];
|
||||
data[width - xs - 1][y][z] = old;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (dir == FlipDirection.WEST_EAST) {
|
||||
int len = (int)Math.floor(length / 2);
|
||||
for (int zs = 0; zs < len; zs++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
BaseBlock old = data[x][y][zs];
|
||||
old.flip();
|
||||
data[x][y][zs] = data[x][y][length - zs - 1];
|
||||
data[x][y][length - zs - 1] = old;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (dir == FlipDirection.UP_DOWN) {
|
||||
int len = (int)Math.floor(height / 2);
|
||||
for (int ys = 0; ys < len; ys++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
BaseBlock old = data[x][ys][z];
|
||||
data[x][ys][z] = data[x][height - ys - 1][z];
|
||||
data[x][height - ys - 1][z] = old;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy to the clipboard.
|
||||
*
|
||||
* @param editSession
|
||||
*/
|
||||
public void copy(EditSession editSession) {
|
||||
for (int x = 0; x < size.getBlockX(); x++) {
|
||||
for (int y = 0; y < size.getBlockY(); y++) {
|
||||
for (int z = 0; z < size.getBlockZ(); z++) {
|
||||
data[x][y][z] =
|
||||
editSession.getBlock(new Vector(x, y, z).add(getOrigin()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste from the clipboard.
|
||||
*
|
||||
* @param editSession
|
||||
* @param newOrigin Position to paste it from
|
||||
* @param noAir True to not paste air
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public void paste(EditSession editSession, Vector newOrigin, boolean noAir)
|
||||
throws MaxChangedBlocksException {
|
||||
place(editSession, newOrigin.add(offset), noAir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Places the blocks in a position from the minimum corner.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pos
|
||||
* @param noAir
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public void place(EditSession editSession, Vector pos, boolean noAir)
|
||||
throws MaxChangedBlocksException {
|
||||
for (int x = 0; x < size.getBlockX(); x++) {
|
||||
for (int y = 0; y < size.getBlockY(); y++) {
|
||||
for (int z = 0; z < size.getBlockZ(); z++) {
|
||||
if (noAir && data[x][y][z].isAir())
|
||||
continue;
|
||||
|
||||
editSession.setBlock(new Vector(x, y, z).add(pos),
|
||||
data[x][y][z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one point in the copy. The point is relative to the origin
|
||||
* of the copy (0, 0, 0) and not to the actual copy origin.
|
||||
*
|
||||
* @param pos
|
||||
* @return null
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
public BaseBlock getPoint(Vector pos) throws ArrayIndexOutOfBoundsException {
|
||||
return data[pos.getBlockX()][pos.getBlockY()][pos.getBlockZ()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the copy.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Vector getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the clipboard data to a .schematic-format file.
|
||||
*
|
||||
* @param path
|
||||
* @throws IOException
|
||||
* @throws DataException
|
||||
*/
|
||||
public void saveSchematic(File path) throws IOException, DataException {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int length = getLength();
|
||||
|
||||
if (width > 65535) {
|
||||
throw new DataException("Width of region too large for a .schematic");
|
||||
}
|
||||
if (height > 65535) {
|
||||
throw new DataException("Height of region too large for a .schematic");
|
||||
}
|
||||
if (length > 65535) {
|
||||
throw new DataException("Length of region too large for a .schematic");
|
||||
}
|
||||
|
||||
HashMap<String,Tag> schematic = new HashMap<String,Tag>();
|
||||
schematic.put("Width", new ShortTag("Width", (short)width));
|
||||
schematic.put("Length", new ShortTag("Length", (short)length));
|
||||
schematic.put("Height", new ShortTag("Height", (short)height));
|
||||
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
||||
schematic.put("WEOriginX", new IntTag("WEOriginX", getOrigin().getBlockX()));
|
||||
schematic.put("WEOriginY", new IntTag("WEOriginY", getOrigin().getBlockY()));
|
||||
schematic.put("WEOriginZ", new IntTag("WEOriginZ", getOrigin().getBlockZ()));
|
||||
schematic.put("WEOffsetX", new IntTag("WEOffsetX", getOffset().getBlockX()));
|
||||
schematic.put("WEOffsetY", new IntTag("WEOffsetY", getOffset().getBlockY()));
|
||||
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", getOffset().getBlockZ()));
|
||||
|
||||
// Copy
|
||||
byte[] blocks = new byte[width * height * length];
|
||||
byte[] blockData = new byte[width * height * length];
|
||||
ArrayList<Tag> tileEntities = new ArrayList<Tag>();
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
int index = y * width * length + z * width + x;
|
||||
blocks[index] = (byte)data[x][y][z].getType();
|
||||
blockData[index] = (byte)data[x][y][z].getData();
|
||||
|
||||
// Store TileEntity data
|
||||
if (data[x][y][z] instanceof TileEntityBlock) {
|
||||
TileEntityBlock tileEntityBlock =
|
||||
(TileEntityBlock)data[x][y][z];
|
||||
|
||||
// Get the list of key/values from the block
|
||||
Map<String,Tag> values = tileEntityBlock.toTileEntityNBT();
|
||||
if (values != null) {
|
||||
values.put("id", new StringTag("id",
|
||||
tileEntityBlock.getTileEntityID()));
|
||||
values.put("x", new IntTag("x", x));
|
||||
values.put("y", new IntTag("y", y));
|
||||
values.put("z", new IntTag("z", z));
|
||||
CompoundTag tileEntityTag =
|
||||
new CompoundTag("TileEntity", values);
|
||||
tileEntities.add(tileEntityTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
||||
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
|
||||
|
||||
// Build and output
|
||||
CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
|
||||
NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(path));
|
||||
stream.writeTag(schematicTag);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a .schematic file into a clipboard.
|
||||
*
|
||||
* @param path
|
||||
* @return clipboard
|
||||
* @throws DataException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static CuboidClipboard loadSchematic(File path)
|
||||
throws DataException, IOException {
|
||||
FileInputStream stream = new FileInputStream(path);
|
||||
NBTInputStream nbtStream = new NBTInputStream(
|
||||
new GZIPInputStream(stream));
|
||||
|
||||
Vector origin = new Vector();
|
||||
Vector offset = new Vector();
|
||||
|
||||
// Schematic tag
|
||||
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
|
||||
if (!schematicTag.getName().equals("Schematic")) {
|
||||
throw new DataException("Tag \"Schematic\" does not exist or is not first");
|
||||
}
|
||||
|
||||
// Check
|
||||
Map<String,Tag> schematic = schematicTag.getValue();
|
||||
if (!schematic.containsKey("Blocks")) {
|
||||
throw new DataException("Schematic file is missing a \"Blocks\" tag");
|
||||
}
|
||||
|
||||
// Get information
|
||||
short width = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue();
|
||||
short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue();
|
||||
short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue();
|
||||
|
||||
try {
|
||||
int originX = (Integer)getChildTag(schematic, "WEOriginX", IntTag.class).getValue();
|
||||
int originY = (Integer)getChildTag(schematic, "WEOriginY", IntTag.class).getValue();
|
||||
int originZ = (Integer)getChildTag(schematic, "WEOriginZ", IntTag.class).getValue();
|
||||
origin = new Vector(originX, originY, originZ);
|
||||
} catch (DataException e) {
|
||||
// No origin data
|
||||
}
|
||||
|
||||
try {
|
||||
int offsetX = (Integer)getChildTag(schematic, "WEOffsetX", IntTag.class).getValue();
|
||||
int offsetY = (Integer)getChildTag(schematic, "WEOffsetY", IntTag.class).getValue();
|
||||
int offsetZ = (Integer)getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue();
|
||||
offset = new Vector(offsetX, offsetY, offsetZ);
|
||||
} catch (DataException e) {
|
||||
// No offset data
|
||||
}
|
||||
|
||||
// Check type of Schematic
|
||||
String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue();
|
||||
if (!materials.equals("Alpha")) {
|
||||
throw new DataException("Schematic file is not an Alpha schematic");
|
||||
}
|
||||
|
||||
// Get blocks
|
||||
byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
|
||||
byte[] blockData = (byte[])getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
|
||||
|
||||
// Need to pull out tile entities
|
||||
List<Tag> tileEntities = (List<Tag>)((ListTag)getChildTag(schematic, "TileEntities", ListTag.class))
|
||||
.getValue();
|
||||
Map<BlockVector,Map<String,Tag>> tileEntitiesMap =
|
||||
new HashMap<BlockVector,Map<String,Tag>>();
|
||||
|
||||
for (Tag tag : tileEntities) {
|
||||
if (!(tag instanceof CompoundTag)) continue;
|
||||
CompoundTag t = (CompoundTag)tag;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
|
||||
for (Map.Entry<String,Tag> entry : t.getValue().entrySet()) {
|
||||
if (entry.getKey().equals("x")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
x = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("y")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
y = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("z")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
z = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
BlockVector vec = new BlockVector(x, y, z);
|
||||
tileEntitiesMap.put(vec, values);
|
||||
}
|
||||
|
||||
Vector size = new Vector(width, height, length);
|
||||
CuboidClipboard clipboard = new CuboidClipboard(size);
|
||||
clipboard.setOrigin(origin);
|
||||
clipboard.setOffset(offset);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
int index = y * width * length + z * width + x;
|
||||
BlockVector pt = new BlockVector(x, y, z);
|
||||
BaseBlock block;
|
||||
|
||||
if (blocks[index] == BlockID.WALL_SIGN || blocks[index] == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(blocks[index], blockData[index]);
|
||||
} else if (blocks[index] == BlockID.CHEST) {
|
||||
block = new ChestBlock(blockData[index]);
|
||||
} else if (blocks[index] == BlockID.FURNACE || blocks[index] == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(blocks[index], blockData[index]);
|
||||
} else if (blocks[index] == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(blockData[index]);
|
||||
} else if (blocks[index] == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(blockData[index]);
|
||||
} else if (blocks[index] == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(blockData[index]);
|
||||
} else {
|
||||
block = new BaseBlock(blocks[index], blockData[index]);
|
||||
}
|
||||
|
||||
if (block instanceof TileEntityBlock
|
||||
&& tileEntitiesMap.containsKey(pt)) {
|
||||
((TileEntityBlock)block).fromTileEntityNBT(
|
||||
tileEntitiesMap.get(pt));
|
||||
}
|
||||
|
||||
clipboard.data[x][y][z] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child tag of a NBT structure.
|
||||
*
|
||||
* @param items
|
||||
* @param key
|
||||
* @param expected
|
||||
* @return child tag
|
||||
* @throws DataException
|
||||
*/
|
||||
private static Tag getChildTag(Map<String,Tag> items, String key,
|
||||
Class<? extends Tag> expected) throws DataException {
|
||||
|
||||
if (!items.containsKey(key)) {
|
||||
throw new DataException("Schematic file is missing a \"" + key + "\" tag");
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new DataException(
|
||||
key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the origin
|
||||
*/
|
||||
public Vector getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param origin the origin to set
|
||||
*/
|
||||
public void setOrigin(Vector origin) {
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offset
|
||||
*/
|
||||
public Vector getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offset
|
||||
*/
|
||||
public void setOffset(Vector offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DisallowedItemException extends WorldEditException {
|
||||
private static final long serialVersionUID = -8080026411461549979L;
|
||||
|
||||
private String type;
|
||||
|
||||
public DisallowedItemException(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public DisallowedItemException(String type, String message) {
|
||||
super(message);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return type;
|
||||
}
|
||||
}
|
188
src/main/java/com/sk89q/worldedit/DoubleArrayList.java
Normal file
188
src/main/java/com/sk89q/worldedit/DoubleArrayList.java
Normal file
@ -0,0 +1,188 @@
|
||||
// $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.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Double array lists to work like a Map, but not really.
|
||||
*
|
||||
* @author sk89q
|
||||
* @param <A>
|
||||
* @param <B>
|
||||
*/
|
||||
public class DoubleArrayList<A,B> implements Iterable<Map.Entry<A,B>> {
|
||||
/**
|
||||
* First list.
|
||||
*/
|
||||
private List<A> listA = new ArrayList<A>();
|
||||
/**
|
||||
* Second list.
|
||||
*/
|
||||
private List<B> listB = new ArrayList<B>();
|
||||
/**
|
||||
* Is reversed when iterating.
|
||||
*/
|
||||
private boolean isReversed = false;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param isReversed
|
||||
*/
|
||||
public DoubleArrayList(boolean isReversed) {
|
||||
this.isReversed = isReversed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item.
|
||||
*
|
||||
* @param a
|
||||
* @param b
|
||||
*/
|
||||
public void put(A a, B b) {
|
||||
listA.add(a);
|
||||
listB.add(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get size.
|
||||
* @return
|
||||
*/
|
||||
public int size() {
|
||||
return listA.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the list.
|
||||
*/
|
||||
public void clear() {
|
||||
listA.clear();
|
||||
listB.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an entry set.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Iterator<Map.Entry<A,B>> iterator() {
|
||||
if (isReversed) {
|
||||
return new ReverseEntryIterator<Map.Entry<A,B>>(
|
||||
listA.listIterator(listA.size()),
|
||||
listB.listIterator(listB.size()));
|
||||
} else {
|
||||
return new ForwardEntryIterator<Map.Entry<A,B>>(
|
||||
listA.iterator(),
|
||||
listB.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry iterator.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class ForwardEntryIterator<T extends Map.Entry<A,B>>
|
||||
implements Iterator<Map.Entry<A,B>> {
|
||||
|
||||
private Iterator<A> keyIterator;
|
||||
private Iterator<B> valueIterator;
|
||||
|
||||
public ForwardEntryIterator(Iterator<A> keyIterator, Iterator<B> valueIterator) {
|
||||
this.keyIterator = keyIterator;
|
||||
this.valueIterator = valueIterator;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return keyIterator.hasNext();
|
||||
}
|
||||
|
||||
public Map.Entry<A,B> next() throws NoSuchElementException {
|
||||
return new Entry<A,B>(keyIterator.next(), valueIterator.next());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry iterator.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class ReverseEntryIterator<T extends Map.Entry<A,B>>
|
||||
implements Iterator<Map.Entry<A,B>> {
|
||||
|
||||
private ListIterator<A> keyIterator;
|
||||
private ListIterator<B> valueIterator;
|
||||
|
||||
public ReverseEntryIterator(ListIterator<A> keyIterator, ListIterator<B> valueIterator) {
|
||||
this.keyIterator = keyIterator;
|
||||
this.valueIterator = valueIterator;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return keyIterator.hasPrevious();
|
||||
}
|
||||
|
||||
public Map.Entry<A,B> next() throws NoSuchElementException {
|
||||
return new Entry<A,B>(keyIterator.previous(), valueIterator.previous());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to masquerade as Map.Entry.
|
||||
*
|
||||
* @param <C>
|
||||
* @param <D>
|
||||
*/
|
||||
public class Entry<C,D> implements Map.Entry<A,B> {
|
||||
private A key;
|
||||
private B value;
|
||||
|
||||
private Entry(A key, B value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public A getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public B getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public B setValue(B value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
2211
src/main/java/com/sk89q/worldedit/EditSession.java
Normal file
2211
src/main/java/com/sk89q/worldedit/EditSession.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Albert
|
||||
*/
|
||||
public class EmptyClipboardException extends WorldEditException {
|
||||
private static final long serialVersionUID = -3197424556127109425L;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// $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;
|
||||
|
||||
public class FileSelectionAbortedException extends FilenameException {
|
||||
private static final long serialVersionUID = 7377072269988014886L;
|
||||
|
||||
public FileSelectionAbortedException() {
|
||||
super("");
|
||||
}
|
||||
|
||||
public FileSelectionAbortedException(String msg) {
|
||||
super("", msg);
|
||||
}
|
||||
}
|
40
src/main/java/com/sk89q/worldedit/FilenameException.java
Normal file
40
src/main/java/com/sk89q/worldedit/FilenameException.java
Normal file
@ -0,0 +1,40 @@
|
||||
// $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;
|
||||
|
||||
public class FilenameException extends WorldEditException {
|
||||
private static final long serialVersionUID = 6072601657326106265L;
|
||||
|
||||
private String filename;
|
||||
|
||||
public FilenameException(String filename) {
|
||||
super();
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public FilenameException(String filename, String msg) {
|
||||
super(msg);
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// $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;
|
||||
|
||||
public class FilenameResolutionException extends FilenameException {
|
||||
private static final long serialVersionUID = 4673670296313383121L;
|
||||
|
||||
public FilenameResolutionException(String filename) {
|
||||
super(filename);
|
||||
}
|
||||
|
||||
public FilenameResolutionException(String filename, String msg) {
|
||||
super(filename, msg);
|
||||
}
|
||||
}
|
165
src/main/java/com/sk89q/worldedit/HeightMap.java
Normal file
165
src/main/java/com/sk89q/worldedit/HeightMap.java
Normal file
@ -0,0 +1,165 @@
|
||||
package com.sk89q.worldedit;
|
||||
// $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.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.filtering.HeightMapFilter;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Allows applications of Kernels onto the region's heightmap.
|
||||
* Currently only used for smoothing (with a GaussianKernel).
|
||||
*
|
||||
* @author Grum
|
||||
*/
|
||||
|
||||
public class HeightMap {
|
||||
private int[] data;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
private Region region;
|
||||
private EditSession session;
|
||||
|
||||
/**
|
||||
* Constructs the HeightMap
|
||||
*
|
||||
* @param session
|
||||
* @param region
|
||||
*/
|
||||
|
||||
public HeightMap(EditSession session, Region region) {
|
||||
this.session = session;
|
||||
this.region = region;
|
||||
|
||||
this.width = region.getWidth();
|
||||
this.height = region.getLength();
|
||||
|
||||
int minX = region.getMinimumPoint().getBlockX();
|
||||
int minY = region.getMinimumPoint().getBlockY();
|
||||
int minZ = region.getMinimumPoint().getBlockZ();
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
|
||||
// Store current heightmap data
|
||||
data = new int[width * height];
|
||||
for (int z = 0; z < height; z++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
data[z * width + x] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the filter 'iterations' amount times.
|
||||
*
|
||||
* @param filter
|
||||
* @param iterations
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
|
||||
public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException {
|
||||
int[] newData = new int[data.length];
|
||||
System.arraycopy(data, 0, newData, 0, data.length);
|
||||
|
||||
for (int i = 0; i < iterations; i++)
|
||||
newData = filter.filter(newData, width, height);
|
||||
|
||||
return apply(newData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a raw heightmap to the region
|
||||
*
|
||||
* @param data
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
|
||||
public int apply(int[] data) throws MaxChangedBlocksException {
|
||||
Vector minY = region.getMinimumPoint();
|
||||
int originX = minY.getBlockX();
|
||||
int originY = minY.getBlockY();
|
||||
int originZ = minY.getBlockZ();
|
||||
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
BaseBlock fillerAir = new BaseBlock(0);
|
||||
|
||||
int blocksChanged = 0;
|
||||
|
||||
// Apply heightmap
|
||||
for (int z = 0; z < height; z++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int index = z * width + x;
|
||||
int curHeight = this.data[index];
|
||||
|
||||
// Clamp newHeight within the selection area
|
||||
int newHeight = Math.min(maxY, data[index]);
|
||||
|
||||
// Offset x,z to be 'real' coordinates
|
||||
int X = x + originX;
|
||||
int Z = z + originZ;
|
||||
|
||||
// We are keeping the topmost blocks so take that in account for the scale
|
||||
double scale = (double) (curHeight - originY) / (double) (newHeight - originY);
|
||||
|
||||
// Depending on growing or shrinking we need to start at the bottom or top
|
||||
if (newHeight > curHeight) {
|
||||
// Set the top block of the column to be the same type (this might go wrong with rounding)
|
||||
BaseBlock existing = session.getBlock(new Vector(X, curHeight, Z));
|
||||
|
||||
// Skip water/lava
|
||||
if (existing.getType() < 8 || existing.getType() > 11) {
|
||||
session.setBlock(new Vector(X, newHeight, Z), existing);
|
||||
blocksChanged++;
|
||||
|
||||
// Grow -- start from 1 below top replacing airblocks
|
||||
for (int y = newHeight - 1 - originY; y >= 0; y--) {
|
||||
int copyFrom = (int) (y * scale);
|
||||
session.setBlock(new Vector(X, originY + y, Z), session.getBlock(new Vector(X, originY + copyFrom, Z)));
|
||||
blocksChanged++;
|
||||
}
|
||||
}
|
||||
} else if (curHeight > newHeight) {
|
||||
// Shrink -- start from bottom
|
||||
for (int y = 0; y < newHeight - originY; y++) {
|
||||
int copyFrom = (int) (y * scale);
|
||||
session.setBlock(new Vector(X, originY + y, Z), session.getBlock(new Vector(X, originY + copyFrom, Z)));
|
||||
blocksChanged++;
|
||||
}
|
||||
|
||||
// Set the top block of the column to be the same type
|
||||
// (this could otherwise go wrong with rounding)
|
||||
session.setBlock(new Vector(X, newHeight, Z), session.getBlock(new Vector(X, curHeight, Z)));
|
||||
blocksChanged++;
|
||||
|
||||
// Fill rest with air
|
||||
for (int y = newHeight + 1; y <= curHeight; y++) {
|
||||
session.setBlock(new Vector(X, y, Z), fillerAir);
|
||||
blocksChanged++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drop trees to the floor -- TODO
|
||||
|
||||
return blocksChanged;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
* Raised when a region is not fully defined.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class IncompleteRegionException extends WorldEditException {
|
||||
private static final long serialVersionUID = 458988897980179094L;
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// $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;
|
||||
|
||||
public class InvalidFilenameException extends FilenameException {
|
||||
private static final long serialVersionUID = 7377072269988014886L;
|
||||
|
||||
public InvalidFilenameException(String filename) {
|
||||
super(filename);
|
||||
}
|
||||
|
||||
public InvalidFilenameException(String filename, String msg) {
|
||||
super(filename, msg);
|
||||
}
|
||||
}
|
32
src/main/java/com/sk89q/worldedit/InvalidItemException.java
Normal file
32
src/main/java/com/sk89q/worldedit/InvalidItemException.java
Normal file
@ -0,0 +1,32 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class InvalidItemException extends DisallowedItemException {
|
||||
private static final long serialVersionUID = -2739618871154124586L;
|
||||
|
||||
public InvalidItemException(String type, String message) {
|
||||
super(type, message);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
// $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;
|
||||
|
||||
public class InvalidToolBindException extends WorldEditException {
|
||||
private static final long serialVersionUID = -1865311004052447699L;
|
||||
|
||||
private int itemId;
|
||||
|
||||
public InvalidToolBindException(int itemId, String msg) {
|
||||
super(msg);
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
}
|
78
src/main/java/com/sk89q/worldedit/LocalConfiguration.java
Normal file
78
src/main/java/com/sk89q/worldedit/LocalConfiguration.java
Normal file
@ -0,0 +1,78 @@
|
||||
// $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.io.File;
|
||||
import java.util.HashSet;
|
||||
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 = new HashSet<Integer>();
|
||||
public int defaultChangeLimit = -1;
|
||||
public int maxChangeLimit = -1;
|
||||
public String shellSaveType = "";
|
||||
public SnapshotRepository snapshotRepo = null;
|
||||
public int maxRadius = -1;
|
||||
public int maxSuperPickaxeSize = 5;
|
||||
public int maxBrushRadius = 6;
|
||||
public boolean logCommands = 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;
|
||||
public int navigationWand = 345;
|
||||
public int navigationWandMaxDistance = 50;
|
||||
public int scriptTimeout = 3000;
|
||||
public Set<Integer> allowedDataCycleBlocks = new HashSet<Integer>();
|
||||
public String saveDir = "schematics";
|
||||
public String scriptsDir = "craftscripts";
|
||||
public boolean showFirstUseVersion = true;
|
||||
|
||||
/**
|
||||
* Loads the configuration.
|
||||
*/
|
||||
public abstract void load();
|
||||
|
||||
/**
|
||||
* Get the working directory to work from.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getWorkingDirectory() {
|
||||
return new File(".");
|
||||
}
|
||||
}
|
617
src/main/java/com/sk89q/worldedit/LocalPlayer.java
Normal file
617
src/main/java/com/sk89q/worldedit/LocalPlayer.java
Normal file
@ -0,0 +1,617 @@
|
||||
// $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.io.File;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.util.TargetBlock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class LocalPlayer {
|
||||
/**
|
||||
* Server.
|
||||
*/
|
||||
protected ServerInterface server;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
protected LocalPlayer(ServerInterface server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the player is holding a pick axe.
|
||||
*
|
||||
* @return whether a pick axe is held
|
||||
*/
|
||||
public boolean isHoldingPickAxe() {
|
||||
int item = getItemInHand();
|
||||
return item == 257 || item == 270 || item == 274 || item == 278
|
||||
|| item == 285;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a position for the player to stand that is not inside a block.
|
||||
* Blocks above the player will be iteratively tested until there is
|
||||
* a series of two free blocks. The player will be teleported to
|
||||
* that free position.
|
||||
*
|
||||
* @param searchPos search position
|
||||
*/
|
||||
public void findFreePosition(WorldVector searchPos) {
|
||||
LocalWorld world = searchPos.getWorld();
|
||||
int x = searchPos.getBlockX();
|
||||
int y = Math.max(0, searchPos.getBlockY());
|
||||
int origY = y;
|
||||
int z = searchPos.getBlockZ();
|
||||
|
||||
byte free = 0;
|
||||
|
||||
while (y <= 129) {
|
||||
if (BlockType.canPassThrough(world.getBlockType(new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
}
|
||||
|
||||
if (free == 2) {
|
||||
if (y - 1 != origY) {
|
||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the player on the ground.
|
||||
*
|
||||
* @param searchPos
|
||||
*/
|
||||
public void setOnGround(WorldVector searchPos) {
|
||||
LocalWorld world = searchPos.getWorld();
|
||||
int x = searchPos.getBlockX();
|
||||
int y = Math.max(0, searchPos.getBlockY());
|
||||
int z = searchPos.getBlockZ();
|
||||
|
||||
while (y >= 0) {
|
||||
if (!BlockType.canPassThrough(world.getBlockType(new Vector(x, y, z)))) {
|
||||
setPosition(new Vector(x + 0.5, y + 1, z + 0.5));
|
||||
return;
|
||||
}
|
||||
|
||||
y--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a position for the player to stand that is not inside a block.
|
||||
* Blocks above the player will be iteratively tested until there is
|
||||
* a series of two free blocks. The player will be teleported to
|
||||
* that free position.
|
||||
*/
|
||||
public void findFreePosition() {
|
||||
findFreePosition(getBlockIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Go up one level to the next free space above.
|
||||
*
|
||||
* @return true if a spot was found
|
||||
*/
|
||||
public boolean ascendLevel() {
|
||||
Vector pos = getBlockIn();
|
||||
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(world.getBlockType(new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
}
|
||||
|
||||
if (free == 2) {
|
||||
spots++;
|
||||
if (spots == 2) {
|
||||
int type = world.getBlockType(new Vector(x, y - 2, z));
|
||||
|
||||
// Don't get put in lava!
|
||||
if (type == 10 || type == 11) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go up one level to the next free space above.
|
||||
*
|
||||
* @return true if a spot was found
|
||||
*/
|
||||
public boolean descendLevel() {
|
||||
Vector pos = getBlockIn();
|
||||
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(world.getBlockType(new Vector(x, y, z)))) {
|
||||
free++;
|
||||
} else {
|
||||
free = 0;
|
||||
}
|
||||
|
||||
if (free == 2) {
|
||||
// So we've found a spot, but we have to drop the player
|
||||
// lightly and also check to see if there's something to
|
||||
// stand upon
|
||||
while (y >= 0) {
|
||||
int type = world.getBlockType(new Vector(x, y, z));
|
||||
|
||||
// Don't want to end up in lava
|
||||
if (type != 0 && type != 10 && type != 11) {
|
||||
// Found a block!
|
||||
setPosition(new Vector(x + 0.5, y + 1, z + 0.5));
|
||||
return true;
|
||||
}
|
||||
|
||||
y--;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
y--;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ascend to the ceiling above.
|
||||
*
|
||||
* @param clearance
|
||||
* @return whether the player was moved
|
||||
*/
|
||||
public boolean ascendToCeiling(int clearance) {
|
||||
Vector pos = getBlockIn();
|
||||
int x = pos.getBlockX();
|
||||
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 (world.getBlockType(new Vector(x, y, z)) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (y <= 127) {
|
||||
// Found a ceiling!
|
||||
if (!BlockType.canPassThrough(world.getBlockType(new Vector(x, y, z)))) {
|
||||
int platformY = Math.max(initialY, y - 3 - clearance);
|
||||
world.setBlockType(new Vector(x, platformY, z),
|
||||
BlockType.GLASS.getID());
|
||||
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
|
||||
return true;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just go up.
|
||||
*
|
||||
* @param distance
|
||||
* @return whether the player was moved
|
||||
*/
|
||||
public boolean ascendUpwards(int distance) {
|
||||
Vector pos = getBlockIn();
|
||||
int x = pos.getBlockX();
|
||||
int initialY = Math.max(0, pos.getBlockY());
|
||||
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(world.getBlockType(new Vector(x, y, z)))) {
|
||||
break; // Hit something
|
||||
} else if (y > maxY + 1) {
|
||||
break;
|
||||
} else if (y == maxY + 1) {
|
||||
world.setBlockType(new Vector(x, y - 2, z),
|
||||
BlockType.GLASS.getID());
|
||||
setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
|
||||
return true;
|
||||
}
|
||||
|
||||
y++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block that is being stood in.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public WorldVector getBlockIn() {
|
||||
WorldVector pos = getPosition();
|
||||
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
|
||||
pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block that is being stood upon.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public WorldVector getBlockOn() {
|
||||
WorldVector pos = getPosition();
|
||||
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
|
||||
pos.getY() - 1, pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block being looked at. May return null.
|
||||
*
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public WorldVector getBlockTrace(int range) {
|
||||
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
||||
return tb.getTargetBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point of the block being looked at. May return null.
|
||||
*
|
||||
* @param range
|
||||
* @return point
|
||||
*/
|
||||
public WorldVector getSolidBlockTrace(int range) {
|
||||
TargetBlock tb = new TargetBlock(this, range, 0.2);
|
||||
return tb.getSolidTargetBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PlayerDirection 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 PlayerDirection getDirection(double rot) {
|
||||
if (0 <= rot && rot < 22.5) {
|
||||
return PlayerDirection.NORTH;
|
||||
} else if (22.5 <= rot && rot < 67.5) {
|
||||
return PlayerDirection.NORTH_EAST;
|
||||
} else if (67.5 <= rot && rot < 112.5) {
|
||||
return PlayerDirection.EAST;
|
||||
} else if (112.5 <= rot && rot < 157.5) {
|
||||
return PlayerDirection.SOUTH_EAST;
|
||||
} else if (157.5 <= rot && rot < 202.5) {
|
||||
return PlayerDirection.SOUTH;
|
||||
} else if (202.5 <= rot && rot < 247.5) {
|
||||
return PlayerDirection.SOUTH_WEST;
|
||||
} else if (247.5 <= rot && rot < 292.5) {
|
||||
return PlayerDirection.WEST;
|
||||
} else if (292.5 <= rot && rot < 337.5) {
|
||||
return PlayerDirection.NORTH_WEST;
|
||||
} else if (337.5 <= rot && rot < 360.0) {
|
||||
return PlayerDirection.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 WorldVector getPosition();
|
||||
|
||||
/**
|
||||
* Get the player's world.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public abstract LocalWorld getWorld();
|
||||
|
||||
/**
|
||||
* 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 boolean passThroughForwardWall(int range) {
|
||||
int searchDist = 0;
|
||||
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
|
||||
LocalWorld world = getPosition().getWorld();
|
||||
BlockWorldVector block;
|
||||
boolean firstBlock = true;
|
||||
int freeToFind = 2;
|
||||
boolean inFree = false;
|
||||
|
||||
while ((block = hitBlox.getNextBlock()) != null) {
|
||||
boolean free = BlockType.canPassThrough(world.getBlockType(block));
|
||||
|
||||
if (firstBlock) {
|
||||
firstBlock = false;
|
||||
|
||||
if (!free) {
|
||||
freeToFind--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
searchDist++;
|
||||
if (searchDist > 20) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inFree != free) {
|
||||
if (free) {
|
||||
freeToFind--;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeToFind == 0) {
|
||||
setOnGround(block);
|
||||
return true;
|
||||
}
|
||||
|
||||
inFree = free;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void printRaw(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEdit message.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public abstract void printDebug(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);
|
||||
|
||||
/**
|
||||
* Open a file open dialog.
|
||||
*
|
||||
* @param extensions null to allow all
|
||||
* @return
|
||||
*/
|
||||
public File openFileOpenDialog(String[] extensions) {
|
||||
printError("File dialogs are not supported in your environment.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file save dialog.
|
||||
*
|
||||
* @param extensions null to allow all
|
||||
* @return
|
||||
*/
|
||||
public File openFileSaveDialog(String[] extensions) {
|
||||
printError("File dialogs are not supported in your environment.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the player can destroy bedrock.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean canDestroyBedrock() {
|
||||
return hasPermission("worldedit.override.bedrock");
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a CUI event.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void dispatchCUIEvent(CUIEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the CUI handshake.
|
||||
*/
|
||||
public void dispatchCUIHandshake() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if equal.
|
||||
*
|
||||
* @param other
|
||||
* @return whether the other object is equivalent
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof LocalPlayer)) {
|
||||
return false;
|
||||
}
|
||||
LocalPlayer other2 = (LocalPlayer)other;
|
||||
return other2.getName().equals(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hash code.
|
||||
*
|
||||
* @return hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
}
|
618
src/main/java/com/sk89q/worldedit/LocalSession.java
Normal file
618
src/main/java/com/sk89q/worldedit/LocalSession.java
Normal file
@ -0,0 +1,618 @@
|
||||
// $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.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import com.sk89q.jchronic.Chronic;
|
||||
import com.sk89q.jchronic.Options;
|
||||
import com.sk89q.jchronic.utils.Span;
|
||||
import com.sk89q.jchronic.utils.Time;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
import com.sk89q.worldedit.tools.BrushTool;
|
||||
import com.sk89q.worldedit.tools.SinglePickaxe;
|
||||
import com.sk89q.worldedit.tools.BlockTool;
|
||||
import com.sk89q.worldedit.tools.Tool;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
|
||||
/**
|
||||
* An instance of this represents the WorldEdit session of a user. A session
|
||||
* stores history and settings. Sessions are not tied particularly to any
|
||||
* player and can be shuffled between players, saved, and loaded.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LocalSession {
|
||||
public static int MAX_HISTORY_SIZE = 15;
|
||||
|
||||
private LocalConfiguration config;
|
||||
|
||||
private LocalWorld selectionWorld;
|
||||
private RegionSelector selector = new CuboidRegionSelector();
|
||||
private boolean placeAtPos1 = false;
|
||||
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
||||
private int historyPointer = 0;
|
||||
private CuboidClipboard clipboard;
|
||||
private boolean toolControl = true;
|
||||
private boolean superPickaxe = false;
|
||||
private BlockTool pickaxeMode = new SinglePickaxe();
|
||||
private Map<Integer, Tool> tools
|
||||
= new HashMap<Integer, Tool>();
|
||||
private int maxBlocksChanged = -1;
|
||||
private boolean useInventory;
|
||||
private Snapshot snapshot;
|
||||
private String lastScript;
|
||||
private boolean beenToldVersion = false;
|
||||
private boolean hasCUISupport = false;
|
||||
private TimeZone timezone = TimeZone.getDefault();
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
public LocalSession(LocalConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session's timezone.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TimeZone getTimeZone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the session's timezone.
|
||||
*
|
||||
* @param timezone
|
||||
*/
|
||||
public void setTimezone(TimeZone timezone) {
|
||||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear history.
|
||||
*/
|
||||
public void clearHistory() {
|
||||
history.clear();
|
||||
historyPointer = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember an edit session for the undo history. If the history maximum
|
||||
* size is reached, old edit sessions will be discarded.
|
||||
*
|
||||
* @param editSession
|
||||
*/
|
||||
public void remember(EditSession editSession) {
|
||||
// Don't store anything if no changes were made
|
||||
if (editSession.size() == 0) { return; }
|
||||
|
||||
// Destroy any sessions after this undo point
|
||||
while (historyPointer < history.size()) {
|
||||
history.remove(historyPointer);
|
||||
}
|
||||
history.add(editSession);
|
||||
while (history.size() > MAX_HISTORY_SIZE) {
|
||||
history.remove(0);
|
||||
}
|
||||
historyPointer = history.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an undo.
|
||||
*
|
||||
* @param newBlockBag
|
||||
* @return whether anything was undone
|
||||
*/
|
||||
public EditSession undo(BlockBag newBlockBag) {
|
||||
historyPointer--;
|
||||
if (historyPointer >= 0) {
|
||||
EditSession editSession = history.get(historyPointer);
|
||||
EditSession newEditSession =
|
||||
new EditSession(editSession.getWorld(), -1, newBlockBag);
|
||||
newEditSession.enableQueue();
|
||||
editSession.undo(newEditSession);
|
||||
return editSession;
|
||||
} else {
|
||||
historyPointer = 0;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a redo
|
||||
*
|
||||
* @param newBlockBag
|
||||
* @return whether anything was redone
|
||||
*/
|
||||
public EditSession redo(BlockBag newBlockBag) {
|
||||
if (historyPointer < history.size()) {
|
||||
EditSession editSession = history.get(historyPointer);
|
||||
EditSession newEditSession =
|
||||
new EditSession(editSession.getWorld(), -1, newBlockBag);
|
||||
newEditSession.enableQueue();
|
||||
editSession.redo(newEditSession);
|
||||
historyPointer++;
|
||||
return editSession;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region selector for defining the selection. If the selection
|
||||
* was defined for a different world, the old selection will be discarded.
|
||||
*
|
||||
* @param world
|
||||
* @return position
|
||||
*/
|
||||
public RegionSelector getRegionSelector(LocalWorld world) {
|
||||
if (selectionWorld == null) {
|
||||
selectionWorld = world;
|
||||
} else if (!selectionWorld.equals(world)) {
|
||||
selectionWorld = world;
|
||||
selector.clear();
|
||||
}
|
||||
return selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the region selector. This won't check worlds so make sure that
|
||||
* this region selector isn't used blindly.
|
||||
*
|
||||
* @return position
|
||||
*/
|
||||
public RegionSelector getRegionSelector() {
|
||||
return selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the region selector.
|
||||
*
|
||||
* @param world
|
||||
* @param selector
|
||||
*/
|
||||
public void setRegionSelector(LocalWorld world, RegionSelector selector) {
|
||||
selectionWorld = world;
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the region is fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isRegionDefined() {
|
||||
return selector.isDefined();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the region is fully defined for the specified world.
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public boolean isSelectionDefined(LocalWorld world) {
|
||||
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
||||
return false;
|
||||
}
|
||||
return selector.isDefined();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use <code>getSelection()</code>.
|
||||
*
|
||||
* @return region
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
@Deprecated
|
||||
public Region getRegion() throws IncompleteRegionException {
|
||||
return selector.getRegion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selection region. If you change the region, you should
|
||||
* call learnRegionChanges(). If the selection is defined in
|
||||
* a different world, the <code>IncompleteRegionException</code>
|
||||
* exception will be thrown.
|
||||
*
|
||||
* @param world
|
||||
* @return region
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Region getSelection(LocalWorld world) throws IncompleteRegionException {
|
||||
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
return selector.getRegion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selection world.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LocalWorld getSelectionWorld() {
|
||||
return selectionWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the clipboard.
|
||||
*
|
||||
* @return clipboard, may be null
|
||||
* @throws EmptyClipboardException
|
||||
*/
|
||||
public CuboidClipboard getClipboard() throws EmptyClipboardException {
|
||||
if (clipboard == null) {
|
||||
throw new EmptyClipboardException();
|
||||
}
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the clipboard.
|
||||
*
|
||||
* @param clipboard
|
||||
*/
|
||||
public void setClipboard(CuboidClipboard clipboard) {
|
||||
this.clipboard = clipboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if tool control is enabled.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean isToolControlEnabled() {
|
||||
return toolControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change tool control setting.
|
||||
*
|
||||
* @param toolControl
|
||||
*/
|
||||
public void setToolControl(boolean toolControl) {
|
||||
this.toolControl = toolControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of blocks that can be changed in an edit session.
|
||||
*
|
||||
* @return block change limit
|
||||
*/
|
||||
public int getBlockChangeLimit() {
|
||||
return maxBlocksChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of blocks that can be changed.
|
||||
*
|
||||
* @param maxBlocksChanged
|
||||
*/
|
||||
public void setBlockChangeLimit(int maxBlocksChanged) {
|
||||
this.maxBlocksChanged = maxBlocksChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the super pick axe is enabled.
|
||||
*
|
||||
* @return status
|
||||
*/
|
||||
public boolean hasSuperPickAxe() {
|
||||
return superPickaxe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable super pick axe.
|
||||
*/
|
||||
public void enableSuperPickAxe() {
|
||||
superPickaxe = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable super pick axe.
|
||||
*/
|
||||
public void disableSuperPickAxe() {
|
||||
superPickaxe = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the super pick axe.
|
||||
*
|
||||
* @return status
|
||||
*/
|
||||
public boolean toggleSuperPickAxe() {
|
||||
superPickaxe = !superPickaxe;
|
||||
return superPickaxe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the placement position.
|
||||
*
|
||||
* @param player
|
||||
* @return position
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Vector getPlacementPosition(LocalPlayer player)
|
||||
throws IncompleteRegionException {
|
||||
if (!placeAtPos1) {
|
||||
return player.getBlockIn();
|
||||
}
|
||||
|
||||
return selector.getPrimaryPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle placement position.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean togglePlacementPosition() {
|
||||
placeAtPos1 = !placeAtPos1;
|
||||
return placeAtPos1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block bag for a player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public BlockBag getBlockBag(LocalPlayer player) {
|
||||
if (!useInventory) {
|
||||
return null;
|
||||
}
|
||||
return player.getInventoryBlockBag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snapshot that has been selected.
|
||||
*
|
||||
* @return the snapshot
|
||||
*/
|
||||
public Snapshot getSnapshot() {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a snapshot.
|
||||
*
|
||||
* @param snapshot
|
||||
*/
|
||||
public void setSnapshot(Snapshot snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the superPickaxeMode
|
||||
*/
|
||||
public BlockTool getSuperPickaxe() {
|
||||
return pickaxeMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the super pickaxe tool.
|
||||
*
|
||||
* @param tool
|
||||
*/
|
||||
public void setSuperPickaxe(BlockTool tool) {
|
||||
this.pickaxeMode = tool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool assigned to the item.
|
||||
*
|
||||
* @param item
|
||||
* @return the tool
|
||||
*/
|
||||
public Tool getTool(int item) {
|
||||
return tools.get(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the brush tool assigned to the item. If there is no tool assigned
|
||||
* or the tool is not assigned, the slot will be replaced with the
|
||||
* brush tool.
|
||||
*
|
||||
* @param item
|
||||
* @return the tool
|
||||
* @throws InvalidToolBindException
|
||||
*/
|
||||
public BrushTool getBrushTool(int item) throws InvalidToolBindException {
|
||||
Tool tool = getTool(item);
|
||||
|
||||
if (tool == null || !(tool instanceof BrushTool)) {
|
||||
tool = new BrushTool();
|
||||
setTool(item, tool);
|
||||
}
|
||||
|
||||
return (BrushTool)tool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tool.
|
||||
*
|
||||
* @param item
|
||||
* @param tool the tool to set
|
||||
* @throws InvalidToolBindException
|
||||
*/
|
||||
public void setTool(int item, Tool tool) throws InvalidToolBindException {
|
||||
if (item > 0 && item < 255) {
|
||||
throw new InvalidToolBindException(item, "Blocks can't be used");
|
||||
} else if (item == 263 || item == 348) {
|
||||
throw new InvalidToolBindException(item, "Item is not usuable");
|
||||
} else if (item == config.wandItem) {
|
||||
throw new InvalidToolBindException(item, "Already used for the wand");
|
||||
} else if (item == config.navigationWand) {
|
||||
throw new InvalidToolBindException(item, "Already used for the navigation wand");
|
||||
}
|
||||
|
||||
this.tools.put(item, tool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether inventory usage is enabled for this session.
|
||||
*
|
||||
* @return the useInventory
|
||||
*/
|
||||
public boolean isUsingInventory() {
|
||||
return useInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the state of inventory usage.
|
||||
*
|
||||
* @param useInventory the useInventory to set
|
||||
*/
|
||||
public void setUseInventory(boolean useInventory) {
|
||||
this.useInventory = useInventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last script used.
|
||||
*
|
||||
* @return the lastScript
|
||||
*/
|
||||
public String getLastScript() {
|
||||
return lastScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last script used.
|
||||
*
|
||||
* @param lastScript the lastScript to set
|
||||
*/
|
||||
public void setLastScript(String lastScript) {
|
||||
this.lastScript = lastScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the player the WorldEdit version.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void tellVersion(LocalPlayer player) {
|
||||
if (config.showFirstUseVersion) {
|
||||
if (!beenToldVersion) {
|
||||
player.printRaw("\u00A78WorldEdit ver. " + WorldEdit.getVersion()
|
||||
+ " (http://sk89q.com/projects/worldedit/)");
|
||||
beenToldVersion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a CUI event but only if the player has CUI support.
|
||||
*
|
||||
* @param player
|
||||
* @param event
|
||||
*/
|
||||
public void dispatchCUIEvent(LocalPlayer player, CUIEvent event) {
|
||||
if (hasCUISupport) {
|
||||
player.dispatchCUIEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the initial setup CUI messages.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void dispatchCUISetup(LocalPlayer player) {
|
||||
if (!hasCUISupport) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selector != null) {
|
||||
dispatchCUISelection(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the selection information.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void dispatchCUISelection(LocalPlayer player) {
|
||||
if (!hasCUISupport) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.dispatchCUIEvent(
|
||||
new SelectionShapeEvent(selector.getTypeId()));
|
||||
|
||||
if (selector instanceof CUIPointBasedRegion) {
|
||||
Vector[] points = ((CUIPointBasedRegion) selector).getCUIPoints();
|
||||
int size = selector.getArea();
|
||||
|
||||
int i = 0;
|
||||
for (Vector pt : points) {
|
||||
if (pt != null) {
|
||||
player.dispatchCUIEvent(
|
||||
new SelectionPointEvent(i, pt, size));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of CUI support.
|
||||
*
|
||||
* @param support
|
||||
*/
|
||||
public void setCUISupport(boolean support) {
|
||||
hasCUISupport = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect date from a user's input.
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public Calendar detectDate(String input) {
|
||||
Time.setTimeZone(getTimeZone());
|
||||
Options opt = new com.sk89q.jchronic.Options();
|
||||
opt.setNow(Calendar.getInstance(getTimeZone()));
|
||||
Span date = Chronic.parse(input, opt);
|
||||
if (date == null) {
|
||||
return null;
|
||||
} else {
|
||||
return date.getBeginCalendar();
|
||||
}
|
||||
}
|
||||
}
|
305
src/main/java/com/sk89q/worldedit/LocalWorld.java
Normal file
305
src/main/java/com/sk89q/worldedit/LocalWorld.java
Normal file
@ -0,0 +1,305 @@
|
||||
// $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.Random;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Represents a world.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class LocalWorld {
|
||||
/**
|
||||
* List of removable entity types.
|
||||
*/
|
||||
public enum EntityType {
|
||||
ARROWS,
|
||||
ITEMS,
|
||||
PAINTINGS,
|
||||
BOATS,
|
||||
MINECARTS,
|
||||
TNT,
|
||||
}
|
||||
|
||||
/**
|
||||
* Random generator.
|
||||
*/
|
||||
protected Random random = new Random();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public abstract void setBlockData(Vector pt, int data);
|
||||
|
||||
/**
|
||||
* Get block data.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public abstract int getBlockData(Vector pt);
|
||||
|
||||
/**
|
||||
* Get block light level.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public abstract int getBlockLightLevel(Vector pt);
|
||||
|
||||
/**
|
||||
* Regenerate an area.
|
||||
*
|
||||
* @param region
|
||||
* @param editSession
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean regenerate(Region region, EditSession editSession);
|
||||
|
||||
/**
|
||||
* Attempts to accurately copy a BaseBlock's extra data to the world.
|
||||
*
|
||||
* @param pt
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean copyToWorld(Vector pt, BaseBlock block);
|
||||
|
||||
/**
|
||||
* Attempts to read a BaseBlock's extra data from the world.
|
||||
*
|
||||
* @param pt
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean copyFromWorld(Vector pt, BaseBlock block);
|
||||
|
||||
/**
|
||||
* Clear a chest's contents.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean clearContainerBlockContents(Vector pt);
|
||||
|
||||
/**
|
||||
* Generate a tree at a location.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pt
|
||||
* @return
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public abstract boolean generateTree(EditSession editSession, Vector pt)
|
||||
throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Generate a big tree at a location.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pt
|
||||
* @return
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public abstract boolean generateBigTree(EditSession editSession, Vector pt)
|
||||
throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Generate a birch tree at a location.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pt
|
||||
* @return
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public abstract boolean generateBirchTree(EditSession editSession, Vector pt)
|
||||
throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Generate a redwood tree at a location.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pt
|
||||
* @return
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public abstract boolean generateRedwoodTree(EditSession editSession,
|
||||
Vector pt) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Generate a tall redwood tree at a location.
|
||||
*
|
||||
* @param editSession
|
||||
* @param pt
|
||||
* @return
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public abstract boolean generateTallRedwoodTree(EditSession editSession,
|
||||
Vector pt) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Drop an item.
|
||||
*
|
||||
* @param pt
|
||||
* @param item
|
||||
* @param times
|
||||
*/
|
||||
public void dropItem(Vector pt, BaseItemStack item, int times) {
|
||||
for (int i = 0; i < times; i++) {
|
||||
dropItem(pt, item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop an item.
|
||||
*
|
||||
* @param pt
|
||||
* @param item
|
||||
*/
|
||||
public abstract void dropItem(Vector pt, BaseItemStack item);
|
||||
|
||||
/**
|
||||
* Simulate a block being mined.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public void simulateBlockMine(Vector pt) {
|
||||
int type = getBlockType(pt);
|
||||
//setBlockType(pt, 0);
|
||||
|
||||
if (type == 1) { dropItem(pt, new BaseItemStack(4)); } // Stone
|
||||
else if (type == 2) { dropItem(pt, new BaseItemStack(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, new BaseItemStack(type));
|
||||
|
||||
if (random.nextDouble() >= 0.9) {
|
||||
dropItem(pt, new BaseItemStack(318));
|
||||
}
|
||||
}
|
||||
else if (type == 16) { dropItem(pt, new BaseItemStack(263)); } // Coal ore
|
||||
else if (type == 17) { dropItem(pt, new BaseItemStack(17, 1, (short)getBlockData(pt))); } // Log
|
||||
else if (type == 18) { // Leaves
|
||||
if (random.nextDouble() > 0.95) {
|
||||
dropItem(pt, new BaseItemStack(6));
|
||||
}
|
||||
}
|
||||
else if (type == 20) { } // Glass
|
||||
else if (type == 21) { dropItem(pt, new BaseItemStack(351, 1, (short)4), (random.nextInt(5)+4)); }
|
||||
else if (type == 26) { dropItem(pt, new BaseItemStack(355)); } // Bed
|
||||
else if (type == 35) { dropItem(pt, new BaseItemStack(35, 1, (short)getBlockData(pt))); } // Cloth
|
||||
else if (type == 43) { // Double step
|
||||
dropItem(pt, new BaseItemStack(44, 1, (short)getBlockData(pt)), 2);
|
||||
}
|
||||
else if (type == 44) { dropItem(pt, new BaseItemStack(44, 1, (short)getBlockData(pt))); } // Step
|
||||
else if (type == 47) { } // Bookshelves
|
||||
else if (type == 51) { } // Fire
|
||||
else if (type == 52) { } // Mob spawner
|
||||
else if (type == 53) { dropItem(pt, new BaseItemStack(5)); } // Wooden stairs
|
||||
else if (type == 55) { dropItem(pt, new BaseItemStack(331)); } // Redstone wire
|
||||
else if (type == 56) { dropItem(pt, new BaseItemStack(264)); } // Diamond ore
|
||||
else if (type == 59) { dropItem(pt, new BaseItemStack(295)); } // Crops
|
||||
else if (type == 60) { dropItem(pt, new BaseItemStack(3)); } // Soil
|
||||
else if (type == 62) { dropItem(pt, new BaseItemStack(61)); } // Furnace
|
||||
else if (type == 63) { dropItem(pt, new BaseItemStack(323)); } // Sign post
|
||||
else if (type == 64) { dropItem(pt, new BaseItemStack(324)); } // Wood door
|
||||
else if (type == 67) { dropItem(pt, new BaseItemStack(4)); } // Cobblestone stairs
|
||||
else if (type == 68) { dropItem(pt, new BaseItemStack(323)); } // Wall sign
|
||||
else if (type == 71) { dropItem(pt, new BaseItemStack(330)); } // Iron door
|
||||
else if (type == 73) { dropItem(pt, new BaseItemStack(331), (random.nextInt(2)+4)); } // Redstone ore
|
||||
else if (type == 74) { dropItem(pt, new BaseItemStack(331), (random.nextInt(2)+4)); } // Glowing redstone ore
|
||||
else if (type == 75) { dropItem(pt, new BaseItemStack(76)); } // Redstone torch
|
||||
else if (type == 78) { } // Snow
|
||||
else if (type == 79) { } // Ice
|
||||
else if (type == 82) { dropItem(pt, new BaseItemStack(337), 4); } // Clay
|
||||
else if (type == 83) { dropItem(pt, new BaseItemStack(338)); } // Reed
|
||||
else if (type == 89) { dropItem(pt, new BaseItemStack(348)); } // Lightstone
|
||||
else if (type == 90) { } // Portal
|
||||
else if (type == 93) { dropItem(pt, new BaseItemStack(356)); } // Repeater
|
||||
else if (type == 94) { dropItem(pt, new BaseItemStack(356)); } // Repeater
|
||||
else if (type != 0) {
|
||||
dropItem(pt, new BaseItemStack(type));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill mobs in an area.
|
||||
*
|
||||
* @param origin
|
||||
* @param radius
|
||||
* @return
|
||||
*/
|
||||
public abstract int killMobs(Vector origin, int radius);
|
||||
|
||||
/**
|
||||
* Remove entities in an area.
|
||||
*
|
||||
* @param type
|
||||
* @param origin
|
||||
* @param radius
|
||||
* @return
|
||||
*/
|
||||
public abstract int removeEntities(EntityType type, Vector origin, int radius);
|
||||
|
||||
/**
|
||||
* Compare if the other world is equal.
|
||||
*
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public abstract boolean equals(Object other);
|
||||
|
||||
/**
|
||||
* Hash code.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
}
|
65
src/main/java/com/sk89q/worldedit/LogFormat.java
Normal file
65
src/main/java/com/sk89q/worldedit/LogFormat.java
Normal file
@ -0,0 +1,65 @@
|
||||
// $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.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Level;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* Used for formatting.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class LogFormat extends Formatter {
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
Level level = record.getLevel();
|
||||
|
||||
if (level == Level.FINEST) {
|
||||
text.append("[FINEST] ");
|
||||
} else if (level == Level.FINER) {
|
||||
text.append("[FINER] ");
|
||||
} else if (level == Level.FINE) {
|
||||
text.append("[FINE] ");
|
||||
} else if (level == Level.INFO) {
|
||||
text.append("[INFO] ");
|
||||
} else if (level == Level.WARNING) {
|
||||
text.append("[WARNING] ");
|
||||
} else if (level == Level.SEVERE) {
|
||||
text.append("[SEVERE] ");
|
||||
}
|
||||
|
||||
text.append(record.getMessage());
|
||||
text.append("\r\n");
|
||||
|
||||
Throwable t = record.getThrown();
|
||||
if (t != null) {
|
||||
StringWriter writer = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(writer));
|
||||
text.append(writer.toString());
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class MaxChangedBlocksException extends WorldEditException {
|
||||
private static final long serialVersionUID = -2621044030640945259L;
|
||||
|
||||
int maxBlocks;
|
||||
|
||||
public MaxChangedBlocksException(int maxBlocks) {
|
||||
this.maxBlocks = maxBlocks;
|
||||
}
|
||||
|
||||
public int getBlockLimit() {
|
||||
return maxBlocks;
|
||||
}
|
||||
}
|
29
src/main/java/com/sk89q/worldedit/MaxRadiusException.java
Normal file
29
src/main/java/com/sk89q/worldedit/MaxRadiusException.java
Normal file
@ -0,0 +1,29 @@
|
||||
// $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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
/**
|
||||
* Thrown when a maximum radius is reached.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class MaxRadiusException extends WorldEditException {
|
||||
private static final long serialVersionUID = -8405382841529528119L;
|
||||
}
|
56
src/main/java/com/sk89q/worldedit/PlayerDirection.java
Normal file
56
src/main/java/com/sk89q/worldedit/PlayerDirection.java
Normal file
@ -0,0 +1,56 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
* Direction.
|
||||
*/
|
||||
public enum PlayerDirection {
|
||||
NORTH(new Vector(-1, 0, 0), new Vector(0, 0, 1), true),
|
||||
NORTH_EAST((new Vector(-1, 0, -1)).normalize(), (new Vector(-1, 0, 1)).normalize(), false),
|
||||
EAST(new Vector(0, 0, -1), new Vector(-1, 0, 0), true),
|
||||
SOUTH_EAST((new Vector(1, 0, -1)).normalize(), (new Vector(-1, 0, -1)).normalize(), false),
|
||||
SOUTH(new Vector(1, 0, 0), new Vector(0, 0, -1), true),
|
||||
SOUTH_WEST((new Vector(1, 0, 1)).normalize(), (new Vector(1, 0, -1)).normalize(), false),
|
||||
WEST(new Vector(0, 0, 1), new Vector(1, 0, 0), true),
|
||||
NORTH_WEST((new Vector(-1, 0, 1)).normalize(), (new Vector(1, 0, 1)).normalize(), false);
|
||||
|
||||
private Vector dir;
|
||||
private Vector leftDir;
|
||||
private boolean isOrthogonal;
|
||||
|
||||
PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) {
|
||||
this.dir = vec;
|
||||
this.leftDir = leftDir;
|
||||
this.isOrthogonal = isOrthogonal;
|
||||
}
|
||||
|
||||
public Vector vector() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public Vector leftVector() {
|
||||
return leftDir;
|
||||
}
|
||||
|
||||
public boolean isOrthogonal() {
|
||||
return isOrthogonal;
|
||||
}
|
||||
}
|
86
src/main/java/com/sk89q/worldedit/ReplacingEditSession.java
Normal file
86
src/main/java/com/sk89q/worldedit/ReplacingEditSession.java
Normal file
@ -0,0 +1,86 @@
|
||||
// $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 com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
|
||||
/**
|
||||
* An edit session that will only replace blocks as specified.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ReplacingEditSession extends EditSession {
|
||||
/**
|
||||
* Filter to use to filter blocks.
|
||||
*/
|
||||
private Mask mask;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param world
|
||||
* @param maxBlocks
|
||||
* @param mask
|
||||
*/
|
||||
public ReplacingEditSession(LocalWorld world,
|
||||
int maxBlocks, Mask mask) {
|
||||
super(world, maxBlocks);
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param world
|
||||
* @param maxBlocks
|
||||
* @param blockBag
|
||||
* @param mask
|
||||
*/
|
||||
public ReplacingEditSession(LocalWorld world, int maxBlocks,
|
||||
BlockBag blockBag, Mask mask) {
|
||||
super(world, maxBlocks, blockBag);
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a block without changing history.
|
||||
*
|
||||
* @param pt
|
||||
* @param block
|
||||
* @return Whether the block changed
|
||||
*/
|
||||
@Override
|
||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
||||
int y = pt.getBlockY();
|
||||
|
||||
if (y < 0 || y > 127) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mask.matches(this, pt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.rawSetBlock(pt, block);
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/com/sk89q/worldedit/ServerInterface.java
Normal file
47
src/main/java/com/sk89q/worldedit/ServerInterface.java
Normal file
@ -0,0 +1,47 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class ServerInterface {
|
||||
/**
|
||||
* Resolves an item name to its ID.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public abstract int resolveItem(String name);
|
||||
|
||||
/**
|
||||
* Checks if a mob type is valid.
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean isValidMobType(String type);
|
||||
|
||||
/**
|
||||
* Reload WorldEdit configuration.
|
||||
*/
|
||||
public abstract void reload();
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class UnknownDirectionException extends WorldEditException {
|
||||
private static final long serialVersionUID = 5705931351293248358L;
|
||||
|
||||
private String dir;
|
||||
|
||||
public UnknownDirectionException(String dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return dir;
|
||||
}
|
||||
}
|
39
src/main/java/com/sk89q/worldedit/UnknownItemException.java
Normal file
39
src/main/java/com/sk89q/worldedit/UnknownItemException.java
Normal file
@ -0,0 +1,39 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
* Thrown when no item exist by the ID.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class UnknownItemException extends WorldEditException {
|
||||
private static final long serialVersionUID = 2661079183700565880L;
|
||||
|
||||
private String type;
|
||||
|
||||
public UnknownItemException(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return type;
|
||||
}
|
||||
}
|
639
src/main/java/com/sk89q/worldedit/Vector.java
Normal file
639
src/main/java/com/sk89q/worldedit/Vector.java
Normal file
@ -0,0 +1,639 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Vector {
|
||||
protected final double x, y, z;
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Vector(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Vector(int x, int y, int z) {
|
||||
this.x = (double)x;
|
||||
this.y = (double)y;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Vector(float x, float y, float z) {
|
||||
this.x = (double)x;
|
||||
this.y = (double)y;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public Vector(Vector pt) {
|
||||
this.x = pt.x;
|
||||
this.y = pt.y;
|
||||
this.z = pt.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*/
|
||||
public Vector() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return (int)Math.round(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X.
|
||||
*
|
||||
* @param x
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setX(double x) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X.
|
||||
*
|
||||
* @param x
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setX(int x) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public int getBlockY() {
|
||||
return (int)Math.round(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y.
|
||||
*
|
||||
* @param y
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setY(double y) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y.
|
||||
*
|
||||
* @param y
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setY(int y) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return (int)Math.round(z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z.
|
||||
*
|
||||
* @param z
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setZ(double z) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z.
|
||||
*
|
||||
* @param z
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector setZ(int z) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Vector add(Vector other) {
|
||||
return new Vector(x + other.x, y + other.y, z + other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector add(double x, double y, double z) {
|
||||
return new Vector(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector add(int x, int y, int z) {
|
||||
return new Vector(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds points.
|
||||
*
|
||||
* @param others
|
||||
* @return New point
|
||||
*/
|
||||
public Vector add(Vector ... others) {
|
||||
double newX = x, newY = y, newZ = z;
|
||||
|
||||
for (int i = 0; i < others.length; i++) {
|
||||
newX += others[i].x;
|
||||
newY += others[i].y;
|
||||
newZ += others[i].z;
|
||||
}
|
||||
return new Vector(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Vector subtract(Vector other) {
|
||||
return new Vector(x - other.x, y - other.y, z - other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector subtract(double x, double y, double z) {
|
||||
return new Vector(this.x - x, this.y - y, this.z - z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector subtract(int x, int y, int z) {
|
||||
return new Vector(this.x - x, this.y - y, this.z - z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract points.
|
||||
*
|
||||
* @param others
|
||||
* @return New point
|
||||
*/
|
||||
public Vector subtract(Vector ... others) {
|
||||
double newX = x, newY = y, newZ = z;
|
||||
|
||||
for (int i = 0; i < others.length; i++) {
|
||||
newX -= others[i].x;
|
||||
newY -= others[i].y;
|
||||
newZ -= others[i].z;
|
||||
}
|
||||
return new Vector(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(Vector other) {
|
||||
return new Vector(x * other.x, y * other.y, z * other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(double x, double y, double z) {
|
||||
return new Vector(this.x * x, this.y * y, this.z * z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(int x, int y, int z) {
|
||||
return new Vector(this.x * x, this.y * y, this.z * z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply points.
|
||||
*
|
||||
* @param others
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(Vector ... others) {
|
||||
double newX = x, newY = y, newZ = z;
|
||||
|
||||
for (int i = 0; i < others.length; i++) {
|
||||
newX *= others[i].x;
|
||||
newY *= others[i].y;
|
||||
newZ *= others[i].z;
|
||||
}
|
||||
return new Vector(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar multiplication.
|
||||
*
|
||||
* @param n
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(double n) {
|
||||
return new Vector(this.x * n, this.y * n, this.z * n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar multiplication.
|
||||
*
|
||||
* @param n
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(float n) {
|
||||
return new Vector(this.x * n, this.y * n, this.z * n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar multiplication.
|
||||
*
|
||||
* @param n
|
||||
* @return New point
|
||||
*/
|
||||
public Vector multiply(int n) {
|
||||
return new Vector(this.x * n, this.y * n, this.z * n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Vector divide(Vector other) {
|
||||
return new Vector(x / other.x, y / other.y, z / other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector divide(double x, double y, double z) {
|
||||
return new Vector(this.x / x, this.y / y, this.z / z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return New point
|
||||
*/
|
||||
public Vector divide(int x, int y, int z) {
|
||||
return new Vector(this.x / x, this.y / y, this.z / z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar division.
|
||||
*
|
||||
* @param n
|
||||
* @return new point
|
||||
*/
|
||||
public Vector divide(int n) {
|
||||
return new Vector(x / n, y / n, z / n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar division.
|
||||
*
|
||||
* @param n
|
||||
* @return new point
|
||||
*/
|
||||
public Vector divide(double n) {
|
||||
return new Vector(x / n, y / n, z / n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar division.
|
||||
*
|
||||
* @param n
|
||||
* @return new point
|
||||
*/
|
||||
public Vector divide(float n) {
|
||||
return new Vector(x / n, y / n, z / n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of the vector.
|
||||
*
|
||||
* @return distance
|
||||
*/
|
||||
public double length() {
|
||||
return Math.sqrt(Math.pow(x, 2) +
|
||||
Math.pow(y, 2) +
|
||||
Math.pow(z, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance away from a point.
|
||||
*
|
||||
* @param pt
|
||||
* @return distance
|
||||
*/
|
||||
public double distance(Vector pt) {
|
||||
return Math.sqrt(Math.pow(pt.x - x, 2) +
|
||||
Math.pow(pt.y - y, 2) +
|
||||
Math.pow(pt.z - z, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance away from a point, squared.
|
||||
*
|
||||
* @param pt
|
||||
* @return distance
|
||||
*/
|
||||
public double distanceSq(Vector pt) {
|
||||
return Math.pow(pt.x - x, 2) +
|
||||
Math.pow(pt.y - y, 2) +
|
||||
Math.pow(pt.z - z, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the normalized vector.
|
||||
*
|
||||
* @return vector
|
||||
*/
|
||||
public Vector normalize() {
|
||||
return divide(length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a vector is contained with another.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @return
|
||||
*/
|
||||
public boolean containedWithin(Vector min, Vector max) {
|
||||
return x >= min.getX() && x <= max.getX()
|
||||
&& y >= min.getY() && y <= max.getY()
|
||||
&& z >= min.getZ() && z <= max.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a vector is contained with another.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @return
|
||||
*/
|
||||
public boolean containedWithinBlock(Vector min, Vector max) {
|
||||
return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX()
|
||||
&& getBlockY() >= min.getBlockY() && getBlockY() <= max.getBlockY()
|
||||
&& getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp the Y component.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @return
|
||||
*/
|
||||
public Vector clampY(int min, int max) {
|
||||
return new Vector(x, Math.max(min, Math.min(max, y)), z);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2D transformation.
|
||||
*
|
||||
* @param angle in degrees
|
||||
* @param aboutX
|
||||
* @param aboutZ
|
||||
* @param translateX
|
||||
* @param translateZ
|
||||
* @return
|
||||
*/
|
||||
public Vector transform2D(double angle,
|
||||
double aboutX, double aboutZ, double translateX, double translateZ) {
|
||||
angle = Math.toRadians(angle);
|
||||
double x = this.x;
|
||||
double z = this.z;
|
||||
double x2 = x * Math.cos(angle) - z * Math.sin(angle);
|
||||
double z2 = x * Math.sin(angle) + z * Math.cos(angle);
|
||||
return new Vector(x2 + aboutX + translateX,
|
||||
y,
|
||||
z2 + aboutZ + translateZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block point from a point.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return point
|
||||
*/
|
||||
public static Vector toBlockPoint(double x, double y, double z) {
|
||||
return new Vector((int)Math.floor(x),
|
||||
(int)Math.floor(y),
|
||||
(int)Math.floor(z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block point from a point.
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public BlockVector toBlockPoint() {
|
||||
return new BlockVector((int)Math.floor(x),
|
||||
(int)Math.floor(y),
|
||||
(int)Math.floor(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 Vector)) {
|
||||
return false;
|
||||
}
|
||||
Vector other = (Vector)obj;
|
||||
return other.getX() == this.x && other.getY() == this.y && other.getZ() == this.z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hash code.
|
||||
*
|
||||
* @return hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((new Double(x)).hashCode() >> 13) ^
|
||||
((new Double(y)).hashCode() >> 7) ^
|
||||
(new Double(z)).hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation "(x, y, z)".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ", " + z + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a BlockVector version.
|
||||
*
|
||||
* @return BlockVector
|
||||
*/
|
||||
public BlockVector toBlockVector() {
|
||||
return new BlockVector(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum components of two vectors.
|
||||
*
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @return minimum
|
||||
*/
|
||||
public static Vector getMinimum(Vector v1, Vector v2) {
|
||||
return new Vector(
|
||||
Math.min(v1.getX(), v2.getX()),
|
||||
Math.min(v1.getY(), v2.getY()),
|
||||
Math.min(v1.getZ(), v2.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum components of two vectors.
|
||||
*
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @return maximum
|
||||
*/
|
||||
public static Vector getMaximum(Vector v1, Vector v2) {
|
||||
return new Vector(
|
||||
Math.max(v1.getX(), v2.getX()),
|
||||
Math.max(v1.getY(), v2.getY()),
|
||||
Math.max(v1.getZ(), v2.getZ()));
|
||||
}
|
||||
}
|
193
src/main/java/com/sk89q/worldedit/Vector2D.java
Normal file
193
src/main/java/com/sk89q/worldedit/Vector2D.java
Normal file
@ -0,0 +1,193 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Vector2D {
|
||||
protected final double x, z;
|
||||
|
||||
/**
|
||||
* Construct the Vector2D object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public Vector2D(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector2D object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public Vector2D(int x, int z) {
|
||||
this.x = (double)x;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector2D object.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
*/
|
||||
public Vector2D(float x, float z) {
|
||||
this.x = (double)x;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector2D object.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
public Vector2D(Vector2D pt) {
|
||||
this.x = pt.x;
|
||||
this.z = pt.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector2D object.
|
||||
*/
|
||||
public Vector2D() {
|
||||
this.x = 0;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return (int)Math.round(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X.
|
||||
*
|
||||
* @param x
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector2D setX(double x) {
|
||||
return new Vector2D(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X.
|
||||
*
|
||||
* @param x
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector2D setX(int x) {
|
||||
return new Vector2D(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return (int)Math.round(z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z.
|
||||
*
|
||||
* @param z
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector2D setZ(double z) {
|
||||
return new Vector2D(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z.
|
||||
*
|
||||
* @param z
|
||||
* @return new vector
|
||||
*/
|
||||
public Vector2D setZ(int z) {
|
||||
return new Vector2D(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a BlockVector version.
|
||||
*
|
||||
* @return BlockVector
|
||||
*/
|
||||
public BlockVector2D toBlockVector2D() {
|
||||
return new BlockVector2D(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if another object is equivalent.
|
||||
*
|
||||
* @param obj
|
||||
* @return whether the other object is equivalent
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Vector2D)) {
|
||||
return false;
|
||||
}
|
||||
Vector other = (Vector)obj;
|
||||
return other.x == this.x && other.z == this.z;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hash code.
|
||||
*
|
||||
* @return hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((new Double(x)).hashCode() >> 13) ^
|
||||
(new Double(z)).hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation "(x, y, z)".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + z + ")";
|
||||
}
|
||||
}
|
1182
src/main/java/com/sk89q/worldedit/WorldEdit.java
Normal file
1182
src/main/java/com/sk89q/worldedit/WorldEdit.java
Normal file
File diff suppressed because it is too large
Load Diff
35
src/main/java/com/sk89q/worldedit/WorldEditException.java
Normal file
35
src/main/java/com/sk89q/worldedit/WorldEditException.java
Normal file
@ -0,0 +1,35 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class WorldEditException extends Exception {
|
||||
private static final long serialVersionUID = 3201997990797993987L;
|
||||
|
||||
protected WorldEditException() {
|
||||
}
|
||||
|
||||
protected WorldEditException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
30
src/main/java/com/sk89q/worldedit/WorldEditNotInstalled.java
Normal file
30
src/main/java/com/sk89q/worldedit/WorldEditNotInstalled.java
Normal file
@ -0,0 +1,30 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
* Raised when WorldEdit is not installed.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldEditNotInstalled extends WorldEditException {
|
||||
private static final long serialVersionUID = -4698408698930848121L;
|
||||
|
||||
}
|
30
src/main/java/com/sk89q/worldedit/WorldEditOperation.java
Normal file
30
src/main/java/com/sk89q/worldedit/WorldEditOperation.java
Normal file
@ -0,0 +1,30 @@
|
||||
// $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;
|
||||
|
||||
/**
|
||||
* Represents a WorldEdit operation.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class WorldEditOperation {
|
||||
public abstract void run(LocalSession session,
|
||||
LocalPlayer player, EditSession editSession) throws Throwable;
|
||||
}
|
126
src/main/java/com/sk89q/worldedit/WorldVector.java
Normal file
126
src/main/java/com/sk89q/worldedit/WorldVector.java
Normal file
@ -0,0 +1,126 @@
|
||||
// $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 world
|
||||
* @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 world
|
||||
* @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 world
|
||||
* @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 world
|
||||
* @param pt
|
||||
*/
|
||||
public WorldVector(LocalWorld world, Vector pt) {
|
||||
super(pt);
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Vector object.
|
||||
*
|
||||
* @param world
|
||||
*/
|
||||
public WorldVector(LocalWorld world) {
|
||||
super();
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LocalWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block point from a point.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return point
|
||||
*/
|
||||
public static WorldVector toBlockPoint(LocalWorld world, double x, double y,
|
||||
double z) {
|
||||
return new WorldVector(world, (int)Math.floor(x),
|
||||
(int)Math.floor(y),
|
||||
(int)Math.floor(z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a BlockVector version.
|
||||
*
|
||||
* @return BlockWorldVector
|
||||
*/
|
||||
public BlockWorldVector toWorldBlockVector() {
|
||||
return new BlockWorldVector(this);
|
||||
}
|
||||
}
|
153
src/main/java/com/sk89q/worldedit/bags/BlockBag.java
Normal file
153
src/main/java/com/sk89q/worldedit/bags/BlockBag.java
Normal file
@ -0,0 +1,153 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.bags;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
|
||||
/**
|
||||
* Represents a source to get blocks from and store removed ones.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class BlockBag {
|
||||
/**
|
||||
* Stores a block as if it was mined.
|
||||
*
|
||||
* @param id
|
||||
* @throws BlockBagException
|
||||
*/
|
||||
public void storeDroppedBlock(int id) throws BlockBagException {
|
||||
int dropped = BlockType.getDroppedBlock(id);
|
||||
if (dropped > 0) {
|
||||
storeBlock(dropped);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a block as if it was placed by hand.
|
||||
*
|
||||
* @param id
|
||||
* @throws BlockBagException
|
||||
*/
|
||||
public void fetchPlacedBlock(int id) throws BlockBagException {
|
||||
try {
|
||||
// Blocks that can't be fetched...
|
||||
if (id == BlockID.BEDROCK
|
||||
|| id == BlockID.GOLD_ORE
|
||||
|| id == BlockID.IRON_ORE
|
||||
|| id == BlockID.COAL_ORE
|
||||
|| id == BlockID.DIAMOND_ORE
|
||||
|| id == BlockID.LEAVES
|
||||
|| id == BlockID.TNT
|
||||
|| id == BlockID.MOB_SPAWNER
|
||||
|| id == BlockID.CROPS
|
||||
|| id == BlockID.REDSTONE_ORE
|
||||
|| id == BlockID.GLOWING_REDSTONE_ORE
|
||||
|| id == BlockID.SNOW
|
||||
|| id == BlockID.LIGHTSTONE
|
||||
|| id == BlockID.PORTAL) {
|
||||
throw new UnplaceableBlockException();
|
||||
}
|
||||
|
||||
// Override liquids
|
||||
if (id == BlockID.WATER
|
||||
|| id == BlockID.STATIONARY_WATER
|
||||
|| id == BlockID.LAVA
|
||||
|| id == BlockID.STATIONARY_LAVA) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetchBlock(id);
|
||||
} catch (OutOfBlocksException e) {
|
||||
// Look for cobblestone
|
||||
if (id == BlockID.STONE) {
|
||||
fetchBlock(BlockID.COBBLESTONE);
|
||||
// Look for dirt
|
||||
} else if (id == BlockID.GRASS) {
|
||||
fetchBlock(BlockID.DIRT);
|
||||
// Look for redstone dust
|
||||
} else if (id == BlockID.REDSTONE_WIRE) {
|
||||
fetchBlock(331);
|
||||
// Look for furnace
|
||||
} else if (id == BlockID.BURNING_FURNACE) {
|
||||
fetchBlock(BlockID.FURNACE);
|
||||
// Look for lit redstone torch
|
||||
} else if (id == BlockID.REDSTONE_TORCH_OFF) {
|
||||
fetchBlock(BlockID.REDSTONE_TORCH_ON);
|
||||
// Look for signs
|
||||
} else if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
fetchBlock(323);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block.
|
||||
*
|
||||
* @param id
|
||||
* @throws BlockBagException
|
||||
*/
|
||||
public abstract void fetchBlock(int id) throws BlockBagException;
|
||||
|
||||
/**
|
||||
* Store a block.
|
||||
*
|
||||
* @param id
|
||||
* @throws BlockBagException
|
||||
*/
|
||||
public abstract void storeBlock(int id) throws BlockBagException;
|
||||
|
||||
/**
|
||||
* Checks to see if a block exists without removing it.
|
||||
*
|
||||
* @param id
|
||||
* @return whether the block exists
|
||||
*/
|
||||
public boolean peekBlock(int id) {
|
||||
try {
|
||||
fetchBlock(id);
|
||||
storeBlock(id);
|
||||
return true;
|
||||
} catch (BlockBagException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush any changes. This is called at the end.
|
||||
*/
|
||||
public abstract void flushChanges();
|
||||
|
||||
/**
|
||||
* Adds a position to be used a source.
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
public abstract void addSourcePosition(Vector pos);
|
||||
/**
|
||||
* Adds a position to be used a source.
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
public abstract void addSingleSourcePosition(Vector pos);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.bags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BlockBagException extends Exception {
|
||||
private static final long serialVersionUID = 4672190086028430655L;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.bags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class OutOfBlocksException extends BlockBagException {
|
||||
private static final long serialVersionUID = 7495899825677689509L;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.bags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class OutOfSpaceException extends BlockBagException {
|
||||
private static final long serialVersionUID = -2962840237632916821L;
|
||||
|
||||
/**
|
||||
* Stores the block ID.
|
||||
*/
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
* @param id
|
||||
*/
|
||||
public OutOfSpaceException(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.bags;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class UnplaceableBlockException extends BlockBagException {
|
||||
private static final long serialVersionUID = 7227883966999843526L;
|
||||
|
||||
}
|
116
src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
Normal file
116
src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
Normal file
@ -0,0 +1,116 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.worldedit.data.BlockData;
|
||||
|
||||
/**
|
||||
* Represents a block.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BaseBlock {
|
||||
/**
|
||||
* BaseBlock type.
|
||||
*/
|
||||
private short type = 0;
|
||||
/**
|
||||
* BaseBlock data.
|
||||
*/
|
||||
private char data = 0;
|
||||
|
||||
/**
|
||||
* Construct the block with its type.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public BaseBlock(int type) {
|
||||
this.type = (short)type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the block with its type and data.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
*/
|
||||
public BaseBlock(int type, int data) {
|
||||
this.type = (short)type;
|
||||
this.data = (char)data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public int getType() {
|
||||
return (int)type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(int type) {
|
||||
this.type = (short)type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the data
|
||||
*/
|
||||
public int getData() {
|
||||
return (int)data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data the data to set
|
||||
*/
|
||||
public void setData(int data) {
|
||||
this.data = (char)data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it's air.
|
||||
*
|
||||
* @return if air
|
||||
*/
|
||||
public boolean isAir() {
|
||||
return type == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this block 90 degrees.
|
||||
*/
|
||||
public void rotate90() {
|
||||
data = (char)BlockData.rotate90(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this block -90 degrees.
|
||||
*/
|
||||
public void rotate90Reverse() {
|
||||
data = (char)BlockData.rotate90Reverse(type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip this block.
|
||||
*/
|
||||
public void flip() {
|
||||
data = (char)BlockData.flip(type, data);
|
||||
}
|
||||
}
|
85
src/main/java/com/sk89q/worldedit/blocks/BaseItem.java
Normal file
85
src/main/java/com/sk89q/worldedit/blocks/BaseItem.java
Normal file
@ -0,0 +1,85 @@
|
||||
// $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.blocks;
|
||||
|
||||
/**
|
||||
* Represents an item.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BaseItem {
|
||||
/**
|
||||
* Item ID.
|
||||
*/
|
||||
private int id;
|
||||
/**
|
||||
* Item damage.
|
||||
*/
|
||||
private short damage;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public BaseItem(int id) {
|
||||
this.id = id;
|
||||
this.damage = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param damage
|
||||
*/
|
||||
public BaseItem(int id, short damage) {
|
||||
this.id = id;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public int getType() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the damage
|
||||
*/
|
||||
public short getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param damage the damage to set
|
||||
*/
|
||||
public void setDamage(short damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
}
|
78
src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java
Normal file
78
src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java
Normal file
@ -0,0 +1,78 @@
|
||||
// $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.blocks;
|
||||
|
||||
/**
|
||||
* Represents a stack of BaseItems.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BaseItemStack extends BaseItem {
|
||||
/**
|
||||
* Amount of an item.
|
||||
*/
|
||||
private int amount = 1;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public BaseItemStack(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param amount
|
||||
*/
|
||||
public BaseItemStack(int id, int amount) {
|
||||
super(id);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id
|
||||
* @param amount
|
||||
* @param damage
|
||||
*/
|
||||
public BaseItemStack(int id, int amount, short damage) {
|
||||
super(id, damage);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
119
src/main/java/com/sk89q/worldedit/blocks/BlockID.java
Normal file
119
src/main/java/com/sk89q/worldedit/blocks/BlockID.java
Normal file
@ -0,0 +1,119 @@
|
||||
// $Id$
|
||||
/*
|
||||
* CraftBook
|
||||
* 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.blocks;
|
||||
|
||||
/**
|
||||
* List of block IDs.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public final class BlockID {
|
||||
public static final int AIR = 0;
|
||||
public static final int STONE = 1;
|
||||
public static final int GRASS = 2;
|
||||
public static final int DIRT = 3;
|
||||
public static final int COBBLESTONE = 4;
|
||||
public static final int WOOD = 5;
|
||||
public static final int SAPLING = 6;
|
||||
public static final int BEDROCK = 7;
|
||||
public static final int WATER = 8;
|
||||
public static final int STATIONARY_WATER = 9;
|
||||
public static final int LAVA = 10;
|
||||
public static final int STATIONARY_LAVA = 11;
|
||||
public static final int SAND = 12;
|
||||
public static final int GRAVEL = 13;
|
||||
public static final int GOLD_ORE = 14;
|
||||
public static final int IRON_ORE = 15;
|
||||
public static final int COAL_ORE = 16;
|
||||
public static final int LOG = 17;
|
||||
public static final int LEAVES = 18;
|
||||
public static final int SPONGE = 19;
|
||||
public static final int GLASS = 20;
|
||||
public static final int LAPIS_LAZULI_ORE = 21;
|
||||
public static final int LAPIS_LAZULI_BLOCK = 22;
|
||||
public static final int DISPENSER = 23;
|
||||
public static final int SANDSTONE = 24;
|
||||
public static final int NOTE_BLOCK = 25;
|
||||
public static final int BED = 26;
|
||||
public static final int POWERED_RAIL = 27;
|
||||
public static final int DETECTOR_RAIL = 28;
|
||||
public static final int WEB = 30;
|
||||
public static final int CLOTH = 35;
|
||||
public static final int YELLOW_FLOWER = 37;
|
||||
public static final int RED_FLOWER = 38;
|
||||
public static final int BROWN_MUSHROOM = 39;
|
||||
public static final int RED_MUSHROOM = 40;
|
||||
public static final int GOLD_BLOCK = 41;
|
||||
public static final int IRON_BLOCK = 42;
|
||||
public static final int DOUBLE_STEP = 43;
|
||||
public static final int STEP = 44;
|
||||
public static final int BRICK = 45;
|
||||
public static final int TNT = 46;
|
||||
public static final int BOOKCASE = 47;
|
||||
public static final int MOSSY_COBBLESTONE = 48;
|
||||
public static final int OBSIDIAN = 49;
|
||||
public static final int TORCH = 50;
|
||||
public static final int FIRE = 51;
|
||||
public static final int MOB_SPAWNER = 52;
|
||||
public static final int WOODEN_STAIRS = 53;
|
||||
public static final int CHEST = 54;
|
||||
public static final int REDSTONE_WIRE = 55;
|
||||
public static final int DIAMOND_ORE = 56;
|
||||
public static final int DIAMOND_BLOCK = 57;
|
||||
public static final int WORKBENCH = 58;
|
||||
public static final int CROPS = 59;
|
||||
public static final int SOIL = 60;
|
||||
public static final int FURNACE = 61;
|
||||
public static final int BURNING_FURNACE = 62;
|
||||
public static final int SIGN_POST = 63;
|
||||
public static final int WOODEN_DOOR = 64;
|
||||
public static final int LADDER = 65;
|
||||
public static final int MINECART_TRACKS = 66;
|
||||
public static final int COBBLESTONE_STAIRS = 67;
|
||||
public static final int WALL_SIGN = 68;
|
||||
public static final int LEVER = 69;
|
||||
public static final int STONE_PRESSURE_PLATE = 70;
|
||||
public static final int IRON_DOOR = 71;
|
||||
public static final int WOODEN_PRESSURE_PLATE = 72;
|
||||
public static final int REDSTONE_ORE = 73;
|
||||
public static final int GLOWING_REDSTONE_ORE = 74;
|
||||
public static final int REDSTONE_TORCH_OFF = 75;
|
||||
public static final int REDSTONE_TORCH_ON = 76;
|
||||
public static final int STONE_BUTTON = 77;
|
||||
public static final int SNOW = 78;
|
||||
public static final int ICE = 79;
|
||||
public static final int SNOW_BLOCK = 80;
|
||||
public static final int CACTUS = 81;
|
||||
public static final int CLAY = 82;
|
||||
public static final int REED = 83;
|
||||
public static final int JUKEBOX = 84;
|
||||
public static final int FENCE = 85;
|
||||
public static final int PUMPKIN = 86;
|
||||
public static final int NETHERSTONE = 87;
|
||||
public static final int NETHERRACK = 87;
|
||||
public static final int SLOW_SAND = 88;
|
||||
public static final int LIGHTSTONE = 89;
|
||||
public static final int PORTAL = 90;
|
||||
public static final int JACKOLANTERN = 91;
|
||||
public static final int CAKE_BLOCK = 92;
|
||||
public static final int REDSTONE_REPEATER_OFF = 93;
|
||||
public static final int REDSTONE_REPEATER_ON = 94;
|
||||
public static final int LOCKED_CHEST = 95;
|
||||
}
|
538
src/main/java/com/sk89q/worldedit/blocks/BlockType.java
Normal file
538
src/main/java/com/sk89q/worldedit/blocks/BlockType.java
Normal file
@ -0,0 +1,538 @@
|
||||
// $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.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* Block types.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public enum BlockType {
|
||||
AIR(0, "Air", "air"),
|
||||
STONE(1, "Stone", new String[] {"stone", "rock"}),
|
||||
GRASS(2, "Grass", "grass"),
|
||||
DIRT(3, "Dirt", "dirt"),
|
||||
COBBLESTONE(4, "Cobblestone", new String[] {"cobblestone", "cobble"}),
|
||||
WOOD(5, "Wood", new String[] {"wood", "woodplank", "plank", "woodplanks", "planks"}),
|
||||
SAPLING(6, "Sapling", "sapling"),
|
||||
BEDROCK(7, "Bedrock", new String[] {"adminium", "bedrock"}),
|
||||
WATER(8, "Water", new String[] {"watermoving", "movingwater"}),
|
||||
STATIONARY_WATER(9, "Water (stationary)",
|
||||
new String[] {"water", "waterstationary", "stationarywater", "stillwater"}),
|
||||
LAVA(10, "Lava", new String[] {"lavamoving", "movinglava"}),
|
||||
STATIONARY_LAVA(11, "Lava (stationary)",
|
||||
new String[] {"lava", "lavastationary", "stationarylava", "stilllava"}),
|
||||
SAND(12, "Sand", "sand"),
|
||||
GRAVEL(13, "Gravel", "gravel"),
|
||||
GOLD_ORE(14, "Gold ore", "goldore"),
|
||||
IRON_ORE(15, "Iron ore", "ironore"),
|
||||
COAL_ORE(16, "Coal ore", "coalore"),
|
||||
LOG(17, "Log", new String[] {"log", "tree", "pine", "oak", "birch", "redwood"}),
|
||||
LEAVES(18, "Leaves", new String[] {"leaves", "leaf"}),
|
||||
SPONGE(19, "Sponge", "sponge"),
|
||||
GLASS(20, "Glass", "glass"),
|
||||
LAPIS_LAZULI_ORE(21, "Lapis lazuli ore", new String[] {"lapislazuliore", "blueore", "lapisore"}),
|
||||
LAPIS_LAZULI(22, "Lapis lazuli", new String[] {"lapislazuli", "lapislazuliblock", "bluerock"}),
|
||||
DISPENSER(23, "Dispenser", "dispenser"),
|
||||
SANDSTONE(24, "Sandstone", "sandstone"),
|
||||
NOTE_BLOCK(25, "Note block", new String[] {"musicblock", "noteblock", "note", "music", "instrument"}),
|
||||
BED(26, "Bed", "bed"),
|
||||
POWERED_RAIL(27, "Powered Rail",
|
||||
new String[] {"poweredrail", "boosterrail", "poweredtrack", "boostertrack"}),
|
||||
DETECTOR_RAIL(28, "Detector Rail", "detectorrail"),
|
||||
WEB(30, "Web", new String[] {"web", "spiderweb"}),
|
||||
CLOTH(35, "Wool", new String[] {"cloth", "wool"}),
|
||||
YELLOW_FLOWER(37, "Yellow flower", new String[] {"yellowflower", "flower"}),
|
||||
RED_FLOWER(38, "Red rose", new String[] {"redflower", "redrose", "rose"}),
|
||||
BROWN_MUSHROOM(39, "Brown mushroom", new String[] {"brownmushroom", "mushroom"}),
|
||||
RED_MUSHROOM(40, "Red mushroom", "redmushroom"),
|
||||
GOLD_BLOCK(41, "Gold block", new String[] {"gold", "goldblock"}),
|
||||
IRON_BLOCK(42, "Iron block", new String[] {"iron", "ironblock"}),
|
||||
DOUBLE_STEP(43, "Double step", new String[] {"doubleslab", "doublestoneslab", "doublestep"}),
|
||||
STEP(44, "Step", new String[] {"slab", "stoneslab", "step", "halfstep"}),
|
||||
BRICK(45, "Brick", new String[] {"brick", "brickblock"}),
|
||||
TNT(46, "TNT", "tnt"),
|
||||
BOOKCASE(47, "Bookcase", new String[] {"bookshelf", "bookshelves"}),
|
||||
MOSSY_COBBLESTONE(48, "Cobblestone (mossy)",
|
||||
new String[] {"mossycobblestone", "mossstone", "mossystone",
|
||||
"mosscobble", "mossycobble", "moss", "mossy", "sossymobblecone"}),
|
||||
OBSIDIAN(49, "Obsidian", "obsidian"),
|
||||
TORCH(50, "Torch", "torch"),
|
||||
FIRE(51, "Fire", new String[] {"fire", "flame", "flames"}),
|
||||
MOB_SPAWNER(52, "Mob spawner", new String[] {"mobspawner", "spawner"}),
|
||||
WOODEN_STAIRS(53, "Wooden stairs",
|
||||
new String[] {"woodstair", "woodstairs", "woodenstair", "woodenstairs"}),
|
||||
CHEST(54, "Chest", new String[] {"chest", "storage"}),
|
||||
REDSTONE_WIRE(55, "Redstone wire", "redstone"),
|
||||
DIAMOND_ORE(56, "Diamond ore", "diamondore"),
|
||||
DIAMOND_BLOCK(57, "Diamond block", new String[] {"diamond", "diamondblock"}),
|
||||
WORKBENCH(58, "Workbench", new String[] {"workbench", "table", "craftingtable"}),
|
||||
CROPS(59, "Crops", new String[] {"crops", "crop", "plant", "plants"}),
|
||||
SOIL(60, "Soil", new String[] {"soil", "farmland"}),
|
||||
FURNACE(61, "Furnace", "furnace"),
|
||||
BURNING_FURNACE(62, "Furnace (burning)", new String[] {"burningfurnace", "litfurnace"}),
|
||||
SIGN_POST(63, "Sign post", new String[] {"sign", "signpost"}),
|
||||
WOODEN_DOOR(64, "Wooden door", new String[] {"wooddoor", "woodendoor", "door"}),
|
||||
LADDER(65, "Ladder", "ladder"),
|
||||
MINECART_TRACKS(66, "Minecart tracks",
|
||||
new String[] {"track", "tracks", "minecrattrack", "minecarttracks", "rails", "rail"}),
|
||||
COBBLESTONE_STAIRS(67, "Cobblestone stairs",
|
||||
new String[] {"cobblestonestair", "cobblestonestairs", "cobblestair", "cobblestairs"}),
|
||||
WALL_SIGN(68, "Wall sign", "wallsign"),
|
||||
LEVER(69, "Lever", new String[] {"lever", "switch", "stonelever", "stoneswitch"}),
|
||||
STONE_PRESSURE_PLATE(70, "Stone pressure plate",
|
||||
new String[] {"stonepressureplate", "stoneplate"}),
|
||||
IRON_DOOR(71, "Iron Door", "irondoor"),
|
||||
WOODEN_PRESSURE_PLATE(72, "Wooden pressure plate",
|
||||
new String[] {"woodpressureplate", "woodplate", "woodenpressureplate", "woodenplate"}),
|
||||
REDSTONE_ORE(73, "Redstone ore", "redstoneore"),
|
||||
GLOWING_REDSTONE_ORE(74, "Glowing redstone ore", "glowingredstoneore"),
|
||||
REDSTONE_TORCH_OFF(75, "Redstone torch (off)",
|
||||
new String[] {"redstonetorchoff", "rstorchoff"}),
|
||||
REDSTONE_TORCH_ON(76, "Redstone torch (on)",
|
||||
new String [] {"redstonetorch", "redstonetorchon", "rstorchon"}),
|
||||
STONE_BUTTON(77, "Stone Button", new String[] {"stonebutton", "button"}),
|
||||
SNOW(78, "Snow", "snow"),
|
||||
ICE(79, "Ice", "ice"),
|
||||
SNOW_BLOCK(80, "Snow block", "snowblock"),
|
||||
CACTUS(81, "Cactus", new String[] {"cactus", "cacti"}),
|
||||
CLAY(82, "Clay", "clay"),
|
||||
SUGAR_CANE(83, "Reed", new String[] {"reed", "cane", "sugarcane", "sugarcanes"}),
|
||||
JUKEBOX(84, "Jukebox", new String[] {"jukebox", "stereo", "recordplayer"}),
|
||||
FENCE(85, "Fence", "fence"),
|
||||
PUMPKIN(86, "Pumpkin", "pumpkin"),
|
||||
NETHERRACK(87, "Netherrack",
|
||||
new String[] {"redmossycobblestone", "redcobblestone", "redmosstone",
|
||||
"redcobble", "netherstone", "netherrack", "nether", "hellstone"}),
|
||||
SOUL_SAND(88, "Soul sand",
|
||||
new String[] {"slowmud", "mud", "soulsand", "hellmud"}),
|
||||
GLOWSTONE(89, "Glowstone",
|
||||
new String[] {"brittlegold", "glowstone", "lightstone", "brimstone", "australium"}),
|
||||
PORTAL(90, "Portal", "portal"),
|
||||
JACK_O_LANTERN(91, "Pumpkin (on)",
|
||||
new String[] {"pumpkinlighted", "pumpkinon", "litpumpkin", "jackolantern"}),
|
||||
CAKE(92, "Cake", new String[] {"cake", "cakeblock"}),
|
||||
REDSTONE_REPEATER_OFF(93, "Redstone repeater (off)", new String[] {"diodeoff", "redstonerepeater", "repeater", "delayer"}),
|
||||
REDSTONE_REPEATER_ON(94, "Redstone repeater (on)", new String[] {"diode", "diodeon", "redstonerepeateron", "repeateron", "delayeron"}),
|
||||
LOCKED_CHEST(95, "Locked chest", new String[] {"lockedchest", "steveco", "supplycrate", "valveneedstoworkonep3nottf2kthx"});
|
||||
|
||||
/**
|
||||
* Stores a list of dropped blocks for blocks.
|
||||
*/
|
||||
private static final Map<Integer,Integer> blockDrops = new HashMap<Integer,Integer>();
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
*/
|
||||
static {
|
||||
blockDrops.put(1, 4);
|
||||
blockDrops.put(2, 3);
|
||||
blockDrops.put(3, 3);
|
||||
blockDrops.put(4, 4);
|
||||
blockDrops.put(5, 5);
|
||||
blockDrops.put(6, 6);
|
||||
blockDrops.put(7, -1);
|
||||
blockDrops.put(12, 12);
|
||||
blockDrops.put(13, 13);
|
||||
blockDrops.put(14, 14);
|
||||
blockDrops.put(15, 15);
|
||||
blockDrops.put(16, 16);
|
||||
blockDrops.put(17, 17);
|
||||
blockDrops.put(18, 18);
|
||||
blockDrops.put(19, 19);
|
||||
blockDrops.put(20, 20); // Have to drop glass for //undo
|
||||
blockDrops.put(21, 21); // Block damage drops not implemented
|
||||
blockDrops.put(22, 22);
|
||||
blockDrops.put(23, 23);
|
||||
blockDrops.put(24, 24);
|
||||
blockDrops.put(25, 25);
|
||||
blockDrops.put(26, 355);
|
||||
blockDrops.put(27, 27);
|
||||
blockDrops.put(28, 28);
|
||||
blockDrops.put(30, 30);
|
||||
blockDrops.put(35, 35);
|
||||
blockDrops.put(37, 37);
|
||||
blockDrops.put(38, 38);
|
||||
blockDrops.put(39, 39);
|
||||
blockDrops.put(40, 40);
|
||||
blockDrops.put(41, 41);
|
||||
blockDrops.put(42, 42);
|
||||
blockDrops.put(43, 43);
|
||||
blockDrops.put(44, 44);
|
||||
blockDrops.put(45, 45);
|
||||
blockDrops.put(47, 47);
|
||||
blockDrops.put(48, 48);
|
||||
blockDrops.put(49, 49);
|
||||
blockDrops.put(50, 50);
|
||||
blockDrops.put(53, 53);
|
||||
blockDrops.put(54, 54);
|
||||
blockDrops.put(55, 331);
|
||||
blockDrops.put(56, 264);
|
||||
blockDrops.put(57, 57);
|
||||
blockDrops.put(58, 58);
|
||||
blockDrops.put(59, 295);
|
||||
blockDrops.put(60, 60);
|
||||
blockDrops.put(61, 61);
|
||||
blockDrops.put(62, 61);
|
||||
blockDrops.put(63, 323);
|
||||
blockDrops.put(64, 324);
|
||||
blockDrops.put(65, 65);
|
||||
blockDrops.put(66, 66);
|
||||
blockDrops.put(67, 67);
|
||||
blockDrops.put(68, 323);
|
||||
blockDrops.put(69, 69);
|
||||
blockDrops.put(70, 70);
|
||||
blockDrops.put(71, 330);
|
||||
blockDrops.put(72, 72);
|
||||
blockDrops.put(73, 331);
|
||||
blockDrops.put(74, 331);
|
||||
blockDrops.put(75, 76);
|
||||
blockDrops.put(76, 76);
|
||||
blockDrops.put(77, 77);
|
||||
blockDrops.put(78, 332);
|
||||
blockDrops.put(80, 80);
|
||||
blockDrops.put(81, 81);
|
||||
blockDrops.put(82, 82);
|
||||
blockDrops.put(83, 338);
|
||||
blockDrops.put(84, 84);
|
||||
blockDrops.put(85, 85);
|
||||
blockDrops.put(86, 86);
|
||||
blockDrops.put(87, 87);
|
||||
blockDrops.put(88, 88);
|
||||
blockDrops.put(89, 348);
|
||||
blockDrops.put(91, 91);
|
||||
blockDrops.put(92, 354);
|
||||
blockDrops.put(93, 356);
|
||||
blockDrops.put(94, 356);
|
||||
blockDrops.put(95, 95);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a map of the IDs for fast access.
|
||||
*/
|
||||
private static final Map<Integer,BlockType> ids = new HashMap<Integer,BlockType>();
|
||||
/**
|
||||
* Stores a map of the names for fast access.
|
||||
*/
|
||||
private static final Map<String,BlockType> lookup = new HashMap<String,BlockType>();
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String[] lookupKeys;
|
||||
|
||||
static {
|
||||
for(BlockType type : EnumSet.allOf(BlockType.class)) {
|
||||
ids.put(type.id, type);
|
||||
for (String key : type.lookupKeys) {
|
||||
lookup.put(key, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
BlockType(int id, String name, String lookupKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = new String[]{lookupKey};
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
BlockType(int id, String name, String[] lookupKeys) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from ID. May return null.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static BlockType fromID(int id) {
|
||||
return ids.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static BlockType lookup(String name) {
|
||||
return lookup.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block numeric ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly block name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block should be placed last.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean shouldPlaceLast() {
|
||||
return shouldPlaceLast(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether a block should be placed last.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean shouldPlaceLast(int id) {
|
||||
return id == 6 // Saplings
|
||||
|| id == 26 // Beds
|
||||
|| id == 27 // Powered rails
|
||||
|| id == 28 // Detector rails
|
||||
|| id == 37 // Yellow flower
|
||||
|| id == 38 // Red flower
|
||||
|| id == 39 // Brown mushroom
|
||||
|| id == 40 // Red mush room
|
||||
|| id == 50 // Torch
|
||||
|| id == 51 // Fire
|
||||
|| id == 55 // Redstone wire
|
||||
|| id == 59 // Crops
|
||||
|| id == 63 // Sign post
|
||||
|| id == 64 // Wooden door
|
||||
|| id == 65 // Ladder
|
||||
|| id == 66 // Minecart tracks
|
||||
|| id == 68 // Wall sign
|
||||
|| id == 69 // Lever
|
||||
|| id == 70 // Stone pressure plate
|
||||
|| id == 71 // Iron door
|
||||
|| id == 72 // Wooden pressure plate
|
||||
|| id == 75 // Redstone torch (off)
|
||||
|| id == 76 // Redstone torch (on)
|
||||
|| id == 77 // Stone button
|
||||
|| id == 78 // Snow
|
||||
|| id == 81 // Cactus
|
||||
|| id == 83 // Reed
|
||||
|| id == 90 // Portal
|
||||
|| id == 92 // Cake
|
||||
|| id == 93 // Repeater (off)
|
||||
|| id == 94; // Repeater (on)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a block can be passed through.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean canPassThrough(int id) {
|
||||
return id == 0 // Air
|
||||
|| id == 8 // Water
|
||||
|| id == 9 // Water
|
||||
|| id == 6 // Saplings
|
||||
|| id == 27 // Powered rails
|
||||
|| id == 28 // Detector rails
|
||||
|| id == 30 // Web <- someone will hate me for this
|
||||
|| id == 37 // Yellow flower
|
||||
|| id == 38 // Red flower
|
||||
|| id == 39 // Brown mushroom
|
||||
|| id == 40 // Red mush room
|
||||
|| id == 50 // Torch
|
||||
|| id == 51 // Fire
|
||||
|| id == 55 // Redstone wire
|
||||
|| id == 59 // Crops
|
||||
|| id == 63 // Sign post
|
||||
|| id == 65 // Ladder
|
||||
|| id == 66 // Minecart tracks
|
||||
|| id == 68 // Wall sign
|
||||
|| id == 69 // Lever
|
||||
|| id == 70 // Stone pressure plate
|
||||
|| id == 72 // Wooden pressure plate
|
||||
|| id == 75 // Redstone torch (off)
|
||||
|| id == 76 // Redstone torch (on)
|
||||
|| id == 77 // Stone button
|
||||
|| id == 78 // Snow
|
||||
|| id == 83 // Reed
|
||||
|| id == 90 // Portal
|
||||
|| id == 93 // Diode (off)
|
||||
|| id == 94; // Diode (on)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block uses its data value.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean usesData(int id) {
|
||||
return id == 6 // Saplings
|
||||
|| id == 8 // Water
|
||||
|| id == 9 // Water
|
||||
|| id == 10 // Lava
|
||||
|| id == 11 // Lava
|
||||
|| id == 17 // Wood
|
||||
|| id == 18 // Leaves
|
||||
|| id == 23 // Dispenser
|
||||
|| id == 25 // Note Block
|
||||
|| id == 26 // Bed
|
||||
|| id == 27 // Powered rails
|
||||
|| id == 28 // Detector rails
|
||||
|| id == 35 // Wool
|
||||
|| id == 43 // Double slab
|
||||
|| id == 44 // Slab
|
||||
|| id == 50 // Torch
|
||||
|| id == 53 // Wooden stairs
|
||||
|| id == 55 // Redstone wire
|
||||
|| id == 59 // Crops
|
||||
|| id == 60 // Soil
|
||||
|| id == 61 // Furnace
|
||||
|| id == 62 // Furnace
|
||||
|| id == 63 // Sign post
|
||||
|| id == 64 // Wooden door
|
||||
|| id == 65 // Ladder
|
||||
|| id == 66 // Minecart track
|
||||
|| id == 67 // Cobblestone stairs
|
||||
|| id == 68 // Wall sign
|
||||
|| id == 69 // Lever
|
||||
|| id == 70 // Stone pressure plate
|
||||
|| id == 71 // Iron door
|
||||
|| id == 72 // Wooden pressure plate
|
||||
|| id == 75 // Redstone torch (off)
|
||||
|| id == 76 // Redstone torch (on)
|
||||
|| id == 77 // Stone button
|
||||
|| id == 81 // Cactus
|
||||
|| id == 86 // Pumpkin
|
||||
|| id == 91 // Jack-o-lantern
|
||||
|| id == 92 // Cake
|
||||
|| id == 93 // Redstone repeater (off)
|
||||
|| id == 94; // Redstone repeater (on)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the block is a container block.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean isContainerBlock(int id) {
|
||||
return id == 23 // Dispenser
|
||||
|| id == 61 // Furnace
|
||||
|| id == 62 // Furnace
|
||||
|| id == 54; // Chest
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a block uses redstone in some way.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean isRedstoneBlock(int id) {
|
||||
return id == 27 // Powered rail
|
||||
|| id == 28 // Detector rail
|
||||
|| id == 69 // Lever
|
||||
|| id == 70 // Stone pressure plate
|
||||
|| id == 72 // Wood pressure plate
|
||||
|| id == 76 // Redstone torch
|
||||
|| id == 75 // Redstone torch
|
||||
|| id == 77 // Stone button
|
||||
|| id == 55 // Redstone wire
|
||||
|| id == 64 // Wooden door
|
||||
|| id == 71 // Iron door
|
||||
|| id == 46 // TNT
|
||||
|| id == 23 // Dispenser
|
||||
|| id == 25 // Note block
|
||||
|| id == 93 // Diode (off)
|
||||
|| id == 94; // Diode (on)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a block can transfer redstone.
|
||||
* Made this since isRedstoneBlock was getting big.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean canTransferRedstone(int id) {
|
||||
return id == 75 // Redstone torch (off)
|
||||
|| id == 76 // Redstone torch (on)
|
||||
|| id == 55 // Redstone wire
|
||||
|| id == 93 // Diode (off)
|
||||
|| id == 94; // Diode (on)
|
||||
}
|
||||
|
||||
/**
|
||||
* Yay for convenience methods.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean isRedstoneSource(int id) {
|
||||
return id == 28 // Detector rail
|
||||
|| id == 75 // Redstone torch (off)
|
||||
|| id == 76 // Redstone torch (on)
|
||||
|| id == 69 // Lever
|
||||
|| id == 70 // Stone plate
|
||||
|| id == 72 // Wood plate
|
||||
|| id == 77; // Button
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block or item that would have been dropped. If nothing is
|
||||
* dropped, 0 will be returned. If the block should not be destroyed
|
||||
* (i.e. bedrock), -1 will be returned.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static int getDroppedBlock(int id) {
|
||||
Integer dropped = blockDrops.get(id);
|
||||
if (dropped == null) {
|
||||
return 0;
|
||||
}
|
||||
return dropped;
|
||||
}
|
||||
}
|
165
src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java
Normal file
165
src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java
Normal file
@ -0,0 +1,165 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Represents chests.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||
/**
|
||||
* Store the list of items.
|
||||
*/
|
||||
private BaseItemStack[] items;
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*/
|
||||
public ChestBlock() {
|
||||
super(54);
|
||||
items = new BaseItemStack[27];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public ChestBlock(int data) {
|
||||
super(54, data);
|
||||
items = new BaseItemStack[27];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param data
|
||||
* @param items
|
||||
*/
|
||||
public ChestBlock(int data, BaseItemStack[] items) {
|
||||
super(54, data);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BaseItemStack[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of items.
|
||||
*/
|
||||
public void setItems(BaseItemStack[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tile entity ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "Chest";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
List<Tag> itemsList = new ArrayList<Tag>();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
BaseItemStack item = items[i];
|
||||
if (item != null) {
|
||||
Map<String,Tag> data = new HashMap<String,Tag>();
|
||||
CompoundTag itemTag = new CompoundTag("Items", data);
|
||||
data.put("id", new ShortTag("id", (short)item.getType()));
|
||||
data.put("Damage", new ShortTag("Damage", item.getDamage()));
|
||||
data.put("Count", new ByteTag("Count", (byte)item.getAmount()));
|
||||
data.put("Slot", new ByteTag("Slot", (byte)i));
|
||||
itemsList.add(itemTag);
|
||||
}
|
||||
}
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Chest")) {
|
||||
throw new DataException("'Chest' tile entity expected");
|
||||
}
|
||||
|
||||
ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class);
|
||||
BaseItemStack[] newItems = new BaseItemStack[27];
|
||||
|
||||
for (Tag tag : items.getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new DataException("CompoundTag expected as child tag of Chest's Items");
|
||||
}
|
||||
|
||||
CompoundTag item = (CompoundTag)tag;
|
||||
Map<String,Tag> itemValues = item.getValue();
|
||||
|
||||
short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class))
|
||||
.getValue();
|
||||
short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class))
|
||||
.getValue();
|
||||
byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class))
|
||||
.getValue();
|
||||
byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class))
|
||||
.getValue();
|
||||
|
||||
if (slot >= 0 && slot <= 26) {
|
||||
newItems[slot] = new BaseItemStack(id, count, damage);
|
||||
}
|
||||
}
|
||||
|
||||
this.items = newItems;
|
||||
}
|
||||
}
|
133
src/main/java/com/sk89q/worldedit/blocks/ClothColor.java
Normal file
133
src/main/java/com/sk89q/worldedit/blocks/ClothColor.java
Normal file
@ -0,0 +1,133 @@
|
||||
// $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.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* Cloth colors.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public enum ClothColor {
|
||||
WHITE(0, "White", "white"),
|
||||
ORANGE(1, "Orange", "orange"),
|
||||
MAGENTA(2, "Magenta", "magenta"),
|
||||
LIGHT_BLUE(3, "Light blue", "lightblue"),
|
||||
YELLOW(4, "Yellow", "yellow"),
|
||||
LIGHT_GREEN(5, "Light green", "lightgreen"),
|
||||
PINK(6, "Pink", new String[] {"pink", "lightred"}),
|
||||
GRAY(7, "Gray", new String[] {"grey", "gray"}),
|
||||
LIGHT_GRAY(8, "Light gray", new String[] {"lightgrey", "lightgray"}),
|
||||
CYAN(9, "Cyan", new String[] {"cyan", "turquoise"}),
|
||||
PURPLE(10, "Purple", new String[] {"purple", "violet"}),
|
||||
BLUE(11, "Blue", "blue"),
|
||||
BROWN(12, "Brown", new String[] {"brown", "cocoa", "coffee"}),
|
||||
DARK_GREEN(13, "Dark green", new String[] {"green", "darkgreen", "cactusgreen", "cactigreen"}),
|
||||
RED(14, "Red", "red"),
|
||||
BLACK(15, "Black", "black");
|
||||
|
||||
/**
|
||||
* Stores a map of the IDs for fast access.
|
||||
*/
|
||||
private static final Map<Integer,ClothColor> ids = new HashMap<Integer,ClothColor>();
|
||||
/**
|
||||
* Stores a map of the names for fast access.
|
||||
*/
|
||||
private static final Map<String,ClothColor> lookup = new HashMap<String,ClothColor>();
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String[] lookupKeys;
|
||||
|
||||
static {
|
||||
for (ClothColor type : EnumSet.allOf(ClothColor.class)) {
|
||||
ids.put(type.id, type);
|
||||
for (String key : type.lookupKeys) {
|
||||
lookup.put(key, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
ClothColor(int id, String name, String lookupKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = new String[]{lookupKey};
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
ClothColor(int id, String name, String[] lookupKeys) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from ID. May return null.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static ClothColor fromID(int id) {
|
||||
return ids.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static ClothColor lookup(String name) {
|
||||
return lookup.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item numeric ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly item name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
41
src/main/java/com/sk89q/worldedit/blocks/ContainerBlock.java
Normal file
41
src/main/java/com/sk89q/worldedit/blocks/ContainerBlock.java
Normal 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.blocks;
|
||||
|
||||
/**
|
||||
* Represents a block that stores items.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface ContainerBlock {
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BaseItemStack[] getItems();
|
||||
|
||||
/**
|
||||
* Set the list of items.
|
||||
*
|
||||
* @param items
|
||||
*/
|
||||
public void setItems(BaseItemStack[] items);
|
||||
}
|
165
src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java
Normal file
165
src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java
Normal file
@ -0,0 +1,165 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Represents dispensers.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DispenserBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||
/**
|
||||
* Store the list of items.
|
||||
*/
|
||||
private BaseItemStack[] items;
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*/
|
||||
public DispenserBlock() {
|
||||
super(54);
|
||||
items = new BaseItemStack[9];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public DispenserBlock(int data) {
|
||||
super(23, data);
|
||||
items = new BaseItemStack[9];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param data
|
||||
* @param items
|
||||
*/
|
||||
public DispenserBlock(int data, BaseItemStack[] items) {
|
||||
super(23, data);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BaseItemStack[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of items.
|
||||
*/
|
||||
public void setItems(BaseItemStack[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tile entity ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "Trap";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
List<Tag> itemsList = new ArrayList<Tag>();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
BaseItemStack item = items[i];
|
||||
if (item != null) {
|
||||
Map<String,Tag> data = new HashMap<String,Tag>();
|
||||
CompoundTag itemTag = new CompoundTag("Items", data);
|
||||
data.put("id", new ShortTag("id", (short)item.getType()));
|
||||
data.put("Damage", new ShortTag("Damage", item.getDamage()));
|
||||
data.put("Count", new ByteTag("Count", (byte)item.getAmount()));
|
||||
data.put("Slot", new ByteTag("Slot", (byte)i));
|
||||
itemsList.add(itemTag);
|
||||
}
|
||||
}
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Trap")) {
|
||||
throw new DataException("'Trap' tile entity expected");
|
||||
}
|
||||
|
||||
ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class);
|
||||
BaseItemStack[] newItems = new BaseItemStack[27];
|
||||
|
||||
for (Tag tag : items.getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new DataException("CompoundTag expected as child tag of Trap Items");
|
||||
}
|
||||
|
||||
CompoundTag item = (CompoundTag)tag;
|
||||
Map<String,Tag> itemValues = item.getValue();
|
||||
|
||||
short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class))
|
||||
.getValue();
|
||||
short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class))
|
||||
.getValue();
|
||||
byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class))
|
||||
.getValue();
|
||||
byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class))
|
||||
.getValue();
|
||||
|
||||
if (slot >= 0 && slot <= 26) {
|
||||
newItems[slot] = new BaseItemStack(id, count, damage);
|
||||
}
|
||||
}
|
||||
|
||||
this.items = newItems;
|
||||
}
|
||||
}
|
218
src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java
Normal file
218
src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java
Normal file
@ -0,0 +1,218 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Represents furnaces.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FurnaceBlock extends BaseBlock implements TileEntityBlock, ContainerBlock {
|
||||
/**
|
||||
* Store the list of items.
|
||||
*/
|
||||
private BaseItemStack[] items;
|
||||
|
||||
/**
|
||||
* Fuel time.
|
||||
*/
|
||||
private short burnTime;
|
||||
|
||||
/**
|
||||
* Cook time.
|
||||
*/
|
||||
private short cookTime;
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public FurnaceBlock(int type) {
|
||||
super(type);
|
||||
items = new BaseItemStack[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
*/
|
||||
public FurnaceBlock(int type, int data) {
|
||||
super(type, data);
|
||||
items = new BaseItemStack[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the chest block.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
* @param items
|
||||
*/
|
||||
public FurnaceBlock(int type, int data, BaseItemStack[] items) {
|
||||
super(type, data);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BaseItemStack[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of items.
|
||||
*/
|
||||
public void setItems(BaseItemStack[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the burnTime
|
||||
*/
|
||||
public short getBurnTime() {
|
||||
return burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param burnTime the burnTime to set
|
||||
*/
|
||||
public void setBurnTime(short burnTime) {
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cookTime
|
||||
*/
|
||||
public short getCookTime() {
|
||||
return cookTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cookTime the cookTime to set
|
||||
*/
|
||||
public void setCookTime(short cookTime) {
|
||||
this.cookTime = cookTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tile entity ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "Furnace";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
List<Tag> itemsList = new ArrayList<Tag>();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
BaseItemStack item = items[i];
|
||||
if (item != null) {
|
||||
Map<String,Tag> data = new HashMap<String,Tag>();
|
||||
CompoundTag itemTag = new CompoundTag("Items", data);
|
||||
data.put("id", new ShortTag("id", (short)item.getType()));
|
||||
data.put("Damage", new ShortTag("Damage", item.getDamage()));
|
||||
data.put("Count", new ByteTag("Count", (byte)item.getAmount()));
|
||||
data.put("Slot", new ByteTag("Slot", (byte)i));
|
||||
itemsList.add(itemTag);
|
||||
}
|
||||
}
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("Items", new ListTag("Items", CompoundTag.class, itemsList));
|
||||
values.put("BurnTime", new ShortTag("BurnTime", burnTime));
|
||||
values.put("CookTime", new ShortTag("CookTime", cookTime));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Furnace")) {
|
||||
throw new DataException("'Furnace' tile entity expected");
|
||||
}
|
||||
|
||||
ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class);
|
||||
BaseItemStack[] newItems = new BaseItemStack[27];
|
||||
|
||||
for (Tag tag : items.getValue()) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new DataException("CompoundTag expected as child tag of Trap Items");
|
||||
}
|
||||
|
||||
CompoundTag item = (CompoundTag)tag;
|
||||
Map<String,Tag> itemValues = item.getValue();
|
||||
|
||||
short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class))
|
||||
.getValue();
|
||||
short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class))
|
||||
.getValue();
|
||||
byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class))
|
||||
.getValue();
|
||||
byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class))
|
||||
.getValue();
|
||||
|
||||
if (slot >= 0 && slot <= 26) {
|
||||
newItems[slot] = new BaseItemStack(id, count, damage);
|
||||
}
|
||||
}
|
||||
|
||||
this.items = newItems;
|
||||
|
||||
t = values.get("BurnTime");
|
||||
if (t instanceof ShortTag) {
|
||||
burnTime = ((ShortTag)t).getValue();
|
||||
}
|
||||
|
||||
t = values.get("CookTime");
|
||||
if (t instanceof ShortTag) {
|
||||
cookTime = ((ShortTag)t).getValue();
|
||||
}
|
||||
}
|
||||
}
|
411
src/main/java/com/sk89q/worldedit/blocks/ItemType.java
Normal file
411
src/main/java/com/sk89q/worldedit/blocks/ItemType.java
Normal file
@ -0,0 +1,411 @@
|
||||
// $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.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* ItemType types.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public enum ItemType {
|
||||
// Blocks
|
||||
AIR(0, "Air", "air"),
|
||||
STONE(1, "Stone", new String[] {"stone", "rock"}),
|
||||
GRASS(2, "Grass", "grass"),
|
||||
DIRT(3, "Dirt", "dirt"),
|
||||
COBBLESTONE(4, "Cobblestone", new String[] {"cobblestone", "cobble"}),
|
||||
WOOD(5, "Wood", new String[] {"wood", "woodplank", "plank", "woodplanks", "planks"}),
|
||||
SAPLING(6, "Sapling", "sapling"),
|
||||
BEDROCK(7, "Bedrock", new String[] {"adminium", "bedrock"}),
|
||||
WATER(8, "Water", new String[] {"watermoving", "movingwater"}),
|
||||
STATIONARY_WATER(9, "Water (stationary)",
|
||||
new String[] {"water", "waterstationary", "stationarywater", "stillwater"}),
|
||||
LAVA(10, "Lava", new String[] {"lavamoving", "movinglava"}),
|
||||
STATIONARY_LAVA(11, "Lava (stationary)",
|
||||
new String[] {"lava", "lavastationary", "stationarylava", "stilllava"}),
|
||||
SAND(12, "Sand", "sand"),
|
||||
GRAVEL(13, "Gravel", "gravel"),
|
||||
GOLD_ORE(14, "Gold ore", "goldore"),
|
||||
IRON_ORE(15, "Iron ore", "ironore"),
|
||||
COAL_ORE(16, "Coal ore", "coalore"),
|
||||
LOG(17, "Log", new String[] {"log", "tree", "pine", "oak", "birch", "redwood"}),
|
||||
LEAVES(18, "Leaves", new String[] {"leaves", "leaf"}),
|
||||
SPONGE(19, "Sponge", "sponge"),
|
||||
GLASS(20, "Glass", "glass"),
|
||||
LAPIS_LAZULI_ORE(21, "Lapis lazuli ore", new String[] {"lapislazuliore", "blueore", "lapisore"}),
|
||||
LAPIS_LAZULI(22, "Lapis lazuli", new String[] {"lapislazuli", "lapislazuliblock", "bluerock"}),
|
||||
DISPENSER(23, "Dispenser", "dispenser"),
|
||||
SANDSTONE(24, "Sandstone", "sandstone"),
|
||||
NOTE_BLOCK(25, "Note block", new String[] {"musicblock", "noteblock", "note", "music", "instrument"}),
|
||||
BED(26, "Bed", "bed"),
|
||||
POWERED_RAIL(27, "Powered Rail",
|
||||
new String[] {"poweredrail", "boosterrail", "poweredtrack", "boostertrack"}),
|
||||
DETECTOR_RAIL(28, "Detector Rail", "detectorrail"),
|
||||
WEB(30, "Web", new String[] {"web", "spiderweb"}),
|
||||
CLOTH(35, "Wool", new String[] {"cloth", "wool"}),
|
||||
YELLOW_FLOWER(37, "Yellow flower", new String[] {"yellowflower", "flower"}),
|
||||
RED_FLOWER(38, "Red rose", new String[] {"redflower", "redrose", "rose"}),
|
||||
BROWN_MUSHROOM(39, "Brown mushroom", new String[] {"brownmushroom", "mushroom"}),
|
||||
RED_MUSHROOM(40, "Red mushroom", "redmushroom"),
|
||||
GOLD_BLOCK(41, "Gold block", new String[] {"gold", "goldblock"}),
|
||||
IRON_BLOCK(42, "Iron block", new String[] {"iron", "ironblock"}),
|
||||
DOUBLE_STEP(43, "Double step", new String[] {"doubleslab", "doublestoneslab", "doublestep"}),
|
||||
STEP(44, "Step", new String[] {"slab", "stoneslab", "step", "halfstep"}),
|
||||
BRICK(45, "Brick", new String[] {"brick", "brickblock"}),
|
||||
TNT(46, "TNT", "tnt"),
|
||||
BOOKCASE(47, "Bookcase", new String[] {"bookshelf", "bookshelves"}),
|
||||
MOSSY_COBBLESTONE(48, "Cobblestone (mossy)",
|
||||
new String[] {"mossycobblestone", "mossstone", "mossystone",
|
||||
"mosscobble", "mossycobble", "moss", "mossy", "sossymobblecone"}),
|
||||
OBSIDIAN(49, "Obsidian", "obsidian"),
|
||||
TORCH(50, "Torch", "torch"),
|
||||
FIRE(51, "Fire", new String[] {"fire", "flame", "flames"}),
|
||||
MOB_SPAWNER(52, "Mob spawner", new String[] {"mobspawner", "spawner"}),
|
||||
WOODEN_STAIRS(53, "Wooden stairs",
|
||||
new String[] {"woodstair", "woodstairs", "woodenstair", "woodenstairs"}),
|
||||
CHEST(54, "Chest", new String[] {"chest", "storage"}),
|
||||
REDSTONE_WIRE(55, "Redstone wire", "redstone"),
|
||||
DIAMOND_ORE(56, "Diamond ore", "diamondore"),
|
||||
DIAMOND_BLOCK(57, "Diamond block", new String[] {"diamond", "diamondblock"}),
|
||||
WORKBENCH(58, "Workbench", new String[] {"workbench", "table", "craftingtable"}),
|
||||
CROPS(59, "Crops", new String[] {"crops", "crop", "plant", "plants"}),
|
||||
SOIL(60, "Soil", new String[] {"soil", "farmland"}),
|
||||
FURNACE(61, "Furnace", "furnace"),
|
||||
BURNING_FURNACE(62, "Furnace (burning)", new String[] {"burningfurnace", "litfurnace"}),
|
||||
SIGN_POST(63, "Sign post", new String[] {"sign", "signpost"}),
|
||||
WOODEN_DOOR(64, "Wooden door", new String[] {"wooddoor", "woodendoor", "door"}),
|
||||
LADDER(65, "Ladder", "ladder"),
|
||||
MINECART_TRACKS(66, "Minecart tracks",
|
||||
new String[] {"track", "tracks", "minecrattrack", "minecarttracks", "rails", "rail"}),
|
||||
COBBLESTONE_STAIRS(67, "Cobblestone stairs",
|
||||
new String[] {"cobblestonestair", "cobblestonestairs", "cobblestair", "cobblestairs"}),
|
||||
WALL_SIGN(68, "Wall sign", "wallsign"),
|
||||
LEVER(69, "Lever", new String[] {"lever", "switch", "stonelever", "stoneswitch"}),
|
||||
STONE_PRESSURE_PLATE(70, "Stone pressure plate",
|
||||
new String[] {"stonepressureplate", "stoneplate"}),
|
||||
IRON_DOOR(71, "Iron Door", "irondoor"),
|
||||
WOODEN_PRESSURE_PLATE(72, "Wooden pressure plate",
|
||||
new String[] {"woodpressureplate", "woodplate", "woodenpressureplate", "woodenplate"}),
|
||||
REDSTONE_ORE(73, "Redstone ore", "redstoneore"),
|
||||
GLOWING_REDSTONE_ORE(74, "Glowing redstone ore", "glowingredstoneore"),
|
||||
REDSTONE_TORCH_OFF(75, "Redstone torch (off)",
|
||||
new String[] {"redstonetorchoff", "rstorchoff"}),
|
||||
REDSTONE_TORCH_ON(76, "Redstone torch (on)",
|
||||
new String [] {"redstonetorch", "redstonetorchon", "rstorchon"}),
|
||||
STONE_BUTTON(77, "Stone Button", new String[] {"stonebutton", "button"}),
|
||||
SNOW(78, "Snow", "snow"),
|
||||
ICE(79, "Ice", "ice"),
|
||||
SNOW_BLOCK(80, "Snow block", "snowblock"),
|
||||
CACTUS(81, "Cactus", new String[] {"cactus", "cacti"}),
|
||||
CLAY(82, "Clay", "clay"),
|
||||
SUGAR_CANE(83, "Reed", new String[] {"reed", "cane", "sugarcane", "sugarcanes"}),
|
||||
JUKEBOX(84, "Jukebox", new String[] {"jukebox", "stereo", "recordplayer"}),
|
||||
FENCE(85, "Fence", "fence"),
|
||||
PUMPKIN(86, "Pumpkin", "pumpkin"),
|
||||
NETHERRACK(87, "Netherrack",
|
||||
new String[] {"redmossycobblestone", "redcobblestone", "redmosstone",
|
||||
"redcobble", "netherstone", "netherrack", "nether", "hellstone"}),
|
||||
SOUL_SAND(88, "Soul sand",
|
||||
new String[] {"slowmud", "mud", "soulsand", "hellmud"}),
|
||||
GLOWSTONE(89, "Glowstone",
|
||||
new String[] {"brittlegold", "glowstone", "lightstone", "brimstone", "australium"}),
|
||||
PORTAL(90, "Portal", "portal"),
|
||||
JACK_O_LANTERN(91, "Pumpkin (on)",
|
||||
new String[] {"pumpkinlighted", "pumpkinon", "litpumpkin", "jackolantern"}),
|
||||
CAKE(92, "Cake", new String[] {"cake", "cakeblock"}),
|
||||
REDSTONE_REPEATER_OFF(93, "Redstone repeater (off)", new String[] {"diodeoff", "redstonerepeater", "repeater", "delayer"}),
|
||||
REDSTONE_REPEATER_ON(94, "Redstone repeater (on)", new String[] {"diode", "diodeon", "redstonerepeateron", "repeateron", "delayeron"}),
|
||||
LOCKED_CHEST(95, "Locked chest", new String[] {"lockedchest", "steveco", "supplycrate", "valveneedstoworkonep3nottf2kthx"}),
|
||||
|
||||
// Items
|
||||
IRON_SHOVEL(256, "Iron shovel", "ironshovel"),
|
||||
IRON_PICK(257, "Iron pick", new String[] {"ironpick", "ironpickaxe"}),
|
||||
IRON_AXE(258, "Iron axe", "ironaxe"),
|
||||
FLINT_AND_TINDER(259, "Flint and tinder",
|
||||
new String[] {"flintandtinder", "lighter", "flintandsteel", "flintsteel",
|
||||
"flintandiron", "flintnsteel", "flintniron", "flintntinder"}),
|
||||
RED_APPLE(260, "Red apple", new String[] {"redapple", "apple"}),
|
||||
BOW(261, "Bow", "bow"),
|
||||
ARROW(262, "Arrow", "arrow"),
|
||||
COAL(263, "Coal", "coal"),
|
||||
DIAMOND(264, "Diamond", "diamond"),
|
||||
IRON_BAR(265, "Iron bar", "ironbar"),
|
||||
GOLD_BAR(266, "Gold bar", "goldbar"),
|
||||
IRON_SWORD(267, "Iron sword", "ironsword"),
|
||||
WOOD_SWORD(268, "Wooden sword", "woodsword"),
|
||||
WOOD_SHOVEL(269, "Wooden shovel", "woodshovel"),
|
||||
WOOD_PICKAXE(270, "Wooden pickaxe", new String[] {"woodpick", "woodpickaxe"}),
|
||||
WOOD_AXE(271, "Wooden axe", "woodaxe"),
|
||||
STONE_SWORD(272, "Stone sword", "stonesword"),
|
||||
STONE_SHOVEL(273, "Stone shovel", "stoneshovel"),
|
||||
STONE_PICKAXE(274, "Stone pickaxe", new String[] {"stonepick", "stonepickaxe"}),
|
||||
STONE_AXE(275, "Stone pickaxe", "stoneaxe"),
|
||||
DIAMOND_SWORD(276, "Diamond sword", "diamondsword"),
|
||||
DIAMOND_SHOVEL(277, "Diamond shovel", "diamondshovel"),
|
||||
DIAMOND_PICKAXE(278, "Diamond pickaxe", new String[] {"diamondpick", "diamondpickaxe"}),
|
||||
DIAMOND_AXE(279, "Diamond axe", "diamondaxe"),
|
||||
STICK(280, "Stick", "stick"),
|
||||
BOWL(281, "Bowl", "bowl"),
|
||||
MUSHROOM_SOUP(282, "Mushroom soup", new String[] {"mushroomsoup", "soup", "brbsoup"}),
|
||||
GOLD_SWORD(283, "Golden sword", "goldsword"),
|
||||
GOLD_SHOVEL(284, "Golden shovel", "goldshovel"),
|
||||
GOLD_PICKAXE(285, "Golden pickaxe", new String[] {"goldpick", "goldpickaxe"}),
|
||||
GOLD_AXE(286, "Golden axe", "goldaxe"),
|
||||
STRING(287, "String", "string"),
|
||||
FEATHER(288, "Feather", "feather"),
|
||||
SULPHUR(289, "Sulphur", new String[] {"sulphur", "sulfur", "gunpowder"}),
|
||||
WOOD_HOE(290, "Wooden hoe", "woodhoe"),
|
||||
STONE_HOE(291, "Stone hoe", "stonehoe"),
|
||||
IRON_HOE(292, "Iron hoe", "ironhoe"),
|
||||
DIAMOND_HOE(293, "Diamond hoe", "diamondhoe"),
|
||||
GOLD_HOE(294, "Golden hoe", "goldhoe"),
|
||||
SEEDS(295, "Seeds", new String[] {"seeds", "seed"}),
|
||||
WHEAT(296, "Wheat", "wheat"),
|
||||
BREAD(297, "Bread", "bread"),
|
||||
LEATHER_HELMET(298, "Leather helmet", "leatherhelmet"),
|
||||
LEATHER_CHEST(299, "Leather chestplate", "leatherchest"),
|
||||
LEATHER_PANTS(300, "Leather pants", "leatherpants"),
|
||||
LEATHER_BOOTS(301, "Leather boots", "leatherboots"),
|
||||
CHAINMAIL_HELMET(302, "Chainmail helmet", "chainmailhelmet"),
|
||||
CHAINMAIL_CHEST(303, "Chainmail chestplate", "chainmailchest"),
|
||||
CHAINMAIL_PANTS(304, "Chainmail pants", "chainmailpants"),
|
||||
CHAINMAIL_BOOTS(305, "Chainmail boots", "chainmailboots"),
|
||||
IRON_HELMET(306, "Iron helmet", "ironhelmet"),
|
||||
IRON_CHEST(307, "Iron chestplate", "ironchest"),
|
||||
IRON_PANTS(308, "Iron pants", "ironpants"),
|
||||
IRON_BOOTS(309, "Iron boots", "ironboots"),
|
||||
DIAMOND_HELMET(310, "Diamond helmet", "diamondhelmet"),
|
||||
DIAMOND_CHEST(311, "Diamond chestplate", "diamondchest"),
|
||||
DIAMOND_PANTS(312, "Diamond pants", "diamondpants"),
|
||||
DIAMOND_BOOTS(313, "Diamond boots", "diamondboots"),
|
||||
GOLD_HELMET(314, "Gold helmet", "goldhelmet"),
|
||||
GOLD_CHEST(315, "Gold chestplate", "goldchest"),
|
||||
GOLD_PANTS(316, "Gold pants", "goldpants"),
|
||||
GOLD_BOOTS(317, "Gold boots", "goldboots"),
|
||||
FLINT(318, "Flint", "flint"),
|
||||
RAW_PORKCHOP(319, "Raw porkchop",
|
||||
new String[] {"rawpork", "rawporkchop", "rawbacon", "baconstrips", "rawmeat"}),
|
||||
COOKED_PORKCHOP(320, "Cooked porkchop",
|
||||
new String[] {"pork", "cookedpork", "cookedporkchop", "cookedbacon", "bacon", "meat"}),
|
||||
PAINTING(321, "Painting", "painting"),
|
||||
GOLD_APPLE(322, "Golden apple", new String[] {"goldapple", "goldenapple"}),
|
||||
SIGN(323, "Wooden sign", "sign"),
|
||||
WOODEN_DOOR_ITEM(324, "Wooden door", new String[] {"wooddoor", "door"}),
|
||||
BUCKET(325, "Bucket", new String[] {"bucket", "bukkit"}),
|
||||
WATER_BUCKET(326, "Water bucket", new String[] {"waterbucket", "waterbukkit"}),
|
||||
LAVA_BUCKET(327, "Lava bucket", new String[] {"lavabucket", "lavabukkit"}),
|
||||
MINECART(328, "Minecart", new String[] {"minecart", "cart"}),
|
||||
SADDLE(329, "Saddle", "saddle"),
|
||||
IRON_DOOR_ITEM(330, "Iron door", "irondoor"),
|
||||
REDSTONE_DUST(331, "Redstone dust", new String[] {"redstonedust", "reddust"}),
|
||||
SNOWBALL(332, "Snowball", "snowball"),
|
||||
WOOD_BOAT(333, "Wooden boat", new String[] {"woodboat", "woodenboat", "boat"}),
|
||||
LEATHER(334, "Leather", new String[] {"leather", "cowhide"}),
|
||||
MILK_BUCKET(335, "Milk bucket", new String[] {"milkbucket", "milk", "milkbukkit"}),
|
||||
BRICK_BAR(336, "Brick", "brick"),
|
||||
CLAY_BALL(337, "Clay", "clay"),
|
||||
SUGAR_CANE_ITEM(338, "Sugar cane", new String[] {"sugarcane", "reed", "reeds"}),
|
||||
PAPER(339, "Paper", "paper"),
|
||||
BOOK(340, "Book", "book"),
|
||||
SLIME_BALL(341, "Slime ball", new String[] {"slimeball", "slime"}),
|
||||
STORAGE_MINECART(342, "Storage minecart", new String[] {"storageminecart", "storagecart"}),
|
||||
POWERED_MINECART(343, "Powered minecart", new String[] {"poweredminecart", "poweredcart"}),
|
||||
EGG(344, "Egg", "egg"),
|
||||
COMPASS(345, "Compass", "compass"),
|
||||
FISHING_ROD(346, "Fishing rod", new String[] {"fishingrod", "fishingpole"}),
|
||||
WATCH(347, "Watch", new String[] {"watch", "clock", "timer" }),
|
||||
LIGHTSTONE_DUST(348, "Glowstone dust", new String[] {
|
||||
"lightstonedust", "glowstonedone", "brightstonedust",
|
||||
"brittlegolddust", "brimstonedust"}),
|
||||
RAW_FISH(349, "Raw fish", new String[] {"rawfish", "fish"}),
|
||||
COOKED_FISH(350, "Cooked fish", "cookedfish"),
|
||||
INK_SACK(351, "Ink sac", new String[] {"inksac", "ink", "dye", "inksack"}),
|
||||
BONE(352, "Bone", "bone"),
|
||||
SUGAR(353, "Sugar", "sugar"),
|
||||
CAKE_ITEM(354, "Cake", "cake"),
|
||||
BED_ITEM(355, "Bed", "bed"),
|
||||
REDSTONE_REPEATER(356, "Redstone repeater", new String[] {"redstonerepeater", "diode", "delayer"}),
|
||||
COOKIE(357, "Cookie", "cookie"),
|
||||
GOLD_RECORD(2256, "Gold Record", new String[] {"goldrecord", "golddisc"}),
|
||||
GREEN_RECORD(2257, "Green Record", new String[] {"greenrecord", "greenddisc"});
|
||||
|
||||
/**
|
||||
* Stores a map of the IDs for fast access.
|
||||
*/
|
||||
private static final Map<Integer,ItemType> ids = new HashMap<Integer,ItemType>();
|
||||
/**
|
||||
* Stores a map of the names for fast access.
|
||||
*/
|
||||
private static final Map<String,ItemType> lookup = new HashMap<String,ItemType>();
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String[] lookupKeys;
|
||||
|
||||
static {
|
||||
for (ItemType type : EnumSet.allOf(ItemType.class)) {
|
||||
ids.put(type.id, type);
|
||||
for (String key : type.lookupKeys) {
|
||||
lookup.put(key, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
ItemType(int id, String name, String lookupKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = new String[] {lookupKey};
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the type.
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
ItemType(int id, String name, String[] lookupKeys) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lookupKeys = lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from ID. May return null.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static ItemType fromID(int id) {
|
||||
return ids.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a name for the item.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static String toName(int id) {
|
||||
ItemType type = ids.get(id);
|
||||
if (type != null) {
|
||||
return type.getName();
|
||||
} else {
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a name for a held item.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static String toHeldName(int id) {
|
||||
if (id == 0) {
|
||||
return "Hand";
|
||||
}
|
||||
ItemType type = ids.get(id);
|
||||
if (type != null) {
|
||||
return type.getName();
|
||||
} else {
|
||||
return "#" + id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type from name. May return null.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static ItemType lookup(String name) {
|
||||
return lookup.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item numeric ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user-friendly item name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of aliases.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String[] getAliases() {
|
||||
return lookupKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an item should not be stacked.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean shouldNotStack(int id) {
|
||||
return (id >= 256 && id <= 259)
|
||||
|| id == 261
|
||||
|| (id >= 267 && id <= 279)
|
||||
|| (id >= 281 && id <= 286)
|
||||
|| (id >= 290 && id <= 294)
|
||||
|| (id >= 298 && id <= 317)
|
||||
|| (id >= 325 && id <= 327)
|
||||
|| id == 335
|
||||
|| id == 354
|
||||
|| id == 355
|
||||
|| id >= 2256;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an item uses its damage value for something
|
||||
* other than damage.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static boolean usesDamageValue(int id) {
|
||||
return id == 35
|
||||
|| id == 351;
|
||||
}
|
||||
}
|
159
src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java
Normal file
159
src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java
Normal file
@ -0,0 +1,159 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Represents chests.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
||||
/**
|
||||
* Store mob spawn type.
|
||||
*/
|
||||
private String mobType;
|
||||
/**
|
||||
* Delay until next spawn.
|
||||
*/
|
||||
private short delay;
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block.
|
||||
*
|
||||
*/
|
||||
public MobSpawnerBlock() {
|
||||
super(52);
|
||||
this.mobType = "Pig";
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block.
|
||||
*
|
||||
* @param mobType
|
||||
*/
|
||||
public MobSpawnerBlock(String mobType) {
|
||||
super(52);
|
||||
this.mobType = mobType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public MobSpawnerBlock(int data) {
|
||||
super(52, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block.
|
||||
*
|
||||
* @param data
|
||||
* @param mobType
|
||||
*/
|
||||
public MobSpawnerBlock(int data, String mobType) {
|
||||
super(52, data);
|
||||
this.mobType = mobType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mob type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getMobType() {
|
||||
return mobType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mob type.
|
||||
*
|
||||
* @param mobType
|
||||
*/
|
||||
public void setMobType(String mobType) {
|
||||
this.mobType = mobType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the delay
|
||||
*/
|
||||
public short getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param delay the delay to set
|
||||
*/
|
||||
public void setDelay(short delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tile entity ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "MobSpawner";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("EntityId", new StringTag("EntityId", mobType));
|
||||
values.put("Delay", new ShortTag("Delay", delay));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tag t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("MobSpawner")) {
|
||||
throw new DataException("'MobSpawner' tile entity expected");
|
||||
}
|
||||
|
||||
StringTag mobTypeTag = (StringTag)Chunk.getChildTag(values, "EntityId", StringTag.class);
|
||||
ShortTag delayTag = (ShortTag)Chunk.getChildTag(values, "Delay", ShortTag.class);
|
||||
|
||||
this.mobType = mobTypeTag.getValue();
|
||||
this.delay = delayTag.getValue();
|
||||
}
|
||||
}
|
126
src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java
Normal file
126
src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java
Normal file
@ -0,0 +1,126 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
||||
/**
|
||||
* Stores the pitch.
|
||||
*/
|
||||
private byte note;
|
||||
|
||||
/**
|
||||
* Construct the note block.
|
||||
*/
|
||||
public NoteBlock() {
|
||||
super(25);
|
||||
this.note = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the note block.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public NoteBlock(int data) {
|
||||
super(25, data);
|
||||
this.note = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the note block.
|
||||
*
|
||||
* @param data
|
||||
* @param note
|
||||
*/
|
||||
public NoteBlock(int data, byte note) {
|
||||
super(25, data);
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the note
|
||||
*/
|
||||
public byte getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param note the note to set
|
||||
*/
|
||||
public void setNote(byte note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the title entity ID.
|
||||
*
|
||||
* @return title entity ID
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "Music";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("note", new ByteTag("note", note));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tag t;
|
||||
|
||||
t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Music")) {
|
||||
throw new DataException("'Music' tile entity expected");
|
||||
}
|
||||
|
||||
t = values.get("note");
|
||||
if (t instanceof ByteTag) {
|
||||
note = ((ByteTag)t).getValue();
|
||||
}
|
||||
}
|
||||
}
|
140
src/main/java/com/sk89q/worldedit/blocks/SignBlock.java
Normal file
140
src/main/java/com/sk89q/worldedit/blocks/SignBlock.java
Normal file
@ -0,0 +1,140 @@
|
||||
// $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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SignBlock extends BaseBlock implements TileEntityBlock {
|
||||
/**
|
||||
* Stores the sign's text.
|
||||
*/
|
||||
private String[] text;
|
||||
|
||||
/**
|
||||
* Construct the sign without text.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
*/
|
||||
public SignBlock(int type, int data) {
|
||||
super(type, data);
|
||||
this.text = new String[]{ "", "", "", "" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the sign with text.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
* @param text
|
||||
*/
|
||||
public SignBlock(int type, int data, String[] text) {
|
||||
super(type, data);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the text
|
||||
*/
|
||||
public String[] getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setText(String[] text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the title entity ID.
|
||||
*
|
||||
* @return title entity ID
|
||||
*/
|
||||
public String getTileEntityID() {
|
||||
return "Sign";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store additional tile entity data. Returns true if the data is used.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException {
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
values.put("Text1", new StringTag("Text1", text[0]));
|
||||
values.put("Text2", new StringTag("Text2", text[1]));
|
||||
values.put("Text3", new StringTag("Text3", text[2]));
|
||||
values.put("Text4", new StringTag("Text4", text[3]));
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Tag t;
|
||||
|
||||
text = new String[]{ "", "", "", "" };
|
||||
|
||||
t = values.get("id");
|
||||
if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Sign")) {
|
||||
throw new DataException("'Sign' tile entity expected");
|
||||
}
|
||||
|
||||
t = values.get("Text1");
|
||||
if (t instanceof StringTag) {
|
||||
text[0] = ((StringTag)t).getValue();
|
||||
}
|
||||
|
||||
t = values.get("Text2");
|
||||
if (t instanceof StringTag) {
|
||||
text[1] = ((StringTag)t).getValue();
|
||||
}
|
||||
|
||||
t = values.get("Text3");
|
||||
if (t instanceof StringTag) {
|
||||
text[2] = ((StringTag)t).getValue();
|
||||
}
|
||||
|
||||
t = values.get("Text4");
|
||||
if (t instanceof StringTag) {
|
||||
text[3] = ((StringTag)t).getValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.blocks;
|
||||
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.data.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class implementing this interface has extra TileEntityBlock data to store.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface TileEntityBlock {
|
||||
/**
|
||||
* Return the name of the title entity ID.
|
||||
*
|
||||
* @return title entity ID
|
||||
*/
|
||||
public String getTileEntityID();
|
||||
/**
|
||||
* Store additional tile entity data.
|
||||
*
|
||||
* @return map of values
|
||||
* @throws DataException
|
||||
*/
|
||||
public Map<String,Tag> toTileEntityNBT()
|
||||
throws DataException;
|
||||
/**
|
||||
* Get additional information from the title entity data.
|
||||
*
|
||||
* @param values
|
||||
* @throws DataException
|
||||
*/
|
||||
public void fromTileEntityNBT(Map<String,Tag> values)
|
||||
throws DataException;
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LogFormat;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRepository;
|
||||
|
||||
public class BukkitConfiguration extends LocalConfiguration {
|
||||
private Configuration config;
|
||||
private Logger logger;
|
||||
|
||||
public boolean noOpPermissions = false;
|
||||
|
||||
public BukkitConfiguration(Configuration config, Logger logger) {
|
||||
this.config = config;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
showFirstUseVersion = false;
|
||||
|
||||
profile = config.getBoolean("debug", profile);
|
||||
wandItem = config.getInt("wand-item", wandItem);
|
||||
defaultChangeLimit = Math.max(-1, config.getInt(
|
||||
"limits.max-blocks-changed.default", defaultChangeLimit));
|
||||
maxChangeLimit = Math.max(-1,
|
||||
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
|
||||
maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
|
||||
maxSuperPickaxeSize = Math.max(1, config.getInt(
|
||||
"limits.max-super-pickaxe-size", maxSuperPickaxeSize));
|
||||
registerHelp = true;
|
||||
logCommands = config.getBoolean("logging.log-commands", logCommands);
|
||||
superPickaxeDrop = config.getBoolean("super-pickaxe.drop-items",
|
||||
superPickaxeDrop);
|
||||
superPickaxeManyDrop = config.getBoolean(
|
||||
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
|
||||
noDoubleSlash = config.getBoolean("no-double-slash", noDoubleSlash);
|
||||
useInventory = config.getBoolean("use-inventory.enable", useInventory);
|
||||
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
|
||||
useInventoryOverride);
|
||||
maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
|
||||
|
||||
navigationWand = config.getInt("navigation-wand.item", navigationWand);
|
||||
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
|
||||
|
||||
scriptTimeout = config.getInt("scripting.timeout", scriptTimeout);
|
||||
scriptsDir = config.getString("scripting.dir", scriptsDir);
|
||||
|
||||
saveDir = config.getString("saving.dir", saveDir);
|
||||
|
||||
disallowedBlocks = new HashSet<Integer>(config.getIntList("limits.disallowed-blocks", null));
|
||||
|
||||
allowedDataCycleBlocks = new HashSet<Integer>(config.getIntList("limits.allowed-data-cycle-blocks", null));
|
||||
|
||||
noOpPermissions = config.getBoolean("no-op-permissions", false);
|
||||
|
||||
LocalSession.MAX_HISTORY_SIZE = Math.max(15, config.getInt("history.size", 15));
|
||||
|
||||
String snapshotsDir = config.getString("snapshots.directory", "");
|
||||
if (!snapshotsDir.trim().equals("")) {
|
||||
snapshotRepo = new SnapshotRepository(snapshotsDir);
|
||||
} else {
|
||||
snapshotRepo = null;
|
||||
}
|
||||
|
||||
String type = config.getString("shell-save-type", "").trim();
|
||||
shellSaveType = type.equals("") ? null : type;
|
||||
|
||||
String logFile = config.getString("logging.file", "");
|
||||
if (!logFile.equals("")) {
|
||||
try {
|
||||
FileHandler handler = new FileHandler(logFile, true);
|
||||
handler.setFormatter(new LogFormat());
|
||||
logger.addHandler(handler);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.WARNING, "Could not use log file " + logFile + ": "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} else {
|
||||
for (Handler handler : logger.getHandlers()) {
|
||||
logger.removeHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
136
src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
Normal file
136
src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java
Normal file
@ -0,0 +1,136 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.cui.CUIEvent;
|
||||
|
||||
public class BukkitPlayer extends LocalPlayer {
|
||||
private Player player;
|
||||
private WorldEditPlugin plugin;
|
||||
|
||||
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
|
||||
super(server);
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemInHand() {
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
return itemStack != null ? itemStack.getTypeId() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldVector getPosition() {
|
||||
Location loc = player.getLocation();
|
||||
return new WorldVector(new BukkitWorld(loc.getWorld()),
|
||||
loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPitch() {
|
||||
return player.getLocation().getPitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getYaw() {
|
||||
return player.getLocation().getYaw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
player.getInventory().addItem(new ItemStack(type, amt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String msg) {
|
||||
player.sendMessage("\u00A7d" + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printDebug(String msg) {
|
||||
player.sendMessage("\u00A77" + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printError(String msg) {
|
||||
player.sendMessage("\u00A7c" + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector pos, float pitch, float yaw) {
|
||||
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
|
||||
pos.getZ(), yaw, pitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getPermissionsResolver().getGroups(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockBag getInventoryBlockBag() {
|
||||
return new BukkitPlayerBlockBag(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|
||||
|| plugin.getPermissionsResolver().hasPermission(player.getName(), perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalWorld getWorld() {
|
||||
return new BukkitWorld(player.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCUIEvent(CUIEvent event) {
|
||||
String[] params = event.getParameters();
|
||||
|
||||
if (params.length > 0) {
|
||||
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId()
|
||||
+ "|" + StringUtil.joinString(params, "|"));
|
||||
} else {
|
||||
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCUIHandshake() {
|
||||
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bags.*;
|
||||
|
||||
public class BukkitPlayerBlockBag extends BlockBag {
|
||||
/**
|
||||
* Player instance.
|
||||
*/
|
||||
private Player player;
|
||||
/**
|
||||
* The player's inventory;
|
||||
*/
|
||||
private ItemStack[] items;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public BukkitPlayerBlockBag(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads inventory on first use.
|
||||
*/
|
||||
private void loadInventory() {
|
||||
if (items == null) {
|
||||
items = player.getInventory().getContents();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void fetchBlock(int id) throws BlockBagException {
|
||||
if (id == 0) {
|
||||
throw new IllegalArgumentException("Can't fetch air block");
|
||||
}
|
||||
|
||||
loadInventory();
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for (int slot = 0; slot < items.length; slot++) {
|
||||
ItemStack item = items[slot];
|
||||
|
||||
if (item == null) continue;
|
||||
|
||||
if (item.getTypeId() == id) {
|
||||
int amount = item.getAmount();
|
||||
|
||||
// Unlimited
|
||||
if (amount < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount > 1) {
|
||||
item.setAmount(amount - 1);
|
||||
found = true;
|
||||
} else {
|
||||
items[slot] = null;
|
||||
found = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
} else {
|
||||
throw new OutOfBlocksException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a block.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void storeBlock(int id) throws BlockBagException {
|
||||
if (id == 0) {
|
||||
throw new IllegalArgumentException("Can't store air block");
|
||||
}
|
||||
|
||||
loadInventory();
|
||||
|
||||
boolean found = false;
|
||||
int freeSlot = -1;
|
||||
|
||||
for (int slot = 0; slot < items.length; slot++) {
|
||||
ItemStack item = items[slot];
|
||||
|
||||
// Delay using up a free slot until we know there are no stacks
|
||||
// of this item to merge into
|
||||
if (item == null) {
|
||||
if (freeSlot == -1) {
|
||||
freeSlot = slot;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.getTypeId() == id) {
|
||||
int amount = item.getAmount();
|
||||
|
||||
// Unlimited
|
||||
if (amount < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (amount < 64) {
|
||||
item.setAmount(amount + 1);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found && freeSlot > -1) {
|
||||
items[freeSlot] = new ItemStack(id, 1);
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
} else {
|
||||
throw new OutOfSpaceException(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush any changes. This is called at the end.
|
||||
*/
|
||||
@Override
|
||||
public void flushChanges() {
|
||||
if (items != null) {
|
||||
player.getInventory().setContents(items);
|
||||
items = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a position to be used a source.
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
@Override
|
||||
public void addSourcePosition(Vector pos) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a position to be used a source.
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
@Override
|
||||
public void addSingleSourcePosition(Vector pos) {
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
|
||||
public class BukkitServerInterface extends ServerInterface {
|
||||
public Server server;
|
||||
public WorldEditPlugin plugin;
|
||||
|
||||
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
|
||||
this.plugin = plugin;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resolveItem(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMobType(String type) {
|
||||
return CreatureType.fromName(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
plugin.loadConfiguration();
|
||||
}
|
||||
|
||||
}
|
58
src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
Normal file
58
src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java
Normal file
@ -0,0 +1,58 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class BukkitUtil {
|
||||
private BukkitUtil() {
|
||||
}
|
||||
|
||||
public static Location toLocation(World world, Vector loc) {
|
||||
return new Location(world, loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public static BlockVector toVector(Block block) {
|
||||
return new BlockVector(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
public static Vector toVector(Location loc) {
|
||||
return new Vector(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public static Vector toVector(org.bukkit.util.Vector vector) {
|
||||
return new Vector(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static Player matchSinglePlayer(Server server, String name) {
|
||||
List<Player> players = server.matchPlayer(name);
|
||||
if (players.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
}
|
613
src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
Normal file
613
src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
Normal file
@ -0,0 +1,613 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
public class BukkitWorld extends LocalWorld {
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
* @param world
|
||||
*/
|
||||
public BukkitWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world handle.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set block type.
|
||||
*
|
||||
* @param pt
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean setBlockType(Vector pt, int type) {
|
||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeId(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block type.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getBlockType(Vector pt) {
|
||||
return world.getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set block data.
|
||||
*
|
||||
* @param pt
|
||||
* @param data
|
||||
*/
|
||||
@Override
|
||||
public void setBlockData(Vector pt, int data) {
|
||||
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block data.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getBlockData(Vector pt) {
|
||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block light level.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getBlockLightLevel(Vector pt) {
|
||||
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate an area.
|
||||
*
|
||||
* @param region
|
||||
* @param editSession
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean regenerate(Region region, EditSession editSession) {
|
||||
BaseBlock[] history = new BaseBlock[16 * 16 * 128];
|
||||
|
||||
for (Vector2D chunk : region.getChunks()) {
|
||||
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
|
||||
|
||||
// First save all the blocks inside
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 128; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
Vector pt = min.add(x, y, z);
|
||||
int index = y * 16 * 16 + z * 16 + x;
|
||||
history[index] = editSession.getBlock(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
// Then restore
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 128; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
Vector pt = min.add(x, y, z);
|
||||
int index = y * 16 * 16 + z * 16 + x;
|
||||
|
||||
// We have to restore the block if it was outside
|
||||
if (!region.contains(pt)) {
|
||||
editSession.smartSetBlock(pt, history[index]);
|
||||
} else { // Otherwise fool with history
|
||||
editSession.rememberChange(pt, history[index],
|
||||
editSession.rawGetBlock(pt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to accurately copy a BaseBlock's extra data to the world.
|
||||
*
|
||||
* @param pt
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean copyToWorld(Vector pt, BaseBlock block) {
|
||||
// Signs
|
||||
if (block instanceof SignBlock) {
|
||||
setSignText(pt, ((SignBlock)block).getText());
|
||||
return true;
|
||||
|
||||
// Furnaces
|
||||
} else if (block instanceof FurnaceBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof Furnace)) return false;
|
||||
Furnace bukkit = (Furnace)state;
|
||||
FurnaceBlock we = (FurnaceBlock)block;
|
||||
bukkit.setBurnTime(we.getBurnTime());
|
||||
bukkit.setCookTime(we.getCookTime());
|
||||
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
|
||||
|
||||
// Chests/dispenser
|
||||
} else if (block instanceof ContainerBlock) {
|
||||
return setContainerBlockContents(pt, ((ContainerBlock)block).getItems());
|
||||
|
||||
// Mob spawners
|
||||
} else if (block instanceof MobSpawnerBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof CreatureSpawner)) return false;
|
||||
CreatureSpawner bukkit = (CreatureSpawner)state;
|
||||
MobSpawnerBlock we = (MobSpawnerBlock)block;
|
||||
bukkit.setCreatureTypeId(we.getMobType());
|
||||
bukkit.setDelay(we.getDelay());
|
||||
return true;
|
||||
|
||||
// Note block
|
||||
} else if (block instanceof NoteBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
|
||||
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
|
||||
NoteBlock we = (NoteBlock)block;
|
||||
bukkit.setNote(we.getNote());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to read a BaseBlock's extra data from the world.
|
||||
*
|
||||
* @param pt
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean copyFromWorld(Vector pt, BaseBlock block) {
|
||||
// Signs
|
||||
if (block instanceof SignBlock) {
|
||||
((SignBlock)block).setText(getSignText(pt));
|
||||
return true;
|
||||
|
||||
// Furnaces
|
||||
} else if (block instanceof FurnaceBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof Furnace)) return false;
|
||||
Furnace bukkit = (Furnace)state;
|
||||
FurnaceBlock we = (FurnaceBlock)block;
|
||||
we.setBurnTime(bukkit.getBurnTime());
|
||||
we.setCookTime(bukkit.getCookTime());
|
||||
((ContainerBlock)block).setItems(getContainerBlockContents(pt));
|
||||
return true;
|
||||
|
||||
// Chests/dispenser
|
||||
} else if (block instanceof ContainerBlock) {
|
||||
((ContainerBlock)block).setItems(getContainerBlockContents(pt));
|
||||
return true;
|
||||
|
||||
// Mob spawners
|
||||
} else if (block instanceof MobSpawnerBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof CreatureSpawner)) return false;
|
||||
CreatureSpawner bukkit = (CreatureSpawner)state;
|
||||
MobSpawnerBlock we = (MobSpawnerBlock)block;
|
||||
we.setMobType(bukkit.getCreatureTypeId());
|
||||
we.setDelay((short)bukkit.getDelay());
|
||||
return true;
|
||||
|
||||
// Note block
|
||||
} else if (block instanceof NoteBlock) {
|
||||
Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (bukkitBlock == null) return false;
|
||||
BlockState state = bukkitBlock.getState();
|
||||
if (!(state instanceof org.bukkit.block.NoteBlock)) return false;
|
||||
org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state;
|
||||
NoteBlock we = (NoteBlock)block;
|
||||
we.setNote(bukkit.getNote());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a chest's contents.
|
||||
*
|
||||
* @param pt
|
||||
*/
|
||||
@Override
|
||||
public boolean clearContainerBlockContents(Vector pt) {
|
||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
|
||||
Inventory inven = chest.getInventory();
|
||||
inven.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a tree at a location.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean generateTree(EditSession editSession, Vector pt) {
|
||||
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.TREE,
|
||||
new EditSessionBlockChangeDelegate(editSession));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a big tree at a location.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) {
|
||||
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIG_TREE,
|
||||
new EditSessionBlockChangeDelegate(editSession));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a birch tree at a location.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) {
|
||||
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.BIRCH,
|
||||
new EditSessionBlockChangeDelegate(editSession));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a redwood tree at a location.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.REDWOOD,
|
||||
new EditSessionBlockChangeDelegate(editSession));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a redwood tree at a location.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return world.generateTree(BukkitUtil.toLocation(world, pt), TreeType.TALL_REDWOOD,
|
||||
new EditSessionBlockChangeDelegate(editSession));
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop an item.
|
||||
*
|
||||
* @param pt
|
||||
* @param item
|
||||
*/
|
||||
@Override
|
||||
public void dropItem(Vector pt, BaseItemStack item) {
|
||||
ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
|
||||
(byte)item.getDamage());
|
||||
world.dropItemNaturally(toLocation(pt), bukkitItem);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill mobs in an area.
|
||||
*
|
||||
* @param origin
|
||||
* @param radius -1 for all mobs
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int killMobs(Vector origin, int radius) {
|
||||
int num = 0;
|
||||
double radiusSq = Math.pow(radius, 2);
|
||||
|
||||
for (LivingEntity ent : world.getLivingEntities()) {
|
||||
if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime) {
|
||||
if (radius == -1
|
||||
|| origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) <= radiusSq) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove entities in an area.
|
||||
*
|
||||
* @param origin
|
||||
* @param radius
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int removeEntities(EntityType type, Vector origin, int radius) {
|
||||
int num = 0;
|
||||
double radiusSq = Math.pow(radius, 2);
|
||||
|
||||
for (Entity ent : world.getEntities()) {
|
||||
if (radius != -1
|
||||
&& origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) > radiusSq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ARROWS:
|
||||
if (ent instanceof Arrow) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
case BOATS:
|
||||
if (ent instanceof Boat) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
case ITEMS:
|
||||
if (ent instanceof Item) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
case MINECARTS:
|
||||
if (ent instanceof Minecart) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
case PAINTINGS:
|
||||
if (ent instanceof Painting) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
case TNT:
|
||||
if (ent instanceof TNTPrimed) {
|
||||
ent.remove();
|
||||
num++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
private Location toLocation(Vector pt) {
|
||||
return new Location(world, pt.getX(), pt.getY(), pt.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a sign's text.
|
||||
*
|
||||
* @param pt
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private boolean setSignText(Vector pt, String[] text) {
|
||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (block == null) return false;
|
||||
BlockState state = block.getState();
|
||||
if (state == null || !(state instanceof Sign)) return false;
|
||||
Sign sign = (Sign)state;
|
||||
sign.setLine(0, text[0]);
|
||||
sign.setLine(1, text[1]);
|
||||
sign.setLine(2, text[2]);
|
||||
sign.setLine(3, text[3]);
|
||||
sign.update();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sign's text.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
private String[] getSignText(Vector pt) {
|
||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (block == null) return new String[] { "", "", "", "" };
|
||||
BlockState state = block.getState();
|
||||
if (state == null || !(state instanceof Sign)) return new String[] { "", "", "", "" };
|
||||
Sign sign = (Sign)state;
|
||||
String line0 = sign.getLine(0);
|
||||
String line1 = sign.getLine(1);
|
||||
String line2 = sign.getLine(2);
|
||||
String line3 = sign.getLine(3);
|
||||
return new String[] {
|
||||
line0 != null ? line0 : "",
|
||||
line1 != null ? line1 : "",
|
||||
line2 != null ? line2 : "",
|
||||
line3 != null ? line3 : "",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a container block's contents.
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
private BaseItemStack[] getContainerBlockContents(Vector pt) {
|
||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (block == null) {
|
||||
return new BaseItemStack[0];
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||
return new BaseItemStack[0];
|
||||
}
|
||||
|
||||
org.bukkit.block.ContainerBlock container = (org.bukkit.block.ContainerBlock)state;
|
||||
Inventory inven = container.getInventory();
|
||||
int size = inven.getSize();
|
||||
BaseItemStack[] contents = new BaseItemStack[size];
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
ItemStack bukkitStack = inven.getItem(i);
|
||||
if (bukkitStack.getTypeId() > 0) {
|
||||
contents[i] = new BaseItemStack(
|
||||
bukkitStack.getTypeId(),
|
||||
bukkitStack.getAmount(),
|
||||
bukkitStack.getDurability());
|
||||
}
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a container block's contents.
|
||||
*
|
||||
* @param pt
|
||||
* @param contents
|
||||
* @return
|
||||
*/
|
||||
private boolean setContainerBlockContents(Vector pt, BaseItemStack[] contents) {
|
||||
Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
if (!(state instanceof org.bukkit.block.ContainerBlock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state;
|
||||
Inventory inven = chest.getInventory();
|
||||
int size = inven.getSize();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i >= contents.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (contents[i] != null) {
|
||||
inven.setItem(i, new ItemStack(contents[i].getType(),
|
||||
contents[i].getAmount(),
|
||||
(byte)contents[i].getDamage()));
|
||||
} else {
|
||||
inven.setItem(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof BukkitWorld)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((BukkitWorld)other).world.equals(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return world.hashCode();
|
||||
}
|
||||
}
|
@ -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.bukkit;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
/**
|
||||
* Proxy class to catch calls to set blocks.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
|
||||
private EditSession editSession;
|
||||
|
||||
public EditSessionBlockChangeDelegate(EditSession editSession) {
|
||||
this.editSession = editSession;
|
||||
}
|
||||
|
||||
public boolean setRawTypeId(int x, int y, int z, int typeId) {
|
||||
try {
|
||||
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
|
||||
} catch (MaxChangedBlocksException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
||||
try {
|
||||
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
|
||||
} catch (MaxChangedBlocksException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getTypeId(int x, int y, int z) {
|
||||
return editSession.getBlockType(new Vector(x, y, z));
|
||||
}
|
||||
}
|
42
src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java
Normal file
42
src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java
Normal 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.bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
|
||||
public class WorldEditAPI {
|
||||
private WorldEditPlugin plugin;
|
||||
|
||||
public WorldEditAPI(WorldEditPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session for a player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public LocalSession getSession(Player player) {
|
||||
return plugin.getWorldEdit().getSession(
|
||||
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to a Player
|
||||
*/
|
||||
public class WorldEditCriticalPlayerListener extends PlayerListener {
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldEditPlugin plugin;
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldEditCriticalPlayerListener(WorldEditPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player joins a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
|
||||
}
|
||||
|
||||
private BukkitPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(plugin, plugin.getServerInterface(), player);
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to a Player
|
||||
*/
|
||||
public class WorldEditPlayerListener extends PlayerListener {
|
||||
/**
|
||||
* Plugin.
|
||||
*/
|
||||
private WorldEditPlugin plugin;
|
||||
|
||||
/**
|
||||
* Called when a player plays an animation, such as an arm swing
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
LocalPlayer localPlayer = wrapPlayer(event.getPlayer());
|
||||
|
||||
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) {
|
||||
plugin.getWorldEdit().handleArmSwing(localPlayer);
|
||||
}
|
||||
|
||||
// As of Minecraft 1.3, a block dig packet is no longer sent for
|
||||
// bedrock, so we have to do an (inaccurate) detection ourself
|
||||
WorldVector pt = localPlayer.getBlockTrace(5);
|
||||
if (pt != null && pt.getWorld().getBlockType(pt) == BlockID.BEDROCK) {
|
||||
if (plugin.getWorldEdit().handleBlockLeftClick(localPlayer, pt)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object;
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public WorldEditPlayerListener(WorldEditPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player leaves a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.getWorldEdit().handleDisconnect(wrapPlayer(event.getPlayer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to use a command
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
String[] split = event.getMessage().split(" ");
|
||||
|
||||
if (plugin.getWorldEdit().handleCommand(wrapPlayer(event.getPlayer()), split)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player interacts
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
|
||||
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
|
||||
event.getClickedBlock().getY(), event.getClickedBlock().getZ());
|
||||
LocalPlayer player = wrapPlayer(event.getPlayer());
|
||||
|
||||
if (plugin.getWorldEdit().handleBlockLeftClick(player, pos)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
LocalWorld world = new BukkitWorld(event.getClickedBlock().getWorld());
|
||||
WorldVector pos = new WorldVector(world, event.getClickedBlock().getX(),
|
||||
event.getClickedBlock().getY(), event.getClickedBlock().getZ());
|
||||
LocalPlayer player = wrapPlayer(event.getPlayer());
|
||||
|
||||
if (plugin.getWorldEdit().handleBlockRightClick(player, pos)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
if (plugin.getWorldEdit().handleRightClick(wrapPlayer(event.getPlayer()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BukkitPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(plugin, plugin.getServerInterface(), player);
|
||||
}
|
||||
}
|
404
src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
Normal file
404
src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java
Normal file
@ -0,0 +1,404 @@
|
||||
// $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.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
||||
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.bukkit.selections.*;
|
||||
import com.sk89q.worldedit.regions.*;
|
||||
|
||||
/**
|
||||
* Plugin for Bukkit.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class WorldEditPlugin extends JavaPlugin {
|
||||
/**
|
||||
* WorldEdit messages get sent here.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
/**
|
||||
* The server interface that all server-related API goes through.
|
||||
*/
|
||||
private ServerInterface server;
|
||||
/**
|
||||
* Main WorldEdit instance.
|
||||
*/
|
||||
private WorldEdit controller;
|
||||
/**
|
||||
* Deprecated API.
|
||||
*/
|
||||
private WorldEditAPI api;
|
||||
|
||||
/**
|
||||
* Holds the configuration for WorldEdit.
|
||||
*/
|
||||
private BukkitConfiguration config;
|
||||
/**
|
||||
* The permissions resolver in use.
|
||||
*/
|
||||
private PermissionsResolverManager perms;
|
||||
|
||||
/**
|
||||
* Called on plugin enable.
|
||||
*/
|
||||
public void onEnable() {
|
||||
logger.info("WorldEdit " + getDescription().getVersion() + " enabled.");
|
||||
|
||||
// Make the data folders that WorldEdit uses
|
||||
getDataFolder().mkdirs();
|
||||
|
||||
// Create the default configuration file
|
||||
createDefaultConfiguration("config.yml");
|
||||
|
||||
// Set up configuration and such, including the permissions
|
||||
// resolver
|
||||
config = new BukkitConfiguration(getConfiguration(), logger);
|
||||
perms = new PermissionsResolverManager(
|
||||
getConfiguration(), getServer(), "WorldEdit", logger);
|
||||
|
||||
// Load the configuration
|
||||
loadConfiguration();
|
||||
|
||||
// Setup interfaces
|
||||
server = new BukkitServerInterface(this, getServer());
|
||||
controller = new WorldEdit(server, config);
|
||||
api = new WorldEditAPI(this);
|
||||
|
||||
// Now we can register events!
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on plugin disable.
|
||||
*/
|
||||
public void onDisable() {
|
||||
controller.clearSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and reloads all configuration.
|
||||
*/
|
||||
protected void loadConfiguration() {
|
||||
getConfiguration().load();
|
||||
config.load();
|
||||
perms.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the events used by WorldEdit.
|
||||
*/
|
||||
protected void registerEvents() {
|
||||
PlayerListener playerListener = new WorldEditPlayerListener(this);
|
||||
PlayerListener criticalPlayerListener = new WorldEditCriticalPlayerListener(this);
|
||||
|
||||
registerEvent(Event.Type.PLAYER_QUIT, playerListener);
|
||||
registerEvent(Event.Type.PLAYER_ANIMATION, playerListener);
|
||||
registerEvent(Event.Type.PLAYER_INTERACT, playerListener);
|
||||
registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener);
|
||||
registerEvent(Event.Type.PLAYER_JOIN, criticalPlayerListener, Priority.Lowest);
|
||||
|
||||
// The permissions resolver has some hooks of its own
|
||||
(new PermissionsResolverServerListener(perms)).register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event.
|
||||
*
|
||||
* @param type
|
||||
* @param listener
|
||||
* @param priority
|
||||
*/
|
||||
protected void registerEvent(Event.Type type, Listener listener, Priority priority) {
|
||||
getServer().getPluginManager()
|
||||
.registerEvent(type, listener, priority, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event at normal priority.
|
||||
*
|
||||
* @param type
|
||||
* @param listener
|
||||
*/
|
||||
protected void registerEvent(Event.Type type, Listener listener) {
|
||||
getServer().getPluginManager()
|
||||
.registerEvent(type, listener, Priority.Normal, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default configuration file from the .jar.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
protected void createDefaultConfiguration(String name) {
|
||||
File actual = new File(getDataFolder(), name);
|
||||
if (!actual.exists()) {
|
||||
|
||||
InputStream input =
|
||||
WorldEdit.class.getResourceAsStream("/defaults/" + name);
|
||||
if (input != null) {
|
||||
FileOutputStream output = null;
|
||||
|
||||
try {
|
||||
output = new FileOutputStream(actual);
|
||||
byte[] buf = new byte[8192];
|
||||
int length = 0;
|
||||
while ((length = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, length);
|
||||
}
|
||||
|
||||
logger.info(getDescription().getName()
|
||||
+ ": Default configuration file written: " + name);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (input != null)
|
||||
input.close();
|
||||
} catch (IOException e) {}
|
||||
|
||||
try {
|
||||
if (output != null)
|
||||
output.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on WorldEdit command.
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd,
|
||||
String commandLabel, String[] args) {
|
||||
// Since WorldEdit is primarily made for use in-game, we're going
|
||||
// to ignore the situation where the command sender is not aplayer.
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Add the command to the array because the underlying command handling
|
||||
// code of WorldEdit expects it
|
||||
String[] split = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, split, 1, args.length);
|
||||
split[0] = "/" + cmd.getName();
|
||||
|
||||
controller.handleCommand(wrapPlayer(player), split);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the session for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public LocalSession getSession(Player player) {
|
||||
return controller.getSession(wrapPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the session for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public EditSession createEditSession(Player player) {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
BlockBag blockBag = session.getBlockBag(wePlayer);
|
||||
|
||||
EditSession editSession =
|
||||
new EditSession(wePlayer.getWorld(),
|
||||
session.getBlockChangeLimit(), blockBag);
|
||||
editSession.enableQueue();
|
||||
|
||||
return editSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember an edit session.
|
||||
*
|
||||
* @param player
|
||||
* @param editSession
|
||||
*/
|
||||
public void remember(Player player, EditSession editSession) {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
|
||||
session.remember(editSession);
|
||||
editSession.flushQueue();
|
||||
|
||||
controller.flushBlockBag(wePlayer, editSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an operation into an EditSession.
|
||||
*
|
||||
* @param player
|
||||
* @param op
|
||||
* @throws Throwable
|
||||
*/
|
||||
public void perform(Player player, WorldEditOperation op)
|
||||
throws Throwable {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
|
||||
EditSession editSession = createEditSession(player);
|
||||
try {
|
||||
op.run(session, wePlayer, editSession);
|
||||
} finally {
|
||||
remember(player, editSession);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the API.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public WorldEditAPI getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration used by WorldEdit.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BukkitConfiguration getLocalConfiguration() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the permissions resolver in use.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PermissionsResolverManager getPermissionsResolver() {
|
||||
return perms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to wrap a Bukkit Player as a LocalPlayer.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public BukkitPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(this, this.server, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server interface.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ServerInterface getServerInterface() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WorldEdit.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WorldEdit getWorldEdit() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region selection for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return the selection or null if there was none
|
||||
*/
|
||||
public Selection getSelection(Player player) {
|
||||
if (player == null) {
|
||||
throw new IllegalArgumentException("Null player not allowed");
|
||||
}
|
||||
if (!player.isOnline()) {
|
||||
throw new IllegalArgumentException("Offline player not allowed");
|
||||
}
|
||||
|
||||
LocalSession session = controller.getSession(wrapPlayer(player));
|
||||
RegionSelector selector = session.getRegionSelector();
|
||||
|
||||
try {
|
||||
Region region = selector.getRegion();
|
||||
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
|
||||
|
||||
if (region instanceof CuboidRegion) {
|
||||
return new CuboidSelection(world, selector, (CuboidRegion)region);
|
||||
} else if (region instanceof Polygonal2DRegion) {
|
||||
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion)region);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (IncompleteRegionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the region selection for a player.
|
||||
*
|
||||
* @param player
|
||||
* @param selection
|
||||
*/
|
||||
public void setSelection(Player player, Selection selection) {
|
||||
if (player == null) {
|
||||
throw new IllegalArgumentException("Null player not allowed");
|
||||
}
|
||||
if (!player.isOnline()) {
|
||||
throw new IllegalArgumentException("Offline player not allowed");
|
||||
}
|
||||
if (selection == null) {
|
||||
throw new IllegalArgumentException("Null selection not allowed");
|
||||
}
|
||||
|
||||
LocalSession session = controller.getSession(wrapPlayer(player));
|
||||
RegionSelector sel = selection.getRegionSelector();
|
||||
session.setRegionSelector(new BukkitWorld(player.getWorld()), sel);
|
||||
session.dispatchCUISelection(wrapPlayer(player));
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
// $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.bukkit.selections;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldedit.regions.*;
|
||||
|
||||
public class CuboidSelection extends RegionSelection {
|
||||
|
||||
protected CuboidRegion cuboid;
|
||||
|
||||
public CuboidSelection(World world, Location pt1, Location pt2) {
|
||||
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
|
||||
}
|
||||
|
||||
public CuboidSelection(World world, Vector pt1, Vector pt2) {
|
||||
super(world);
|
||||
|
||||
if (pt1 == null) {
|
||||
throw new IllegalArgumentException("Null point 1 not permitted");
|
||||
}
|
||||
|
||||
if (pt2 == null) {
|
||||
throw new IllegalArgumentException("Null point 2 not permitted");
|
||||
}
|
||||
|
||||
CuboidRegionSelector sel = new CuboidRegionSelector();
|
||||
sel.selectPrimary(pt1);
|
||||
sel.selectSecondary(pt2);
|
||||
|
||||
try {
|
||||
cuboid = sel.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new RuntimeException("IncompleteRegionException unexpectedly thrown");
|
||||
}
|
||||
|
||||
setRegionSelector(sel);
|
||||
setRegion(cuboid);
|
||||
}
|
||||
|
||||
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
|
||||
super(world, sel, region);
|
||||
this.cuboid = region;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
// $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.bukkit.selections;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.regions.*;
|
||||
|
||||
public class Polygonal2DSelection extends RegionSelection {
|
||||
|
||||
protected Polygonal2DRegion poly2d;
|
||||
|
||||
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
|
||||
super(world, sel, region);
|
||||
this.poly2d = region;
|
||||
}
|
||||
|
||||
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
|
||||
super(world);
|
||||
|
||||
minY = Math.min(Math.max(0, minY), 127);
|
||||
maxY = Math.min(Math.max(0, maxY), 127);
|
||||
|
||||
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector();
|
||||
poly2d = sel.getIncompleteRegion();
|
||||
|
||||
for (BlockVector2D pt : points) {
|
||||
if (pt == null) {
|
||||
throw new IllegalArgumentException("Null point not permitted");
|
||||
}
|
||||
|
||||
poly2d.addPoint(pt);
|
||||
}
|
||||
|
||||
poly2d.setMinimumY(minY);
|
||||
poly2d.setMaximumY(maxY);
|
||||
|
||||
sel.learnChanges();
|
||||
|
||||
setRegionSelector(sel);
|
||||
setRegion(poly2d);
|
||||
}
|
||||
|
||||
public List<BlockVector2D> getNativePoints() {
|
||||
return Collections.unmodifiableList(poly2d.getPoints());
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
// $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.bukkit.selections;
|
||||
|
||||
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
|
||||
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
|
||||
public abstract class RegionSelection implements Selection {
|
||||
|
||||
private World world;
|
||||
private RegionSelector selector;
|
||||
private Region region;
|
||||
|
||||
public RegionSelection(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public RegionSelection(World world, RegionSelector selector, Region region) {
|
||||
this.world = world;
|
||||
this.region = region;
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
protected Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
protected void setRegion(Region region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public RegionSelector getRegionSelector() {
|
||||
return selector;
|
||||
}
|
||||
|
||||
protected void setRegionSelector(RegionSelector selector) {
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
public Location getMinimumPoint() {
|
||||
return toLocation(world, region.getMinimumPoint());
|
||||
}
|
||||
|
||||
public Vector getNativeMinimumPoint() {
|
||||
return region.getMinimumPoint();
|
||||
}
|
||||
|
||||
public Location getMaximumPoint() {
|
||||
return toLocation(world, region.getMaximumPoint());
|
||||
}
|
||||
|
||||
public Vector getNativeMaximumPoint() {
|
||||
return region.getMaximumPoint();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return region.getWidth();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return region.getHeight();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return region.getLength();
|
||||
}
|
||||
|
||||
public boolean contains(Location pt) {
|
||||
if (!pt.getWorld().equals(world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return region.contains(toVector(pt));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
// $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.bukkit.selections;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
|
||||
public interface Selection {
|
||||
/**
|
||||
* Get the lower point of a region.
|
||||
*
|
||||
* @return min. point
|
||||
*/
|
||||
public Location getMinimumPoint();
|
||||
|
||||
/**
|
||||
* Get the lower point of a region.
|
||||
*
|
||||
* @return min. point
|
||||
*/
|
||||
public Vector getNativeMinimumPoint();
|
||||
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return max. point
|
||||
*/
|
||||
public Location getMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return max. point
|
||||
*/
|
||||
public Vector getNativeMaximumPoint();
|
||||
|
||||
/**
|
||||
* Get the region selector. This is for internal use.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RegionSelector getRegionSelector();
|
||||
|
||||
/**
|
||||
* Get the world.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public World getWorld();
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
public int getWidth();
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public int getLength();
|
||||
|
||||
/**
|
||||
* Returns true based on whether the region contains the point,
|
||||
*
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(Location pt);
|
||||
}
|
233
src/main/java/com/sk89q/worldedit/commands/BrushCommands.java
Normal file
233
src/main/java/com/sk89q/worldedit/commands/BrushCommands.java
Normal file
@ -0,0 +1,233 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.CuboidClipboard;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.masks.BlockTypeMask;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
||||
import com.sk89q.worldedit.tools.BrushTool;
|
||||
import com.sk89q.worldedit.tools.brushes.ClipboardBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.CylinderBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.HollowCylinderBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.HollowSphereBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.SmoothBrush;
|
||||
import com.sk89q.worldedit.tools.brushes.SphereBrush;
|
||||
|
||||
/**
|
||||
* Brush shape commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class BrushCommands {
|
||||
@Command(
|
||||
aliases = {"sphere", "s"},
|
||||
usage = "<block> [radius]",
|
||||
flags = "h",
|
||||
desc = "Choose the sphere brush",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.sphere"})
|
||||
public static void sphereBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = we.getBlockPattern(player, args.getString(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
if (args.hasFlag('h')) {
|
||||
tool.setBrush(new HollowSphereBrush());
|
||||
} else {
|
||||
tool.setBrush(new SphereBrush());
|
||||
}
|
||||
|
||||
player.print(String.format("Sphere brush shape equipped (%d).",
|
||||
radius));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cylinder", "cyl", "c"},
|
||||
usage = "<block> [radius] [height]",
|
||||
flags = "h",
|
||||
desc = "Choose the cylinder brush",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.cylinder"})
|
||||
public static void cylinderBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
if (height > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius/height: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = we.getBlockPattern(player, args.getString(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
|
||||
if (args.hasFlag('h')) {
|
||||
tool.setBrush(new HollowCylinderBrush(height));
|
||||
} else {
|
||||
tool.setBrush(new CylinderBrush(height));
|
||||
}
|
||||
|
||||
player.print(String.format("Cylinder brush shape equipped (%d by %d).",
|
||||
radius, height));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clipboard", "copy"},
|
||||
usage = "",
|
||||
flags = "a",
|
||||
desc = "Choose the clipboard brush",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.clipboard"})
|
||||
public static void clipboardBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
|
||||
if (clipboard == null) {
|
||||
player.printError("Copy something first.");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector size = clipboard.getSize();
|
||||
|
||||
if (size.getBlockX() > config.maxBrushRadius
|
||||
|| size.getBlockY() > config.maxBrushRadius
|
||||
|| size.getBlockZ() > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius/height: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')));
|
||||
|
||||
player.print("Clipboard brush shape equipped.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"smooth"},
|
||||
usage = "[size] [iterations]",
|
||||
desc = "Choose the terrain softener brush",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.smooth"})
|
||||
public static void smoothBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 0 ? args.getInteger(0) : 2;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4;
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
tool.setSize(radius);
|
||||
tool.setBrush(new SmoothBrush(iterations));
|
||||
|
||||
player.print(String.format("Smooth brush equipped (%d x %dx).",
|
||||
radius, iterations));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ex", "extinguish"},
|
||||
usage = "[radius]",
|
||||
desc = "Shortcut fire extinguisher brush",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.ex"})
|
||||
public static void extinguishBrush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.argsLength() > 1 ? args.getInteger(1) : 5;
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
||||
Pattern fill = new SingleBlockPattern(new BaseBlock(0));
|
||||
tool.setFill(fill);
|
||||
tool.setSize(radius);
|
||||
tool.setMask(new BlockTypeMask(BlockID.FIRE));
|
||||
tool.setBrush(new SphereBrush());
|
||||
|
||||
player.print(String.format("Extinguisher equipped (%d).",
|
||||
radius));
|
||||
}
|
||||
}
|
165
src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java
Normal file
165
src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java
Normal file
@ -0,0 +1,165 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Set;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.data.LegacyChunkStore;
|
||||
import com.sk89q.worldedit.data.McRegionChunkStore;
|
||||
|
||||
/**
|
||||
* Chunk tools.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ChunkCommands {
|
||||
@Command(
|
||||
aliases = {"chunkinfo"},
|
||||
usage = "",
|
||||
desc = "Get information about the chunk that you are inside",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.chunkinfo"})
|
||||
public static void chunkInfo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockIn();
|
||||
int chunkX = (int)Math.floor(pos.getBlockX() / 16.0);
|
||||
int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0);
|
||||
|
||||
String folder1 = Integer.toString(WorldEdit.divisorMod(chunkX, 64), 36);
|
||||
String folder2 = Integer.toString(WorldEdit.divisorMod(chunkZ, 64), 36);
|
||||
String filename = "c." + Integer.toString(chunkX, 36)
|
||||
+ "." + Integer.toString(chunkZ, 36) + ".dat";
|
||||
|
||||
player.print("Chunk: " + chunkX + ", " + chunkZ);
|
||||
player.print("Old format: " + folder1 + "/" + folder2 + "/" + filename);
|
||||
player.print("McRegion: region/" + McRegionChunkStore.getFilename(
|
||||
new Vector2D(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"listchunks"},
|
||||
usage = "",
|
||||
desc = "List chunks that your selection includes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.listchunks"})
|
||||
public static void listChunks(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
player.print(LegacyChunkStore.getFilename(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"delchunks"},
|
||||
usage = "",
|
||||
desc = "Delete chunks that your selection includes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.delchunks"})
|
||||
public static void deleteChunks(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
Set<Vector2D> chunks = session.getSelection(player.getWorld()).getChunks();
|
||||
FileOutputStream out = null;
|
||||
|
||||
if (config.shellSaveType == null) {
|
||||
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
||||
} else if (config.shellSaveType.equalsIgnoreCase("bat")) {
|
||||
try {
|
||||
out = new FileOutputStream("worldedit-delchunks.bat");
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
||||
writer.write("@ECHO off\r\n");
|
||||
writer.write("ECHO This batch file was generated by WorldEdit.\r\n");
|
||||
writer.write("ECHO It contains a list of chunks that were in the selected region\r\n");
|
||||
writer.write("ECHO at the time that the /delchunks command was used. Run this file\r\n");
|
||||
writer.write("ECHO in order to delete the chunk files listed in this file.\r\n");
|
||||
writer.write("ECHO.\r\n");
|
||||
writer.write("PAUSE\r\n");
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
String filename = LegacyChunkStore.getFilename(chunk);
|
||||
writer.write("ECHO " + filename + "\r\n");
|
||||
writer.write("DEL \"world/" + filename + "\"\r\n");
|
||||
}
|
||||
|
||||
writer.write("ECHO Complete.\r\n");
|
||||
writer.write("PAUSE\r\n");
|
||||
writer.close();
|
||||
player.print("worldedit-delchunks.bat written. Run it when no one is near the region.");
|
||||
} catch (IOException e) {
|
||||
player.printError("Error occurred: " + e.getMessage());
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ie) {}
|
||||
}
|
||||
}
|
||||
} else if (config.shellSaveType.equalsIgnoreCase("bash")) {
|
||||
try {
|
||||
out = new FileOutputStream("worldedit-delchunks.sh");
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
|
||||
writer.write("#!/bin/bash\n");
|
||||
writer.write("echo This shell file was generated by WorldEdit.\n");
|
||||
writer.write("echo It contains a list of chunks that were in the selected region\n");
|
||||
writer.write("echo at the time that the /delchunks command was used. Run this file\n");
|
||||
writer.write("echo in order to delete the chunk files listed in this file.\n");
|
||||
writer.write("echo\n");
|
||||
writer.write("read -p \"Press any key to continue...\"\n");
|
||||
|
||||
for (Vector2D chunk : chunks) {
|
||||
String filename = LegacyChunkStore.getFilename(chunk);
|
||||
writer.write("echo " + filename + "\n");
|
||||
writer.write("rm \"world/" + filename + "\"\n");
|
||||
}
|
||||
|
||||
writer.write("echo Complete.\n");
|
||||
writer.write("read -p \"Press any key to continue...\"\n");
|
||||
writer.close();
|
||||
player.print("worldedit-delchunks.sh written. Run it when no one is near the region.");
|
||||
player.print("You will have to chmod it to be executable.");
|
||||
} catch (IOException e) {
|
||||
player.printError("Error occurred: " + e.getMessage());
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ie) {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,265 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Clipboard commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ClipboardCommands {
|
||||
@Command(
|
||||
aliases = {"/copy"},
|
||||
usage = "",
|
||||
desc = "Copy the selection to the clipboard",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.copy"})
|
||||
public static void copy(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
Vector pos = player.getBlockIn();
|
||||
|
||||
CuboidClipboard clipboard = new CuboidClipboard(
|
||||
max.subtract(min).add(new Vector(1, 1, 1)),
|
||||
min, min.subtract(pos));
|
||||
clipboard.copy(editSession);
|
||||
session.setClipboard(clipboard);
|
||||
|
||||
player.print("Block(s) copied.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/cut"},
|
||||
usage = "[leave-id]",
|
||||
desc = "Cut the selection to the clipboard",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.cut"})
|
||||
public static void cut(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = new BaseBlock(0);
|
||||
|
||||
if (args.argsLength() > 0) {
|
||||
block = we.getBlock(player, args.getString(0));
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
Vector pos = player.getBlockIn();
|
||||
|
||||
CuboidClipboard clipboard = new CuboidClipboard(
|
||||
max.subtract(min).add(new Vector(1, 1, 1)),
|
||||
min, min.subtract(pos));
|
||||
clipboard.copy(editSession);
|
||||
session.setClipboard(clipboard);
|
||||
|
||||
editSession.setBlocks(session.getSelection(player.getWorld()), block);
|
||||
player.print("Block(s) cut.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/paste"},
|
||||
usage = "",
|
||||
flags = "ao",
|
||||
desc = "Paste the clipboard's contents",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.paste"})
|
||||
public static void paste(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
boolean atOrigin = args.hasFlag('o');
|
||||
boolean pasteNoAir = args.hasFlag('a');
|
||||
|
||||
if (atOrigin) {
|
||||
Vector pos = session.getClipboard().getOrigin();
|
||||
session.getClipboard().place(editSession, pos, pasteNoAir);
|
||||
player.findFreePosition();
|
||||
player.print("Pasted to copy origin. Undo with //undo");
|
||||
} else {
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
session.getClipboard().paste(editSession, pos, pasteNoAir);
|
||||
player.findFreePosition();
|
||||
player.print("Pasted relative to you. Undo with //undo");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/rotate"},
|
||||
usage = "<angle-in-degrees>",
|
||||
desc = "Rotate the contents of the clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.rotate"})
|
||||
public static void rotate(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int angle = args.getInteger(0);
|
||||
|
||||
if (angle % 90 == 0) {
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
clipboard.rotate2D(angle);
|
||||
player.print("Clipboard rotated by " + angle + " degrees.");
|
||||
} else {
|
||||
player.printError("Angles must be divisible by 90 degrees.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/flip"},
|
||||
usage = "[dir]",
|
||||
desc = "Flip the contents of the clipboard",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.flip"})
|
||||
public static void flip(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
CuboidClipboard.FlipDirection dir = we.getFlipDirection(player,
|
||||
args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
|
||||
|
||||
CuboidClipboard clipboard = session.getClipboard();
|
||||
clipboard.flip(dir);
|
||||
player.print("Clipboard flipped.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/load"},
|
||||
usage = "<filename>",
|
||||
desc = "Load a schematic into your clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.load"})
|
||||
public static void load(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
String filename = args.getString(0);
|
||||
File dir = we.getWorkingDirectoryFile(config.saveDir);
|
||||
File f = we.getSafeOpenFile(player, dir, filename, "schematic",
|
||||
new String[] {"schematic"});
|
||||
|
||||
try {
|
||||
String filePath = f.getCanonicalPath();
|
||||
String dirPath = dir.getCanonicalPath();
|
||||
|
||||
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
|
||||
player.printError("Schematic could not read or it does not exist.");
|
||||
} else {
|
||||
session.setClipboard(CuboidClipboard.loadSchematic(f));
|
||||
WorldEdit.logger.info(player.getName() + " loaded " + filePath);
|
||||
player.print(filename + " loaded. Paste it with //paste");
|
||||
}
|
||||
} catch (DataException e) {
|
||||
player.printError("Load error: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.printError("Schematic could not read or it does not exist: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/save"},
|
||||
usage = "<filename>",
|
||||
desc = "Save a schematic into your clipboard",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.save"})
|
||||
public static void save(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
String filename = args.getString(0);
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(config.saveDir);
|
||||
File f = we.getSafeSaveFile(player, dir, filename, "schematic",
|
||||
new String[] {"schematic"});
|
||||
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdir()) {
|
||||
player.printError("The storage folder could not be created.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Create parent directories
|
||||
File parent = f.getParentFile();
|
||||
if (parent != null && !parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
session.getClipboard().saveSchematic(f);
|
||||
WorldEdit.logger.info(player.getName() + " saved " + f.getCanonicalPath());
|
||||
player.print(filename + " saved.");
|
||||
} catch (DataException se) {
|
||||
player.printError("Save error: " + se.getMessage());
|
||||
} catch (IOException e) {
|
||||
player.printError("Schematic could not written: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clearclipboard"},
|
||||
usage = "",
|
||||
desc = "Clear your clipboard",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.clipboard.clear"})
|
||||
public static void clearClipboard(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setClipboard(null);
|
||||
player.print("Clipboard cleared.");
|
||||
}
|
||||
}
|
167
src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java
Normal file
167
src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java
Normal file
@ -0,0 +1,167 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
|
||||
/**
|
||||
* General WorldEdit commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class GeneralCommands {
|
||||
@Command(
|
||||
aliases = {"/limit"},
|
||||
usage = "<limit>",
|
||||
desc = "Modify block change limit",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.limit"})
|
||||
public static void limit(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int limit = Math.max(-1, args.getInteger(0));
|
||||
if (!player.hasPermission("worldedit.limit.unrestricted")
|
||||
&& config.maxChangeLimit > -1) {
|
||||
if (limit > config.maxChangeLimit) {
|
||||
player.printError("Your maximum allowable limit is "
|
||||
+ config.maxChangeLimit + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
session.setBlockChangeLimit(limit);
|
||||
player.print("Block change limit set to " + limit + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"toggleplace"},
|
||||
usage = "",
|
||||
desc = "",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void togglePlace(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (session.togglePlacementPosition()) {
|
||||
player.print("Now placing at pos #1.");
|
||||
} else {
|
||||
player.print("Now placing at the block you stand in.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"searchitem", "/l", "search"},
|
||||
usage = "<query>",
|
||||
flags = "bi",
|
||||
desc = "Search for an item",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void searchItem(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String query = args.getString(0).trim().toLowerCase();
|
||||
boolean blocksOnly = args.hasFlag('b');
|
||||
boolean itemsOnly = args.hasFlag('i');
|
||||
|
||||
try {
|
||||
int id = Integer.parseInt(query);
|
||||
|
||||
ItemType type = ItemType.fromID(id);
|
||||
|
||||
if (type != null) {
|
||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
} else {
|
||||
player.printError("No item found by ID " + id);
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
if (query.length() <= 2) {
|
||||
player.printError("Enter a longer search string (len > 2).");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blocksOnly && !itemsOnly) {
|
||||
player.print("Searching for: " + query);
|
||||
} else if (blocksOnly && itemsOnly) {
|
||||
player.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
|
||||
return;
|
||||
} else if (blocksOnly) {
|
||||
player.print("Searching for blocks: " + query);
|
||||
} else {
|
||||
player.print("Searching for items: " + query);
|
||||
}
|
||||
|
||||
int found = 0;
|
||||
|
||||
for (ItemType type : ItemType.values()) {
|
||||
if (found >= 15) {
|
||||
player.print("Too many results!");
|
||||
break;
|
||||
}
|
||||
|
||||
if (blocksOnly && type.getID() > 255) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itemsOnly && type.getID() <= 255) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String alias : type.getAliases()) {
|
||||
if (alias.contains(query)) {
|
||||
player.print("#" + type.getID() + " (" + type.getName() + ")");
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 0) {
|
||||
player.printError("No items found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"we", "worldedit"},
|
||||
desc = "WorldEdit commands"
|
||||
)
|
||||
@NestedCommand({WorldEditCommands.class})
|
||||
public static void we(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
/**
|
||||
* Generation commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class GenerationCommands {
|
||||
@Command(
|
||||
aliases = {"/hcyl"},
|
||||
usage = "<block> <radius> [height] ",
|
||||
desc = "Generate a hollow cylinder",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.cylinder"})
|
||||
public static void hcyl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = editSession.makeHollowCylinder(pos, block, radius, height);
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/cyl"},
|
||||
usage = "<block> <radius> [height] ",
|
||||
desc = "Generate a cylinder",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.cylinder"})
|
||||
public static void cyl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = editSession.makeCylinder(pos, block, radius, height);
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hsphere"},
|
||||
usage = "<block> <radius> [raised?] ",
|
||||
desc = "Generate a hollow sphere",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.sphere"})
|
||||
public static void hsphere(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
boolean raised = args.argsLength() > 2
|
||||
? (args.getString(2).equalsIgnoreCase("true")
|
||||
|| args.getString(2).equalsIgnoreCase("yes"))
|
||||
: false;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
if (raised) {
|
||||
pos = pos.add(0, radius, 0);
|
||||
}
|
||||
|
||||
int affected = editSession.makeSphere(pos, block, radius, false);
|
||||
player.findFreePosition();
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/sphere"},
|
||||
usage = "<block> <radius> [raised?] ",
|
||||
desc = "Generate a filled sphere",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.sphere"})
|
||||
public static void sphere(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern block = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
boolean raised = args.argsLength() > 2
|
||||
? (args.getString(2).equalsIgnoreCase("true")
|
||||
|| args.getString(2).equalsIgnoreCase("yes"))
|
||||
: false;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
if (raised) {
|
||||
pos = pos.add(0, radius, 0);
|
||||
}
|
||||
|
||||
int affected = editSession.makeSphere(pos, block, radius, true);
|
||||
player.findFreePosition();
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"forestgen"},
|
||||
usage = "[size] [type] [density]",
|
||||
desc = "Generate a forest",
|
||||
min = 0,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.forest"})
|
||||
public static void forestGen(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
TreeGenerator.TreeType type = args.argsLength() > 1 ?
|
||||
type = TreeGenerator.lookup(args.getString(1))
|
||||
: TreeGenerator.TreeType.TREE;
|
||||
double density = args.argsLength() > 2 ? args.getDouble(2) / 100 : 0.05;
|
||||
|
||||
if (type == null) {
|
||||
player.printError("Tree type '" + args.getString(1) + "' is unknown.");
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
|
||||
int affected = editSession.makeForest(player.getPosition(),
|
||||
size, density, new TreeGenerator(type));
|
||||
player.print(affected + " trees created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"pumpkins"},
|
||||
usage = "[size]",
|
||||
desc = "Generate pumpkin patches",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.generation.pumpkins"})
|
||||
public static void pumpkins(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.makePumpkinPatches(player.getPosition(), size);
|
||||
player.print(affected + " pumpkin patches created.");
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* History little commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class HistoryCommands {
|
||||
@Command(
|
||||
aliases = {"/undo", "undo"},
|
||||
usage = "[times]",
|
||||
desc = "Undoes the last action",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.undo"})
|
||||
public static void undo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int times = Math.max(1, args.getInteger(0, 1));
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
EditSession undone = session.undo(session.getBlockBag(player));
|
||||
if (undone != null) {
|
||||
player.print("Undo successful.");
|
||||
we.flushBlockBag(player, undone);
|
||||
} else {
|
||||
player.printError("Nothing left to undo.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/redo", "redo"},
|
||||
usage = "[times]",
|
||||
desc = "Redoes the last action (from history)",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.redo"})
|
||||
public static void redo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int times = Math.max(1, args.getInteger(0, 1));
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
EditSession redone = session.redo(session.getBlockBag(player));
|
||||
if (redone != null) {
|
||||
player.print("Redo successful.");
|
||||
we.flushBlockBag(player, redone);
|
||||
} else {
|
||||
player.printError("Nothing left to redo.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"clearhistory"},
|
||||
usage = "",
|
||||
desc = "Clear your history",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.history.clear"})
|
||||
public static void clearHistory(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.clearHistory();
|
||||
player.print("History cleared.");
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class InsufficientArgumentsException extends WorldEditException {
|
||||
private static final long serialVersionUID = 995264804658899764L;
|
||||
|
||||
public InsufficientArgumentsException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Navigation commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class NavigationCommands {
|
||||
@Command(
|
||||
aliases = {"unstuck"},
|
||||
usage = "",
|
||||
desc = "Escape from being stuck inside a block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.unstuck"})
|
||||
public static void unstuck(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.print("There you go!");
|
||||
player.findFreePosition();
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ascend"},
|
||||
usage = "",
|
||||
desc = "Go up a floor",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.ascend"})
|
||||
public static void ascend(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.ascendLevel()) {
|
||||
player.print("Ascended a level.");
|
||||
} else {
|
||||
player.printError("No free spot above you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"descend"},
|
||||
usage = "",
|
||||
desc = "Go down a floor",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.descend"})
|
||||
public static void descend(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.descendLevel()) {
|
||||
player.print("Descended a level.");
|
||||
} else {
|
||||
player.printError("No free spot below you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ceil"},
|
||||
usage = "[clearance]",
|
||||
desc = "Go to the celing",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.ceiling"})
|
||||
public static void ceiling(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int clearence = args.argsLength() > 0 ?
|
||||
Math.max(0, args.getInteger(0)) : 0;
|
||||
|
||||
if (player.ascendToCeiling(clearence)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("No free spot above you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"thru"},
|
||||
usage = "",
|
||||
desc = "Passthrough walls",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.thru"})
|
||||
public static void thru(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (player.passThroughForwardWall(6)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("No free spot ahead of you found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"jumpto"},
|
||||
usage = "",
|
||||
desc = "Teleport to a location",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.jumpto"})
|
||||
public static void jumpTo(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
WorldVector pos = player.getSolidBlockTrace(300);
|
||||
if (pos != null) {
|
||||
player.findFreePosition(pos);
|
||||
player.print("Poof!");
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"up"},
|
||||
usage = "<block>",
|
||||
desc = "Go upwards some distance",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.navigation.up"})
|
||||
public static void up(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int distance = args.getInteger(0);
|
||||
|
||||
if (player.ascendUpwards(distance)) {
|
||||
player.print("Whoosh!");
|
||||
} else {
|
||||
player.printError("You would hit something above you.");
|
||||
}
|
||||
}
|
||||
}
|
250
src/main/java/com/sk89q/worldedit/commands/RegionCommands.java
Normal file
250
src/main/java/com/sk89q/worldedit/commands/RegionCommands.java
Normal file
@ -0,0 +1,250 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.filtering.GaussianKernel;
|
||||
import com.sk89q.worldedit.filtering.HeightMapFilter;
|
||||
import com.sk89q.worldedit.patterns.*;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Region related commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class RegionCommands {
|
||||
@Command(
|
||||
aliases = {"/set"},
|
||||
usage = "<block>",
|
||||
desc = "Set all the blocks inside the selection to a block",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.set"})
|
||||
public static void set(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
|
||||
int affected;
|
||||
|
||||
if (pattern instanceof SingleBlockPattern) {
|
||||
affected = editSession.setBlocks(session.getSelection(player.getWorld()),
|
||||
((SingleBlockPattern)pattern).getBlock());
|
||||
} else {
|
||||
affected = editSession.setBlocks(session.getSelection(player.getWorld()), pattern);
|
||||
}
|
||||
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/replace"},
|
||||
usage = "[from-block] <to-block>",
|
||||
desc = "Replace all blocks in the selection with another",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.replace"})
|
||||
public static void replace(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Integer> from;
|
||||
Pattern to;
|
||||
if (args.argsLength() == 1) {
|
||||
from = null;
|
||||
to = we.getBlockPattern(player, args.getString(0));
|
||||
} else {
|
||||
from = we.getBlockIDs(player, args.getString(0), true);
|
||||
to = we.getBlockPattern(player, args.getString(1));
|
||||
}
|
||||
|
||||
int affected = 0;
|
||||
if (to instanceof SingleBlockPattern) {
|
||||
affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from,
|
||||
((SingleBlockPattern)to).getBlock());
|
||||
} else {
|
||||
affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from, to);
|
||||
}
|
||||
|
||||
player.print(affected + " block(s) have been replaced.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/overlay"},
|
||||
usage = "<block>",
|
||||
desc = "Set a block on top of blocks in the region",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.overlay"})
|
||||
public static void overlay(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pat = we.getBlockPattern(player, args.getString(0));
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int affected = 0;
|
||||
if (pat instanceof SingleBlockPattern) {
|
||||
affected = editSession.overlayCuboidBlocks(region,
|
||||
((SingleBlockPattern)pat).getBlock());
|
||||
} else {
|
||||
affected = editSession.overlayCuboidBlocks(region, pat);
|
||||
}
|
||||
player.print(affected + " block(s) have been overlayed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/walls"},
|
||||
usage = "<block>",
|
||||
desc = "Build the four sides of the selection",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.walls"})
|
||||
public static void walls(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0));
|
||||
int affected = editSession.makeCuboidWalls(session.getSelection(player.getWorld()), block);
|
||||
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/faces", "/outline"},
|
||||
usage = "<block>",
|
||||
desc = "Build the walls, ceiling, and roof of a selection",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.faces"})
|
||||
public static void faces(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0));
|
||||
int affected = editSession.makeCuboidFaces(session.getSelection(player.getWorld()), block);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/smooth"},
|
||||
usage = "[iterations]",
|
||||
desc = "Smooth the elevation in the selection",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.smooth"})
|
||||
public static void smooth(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int iterations = 1;
|
||||
if (args.argsLength() > 0) {
|
||||
iterations = args.getInteger(0);
|
||||
}
|
||||
|
||||
HeightMap heightMap = new HeightMap(editSession, session.getSelection(player.getWorld()));
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
int affected = heightMap.applyFilter(filter, iterations);
|
||||
player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
|
||||
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/move"},
|
||||
usage = "[count] [direction] [leave-id]",
|
||||
desc = "Move the contents of the selection",
|
||||
min = 0,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.move"})
|
||||
public static void move(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
Vector dir = we.getDirection(player,
|
||||
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
|
||||
BaseBlock replace;
|
||||
|
||||
// Replacement block argument
|
||||
if (args.argsLength() > 2) {
|
||||
replace = we.getBlock(player, args.getString(2));
|
||||
} else {
|
||||
replace = new BaseBlock(0);
|
||||
}
|
||||
|
||||
int affected = editSession.moveCuboidRegion(session.getSelection(player.getWorld()),
|
||||
dir, count, true, replace);
|
||||
player.print(affected + " blocks moved.");
|
||||
}
|
||||
|
||||
|
||||
@Command(
|
||||
aliases = {"/stack"},
|
||||
usage = "[count] [direction]",
|
||||
flags = "a",
|
||||
desc = "Repeat the contents of the selection",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.region.stack"})
|
||||
public static void stack(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
Vector dir = we.getDiagonalDirection(player,
|
||||
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
|
||||
|
||||
int affected = editSession.stackCuboidRegion(session.getSelection(player.getWorld()),
|
||||
dir, count, !args.hasFlag('a'));
|
||||
player.print(affected + " blocks changed. Undo with //undo");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/regen"},
|
||||
usage = "",
|
||||
desc = "Regenerates the contents of the selection",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.regen"})
|
||||
public static void regenerateChunk(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
player.getWorld().regenerate(region, editSession);
|
||||
player.print("Region regenerated.");
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.io.File;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Scripting commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ScriptingCommands {
|
||||
@Command(
|
||||
aliases = {"cs"},
|
||||
usage = "<filename> [args...]",
|
||||
desc = "Execute a CraftScript",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.scripting.execute"})
|
||||
public static void execute(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
// @TODO: Check for worldedit.scripting.execute.<script> permission
|
||||
|
||||
String[] scriptArgs = args.getSlice(1);
|
||||
|
||||
session.setLastScript(args.getString(0));
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir);
|
||||
File f = we.getSafeOpenFile(player, dir, args.getString(0), "js",
|
||||
new String[] {"js"});
|
||||
|
||||
we.runScript(player, f, scriptArgs);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {".s"},
|
||||
usage = "[args...]",
|
||||
desc = "Execute last CraftScript",
|
||||
min = 0,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.scripting.execute"})
|
||||
public static void executeLast(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
// @TODO: Check for worldedit.scripting.execute.<script> permission
|
||||
|
||||
String lastScript = session.getLastScript();
|
||||
|
||||
if (lastScript == null) {
|
||||
player.printError("Use /cs with a script name first.");
|
||||
return;
|
||||
}
|
||||
|
||||
String[] scriptArgs = args.getSlice(0);
|
||||
|
||||
File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir);
|
||||
File f = we.getSafeOpenFile(player, dir, lastScript, "js",
|
||||
new String[] {"js"});
|
||||
|
||||
we.runScript(player, f, scriptArgs);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,553 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.data.ChunkStore;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
|
||||
/**
|
||||
* Selection commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SelectionCommands {
|
||||
@Command(
|
||||
aliases = {"/pos1"},
|
||||
usage = "",
|
||||
desc = "Set position 1",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.pos"})
|
||||
public static void pos1(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectPrimary(player.getBlockIn())) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainPrimarySelection(player, session, player.getBlockIn());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/pos2"},
|
||||
usage = "",
|
||||
desc = "Set position 2",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.pos"})
|
||||
public static void pos2(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectSecondary(player.getBlockIn())) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainSecondarySelection(player, session, player.getBlockIn());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hpos1"},
|
||||
usage = "",
|
||||
desc = "Set position 1 to targeted block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.hpos"})
|
||||
public static void hpos1(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockTrace(300);
|
||||
|
||||
if (pos != null) {
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectPrimary(pos)) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainPrimarySelection(player, session, pos);
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/hpos2"},
|
||||
usage = "",
|
||||
desc = "Set position 2 to targeted block",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.hpos"})
|
||||
public static void hpos2(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector pos = player.getBlockTrace(300);
|
||||
|
||||
if (pos != null) {
|
||||
if (!session.getRegionSelector(player.getWorld())
|
||||
.selectSecondary(pos)) {
|
||||
player.printError("Position already set.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.getRegionSelector(player.getWorld())
|
||||
.explainSecondarySelection(player, session, pos);
|
||||
} else {
|
||||
player.printError("No block in sight!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/chunk"},
|
||||
usage = "",
|
||||
desc = "Set the selection to your current chunk",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.chunk"})
|
||||
public static void chunk(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector2D min2D = ChunkStore.toChunk(player.getBlockIn());
|
||||
Vector min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
|
||||
Vector max = min.add(15, 127, 15);
|
||||
|
||||
CuboidRegionSelector selector = new CuboidRegionSelector();
|
||||
selector.selectPrimary(min);
|
||||
selector.selectSecondary(max);
|
||||
session.setRegionSelector(player.getWorld(), selector);
|
||||
|
||||
session.dispatchCUISelection(player);
|
||||
|
||||
player.print("Chunk selected: "
|
||||
+ min2D.getBlockX() + ", " + min2D.getBlockZ());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/wand"},
|
||||
usage = "",
|
||||
desc = "Get the wand object",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.wand"})
|
||||
public static void wand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.giveItem(we.getConfiguration().wandItem, 1);
|
||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"toggleeditwand"},
|
||||
usage = "",
|
||||
desc = "Toggle functionality of the edit wand",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.wand.toggle"})
|
||||
public static void toggleWand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setToolControl(!session.isToolControlEnabled());
|
||||
|
||||
if (session.isToolControlEnabled()) {
|
||||
player.print("Edit wand enabled.");
|
||||
} else {
|
||||
player.print("Edit wand disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/expand"},
|
||||
usage = "<amount> [reverse-amount] <direction>",
|
||||
desc = "Expand the selection area",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.expand"})
|
||||
public static void expand(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector dir;
|
||||
|
||||
// Special syntax (//expand vert) to expand the selection between
|
||||
// sky and bedrock.
|
||||
if (args.getString(0).equalsIgnoreCase("vert")
|
||||
|| args.getString(0).equalsIgnoreCase("vertical")) {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
try {
|
||||
int oldSize = region.getArea();
|
||||
region.expand(new Vector(0, 128, 0));
|
||||
region.expand(new Vector(0, -128, 0));
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
player.print("Region expanded " + (newSize - oldSize)
|
||||
+ " blocks [top-to-bottom].");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int change = args.getInteger(0);
|
||||
int reverseChange = 0;
|
||||
|
||||
// Specifying a direction
|
||||
if (args.argsLength() == 2) {
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
}
|
||||
// Specifying a direction and a reverse amount
|
||||
} else if (args.argsLength() == 3) {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player,
|
||||
args.getString(2).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.expand(dir.multiply(change));
|
||||
|
||||
if (reverseChange != 0) {
|
||||
region.expand(dir.multiply(reverseChange));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/contract"},
|
||||
usage = "<amount> [reverse-amount] [direction]",
|
||||
desc = "Contract the selection area",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.contract"})
|
||||
public static void contract(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Vector dir;
|
||||
int change = args.getInteger(0);
|
||||
int reverseChange = 0;
|
||||
|
||||
// Either a reverse amount or a direction
|
||||
if (args.argsLength() == 2) {
|
||||
try {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player, "me");
|
||||
} catch (NumberFormatException e) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
}
|
||||
// Both reverse amount and direction
|
||||
} else if (args.argsLength() == 3) {
|
||||
reverseChange = args.getInteger(1) * -1;
|
||||
dir = we.getDirection(player,
|
||||
args.getString(2).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
try {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
int oldSize = region.getArea();
|
||||
region.contract(dir.multiply(change));
|
||||
if (reverseChange != 0) {
|
||||
region.contract(dir.multiply(reverseChange));
|
||||
}
|
||||
session.getRegionSelector().learnChanges();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region contracted " + (oldSize - newSize) + " blocks.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/shift"},
|
||||
usage = "<amount> [direction]",
|
||||
desc = "Shift the selection area",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.shift"})
|
||||
public static void shift(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
Vector dir;
|
||||
|
||||
int change = args.getInteger(0);
|
||||
if (args.argsLength() == 2) {
|
||||
dir = we.getDirection(player,
|
||||
args.getString(1).toLowerCase());
|
||||
} else {
|
||||
dir = we.getDirection(player, "me");
|
||||
}
|
||||
|
||||
try {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
region.expand(dir.multiply(change));
|
||||
region.contract(dir.multiply(change));
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region shifted.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/outset"},
|
||||
usage = "<amount>",
|
||||
desc = "Outset the selection area",
|
||||
flags = "hv",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.outset"})
|
||||
public static void outset(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
int change = args.getInteger(0);
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
|
||||
try {
|
||||
if (!args.hasFlag('h')) {
|
||||
region.expand((new Vector(0, 1, 0)).multiply(change));
|
||||
region.expand((new Vector(0, -1, 0)).multiply(change));
|
||||
}
|
||||
|
||||
if (!args.hasFlag('v')) {
|
||||
region.expand((new Vector(1, 0, 0)).multiply(change));
|
||||
region.expand((new Vector(-1, 0, 0)).multiply(change));
|
||||
region.expand((new Vector(0, 0, 1)).multiply(change));
|
||||
region.expand((new Vector(0, 0, -1)).multiply(change));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region outset.");
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/inset"},
|
||||
usage = "<amount>",
|
||||
desc = "Inset the selection area",
|
||||
flags = "hv",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.inset"})
|
||||
public static void inset(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
int change = args.getInteger(0);
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
|
||||
if (!args.hasFlag('h')) {
|
||||
region.contract((new Vector(0, 1, 0)).multiply(change));
|
||||
region.contract((new Vector(0, -1, 0)).multiply(change));
|
||||
}
|
||||
|
||||
if (!args.hasFlag('v')) {
|
||||
region.contract((new Vector(1, 0, 0)).multiply(change));
|
||||
region.contract((new Vector(-1, 0, 0)).multiply(change));
|
||||
region.contract((new Vector(0, 0, 1)).multiply(change));
|
||||
region.contract((new Vector(0, 0, -1)).multiply(change));
|
||||
}
|
||||
|
||||
session.getRegionSelector().learnChanges();
|
||||
|
||||
session.getRegionSelector().explainRegionAdjust(player, session);
|
||||
|
||||
player.print("Region inset.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/size"},
|
||||
usage = "",
|
||||
desc = "Get information about the selection",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.selection.size"})
|
||||
public static void size(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Vector size = region.getMaximumPoint()
|
||||
.subtract(region.getMinimumPoint())
|
||||
.add(1, 1, 1);
|
||||
|
||||
player.print("Type: " + session.getRegionSelector().getTypeName());
|
||||
|
||||
for (String line : session.getRegionSelector().getInformationLines()) {
|
||||
player.print(line);
|
||||
}
|
||||
|
||||
player.print("Size: " + size);
|
||||
player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint()));
|
||||
player.print("# of blocks: " + region.getArea());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/count"},
|
||||
usage = "<block>",
|
||||
desc = "Counts the number of a certain type of block",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.analysis.count"})
|
||||
public static void count(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Set<Integer> searchIDs = we.getBlockIDs(player,
|
||||
args.getString(0), true);
|
||||
player.print("Counted: " +
|
||||
editSession.countBlocks(session.getSelection(player.getWorld()), searchIDs));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/distr"},
|
||||
usage = "",
|
||||
desc = "Get the distribution of blocks in the selection",
|
||||
flags = "c",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.analysis.distr"})
|
||||
public static void distr(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
List<Countable<Integer>> distribution =
|
||||
editSession.getBlockDistribution(session.getSelection(player.getWorld()));
|
||||
|
||||
Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
if (distribution.size() > 0) { // *Should* always be true
|
||||
int size = session.getSelection(player.getWorld()).getArea();
|
||||
|
||||
player.print("# total blocks: " + size);
|
||||
|
||||
if (args.hasFlag('c')) {
|
||||
logger.info("Block distribution (req. by " + player.getName() + "):");
|
||||
logger.info("# total blocks: " + size);
|
||||
}
|
||||
|
||||
for (Countable<Integer> c : distribution) {
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double)size * 100,
|
||||
BlockType.fromID(c.getID()).getName(), c.getID());
|
||||
player.print(str);
|
||||
|
||||
if (args.hasFlag('c')) {
|
||||
logger.info(str);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("No blocks counted.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/sel", ","},
|
||||
usage = "[type]",
|
||||
desc = "Choose a region selector",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void select(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String typeName = args.getString(0);
|
||||
if (typeName.equalsIgnoreCase("cuboid")) {
|
||||
session.setRegionSelector(player.getWorld(), new CuboidRegionSelector());
|
||||
session.dispatchCUISelection(player);
|
||||
player.print("Cuboid: left click for point 1, right click for point 2");
|
||||
} else if (typeName.equalsIgnoreCase("poly")) {
|
||||
session.setRegionSelector(player.getWorld(), new Polygonal2DRegionSelector());
|
||||
session.dispatchCUISelection(player);
|
||||
player.print("2D polygon selector: Left/right click to add a point.");
|
||||
} else {
|
||||
player.printError("Only 'cuboid' and 'poly' are accepted.");
|
||||
}
|
||||
}
|
||||
}
|
205
src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java
Normal file
205
src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java
Normal file
@ -0,0 +1,205 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
|
||||
/**
|
||||
* Snapshot commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class SnapshotCommands {
|
||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||
|
||||
@Command(
|
||||
aliases = {"list"},
|
||||
usage = "[num]",
|
||||
desc = "List snapshots",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.list"})
|
||||
public static void list(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int num = args.argsLength() > 0 ?
|
||||
Math.min(40, Math.max(5, args.getInteger(0))) : 5;
|
||||
|
||||
if (config.snapshotRepo != null) {
|
||||
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true);
|
||||
|
||||
if (snapshots.size() > 0) {
|
||||
for (byte i = 0; i < Math.min(num, snapshots.size()); i++) {
|
||||
player.print((i + 1) + ". " + snapshots.get(i).getName());
|
||||
}
|
||||
|
||||
player.print("Use /snap use [snapshot] or /snap use latest.");
|
||||
} else {
|
||||
player.printError("No snapshots are available. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"use"},
|
||||
usage = "<snapshot>",
|
||||
desc = "Choose a snapshot to use",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void use(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
String name = args.getString(0);
|
||||
|
||||
// Want the latest snapshot?
|
||||
if (name.equalsIgnoreCase("latest")) {
|
||||
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot != null) {
|
||||
session.setSnapshot(null);
|
||||
player.print("Now using newest snapshot.");
|
||||
} else {
|
||||
player.printError("No snapshots were found.");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
|
||||
player.print("Snapshot set to: " + name);
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"before"},
|
||||
usage = "<date>",
|
||||
desc = "Choose the nearest snapshot before a date",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void before(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar date = session.detectDate(args.getJoinedStrings(0));
|
||||
|
||||
if (date == null) {
|
||||
player.printError("Could not detect the date inputted.");
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot before "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"after"},
|
||||
usage = "<date>",
|
||||
desc = "Choose the nearest snapshot after a date",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void after(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar date = session.detectDate(args.getJoinedStrings(0));
|
||||
|
||||
if (date == null) {
|
||||
player.printError("Could not detect the date inputted.");
|
||||
} else {
|
||||
dateFormat.setTimeZone(session.getTimeZone());
|
||||
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date);
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot after "
|
||||
+ dateFormat.format(date.getTime()) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
player.print("Snapshot set to: " + snapshot.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.data.ChunkStore;
|
||||
import com.sk89q.worldedit.data.DataException;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
|
||||
import com.sk89q.worldedit.snapshots.Snapshot;
|
||||
import com.sk89q.worldedit.snapshots.SnapshotRestore;
|
||||
|
||||
public class SnapshotUtilCommands {
|
||||
private static Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
@Command(
|
||||
aliases = {"snapshot", "snap"},
|
||||
desc = "Snapshot commands"
|
||||
)
|
||||
@NestedCommand({SnapshotCommands.class})
|
||||
public static void snapshot(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"restore", "/restore"},
|
||||
usage = "[snapshot]",
|
||||
desc = "Restore the selection from a snapshot",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snapshots.restore"})
|
||||
public static void restore(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
if (config.snapshotRepo == null) {
|
||||
player.printError("Snapshot/backup restore is not configured.");
|
||||
return;
|
||||
}
|
||||
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
Snapshot snapshot;
|
||||
|
||||
if (args.argsLength() > 0) {
|
||||
try {
|
||||
snapshot = config.snapshotRepo.getSnapshot(args.getString(0));
|
||||
} catch (InvalidSnapshotException e) {
|
||||
player.printError("That snapshot does not exist or is not available.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
snapshot = session.getSnapshot();
|
||||
}
|
||||
|
||||
ChunkStore chunkStore = null;
|
||||
|
||||
// No snapshot set?
|
||||
if (snapshot == null) {
|
||||
snapshot = config.snapshotRepo.getDefaultSnapshot();
|
||||
|
||||
if (snapshot == null) {
|
||||
player.printError("No snapshots were found. See console for details.");
|
||||
|
||||
// Okay, let's toss some debugging information!
|
||||
File dir = config.snapshotRepo.getDirectory();
|
||||
|
||||
try {
|
||||
logger.info("WorldEdit found no snapshots: looked in: " +
|
||||
dir.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.info("WorldEdit found no snapshots: looked in "
|
||||
+ "(NON-RESOLVABLE PATH - does it exist?): " +
|
||||
dir.getPath());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Load chunk store
|
||||
try {
|
||||
chunkStore = snapshot.getChunkStore();
|
||||
player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring...");
|
||||
} catch (DataException e) {
|
||||
player.printError("Failed to load snapshot: " + e.getMessage());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
player.printError("Failed to load snapshot: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Restore snapshot
|
||||
SnapshotRestore restore = new SnapshotRestore(chunkStore, region);
|
||||
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
|
||||
|
||||
restore.restore(editSession);
|
||||
|
||||
if (restore.hadTotalFailure()) {
|
||||
String error = restore.getLastErrorMessage();
|
||||
if (error != null) {
|
||||
player.printError("Errors prevented any blocks from being restored.");
|
||||
player.printError("Last error: " + error);
|
||||
} else {
|
||||
player.printError("No chunks could be loaded. (Bad archive?)");
|
||||
}
|
||||
} else {
|
||||
player.print(String.format("Restored; %d "
|
||||
+ "missing chunks and %d other errors.",
|
||||
restore.getMissingChunks().size(),
|
||||
restore.getErrorChunks().size()));
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
chunkStore.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.tools.AreaPickaxe;
|
||||
import com.sk89q.worldedit.tools.RecursivePickaxe;
|
||||
import com.sk89q.worldedit.tools.SinglePickaxe;
|
||||
|
||||
public class SuperPickaxeCommands {
|
||||
@Command(
|
||||
aliases = {"single"},
|
||||
usage = "",
|
||||
desc = "Enable the single block super pickaxe mode",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe"})
|
||||
public static void single(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setSuperPickaxe(new SinglePickaxe());
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"area"},
|
||||
usage = "<radius>",
|
||||
desc = "Enable the area super pickaxe pickaxe mode",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe.area"})
|
||||
public static void area(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
|
||||
return;
|
||||
}
|
||||
|
||||
session.setSuperPickaxe(new AreaPickaxe(range));
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"recur", "recursive"},
|
||||
usage = "<radius>",
|
||||
desc = "Enable the recursive super pickaxe pickaxe mode",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe.recursive"})
|
||||
public static void recursive(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
|
||||
return;
|
||||
}
|
||||
|
||||
session.setSuperPickaxe(new RecursivePickaxe(range));
|
||||
session.enableSuperPickAxe();
|
||||
player.print("Mode changed. Left click with a pickaxe. // to disable.");
|
||||
}
|
||||
}
|
135
src/main/java/com/sk89q/worldedit/commands/ToolCommands.java
Normal file
135
src/main/java/com/sk89q/worldedit/commands/ToolCommands.java
Normal file
@ -0,0 +1,135 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.tools.*;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
|
||||
public class ToolCommands {
|
||||
@Command(
|
||||
aliases = {"none"},
|
||||
usage = "",
|
||||
desc = "Turn off all superpickaxe alternate modes",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void none(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), null);
|
||||
player.print("Tool unbound from your current item.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"info"},
|
||||
usage = "",
|
||||
desc = "Block information tool",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.info"})
|
||||
public static void info(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new QueryTool());
|
||||
player.print("Info tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tree"},
|
||||
usage = "[type]",
|
||||
desc = "Tree generator tool",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.tree"})
|
||||
public static void tree(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
TreeGenerator.TreeType type = args.argsLength() > 0 ?
|
||||
type = TreeGenerator.lookup(args.getString(0))
|
||||
: TreeGenerator.TreeType.TREE;
|
||||
|
||||
if (type == null) {
|
||||
player.printError("Tree type '" + args.getString(0) + "' is unknown.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.setTool(player.getItemInHand(), new TreePlanter(new TreeGenerator(type)));
|
||||
player.print("Tree tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"repl"},
|
||||
usage = "<block>",
|
||||
desc = "Block replacer tool",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.replacer"})
|
||||
public static void repl(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
|
||||
session.setTool(player.getItemInHand(), new BlockReplacer(targetBlock));
|
||||
player.print("Block replacer tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cycler"},
|
||||
usage = "",
|
||||
desc = "Block data cycler tool",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.tool.data-cycler"})
|
||||
public static void cycler(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
session.setTool(player.getItemInHand(), new BlockDataCyler());
|
||||
player.print("Block data cycler tool bound to "
|
||||
+ ItemType.toHeldName(player.getItemInHand()) + ".");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"brush", "br"},
|
||||
desc = "Brush tool"
|
||||
)
|
||||
@NestedCommand({BrushCommands.class})
|
||||
public static void brush(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
}
|
136
src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java
Normal file
136
src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java
Normal file
@ -0,0 +1,136 @@
|
||||
// $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.commands;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.NestedCommand;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
|
||||
/**
|
||||
* Tool commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ToolUtilCommands {
|
||||
@Command(
|
||||
aliases = {"/", ","},
|
||||
usage = "",
|
||||
desc = "Toggle the super pickaxe pickaxe function",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.superpickaxe"})
|
||||
public static void togglePickaxe(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
if (session.toggleSuperPickAxe()) {
|
||||
player.print("Super pick axe enabled.");
|
||||
} else {
|
||||
player.print("Super pick axe disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"superpickaxe", "pickaxe", "sp"},
|
||||
desc = "Select super pickaxe mode"
|
||||
)
|
||||
@NestedCommand({SuperPickaxeCommands.class})
|
||||
public static void pickaxe(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tool"},
|
||||
desc = "Select a tool to bind"
|
||||
)
|
||||
@NestedCommand({ToolCommands.class})
|
||||
public static void tool(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"mask"},
|
||||
usage = "[mask]",
|
||||
desc = "Set the brush mask",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.mask"})
|
||||
public static void mask(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
if (args.argsLength() == 0) {
|
||||
session.getBrushTool(player.getItemInHand()).setMask(null);
|
||||
player.print("Brush mask disabled.");
|
||||
} else {
|
||||
Mask mask = we.getBlockMask(player, args.getString(0));
|
||||
session.getBrushTool(player.getItemInHand()).setMask(mask);
|
||||
player.print("Brush mask set.");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"mat", "material", "fill"},
|
||||
usage = "[pattern]",
|
||||
desc = "Set the brush material",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.material"})
|
||||
public static void material(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
session.getBrushTool(player.getItemInHand()).setFill(pattern);
|
||||
player.print("Brush material set.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"size"},
|
||||
usage = "[pattern]",
|
||||
desc = "Set the brush size",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.size"})
|
||||
public static void size(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int radius = args.getInteger(0);
|
||||
if (radius > config.maxBrushRadius) {
|
||||
player.printError("Maximum allowed brush radius: "
|
||||
+ config.maxBrushRadius);
|
||||
return;
|
||||
}
|
||||
|
||||
session.getBrushTool(player.getItemInHand()).setSize(radius);
|
||||
player.print("Brush size set.");
|
||||
}
|
||||
}
|
374
src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java
Normal file
374
src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java
Normal file
@ -0,0 +1,374 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.LocalWorld.EntityType;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.patterns.*;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Utility commands.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class UtilityCommands {
|
||||
@Command(
|
||||
aliases = {"/fill"},
|
||||
usage = " <block> <radius> [depth] ",
|
||||
desc = "Fill a hole",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.fill"})
|
||||
public static void fill(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
we.checkMaxRadius(radius);
|
||||
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = 0;
|
||||
if (pattern instanceof SingleBlockPattern) {
|
||||
affected = editSession.fillXZ(pos,
|
||||
((SingleBlockPattern)pattern).getBlock(),
|
||||
radius, depth, false);
|
||||
} else {
|
||||
affected = editSession.fillXZ(pos, pattern, radius, depth, false);
|
||||
}
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/fillr"},
|
||||
usage = " <block> <radius> [depth] ",
|
||||
desc = "Fill a hole recursively",
|
||||
min = 2,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.fill.recursive"})
|
||||
public static void fillr(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
||||
int radius = Math.max(1, args.getInteger(1));
|
||||
we.checkMaxRadius(radius);
|
||||
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
||||
|
||||
Vector pos = session.getPlacementPosition(player);
|
||||
int affected = 0;
|
||||
if (pattern instanceof SingleBlockPattern) {
|
||||
affected = editSession.fillXZ(pos,
|
||||
((SingleBlockPattern)pattern).getBlock(),
|
||||
radius, depth, true);
|
||||
} else {
|
||||
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
|
||||
}
|
||||
player.print(affected + " block(s) have been created.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/drain"},
|
||||
usage = "<radius>",
|
||||
desc = "Drain a pool",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.drain"})
|
||||
public static void drain(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.drainArea(
|
||||
session.getPlacementPosition(player), radius);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"fixlava"},
|
||||
usage = "<radius>",
|
||||
desc = "Fix lava to be stationary",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.fixlava"})
|
||||
public static void fixLava(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 10, 11);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"fixwater"},
|
||||
usage = "<radius>",
|
||||
desc = "Fix water to be stationary",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.fixwater"})
|
||||
public static void fixWater(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = Math.max(0, args.getInteger(0));
|
||||
we.checkMaxRadius(radius);
|
||||
int affected = editSession.fixLiquid(
|
||||
session.getPlacementPosition(player), radius, 8, 9);
|
||||
player.print(affected + " block(s) have been changed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removeabove"},
|
||||
usage = "[size] [height] ",
|
||||
desc = "Remove blocks above your head. ",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removeabove"})
|
||||
public static void removeAbove(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
we.checkMaxRadius(size);
|
||||
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
|
||||
|
||||
int affected = editSession.removeAbove(
|
||||
session.getPlacementPosition(player), size, height);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removebelow"},
|
||||
usage = "[size] [height] ",
|
||||
desc = "Remove blocks below your head. ",
|
||||
min = 0,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removebelow"})
|
||||
public static void removeBelow(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
||||
we.checkMaxRadius(size);
|
||||
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
|
||||
|
||||
int affected = editSession.removeBelow(
|
||||
session.getPlacementPosition(player), size, height);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"removenear"},
|
||||
usage = "<block> [size] ",
|
||||
desc = "Remove blocks near you.",
|
||||
min = 1,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.removenear"})
|
||||
public static void removeNear(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
BaseBlock block = we.getBlock(player, args.getString(0), true);
|
||||
int size = Math.max(1, args.getInteger(1, 50));
|
||||
we.checkMaxRadius(size);
|
||||
|
||||
int affected = editSession.removeNear(
|
||||
session.getPlacementPosition(player), block.getType(), size);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"replacenear"},
|
||||
usage = "<size> <from-id> <to-id> ",
|
||||
desc = "Replace nearby blocks",
|
||||
min = 3,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions({"worldedit.replacenear"})
|
||||
public static void replaceNear(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = Math.max(1, args.getInteger(0));
|
||||
Set<Integer> from;
|
||||
BaseBlock to;
|
||||
if (args.argsLength() == 2) {
|
||||
from = null;
|
||||
to = we.getBlock(player, args.getString(1));
|
||||
} else {
|
||||
from = we.getBlockIDs(player, args.getString(1), true);
|
||||
to = we.getBlock(player, args.getString(2));
|
||||
}
|
||||
|
||||
Vector min = player.getBlockIn().subtract(size, size, size);
|
||||
Vector max = player.getBlockIn().add(size, size, size);
|
||||
Region region = new CuboidRegion(min, max);
|
||||
|
||||
int affected = editSession.replaceBlocks(region, from, to);
|
||||
player.print(affected + " block(s) have been replaced.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"snow"},
|
||||
usage = "[radius]",
|
||||
desc = "Simulates snow",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.snow"})
|
||||
public static void snow(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.simulateSnow(player.getBlockIn(), size);
|
||||
player.print(affected + " surfaces covered. Let it snow~");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"thaw"},
|
||||
usage = "[radius]",
|
||||
desc = "Thaws the area",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.thaw"})
|
||||
public static void thaw(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
|
||||
|
||||
int affected = editSession.thaw(player.getBlockIn(), size);
|
||||
player.print(affected + " surfaces thawed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"ex", "ext", "extinguish"},
|
||||
usage = "[radius]",
|
||||
desc = "Extinguish nearby fire",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.extinguish"})
|
||||
public static void extinguish(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
|
||||
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
|
||||
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0))
|
||||
: defaultRadius;
|
||||
we.checkMaxRadius(size);
|
||||
|
||||
int affected = editSession.removeNear(
|
||||
session.getPlacementPosition(player), 51, size);
|
||||
player.print(affected + " block(s) have been removed.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"butcher"},
|
||||
usage = "[radius]",
|
||||
desc = "Kill all or nearby mobs",
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({"worldedit.butcher"})
|
||||
public static void butcher(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
int radius = args.argsLength() > 0 ?
|
||||
Math.max(1, args.getInteger(0)) : -1;
|
||||
|
||||
Vector origin = session.getPlacementPosition(player);
|
||||
int killed = player.getWorld().killMobs(origin, radius);
|
||||
player.print("Killed " + killed + " mobs.");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"remove", "rem", "rement"},
|
||||
usage = "<type> <radius>",
|
||||
desc = "Remove all entities of a type",
|
||||
min = 2,
|
||||
max = 2
|
||||
)
|
||||
@CommandPermissions({"worldedit.remove"})
|
||||
public static void remove(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
String typeStr = args.getString(0);
|
||||
int radius = args.getInteger(1);
|
||||
|
||||
if (radius < -1) {
|
||||
player.printError("Use -1 to remove all entities in loaded chunks");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityType type = null;
|
||||
|
||||
if (typeStr.matches("arrows?")) {
|
||||
type = EntityType.ARROWS;
|
||||
} else if (typeStr.matches("items?")
|
||||
|| typeStr.matches("drops?")) {
|
||||
type = EntityType.ITEMS;
|
||||
} else if (typeStr.matches("paintings?")
|
||||
|| typeStr.matches("art")) {
|
||||
type = EntityType.PAINTINGS;
|
||||
} else if (typeStr.matches("boats?")) {
|
||||
type = EntityType.BOATS;
|
||||
} else if (typeStr.matches("minecarts?")
|
||||
|| typeStr.matches("carts?")) {
|
||||
type = EntityType.MINECARTS;
|
||||
} else if (typeStr.matches("tnt")) {
|
||||
type = EntityType.TNT;
|
||||
} else {
|
||||
player.printError("Acceptable types: arrows, items, paintings, boats, minecarts, tnt");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector origin = session.getPlacementPosition(player);
|
||||
int removed = player.getWorld().removeEntities(type, origin, radius);
|
||||
player.print("Marked " + removed + " entit(ies) for removal.");
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
// $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.commands;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
public class WorldEditCommands {
|
||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
|
||||
|
||||
@Command(
|
||||
aliases = {"version", "ver"},
|
||||
usage = "",
|
||||
desc = "Get WorldEdit version",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void version(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
player.print("WorldEdit version " + WorldEdit.getVersion());
|
||||
player.print("http://www.sk89q.com/projects/worldedit/");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"reload"},
|
||||
usage = "",
|
||||
desc = "Reload WorldEdit",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions({"worldedit.reload"})
|
||||
public static void reload(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
|
||||
we.getServer().reload();
|
||||
player.print("Configuration reloaded!");
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"cui"},
|
||||
usage = "",
|
||||
desc = "Complete CUI handshake",
|
||||
min = 0,
|
||||
max = 0
|
||||
)
|
||||
public static void cui(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
session.setCUISupport(true);
|
||||
session.dispatchCUISetup(player);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"tz"},
|
||||
usage = "[timezone]",
|
||||
desc = "Set your timezone",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
public static void tz(CommandContext args, WorldEdit we,
|
||||
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||
throws WorldEditException {
|
||||
TimeZone tz = TimeZone.getTimeZone(args.getString(0));
|
||||
session.setTimezone(tz);
|
||||
player.print("Timezone set for this session to: " + tz.getDisplayName());
|
||||
player.print("The current time in that timezone is: "
|
||||
+ dateFormat.format(Calendar.getInstance(tz).getTime()));
|
||||
}
|
||||
}
|
25
src/main/java/com/sk89q/worldedit/cui/CUIEvent.java
Normal file
25
src/main/java/com/sk89q/worldedit/cui/CUIEvent.java
Normal file
@ -0,0 +1,25 @@
|
||||
// $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.cui;
|
||||
|
||||
public interface CUIEvent {
|
||||
public String getTypeId();
|
||||
public String[] getParameters();
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// $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.cui;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public interface CUIPointBasedRegion {
|
||||
public Vector[] getCUIPoints();
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// $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.cui;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class SelectionPointEvent implements CUIEvent {
|
||||
|
||||
protected int id;
|
||||
protected Vector pos;
|
||||
protected int area;
|
||||
|
||||
public SelectionPointEvent(int id, Vector pos, int area) {
|
||||
this.id = id;
|
||||
this.pos = pos;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "p";
|
||||
}
|
||||
|
||||
public String[] getParameters() {
|
||||
return new String[] {
|
||||
String.valueOf(id),
|
||||
String.valueOf(pos.getBlockX()),
|
||||
String.valueOf(pos.getBlockY()),
|
||||
String.valueOf(pos.getBlockZ()),
|
||||
String.valueOf(area)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// $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.cui;
|
||||
|
||||
public class SelectionShapeEvent implements CUIEvent {
|
||||
|
||||
protected String shapeName;
|
||||
|
||||
public SelectionShapeEvent(String shapeName) {
|
||||
this.shapeName = shapeName;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "s";
|
||||
}
|
||||
|
||||
public String[] getParameters() {
|
||||
return new String[] { shapeName };
|
||||
}
|
||||
|
||||
}
|
232
src/main/java/com/sk89q/worldedit/data/BlockData.java
Normal file
232
src/main/java/com/sk89q/worldedit/data/BlockData.java
Normal file
@ -0,0 +1,232 @@
|
||||
// $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.data;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
* Block data related classes.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public final class BlockData {
|
||||
/**
|
||||
* Rotate a block's data value 90 degrees (north->east->south->west->north);
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static int rotate90(int type, int data) {
|
||||
if (type == BlockID.TORCH
|
||||
|| type == BlockID.REDSTONE_TORCH_OFF
|
||||
|| type == BlockID.REDSTONE_TORCH_ON) {
|
||||
switch (data) {
|
||||
case 1: return 3;
|
||||
case 2: return 4;
|
||||
case 3: return 2;
|
||||
case 4: return 1;
|
||||
}
|
||||
} else if (type == BlockID.MINECART_TRACKS) {
|
||||
switch (data) {
|
||||
case 0: return 1;
|
||||
case 1: return 0;
|
||||
case 2: return 5;
|
||||
case 3: return 4;
|
||||
case 4: return 2;
|
||||
case 5: return 3;
|
||||
case 6: return 7;
|
||||
case 7: return 8;
|
||||
case 8: return 9;
|
||||
case 9: return 6;
|
||||
}
|
||||
} else if (type == BlockID.WOODEN_STAIRS
|
||||
|| type == BlockID.COBBLESTONE_STAIRS) {
|
||||
switch (data) {
|
||||
case 0: return 2;
|
||||
case 1: return 3;
|
||||
case 2: return 1;
|
||||
case 3: return 0;
|
||||
}
|
||||
} else if (type == BlockID.LEVER) {
|
||||
int thrown = data & 0x8;
|
||||
int withoutThrown = data ^ 0x8;
|
||||
switch (withoutThrown) {
|
||||
case 1: return 3 | thrown;
|
||||
case 2: return 4 | thrown;
|
||||
case 3: return 2 | thrown;
|
||||
case 4: return 1 | thrown;
|
||||
}
|
||||
} else if (type == BlockID.WOODEN_DOOR
|
||||
|| type == BlockID.IRON_DOOR) {
|
||||
int topHalf = data & 0x8;
|
||||
int swung = data & 0x4;
|
||||
int withoutFlags = data ^ (0x8 | 0x4);
|
||||
switch (withoutFlags) {
|
||||
case 0: return 1 | topHalf | swung;
|
||||
case 1: return 2 | topHalf | swung;
|
||||
case 2: return 3 | topHalf | swung;
|
||||
case 3: return 0 | topHalf | swung;
|
||||
}
|
||||
} else if (type == BlockID.STONE_BUTTON) {
|
||||
int thrown = data & 0x8;
|
||||
int withoutThrown = data ^ 0x8;
|
||||
switch (withoutThrown) {
|
||||
case 1: return 3 | thrown;
|
||||
case 2: return 4 | thrown;
|
||||
case 3: return 2 | thrown;
|
||||
case 4: return 1 | thrown;
|
||||
}
|
||||
} else if (type == BlockID.SIGN_POST) {
|
||||
return (data + 4) % 16;
|
||||
} else if (type == BlockID.LADDER
|
||||
|| type == BlockID.WALL_SIGN
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE
|
||||
|| type == BlockID.DISPENSER) {
|
||||
switch (data) {
|
||||
case 2: return 5;
|
||||
case 3: return 4;
|
||||
case 4: return 2;
|
||||
case 5: return 3;
|
||||
}
|
||||
} else if (type == BlockID.PUMPKIN
|
||||
|| type == BlockID.JACKOLANTERN) {
|
||||
switch (data) {
|
||||
case 0: return 1;
|
||||
case 1: return 2;
|
||||
case 2: return 3;
|
||||
case 3: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate a block's data value -90 degrees (north<-east<-south<-west<-north);
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static int rotate90Reverse(int type, int data) {
|
||||
// case ([0-9]+): return ([0-9]+) -> case \2: return \1
|
||||
|
||||
if (type == BlockID.TORCH
|
||||
|| type == BlockID.REDSTONE_TORCH_OFF
|
||||
|| type == BlockID.REDSTONE_TORCH_ON) {
|
||||
switch (data) {
|
||||
case 3: return 1;
|
||||
case 4: return 2;
|
||||
case 2: return 3;
|
||||
case 1: return 4;
|
||||
}
|
||||
} else if (type == BlockID.MINECART_TRACKS) {
|
||||
switch (data) {
|
||||
case 1: return 0;
|
||||
case 0: return 1;
|
||||
case 5: return 2;
|
||||
case 4: return 3;
|
||||
case 2: return 4;
|
||||
case 3: return 5;
|
||||
case 7: return 6;
|
||||
case 8: return 7;
|
||||
case 9: return 8;
|
||||
case 6: return 9;
|
||||
}
|
||||
} else if (type == BlockID.WOODEN_STAIRS
|
||||
|| type == BlockID.COBBLESTONE_STAIRS) {
|
||||
switch (data) {
|
||||
case 2: return 0;
|
||||
case 3: return 1;
|
||||
case 1: return 2;
|
||||
case 0: return 3;
|
||||
}
|
||||
} else if (type == BlockID.LEVER) {
|
||||
int thrown = data & 0x8;
|
||||
int withoutThrown = data ^ 0x8;
|
||||
switch (withoutThrown) {
|
||||
case 3: return 1 | thrown;
|
||||
case 4: return 2 | thrown;
|
||||
case 2: return 3 | thrown;
|
||||
case 1: return 4 | thrown;
|
||||
}
|
||||
} else if (type == BlockID.WOODEN_DOOR
|
||||
|| type == BlockID.IRON_DOOR) {
|
||||
int topHalf = data & 0x8;
|
||||
int swung = data & 0x4;
|
||||
int withoutFlags = data ^ (0x8 | 0x4);
|
||||
switch (withoutFlags) {
|
||||
case 1: return 0 | topHalf | swung;
|
||||
case 2: return 1 | topHalf | swung;
|
||||
case 3: return 2 | topHalf | swung;
|
||||
case 0: return 3 | topHalf | swung;
|
||||
}
|
||||
} else if (type == BlockID.STONE_BUTTON) {
|
||||
int thrown = data & 0x8;
|
||||
int withoutThrown = data ^ 0x8;
|
||||
switch (withoutThrown) {
|
||||
case 3: return 1 | thrown;
|
||||
case 4: return 2 | thrown;
|
||||
case 2: return 3 | thrown;
|
||||
case 1: return 4 | thrown;
|
||||
}
|
||||
} else if (type == BlockID.SIGN_POST) {
|
||||
int newData = (data - 4);
|
||||
if (newData < 0) {
|
||||
newData += 16;
|
||||
}
|
||||
return newData;
|
||||
} else if (type == BlockID.LADDER
|
||||
|| type == BlockID.WALL_SIGN
|
||||
|| type == BlockID.FURNACE
|
||||
|| type == BlockID.BURNING_FURNACE
|
||||
|| type == BlockID.DISPENSER) {
|
||||
switch (data) {
|
||||
case 5: return 2;
|
||||
case 4: return 3;
|
||||
case 2: return 4;
|
||||
case 3: return 5;
|
||||
}
|
||||
} else if (type == BlockID.PUMPKIN
|
||||
|| type == BlockID.JACKOLANTERN) {
|
||||
switch (data) {
|
||||
case 1: return 0;
|
||||
case 2: return 1;
|
||||
case 3: return 2;
|
||||
case 0: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip a block's data value.
|
||||
*
|
||||
* @param type
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static int flip(int type, int data) {
|
||||
return rotate90(type, rotate90(type, data));
|
||||
}
|
||||
}
|
240
src/main/java/com/sk89q/worldedit/data/Chunk.java
Normal file
240
src/main/java/com/sk89q/worldedit/data/Chunk.java
Normal file
@ -0,0 +1,240 @@
|
||||
// $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.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
|
||||
/**
|
||||
* Represents a chunk.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Chunk {
|
||||
private CompoundTag rootTag;
|
||||
private byte[] blocks;
|
||||
private byte[] data;
|
||||
private int rootX;
|
||||
private int rootZ;
|
||||
private Map<BlockVector,Map<String,Tag>> tileEntities;
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
*
|
||||
* @param tag
|
||||
* @throws DataException
|
||||
*/
|
||||
public Chunk(CompoundTag tag) throws DataException {
|
||||
rootTag = tag;
|
||||
|
||||
blocks = ((ByteArrayTag)getChildTag(
|
||||
rootTag.getValue(), "Blocks", ByteArrayTag.class)).getValue();
|
||||
data = ((ByteArrayTag)getChildTag(
|
||||
rootTag.getValue(), "Data", ByteArrayTag.class)).getValue();
|
||||
rootX = ((IntTag)getChildTag(
|
||||
rootTag.getValue(), "xPos", IntTag.class)).getValue();
|
||||
rootZ = ((IntTag)getChildTag(
|
||||
rootTag.getValue(), "zPos", IntTag.class)).getValue();
|
||||
|
||||
if (blocks.length != 32768) {
|
||||
throw new InvalidFormatException("Chunk blocks byte array expected "
|
||||
+ "to be 32,768 bytes; found " + blocks.length);
|
||||
}
|
||||
|
||||
if (data.length != 16384) {
|
||||
throw new InvalidFormatException("Chunk block data byte array "
|
||||
+ "expected to be 16,384 bytes; found " + data.length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block ID of a block.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @throws DataException
|
||||
*/
|
||||
public int getBlockID(Vector pos) throws DataException {
|
||||
int x = pos.getBlockX() - rootX * 16;
|
||||
int y = pos.getBlockY();
|
||||
int z = pos.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
|
||||
try {
|
||||
return blocks[index];
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block data of a block.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @throws DataException
|
||||
*/
|
||||
public int getBlockData(Vector pos) throws DataException {
|
||||
int x = pos.getBlockX() - rootX * 16;
|
||||
int y = pos.getBlockY();
|
||||
int z = pos.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
|
||||
try {
|
||||
if (!shift) {
|
||||
return (data[index] & 0xF0) >> 4;
|
||||
} else {
|
||||
return data[index] & 0xF;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load the tile entities.
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
private void populateTileEntities() throws DataException {
|
||||
List<Tag> tags = (List<Tag>)((ListTag)getChildTag(
|
||||
rootTag.getValue(), "TileEntities", ListTag.class))
|
||||
.getValue();
|
||||
|
||||
tileEntities = new HashMap<BlockVector,Map<String,Tag>>();
|
||||
|
||||
for (Tag tag : tags) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new InvalidFormatException("CompoundTag expected in TileEntities");
|
||||
}
|
||||
|
||||
CompoundTag t = (CompoundTag)tag;
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
|
||||
Map<String,Tag> values = new HashMap<String,Tag>();
|
||||
|
||||
for (Map.Entry<String,Tag> entry : t.getValue().entrySet()) {
|
||||
if (entry.getKey().equals("x")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
x = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("y")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
y = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
} else if (entry.getKey().equals("z")) {
|
||||
if (entry.getValue() instanceof IntTag) {
|
||||
z = ((IntTag)entry.getValue()).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
BlockVector vec = new BlockVector(x, y, z);
|
||||
tileEntities.put(vec, values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map of tags keyed to strings for a block's tile entity data. May
|
||||
* return null if there is no tile entity data. Not public yet because
|
||||
* what this function returns isn't ideal for usage.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @throws DataException
|
||||
*/
|
||||
private Map<String,Tag> getBlockTileEntity(Vector pos) throws DataException {
|
||||
if (tileEntities == null)
|
||||
populateTileEntities();
|
||||
|
||||
return tileEntities.get(new BlockVector(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block;
|
||||
*
|
||||
* @param pos
|
||||
* @return block
|
||||
* @throws DataException
|
||||
*/
|
||||
public BaseBlock getBlock(Vector pos) throws DataException {
|
||||
int id = getBlockID(pos);
|
||||
int data = getBlockData(pos);
|
||||
BaseBlock block;
|
||||
|
||||
if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(id, data);
|
||||
} else if (id == BlockID.CHEST) {
|
||||
block = new ChestBlock(data);
|
||||
} else if (id == BlockID.FURNACE || id == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(id, data);
|
||||
} else if (id == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(data);
|
||||
} else if (id == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(data);
|
||||
} else if (id == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(data);
|
||||
} else {
|
||||
block = new BaseBlock(id, data);
|
||||
}
|
||||
|
||||
if (block instanceof TileEntityBlock) {
|
||||
Map<String,Tag> tileEntity = getBlockTileEntity(pos);
|
||||
((TileEntityBlock)block).fromTileEntityNBT(tileEntity);
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child tag of a NBT structure.
|
||||
*
|
||||
* @param items
|
||||
* @param key
|
||||
* @param expected
|
||||
* @return child tag
|
||||
* @throws InvalidFormatException
|
||||
*/
|
||||
public static Tag getChildTag(Map<String,Tag> items, String key,
|
||||
Class<? extends Tag> expected)
|
||||
throws InvalidFormatException {
|
||||
if (!items.containsKey(key)) {
|
||||
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new InvalidFormatException(
|
||||
key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
85
src/main/java/com/sk89q/worldedit/data/ChunkStore.java
Normal file
85
src/main/java/com/sk89q/worldedit/data/ChunkStore.java
Normal file
@ -0,0 +1,85 @@
|
||||
// $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.data;
|
||||
|
||||
import java.io.*;
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
* Represents chunk storage mechanisms.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class ChunkStore {
|
||||
/**
|
||||
* Convert a position to a chunk.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
public static BlockVector2D toChunk(Vector pos) {
|
||||
int chunkX = (int)Math.floor(pos.getBlockX() / 16.0);
|
||||
int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0);
|
||||
|
||||
return new BlockVector2D(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag for a chunk.
|
||||
*
|
||||
* @param pos
|
||||
* @return tag
|
||||
* @throws DataException
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract CompoundTag getChunkTag(Vector2D pos)
|
||||
throws DataException, IOException;
|
||||
|
||||
/**
|
||||
* Get a chunk at a location.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @throws ChunkStoreException
|
||||
* @throws IOException
|
||||
* @throws DataException
|
||||
*/
|
||||
public Chunk getChunk(Vector2D pos)
|
||||
throws DataException, IOException {
|
||||
return new Chunk(getChunkTag(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Close resources.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the chunk store is of this type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean isValid();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// $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.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ChunkStoreException extends DataException {
|
||||
private static final long serialVersionUID = 1483900743779953289L;
|
||||
|
||||
public ChunkStoreException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ChunkStoreException() {
|
||||
super();
|
||||
}
|
||||
}
|
37
src/main/java/com/sk89q/worldedit/data/DataException.java
Normal file
37
src/main/java/com/sk89q/worldedit/data/DataException.java
Normal file
@ -0,0 +1,37 @@
|
||||
// $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.data;
|
||||
|
||||
/**
|
||||
* Thrown when there is an exception related to data handling.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class DataException extends Exception {
|
||||
private static final long serialVersionUID = 5806521052111023788L;
|
||||
|
||||
public DataException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DataException() {
|
||||
super();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// $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.data;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Represents the chunk store used by Minecraft alpha.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class FileLegacyChunkStore extends LegacyChunkStore {
|
||||
/**
|
||||
* Folder to read from.
|
||||
*/
|
||||
private File path;
|
||||
|
||||
/**
|
||||
* Create an instance. The passed path is the folder to read the
|
||||
* chunk files from.
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public FileLegacyChunkStore(File path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the input stream for a chunk file.
|
||||
*
|
||||
* @param f1
|
||||
* @param f2
|
||||
* @param name
|
||||
* @return
|
||||
* @throws DataException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
protected InputStream getInputStream(String f1, String f2, String name)
|
||||
throws DataException, IOException {
|
||||
String file = f1 + File.separator + f2 + File.separator + name;
|
||||
try {
|
||||
return new FileInputStream(new File(path, file));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MissingChunkException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true; // Yeah, oh well
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
// $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.data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class FileMcRegionChunkStore extends McRegionChunkStore {
|
||||
/**
|
||||
* Folder to read from.
|
||||
*/
|
||||
private File path;
|
||||
|
||||
/**
|
||||
* Create an instance. The passed path is the folder to read the
|
||||
* chunk files from.
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public FileMcRegionChunkStore(File path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getInputStream(String name) throws IOException,
|
||||
DataException {
|
||||
|
||||
String file = "region" + File.separator + name;
|
||||
|
||||
try {
|
||||
return new FileInputStream(new File(path, file));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new MissingChunkException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return new File(path, "region").isDirectory();
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user