From 842c46928595511acddaea24a13fe08d95b160a6 Mon Sep 17 00:00:00 2001 From: aumgn Date: Tue, 20 Mar 2012 15:14:41 +0100 Subject: [PATCH] Make regions Cloneable --- .../java/com/sk89q/worldedit/regions/AbstractRegion.java | 8 ++++++++ .../java/com/sk89q/worldedit/regions/CuboidRegion.java | 4 ++++ .../java/com/sk89q/worldedit/regions/CylinderRegion.java | 4 ++++ .../java/com/sk89q/worldedit/regions/EllipsoidRegion.java | 4 ++++ .../com/sk89q/worldedit/regions/Polygonal2DRegion.java | 6 ++++++ src/main/java/com/sk89q/worldedit/regions/Region.java | 4 +++- 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index 8896f9833..96507ab2e 100644 --- a/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -66,4 +66,12 @@ public abstract class AbstractRegion implements Region { expand(change); contract(change); } + + public AbstractRegion clone() { + try { + return (AbstractRegion) super.clone(); + } catch (CloneNotSupportedException exc) { + return null; + } + } } diff --git a/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index c46de4ae6..16e4028c9 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -434,4 +434,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { public String toString() { return getMinimumPoint() + " - " + getMaximumPoint(); } + + public CuboidRegion clone() { + return (CuboidRegion) super.clone(); + } } diff --git a/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index 3c21db4b5..f6da7d825 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -388,4 +388,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { public String toString() { return center + " - " + radius; } + + public CylinderRegion clone() { + return (CylinderRegion) super.clone(); + } } diff --git a/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index f212f778b..77664a902 100644 --- a/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -275,4 +275,8 @@ public class EllipsoidRegion extends AbstractRegion { public void extendRadius(Vector minRadius) { setRadius(Vector.getMaximum(minRadius, getRadius())); } + + public EllipsoidRegion clone() { + return (EllipsoidRegion) super.clone(); + } } diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 9dcaa5d41..d5d140e5e 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -519,4 +519,10 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { sb.append(" * (" + minY + " - " + maxY + ")"); return sb.toString(); } + + public Polygonal2DRegion clone() { + Polygonal2DRegion clone = (Polygonal2DRegion) super.clone(); + clone.points = new ArrayList(points); + return clone; + } } diff --git a/src/main/java/com/sk89q/worldedit/regions/Region.java b/src/main/java/com/sk89q/worldedit/regions/Region.java index 78c055f0f..309bf17b6 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -29,7 +29,7 @@ import java.util.Set; * * @author sk89q */ -public interface Region extends Iterable { +public interface Region extends Iterable, Cloneable { /** * Get the lower point of a region. * @@ -151,4 +151,6 @@ public interface Region extends Iterable { * @return */ public void setWorld(LocalWorld world); + + public Region clone(); }