geforkt von Mirrors/FastAsyncWorldEdit
Moved RegionSelectors and RegionIterators into subpackages.
Dieser Commit ist enthalten in:
Ursprung
2e904577b7
Commit
1fd1e7aaf8
@ -29,7 +29,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit.selections;
|
||||
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
@ -23,6 +23,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.bukkit.World;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
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;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
|
||||
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
|
||||
|
||||
public abstract class RegionSelection implements Selection {
|
||||
|
||||
|
@ -22,7 +22,7 @@ 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;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
public interface Selection {
|
||||
/**
|
||||
|
@ -6,8 +6,8 @@ import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.forge.WorldEditMod;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
public class CuboidSelection extends RegionSelection {
|
||||
protected CuboidRegion cuboid;
|
||||
|
@ -8,8 +8,8 @@ import net.minecraft.world.World;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.forge.WorldEditMod;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
public class Polygonal2DSelection extends RegionSelection {
|
||||
protected Polygonal2DRegion poly2d;
|
||||
|
@ -8,7 +8,7 @@ import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.forge.WorldEditMod;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
public abstract class RegionSelection implements Selection {
|
||||
private WeakReference<World> world;
|
||||
|
@ -4,7 +4,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
public abstract interface Selection {
|
||||
public abstract Location getMinimumPoint();
|
||||
|
@ -32,9 +32,9 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.world.snapshot.Snapshot;
|
||||
|
||||
|
@ -33,21 +33,19 @@ import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.registry.BlockRegistry;
|
||||
import com.sk89q.worldedit.extension.registry.MaskRegistry;
|
||||
import com.sk89q.worldedit.extension.registry.PatternRegistry;
|
||||
import com.sk89q.worldedit.extent.ExtentDelegate;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.pattern.Patterns;
|
||||
import com.sk89q.worldedit.internal.InternalEditSessionFactory;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.scripting.CraftScriptContext;
|
||||
import com.sk89q.worldedit.scripting.CraftScriptEngine;
|
||||
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.LogFormat;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.io.*;
|
||||
|
@ -30,7 +30,7 @@ import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
|
@ -44,16 +44,16 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
import com.sk89q.worldedit.regions.ConvexPolyhedralRegionSelector;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.CylinderRegionSelector;
|
||||
import com.sk89q.worldedit.regions.EllipsoidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.ExtendingCuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.SphereRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
|
||||
|
||||
/**
|
||||
* Selection commands.
|
||||
|
@ -20,7 +20,7 @@
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
|
||||
/**
|
||||
* A wand that can be used at a distance.
|
||||
|
@ -19,19 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.iterator.RegionIterator;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractRegion implements Region {
|
||||
/**
|
||||
* Stores the world.
|
||||
|
@ -19,14 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
|
||||
/**
|
||||
* Represents a cylindrical region.
|
||||
|
@ -28,6 +28,8 @@ import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
|
||||
|
||||
/**
|
||||
* Represents a 2D polygonal region.
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
public class FlatRegion3DIterator implements Iterator<BlockVector> {
|
||||
|
@ -17,12 +17,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.regions;
|
||||
package com.sk89q.worldedit.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
public class FlatRegionIterator implements Iterator<Vector2D> {
|
||||
|
@ -1,94 +1,95 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class RegionIterator implements Iterator<BlockVector> {
|
||||
private final Region region;
|
||||
private final int maxX;
|
||||
private final int maxY;
|
||||
private final int maxZ;
|
||||
private final Vector min;
|
||||
private int nextX;
|
||||
private int nextY;
|
||||
private int nextZ;
|
||||
|
||||
public RegionIterator(Region region) {
|
||||
this.region = region;
|
||||
|
||||
Vector max = region.getMaximumPoint();
|
||||
this.maxX = max.getBlockX();
|
||||
this.maxY = max.getBlockY();
|
||||
this.maxZ = max.getBlockZ();
|
||||
|
||||
this.min = region.getMinimumPoint();
|
||||
this.nextX = min.getBlockX();
|
||||
this.nextY = min.getBlockY();
|
||||
this.nextZ = min.getBlockZ();
|
||||
|
||||
forward();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return nextX != Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private void forward() {
|
||||
while (hasNext() && !region.contains(new BlockVector(nextX, nextY, nextZ))) {
|
||||
forwardOne();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockVector next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
|
||||
BlockVector answer = new BlockVector(nextX, nextY, nextZ);
|
||||
|
||||
forwardOne();
|
||||
forward();
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
private void forwardOne() {
|
||||
if (++nextX <= maxX) {
|
||||
return;
|
||||
}
|
||||
nextX = min.getBlockX();
|
||||
|
||||
if (++nextY <= maxY) {
|
||||
return;
|
||||
}
|
||||
nextY = min.getBlockY();
|
||||
|
||||
if (++nextZ <= maxZ) {
|
||||
return;
|
||||
}
|
||||
nextX = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.iterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
public class RegionIterator implements Iterator<BlockVector> {
|
||||
private final Region region;
|
||||
private final int maxX;
|
||||
private final int maxY;
|
||||
private final int maxZ;
|
||||
private final Vector min;
|
||||
private int nextX;
|
||||
private int nextY;
|
||||
private int nextZ;
|
||||
|
||||
public RegionIterator(Region region) {
|
||||
this.region = region;
|
||||
|
||||
Vector max = region.getMaximumPoint();
|
||||
this.maxX = max.getBlockX();
|
||||
this.maxY = max.getBlockY();
|
||||
this.maxZ = max.getBlockZ();
|
||||
|
||||
this.min = region.getMinimumPoint();
|
||||
this.nextX = min.getBlockX();
|
||||
this.nextY = min.getBlockY();
|
||||
this.nextZ = min.getBlockZ();
|
||||
|
||||
forward();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return nextX != Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
private void forward() {
|
||||
while (hasNext() && !region.contains(new BlockVector(nextX, nextY, nextZ))) {
|
||||
forwardOne();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockVector next() {
|
||||
if (!hasNext()) throw new java.util.NoSuchElementException();
|
||||
|
||||
BlockVector answer = new BlockVector(nextX, nextY, nextZ);
|
||||
|
||||
forwardOne();
|
||||
forward();
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
private void forwardOne() {
|
||||
if (++nextX <= maxX) {
|
||||
return;
|
||||
}
|
||||
nextX = min.getBlockX();
|
||||
|
||||
if (++nextY <= maxY) {
|
||||
return;
|
||||
}
|
||||
nextY = min.getBlockY();
|
||||
|
||||
if (++nextZ <= maxZ) {
|
||||
return;
|
||||
}
|
||||
nextX = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -1,219 +1,221 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPolygonEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
|
||||
public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
||||
private int maxVertices;
|
||||
private final ConvexPolyhedralRegion region;
|
||||
private BlockVector pos1;
|
||||
|
||||
public ConvexPolyhedralRegionSelector(LocalWorld world, int maxVertices) {
|
||||
this.maxVertices = maxVertices;
|
||||
region = new ConvexPolyhedralRegion(world);
|
||||
}
|
||||
|
||||
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector, int maxVertices) {
|
||||
this.maxVertices = maxVertices;
|
||||
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
|
||||
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
|
||||
|
||||
pos1 = convexPolyhedralRegionSelector.pos1;
|
||||
region = new ConvexPolyhedralRegion(convexPolyhedralRegionSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
region = new ConvexPolyhedralRegion(oldSelector.getIncompleteRegion().getWorld());
|
||||
return;
|
||||
}
|
||||
|
||||
final int minY = oldRegion.getMinimumPoint().getBlockY();
|
||||
final int maxY = oldRegion.getMaximumPoint().getBlockY();
|
||||
|
||||
region = new ConvexPolyhedralRegion(oldRegion.getWorld());
|
||||
|
||||
for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(maxVertices < 0 ? maxVertices : maxVertices / 2))) {
|
||||
region.addVertex(pt.toVector(minY));
|
||||
region.addVertex(pt.toVector(maxY));
|
||||
}
|
||||
|
||||
learnChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
clear();
|
||||
pos1 = pos.toBlockVector();
|
||||
return region.addVertex(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (maxVertices >= 0 && region.getVertices().size() > maxVertices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return region.addVertex(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
return pos1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getRegion() throws IncompleteRegionException {
|
||||
if (!region.isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefined() {
|
||||
return region.isDefined();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void learnChanges() {
|
||||
pos1 = region.getVertices().iterator().next().toBlockVector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
region.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Convex Polyhedron";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ret.add("Vertices: "+region.getVertices().size());
|
||||
ret.add("Triangles: "+region.getTriangles().size());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Started new selection with vertex "+pos+".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Added vertex "+pos+" to the selection.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeID() {
|
||||
return "polyhedron";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
Collection<Vector> vertices = region.getVertices();
|
||||
Collection<Triangle> triangles = region.getTriangles();
|
||||
|
||||
player.dispatchCUIEvent(new SelectionShapeEvent(getTypeID()));
|
||||
|
||||
Map<Vector, Integer> vertexIds = new HashMap<Vector, Integer>(vertices.size());
|
||||
int lastVertexId = -1;
|
||||
for (Vector vertex : vertices) {
|
||||
vertexIds.put(vertex, ++lastVertexId);
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea()));
|
||||
}
|
||||
|
||||
for (Triangle triangle : triangles) {
|
||||
final int[] v = new int[3];
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
v[i] = vertexIds.get(triangle.getVertex(i));
|
||||
}
|
||||
session.dispatchCUIEvent(player, new SelectionPolygonEvent(v));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
} else {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPolygonEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
|
||||
public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
||||
private int maxVertices;
|
||||
private final ConvexPolyhedralRegion region;
|
||||
private BlockVector pos1;
|
||||
|
||||
public ConvexPolyhedralRegionSelector(LocalWorld world, int maxVertices) {
|
||||
this.maxVertices = maxVertices;
|
||||
region = new ConvexPolyhedralRegion(world);
|
||||
}
|
||||
|
||||
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector, int maxVertices) {
|
||||
this.maxVertices = maxVertices;
|
||||
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
|
||||
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
|
||||
|
||||
pos1 = convexPolyhedralRegionSelector.pos1;
|
||||
region = new ConvexPolyhedralRegion(convexPolyhedralRegionSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
region = new ConvexPolyhedralRegion(oldSelector.getIncompleteRegion().getWorld());
|
||||
return;
|
||||
}
|
||||
|
||||
final int minY = oldRegion.getMinimumPoint().getBlockY();
|
||||
final int maxY = oldRegion.getMaximumPoint().getBlockY();
|
||||
|
||||
region = new ConvexPolyhedralRegion(oldRegion.getWorld());
|
||||
|
||||
for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(maxVertices < 0 ? maxVertices : maxVertices / 2))) {
|
||||
region.addVertex(pt.toVector(minY));
|
||||
region.addVertex(pt.toVector(maxY));
|
||||
}
|
||||
|
||||
learnChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
clear();
|
||||
pos1 = pos.toBlockVector();
|
||||
return region.addVertex(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (maxVertices >= 0 && region.getVertices().size() > maxVertices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return region.addVertex(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
return pos1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getRegion() throws IncompleteRegionException {
|
||||
if (!region.isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefined() {
|
||||
return region.isDefined();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void learnChanges() {
|
||||
pos1 = region.getVertices().iterator().next().toBlockVector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
region.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Convex Polyhedron";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInformationLines() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ret.add("Vertices: "+region.getVertices().size());
|
||||
ret.add("Triangles: "+region.getTriangles().size());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Started new selection with vertex "+pos+".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
session.describeCUI(player);
|
||||
|
||||
player.print("Added vertex "+pos+" to the selection.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeID() {
|
||||
return "polyhedron";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
Collection<Vector> vertices = region.getVertices();
|
||||
Collection<Triangle> triangles = region.getTriangles();
|
||||
|
||||
player.dispatchCUIEvent(new SelectionShapeEvent(getTypeID()));
|
||||
|
||||
Map<Vector, Integer> vertexIds = new HashMap<Vector, Integer>(vertices.size());
|
||||
int lastVertexId = -1;
|
||||
for (Vector vertex : vertices) {
|
||||
vertexIds.put(vertex, ++lastVertexId);
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea()));
|
||||
}
|
||||
|
||||
for (Triangle triangle : triangles) {
|
||||
final int[] v = new int[3];
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
v[i] = vertexIds.get(triangle.getVertex(i));
|
||||
}
|
||||
session.dispatchCUIEvent(player, new SelectionPolygonEvent(v));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
} else {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,223 +1,225 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
|
||||
/**
|
||||
* Selector for cuboids.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected BlockVector pos1;
|
||||
protected BlockVector pos2;
|
||||
protected CuboidRegion region;
|
||||
|
||||
public CuboidRegionSelector(LocalWorld world) {
|
||||
region = new CuboidRegion(world, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
public CuboidRegionSelector() {
|
||||
this((LocalWorld) null);
|
||||
}
|
||||
|
||||
public CuboidRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof CuboidRegionSelector) {
|
||||
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
|
||||
|
||||
pos1 = cuboidRegionSelector.pos1;
|
||||
pos2 = cuboidRegionSelector.pos2;
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||
pos2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||
}
|
||||
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public CuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this(world);
|
||||
this.pos1 = pos1.toBlockVector();
|
||||
this.pos2 = pos2.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos1 != null && (pos.compareTo(pos1) == 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (pos2 != null && (pos.compareTo(pos2)) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos2 = pos.toBlockVector();
|
||||
region.setPos2(pos2);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("First position set to " + pos1 + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("First position set to " + pos1 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("Second position set to " + pos2 + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Second position set to " + pos2 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
if (pos1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (pos1 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return pos1;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return pos1 != null && pos2 != null;
|
||||
}
|
||||
|
||||
public CuboidRegion getRegion() throws IncompleteRegionException {
|
||||
if (pos1 == null || pos2 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public CuboidRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
pos1 = region.getPos1().toBlockVector();
|
||||
pos2 = region.getPos2().toBlockVector();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
pos2 = null;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (pos1 != null) {
|
||||
lines.add("Position 1: " + pos1);
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
lines.add("Position 2: " + pos2);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
if (pos1 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pos2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
if (pos1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Selector for cuboids.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected BlockVector pos1;
|
||||
protected BlockVector pos2;
|
||||
protected CuboidRegion region;
|
||||
|
||||
public CuboidRegionSelector(LocalWorld world) {
|
||||
region = new CuboidRegion(world, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
public CuboidRegionSelector() {
|
||||
this((LocalWorld) null);
|
||||
}
|
||||
|
||||
public CuboidRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof CuboidRegionSelector) {
|
||||
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
|
||||
|
||||
pos1 = cuboidRegionSelector.pos1;
|
||||
pos2 = cuboidRegionSelector.pos2;
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||
pos2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||
}
|
||||
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public CuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this(world);
|
||||
this.pos1 = pos1.toBlockVector();
|
||||
this.pos2 = pos2.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos1 != null && (pos.compareTo(pos1) == 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (pos2 != null && (pos.compareTo(pos2)) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos2 = pos.toBlockVector();
|
||||
region.setPos2(pos2);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("First position set to " + pos1 + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("First position set to " + pos1 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("Second position set to " + pos2 + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Second position set to " + pos2 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
if (pos1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (pos1 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return pos1;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return pos1 != null && pos2 != null;
|
||||
}
|
||||
|
||||
public CuboidRegion getRegion() throws IncompleteRegionException {
|
||||
if (pos1 == null || pos2 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public CuboidRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
pos1 = region.getPos1().toBlockVector();
|
||||
pos2 = region.getPos2().toBlockVector();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
pos2 = null;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (pos1 != null) {
|
||||
lines.add("Position 1: " + pos1);
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
lines.add("Position 2: " + pos2);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
if (pos1 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pos2 == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
if (pos1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,218 +1,221 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionCylinderEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* Selector for polygonal regions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected CylinderRegion region;
|
||||
protected static final NumberFormat format;
|
||||
|
||||
static {
|
||||
format = (NumberFormat) NumberFormat.getInstance().clone();
|
||||
format.setMaximumFractionDigits(3);
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(LocalWorld world) {
|
||||
region = new CylinderRegion(world);
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof CylinderRegionSelector) {
|
||||
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
|
||||
|
||||
region = new CylinderRegion(cylSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector pos1 = oldRegion.getMinimumPoint();
|
||||
Vector pos2 = oldRegion.getMaximumPoint();
|
||||
|
||||
Vector center = pos1.add(pos2).divide(2).floor();
|
||||
region.setCenter(center.toVector2D());
|
||||
region.setRadius(pos2.toVector2D().subtract(center.toVector2D()));
|
||||
|
||||
region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
|
||||
region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
|
||||
}
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) {
|
||||
this(world);
|
||||
|
||||
region.setCenter(center);
|
||||
region.setRadius(radius);
|
||||
|
||||
region.setMinimumY(Math.min(minY, maxY));
|
||||
region.setMaximumY(Math.max(minY, maxY));
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region = new CylinderRegion(region.getWorld());
|
||||
region.setCenter(pos.toVector2D());
|
||||
region.setY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
Vector center = region.getCenter();
|
||||
if ((center.compareTo(Vector.ZERO)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Vector2D diff = pos.subtract(center).toVector2D();
|
||||
final Vector2D minRadius = Vector2D.getMaximum(diff, diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
|
||||
region.setY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new cylindrical selection at " + pos + ".");
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
Vector center = region.getCenter();
|
||||
if (!center.equals(Vector.ZERO)) {
|
||||
player.print("Radius set to " + format.format(region.getRadius().getX()) + "/" + format.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.printError("You must select the center point before setting the radius.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region.getCenter().toBlockVector();
|
||||
}
|
||||
|
||||
public CylinderRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public CylinderRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return !region.getRadius().equals(Vector2D.ZERO);
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
region = new CylinderRegion(region.getWorld());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "Cylinder";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (!region.getCenter().equals(Vector.ZERO)) {
|
||||
lines.add("Center: " + region.getCenter());
|
||||
}
|
||||
if (!region.getRadius().equals(Vector2D.ZERO)) {
|
||||
lines.add("Radius: " + region.getRadius());
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter(), region.getRadius()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
} else {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
|
||||
}
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "cylinder";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionCylinderEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.CylinderRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* Selector for polygonal regions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected CylinderRegion region;
|
||||
protected static final NumberFormat format;
|
||||
|
||||
static {
|
||||
format = (NumberFormat) NumberFormat.getInstance().clone();
|
||||
format.setMaximumFractionDigits(3);
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(LocalWorld world) {
|
||||
region = new CylinderRegion(world);
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof CylinderRegionSelector) {
|
||||
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
|
||||
|
||||
region = new CylinderRegion(cylSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector pos1 = oldRegion.getMinimumPoint();
|
||||
Vector pos2 = oldRegion.getMaximumPoint();
|
||||
|
||||
Vector center = pos1.add(pos2).divide(2).floor();
|
||||
region.setCenter(center.toVector2D());
|
||||
region.setRadius(pos2.toVector2D().subtract(center.toVector2D()));
|
||||
|
||||
region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
|
||||
region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
|
||||
}
|
||||
}
|
||||
|
||||
public CylinderRegionSelector(LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) {
|
||||
this(world);
|
||||
|
||||
region.setCenter(center);
|
||||
region.setRadius(radius);
|
||||
|
||||
region.setMinimumY(Math.min(minY, maxY));
|
||||
region.setMaximumY(Math.max(minY, maxY));
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region = new CylinderRegion(region.getWorld());
|
||||
region.setCenter(pos.toVector2D());
|
||||
region.setY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
Vector center = region.getCenter();
|
||||
if ((center.compareTo(Vector.ZERO)) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Vector2D diff = pos.subtract(center).toVector2D();
|
||||
final Vector2D minRadius = Vector2D.getMaximum(diff, diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
|
||||
region.setY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new cylindrical selection at " + pos + ".");
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
Vector center = region.getCenter();
|
||||
if (!center.equals(Vector.ZERO)) {
|
||||
player.print("Radius set to " + format.format(region.getRadius().getX()) + "/" + format.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.printError("You must select the center point before setting the radius.");
|
||||
return;
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region.getCenter().toBlockVector();
|
||||
}
|
||||
|
||||
public CylinderRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public CylinderRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return !region.getRadius().equals(Vector2D.ZERO);
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
region = new CylinderRegion(region.getWorld());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "Cylinder";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
if (!region.getCenter().equals(Vector.ZERO)) {
|
||||
lines.add("Center: " + region.getCenter());
|
||||
}
|
||||
if (!region.getRadius().equals(Vector2D.ZERO)) {
|
||||
lines.add("Radius: " + region.getRadius());
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter(), region.getRadius()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
} else {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
|
||||
}
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "cylinder";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
}
|
@ -1,195 +1,197 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
|
||||
/**
|
||||
* Selector for ellipsoids.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected EllipsoidRegion region;
|
||||
|
||||
public EllipsoidRegionSelector(LocalWorld world) {
|
||||
region = new EllipsoidRegion(world, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector() {
|
||||
this((LocalWorld) null);
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof EllipsoidRegionSelector) {
|
||||
final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;
|
||||
|
||||
region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
|
||||
} else {
|
||||
Region oldRegion = null;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockVector pos1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||
BlockVector pos2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||
|
||||
Vector center = pos1.add(pos2).divide(2).floor();
|
||||
region.setCenter(center);
|
||||
region.setRadius(pos2.subtract(center));
|
||||
}
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector(LocalWorld world, Vector center, Vector radius) {
|
||||
this(world);
|
||||
|
||||
region.setCenter(center);
|
||||
region.setRadius(radius);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region.setCenter(pos.toBlockVector());
|
||||
region.setRadius(new Vector());
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
final Vector diff = pos.subtract(region.getCenter());
|
||||
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Center position set to " + region.getCenter() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return region.getRadius().lengthSq() > 0;
|
||||
}
|
||||
|
||||
public EllipsoidRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public EllipsoidRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
region.setCenter(new Vector());
|
||||
region.setRadius(new Vector());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "ellipsoid";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
final Vector center = region.getCenter();
|
||||
if (center.lengthSq() > 0) {
|
||||
lines.add("Center: " + center);
|
||||
}
|
||||
|
||||
final Vector radius = region.getRadius();
|
||||
if (radius.lengthSq() > 0) {
|
||||
lines.add("X/Y/Z radius: " + radius);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter()));
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "ellipsoid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
return region.getCenter().toBlockVector();
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
import com.sk89q.worldedit.regions.EllipsoidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Selector for ellipsoids.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected EllipsoidRegion region;
|
||||
|
||||
public EllipsoidRegionSelector(LocalWorld world) {
|
||||
region = new EllipsoidRegion(world, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector() {
|
||||
this((LocalWorld) null);
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld());
|
||||
if (oldSelector instanceof EllipsoidRegionSelector) {
|
||||
final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;
|
||||
|
||||
region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
|
||||
} else {
|
||||
Region oldRegion = null;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockVector pos1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||
BlockVector pos2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||
|
||||
Vector center = pos1.add(pos2).divide(2).floor();
|
||||
region.setCenter(center);
|
||||
region.setRadius(pos2.subtract(center));
|
||||
}
|
||||
}
|
||||
|
||||
public EllipsoidRegionSelector(LocalWorld world, Vector center, Vector radius) {
|
||||
this(world);
|
||||
|
||||
region.setCenter(center);
|
||||
region.setRadius(radius);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
region.setCenter(pos.toBlockVector());
|
||||
region.setRadius(new Vector());
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
final Vector diff = pos.subtract(region.getCenter());
|
||||
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
|
||||
region.extendRadius(minRadius);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Center position set to " + region.getCenter() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return region.getRadius().lengthSq() > 0;
|
||||
}
|
||||
|
||||
public EllipsoidRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public EllipsoidRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
region.setCenter(new Vector());
|
||||
region.setRadius(new Vector());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "ellipsoid";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
final List<String> lines = new ArrayList<String>();
|
||||
|
||||
final Vector center = region.getCenter();
|
||||
if (center.lengthSq() > 0) {
|
||||
lines.add("Center: " + center);
|
||||
}
|
||||
|
||||
final Vector radius = region.getRadius();
|
||||
if (radius.lengthSq() > 0) {
|
||||
lines.add("X/Y/Z radius: " + radius);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter()));
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "ellipsoid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
return region.getCenter().toBlockVector();
|
||||
}
|
||||
}
|
@ -1,116 +1,116 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
* Alternative selector for cuboids.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
public ExtendingCuboidRegionSelector(LocalWorld world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
|
||||
super(oldSelector);
|
||||
|
||||
if (pos1 == null || pos2 == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos1 = region.getMinimumPoint().toBlockVector();
|
||||
pos2 = region.getMaximumPoint().toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public ExtendingCuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this(world);
|
||||
pos1 = Vector.getMinimum(pos1, pos2);
|
||||
pos2 = Vector.getMaximum(pos1, pos2);
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos1 != null && pos2 != null && pos.compareTo(pos1) == 0 && pos.compareTo(pos2) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos2 = pos.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (pos1 == null || pos2 == null) {
|
||||
return selectPrimary(pos);
|
||||
}
|
||||
|
||||
if (region.contains(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double x1 = Math.min(pos.getX(), pos1.getX());
|
||||
double y1 = Math.min(pos.getY(), pos1.getY());
|
||||
double z1 = Math.min(pos.getZ(), pos1.getZ());
|
||||
|
||||
double x2 = Math.max(pos.getX(), pos2.getX());
|
||||
double y2 = Math.max(pos.getY(), pos2.getY());
|
||||
double z2 = Math.max(pos.getZ(), pos2.getZ());
|
||||
|
||||
final BlockVector o1 = pos1;
|
||||
final BlockVector o2 = pos2;
|
||||
pos1 = new BlockVector(x1, y1, z1);
|
||||
pos2 = new BlockVector(x2, y2, z2);
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
|
||||
assert(region.contains(o1));
|
||||
assert(region.contains(o2));
|
||||
assert(region.contains(pos));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Started selection at " + pos + " (" + region.getArea() + ").");
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Extended selection to encompass " + pos + " (" + region.getArea() + ").");
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
* Alternative selector for cuboids.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
public ExtendingCuboidRegionSelector(LocalWorld world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
|
||||
super(oldSelector);
|
||||
|
||||
if (pos1 == null || pos2 == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
pos1 = region.getMinimumPoint().toBlockVector();
|
||||
pos2 = region.getMaximumPoint().toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
public ExtendingCuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) {
|
||||
this(world);
|
||||
pos1 = Vector.getMinimum(pos1, pos2);
|
||||
pos2 = Vector.getMaximum(pos1, pos2);
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos1 != null && pos2 != null && pos.compareTo(pos1) == 0 && pos.compareTo(pos2) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos2 = pos.toBlockVector();
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (pos1 == null || pos2 == null) {
|
||||
return selectPrimary(pos);
|
||||
}
|
||||
|
||||
if (region.contains(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double x1 = Math.min(pos.getX(), pos1.getX());
|
||||
double y1 = Math.min(pos.getY(), pos1.getY());
|
||||
double z1 = Math.min(pos.getZ(), pos1.getZ());
|
||||
|
||||
double x2 = Math.max(pos.getX(), pos2.getX());
|
||||
double y2 = Math.max(pos.getY(), pos2.getY());
|
||||
double z2 = Math.max(pos.getZ(), pos2.getZ());
|
||||
|
||||
final BlockVector o1 = pos1;
|
||||
final BlockVector o2 = pos2;
|
||||
pos1 = new BlockVector(x1, y1, z1);
|
||||
pos2 = new BlockVector(x2, y2, z2);
|
||||
region.setPos1(pos1);
|
||||
region.setPos2(pos2);
|
||||
|
||||
assert(region.contains(o1));
|
||||
assert(region.contains(o2));
|
||||
assert(region.contains(pos));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Started selection at " + pos + " (" + region.getArea() + ").");
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Extended selection to encompass " + pos + " (" + region.getArea() + ").");
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
}
|
@ -1,219 +1,221 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
|
||||
/**
|
||||
* Selector for polygonal regions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
private int maxPoints;
|
||||
private BlockVector pos1;
|
||||
private Polygonal2DRegion region;
|
||||
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(LocalWorld world) {
|
||||
this(world, 50);
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(LocalWorld world, int maxPoints) {
|
||||
this.maxPoints = maxPoints;
|
||||
region = new Polygonal2DRegion(world);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector, 50);
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld(), maxPoints);
|
||||
if (oldSelector instanceof Polygonal2DRegionSelector) {
|
||||
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
|
||||
|
||||
pos1 = polygonal2DRegionSelector.pos1;
|
||||
region = new Polygonal2DRegion(polygonal2DRegionSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int minY = oldRegion.getMinimumPoint().getBlockY();
|
||||
final int maxY = oldRegion.getMaximumPoint().getBlockY();
|
||||
|
||||
List<BlockVector2D> points = oldRegion.polygonize(maxPoints);
|
||||
|
||||
pos1 = points.get(0).toVector(minY).toBlockVector();
|
||||
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
|
||||
}
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
|
||||
final BlockVector2D pos2D = points.get(0);
|
||||
pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
|
||||
region = new Polygonal2DRegion(world, points, minY, maxY);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos.equals(pos1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos.toBlockVector();
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (region.size() > 0) {
|
||||
final List<BlockVector2D> points = region.getPoints();
|
||||
|
||||
final BlockVector2D lastPoint = points.get(region.size() - 1);
|
||||
if (lastPoint.getBlockX() == pos.getBlockX() && lastPoint.getBlockZ() == pos.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (maxPoints >= 0 && points.size() > maxPoints) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new polygon at " + pos + ".");
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Added point #" + region.size() + " at " + pos + ".");
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (pos1 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return pos1;
|
||||
}
|
||||
|
||||
public Polygonal2DRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public Polygonal2DRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return region.size() > 2;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
BlockVector2D pt = region.getPoints().get(0);
|
||||
pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "2Dx1D polygon";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
return Collections.singletonList("# points: " + region.size());
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public int getPointCount() {
|
||||
return region.getPoints().size();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
final List<BlockVector2D> points = region.getPoints();
|
||||
for (int id = 0; id < points.size(); id++) {
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Selector for polygonal regions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
private int maxPoints;
|
||||
private BlockVector pos1;
|
||||
private Polygonal2DRegion region;
|
||||
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(LocalWorld world) {
|
||||
this(world, 50);
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(LocalWorld world, int maxPoints) {
|
||||
this.maxPoints = maxPoints;
|
||||
region = new Polygonal2DRegion(world);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
|
||||
this(oldSelector, 50);
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
|
||||
this(oldSelector.getIncompleteRegion().getWorld(), maxPoints);
|
||||
if (oldSelector instanceof Polygonal2DRegionSelector) {
|
||||
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
|
||||
|
||||
pos1 = polygonal2DRegionSelector.pos1;
|
||||
region = new Polygonal2DRegion(polygonal2DRegionSelector.region);
|
||||
} else {
|
||||
final Region oldRegion;
|
||||
try {
|
||||
oldRegion = oldSelector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int minY = oldRegion.getMinimumPoint().getBlockY();
|
||||
final int maxY = oldRegion.getMaximumPoint().getBlockY();
|
||||
|
||||
List<BlockVector2D> points = oldRegion.polygonize(maxPoints);
|
||||
|
||||
pos1 = points.get(0).toVector(minY).toBlockVector();
|
||||
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
|
||||
}
|
||||
}
|
||||
|
||||
public Polygonal2DRegionSelector(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
|
||||
final BlockVector2D pos2D = points.get(0);
|
||||
pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
|
||||
region = new Polygonal2DRegion(world, points, minY, maxY);
|
||||
}
|
||||
|
||||
public boolean selectPrimary(Vector pos) {
|
||||
if (pos.equals(pos1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pos1 = pos.toBlockVector();
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
if (region.size() > 0) {
|
||||
final List<BlockVector2D> points = region.getPoints();
|
||||
|
||||
final BlockVector2D lastPoint = points.get(region.size() - 1);
|
||||
if (lastPoint.getBlockX() == pos.getBlockX() && lastPoint.getBlockZ() == pos.getBlockZ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (maxPoints >= 0 && points.size() > maxPoints) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
region.addPoint(pos);
|
||||
region.expandY(pos.getBlockY());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new polygon at " + pos + ".");
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Added point #" + region.size() + " at " + pos + ".");
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
if (pos1 == null) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return pos1;
|
||||
}
|
||||
|
||||
public Polygonal2DRegion getRegion() throws IncompleteRegionException {
|
||||
if (!isDefined()) {
|
||||
throw new IncompleteRegionException();
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
public Polygonal2DRegion getIncompleteRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return region.size() > 2;
|
||||
}
|
||||
|
||||
public void learnChanges() {
|
||||
BlockVector2D pt = region.getPoints().get(0);
|
||||
pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
pos1 = null;
|
||||
region = new Polygonal2DRegion(region.getWorld());
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return "2Dx1D polygon";
|
||||
}
|
||||
|
||||
public List<String> getInformationLines() {
|
||||
return Collections.singletonList("# points: " + region.size());
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public int getPointCount() {
|
||||
return region.getPoints().size();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
final List<BlockVector2D> points = region.getPoints();
|
||||
for (int id = 0; id < points.size(); id++) {
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
}
|
@ -1,140 +1,138 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
* Region selection factory.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface RegionSelector {
|
||||
/**
|
||||
* Called when the first point is selected.
|
||||
*
|
||||
* @param pos
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean selectPrimary(Vector pos);
|
||||
|
||||
/**
|
||||
* Called when the second point is selected.
|
||||
*
|
||||
* @param pos
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean selectSecondary(Vector pos);
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her primary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her secondary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* The the player information about the region's changes. This may resend
|
||||
* all the defining region information if needed.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
*/
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session);
|
||||
|
||||
/**
|
||||
* Get the primary position.
|
||||
*
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException;
|
||||
|
||||
/**
|
||||
* Get the selection.
|
||||
*
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Region getRegion() throws IncompleteRegionException;
|
||||
|
||||
/**
|
||||
* Get the region even if it's not fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Region getIncompleteRegion();
|
||||
|
||||
/**
|
||||
* Returns whether the region has been fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDefined();
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks or -1 if undefined
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
*/
|
||||
public void learnChanges();
|
||||
|
||||
/**
|
||||
* Clear the selection.
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Get a lowercase name of this region selector type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeName();
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getInformationLines();
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Region selection factory.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public interface RegionSelector {
|
||||
/**
|
||||
* Called when the first point is selected.
|
||||
*
|
||||
* @param pos
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean selectPrimary(Vector pos);
|
||||
|
||||
/**
|
||||
* Called when the second point is selected.
|
||||
*
|
||||
* @param pos
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean selectSecondary(Vector pos);
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her primary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her secondary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* The the player information about the region's changes. This may resend
|
||||
* all the defining region information if needed.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
*/
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session);
|
||||
|
||||
/**
|
||||
* Get the primary position.
|
||||
*
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException;
|
||||
|
||||
/**
|
||||
* Get the selection.
|
||||
*
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Region getRegion() throws IncompleteRegionException;
|
||||
|
||||
/**
|
||||
* Get the region even if it's not fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Region getIncompleteRegion();
|
||||
|
||||
/**
|
||||
* Returns whether the region has been fully defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDefined();
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks or -1 if undefined
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
*/
|
||||
public void learnChanges();
|
||||
|
||||
/**
|
||||
* Clear the selection.
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Get a lowercase name of this region selector type.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeName();
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getInformationLines();
|
||||
}
|
@ -1,75 +1,75 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions;
|
||||
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
* Selector for spheres.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
public SphereRegionSelector(LocalWorld world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public SphereRegionSelector() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SphereRegionSelector(RegionSelector oldSelector) {
|
||||
super(oldSelector);
|
||||
final Vector radius = region.getRadius();
|
||||
final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
|
||||
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
|
||||
}
|
||||
|
||||
public SphereRegionSelector(LocalWorld world, Vector center, int radius) {
|
||||
super(world, center, new Vector(radius, radius, radius));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
final double radiusScalar = Math.ceil(pos.distance(region.getCenter()));
|
||||
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius().getX() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius().getX() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "sphere";
|
||||
}
|
||||
}
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||
*
|
||||
* 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.regions.selector;
|
||||
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
/**
|
||||
* Selector for spheres.
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
public SphereRegionSelector(LocalWorld world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public SphereRegionSelector() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SphereRegionSelector(RegionSelector oldSelector) {
|
||||
super(oldSelector);
|
||||
final Vector radius = region.getRadius();
|
||||
final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ());
|
||||
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
|
||||
}
|
||||
|
||||
public SphereRegionSelector(LocalWorld world, Vector center, int radius) {
|
||||
super(world, center, new Vector(radius, radius, radius));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean selectSecondary(Vector pos) {
|
||||
final double radiusScalar = Math.ceil(pos.distance(region.getCenter()));
|
||||
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
if (isDefined()) {
|
||||
player.print("Radius set to " + region.getRadius().getX() + " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Radius set to " + region.getRadius().getX() + ".");
|
||||
}
|
||||
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "sphere";
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.spout.selections.CuboidSelection;
|
||||
import com.sk89q.worldedit.spout.selections.Polygonal2DSelection;
|
||||
import com.sk89q.worldedit.spout.selections.Selection;
|
||||
|
@ -24,8 +24,8 @@ package com.sk89q.worldedit.spout.selections;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.spout.SpoutUtil;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.spout.api.geo.World;
|
||||
import org.spout.api.geo.discrete.Point;
|
||||
|
||||
|
@ -24,8 +24,8 @@ package com.sk89q.worldedit.spout.selections;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.spout.SpoutUtil;
|
||||
import org.spout.api.geo.World;
|
||||
|
||||
|
@ -23,7 +23,7 @@ package com.sk89q.worldedit.spout.selections;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import com.sk89q.worldedit.spout.SpoutUtil;
|
||||
import org.spout.api.geo.World;
|
||||
import org.spout.api.geo.discrete.Point;
|
||||
|
@ -22,7 +22,7 @@
|
||||
package com.sk89q.worldedit.spout.selections;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelector;
|
||||
import org.spout.api.geo.World;
|
||||
import org.spout.api.geo.discrete.Point;
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren