mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Major cleanup and refactoring. Non-cuboid regions now technically supported; players now abstracted through WorldEditPlayer; use of Point across the board; command cleanup.
This commit is contained in:
131
src/com/sk89q/worldedit/CuboidRegion.java
Normal file
131
src/com/sk89q/worldedit/CuboidRegion.java
Normal file
@ -0,0 +1,131 @@
|
||||
// $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.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Albert
|
||||
*/
|
||||
public class CuboidRegion implements Region {
|
||||
/**
|
||||
* Store the first point.
|
||||
*/
|
||||
private Point pos1;
|
||||
/**
|
||||
* Store the second point.
|
||||
*/
|
||||
private Point pos2;
|
||||
|
||||
/**
|
||||
* Construct a new instance of this cuboid region.
|
||||
*
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
*/
|
||||
public CuboidRegion(Point pos1, Point pos2) {
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lower point of the cuboid.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Point getMinimumPoint() {
|
||||
return new Point(Math.min(pos1.getX(), pos2.getX()),
|
||||
Math.min(pos1.getY(), pos2.getY()),
|
||||
Math.min(pos1.getZ(), pos2.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upper point of the cuboid.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Point getMaximumPoint() {
|
||||
return new Point(Math.max(pos1.getX(), pos2.getX()),
|
||||
Math.max(pos1.getY(), pos2.getY()),
|
||||
Math.max(pos1.getZ(), pos2.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getSize() {
|
||||
Point min = getMinimumPoint();
|
||||
Point max = getMaximumPoint();
|
||||
|
||||
return (int)((max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getWidth() {
|
||||
Point min = getMinimumPoint();
|
||||
Point max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getX() - min.getX() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getHeight() {
|
||||
Point min = getMinimumPoint();
|
||||
Point max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getY() - min.getY() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getLength() {
|
||||
Point min = getMinimumPoint();
|
||||
Point max = getMaximumPoint();
|
||||
|
||||
return (int)(max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the iterator.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Iterator<Point> iterator() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
}
|
@ -20,50 +20,289 @@
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Albert
|
||||
*/
|
||||
public final class Point<T> {
|
||||
private final T x, y, z;
|
||||
public final class Point {
|
||||
private final double x, y, z;
|
||||
|
||||
/**
|
||||
* Construct the Point object.
|
||||
*
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Point(T x, T y, T z) {
|
||||
public Point(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Point object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Point(int x, int y, int z) {
|
||||
this.x = (double)x;
|
||||
this.y = (double)y;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Point object.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Point(float x, float y, float z) {
|
||||
this.x = (double)x;
|
||||
this.y = (double)y;
|
||||
this.z = (double)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Point object.
|
||||
*/
|
||||
public Point() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public T getX() {
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return (int)x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public T getY() {
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public int getBlockY() {
|
||||
return (int)y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public T getZ() {
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return (int)z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point add(Point other) {
|
||||
return new Point(x + other.x, y + other.y, z + other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point add(double x, double y, double z) {
|
||||
return new Point(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point add(int x, int y, int z) {
|
||||
return new Point(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point add(Point ... 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 Point(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point subtract(Point other) {
|
||||
return new Point(x - other.x, y - other.y, z - other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point subtract(double x, double y, double z) {
|
||||
return new Point(this.x - x, this.y - y, this.z - z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point subtract(int x, int y, int z) {
|
||||
return new Point(this.x - x, this.y - y, this.z - z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point subtract(Point ... 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 Point(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point multiply(Point other) {
|
||||
return new Point(x * other.x, y * other.y, z * other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point multiply(double x, double y, double z) {
|
||||
return new Point(this.x * x, this.y * y, this.z * z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point multiply(int x, int y, int z) {
|
||||
return new Point(this.x * x, this.y * y, this.z * z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point multiply(Point ... 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 Point(newX, newY, newZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point divide(Point other) {
|
||||
return new Point(x / other.x, y / other.y, z / other.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point divide(double x, double y, double z) {
|
||||
return new Point(this.x / x, this.y / y, this.z / z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide two points.
|
||||
*
|
||||
* @param other
|
||||
* @return New point
|
||||
*/
|
||||
public Point divide(int x, int y, int z) {
|
||||
return new Point(this.x / x, this.y / y, this.z / z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block point from a point.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public static Point toBlockPoint(double x, double y, double z) {
|
||||
return new Point((int)Math.floor(x),
|
||||
(int)Math.floor(y),
|
||||
(int)Math.floor(z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if another object is equivalent.
|
||||
*
|
||||
@ -76,11 +315,7 @@ public final class Point<T> {
|
||||
return false;
|
||||
}
|
||||
Point other = (Point)obj;
|
||||
return new EqualsBuilder()
|
||||
.append(x, other.x)
|
||||
.append(y, other.y)
|
||||
.append(z, other.z)
|
||||
.isEquals();
|
||||
return other.x == this.x && other.y == this.y && other.z == this.z;
|
||||
|
||||
}
|
||||
|
||||
@ -97,5 +332,4 @@ public final class Point<T> {
|
||||
append(z).
|
||||
toHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
63
src/com/sk89q/worldedit/Region.java
Normal file
63
src/com/sk89q/worldedit/Region.java
Normal file
@ -0,0 +1,63 @@
|
||||
// $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 interface Region extends Iterable<Point> {
|
||||
/**
|
||||
* Get the lower point of a region.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Point getMinimumPoint();
|
||||
/**
|
||||
* Get the upper point of a region.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Point getMaximumPoint();
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getSize();
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getWidth();
|
||||
/**
|
||||
* Get Y-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getHeight();
|
||||
/**
|
||||
* Get Z-size.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getLength();
|
||||
}
|
Reference in New Issue
Block a user