Add config entries for polygonal region points limit

This commit is contained in:
aumgn 2012-04-22 17:11:50 +02:00
parent d2a72579ae
commit cd64ca459d
6 changed files with 38 additions and 3 deletions

View File

@ -82,6 +82,8 @@ public abstract class LocalConfiguration {
public Set<Integer> disallowedBlocks = new HashSet<Integer>();
public int defaultChangeLimit = -1;
public int maxChangeLimit = -1;
public int defaultMaxPolygonalPoints = -1;
public int maxPolygonalPoints = 20;
public String shellSaveType = "";
public SnapshotRepository snapshotRepo = null;
public int maxRadius = -1;

View File

@ -761,6 +761,18 @@ public class WorldEdit {
}
}
public int getMaximumPolygonalPoints(LocalPlayer player) {
if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolygonalPoints < 0) {
return config.defaultMaxPolygonalPoints;
} else {
if (config.defaultMaxPolygonalPoints < 0) {
return config.maxPolygonalPoints;
}
return Math.min(config.defaultMaxPolygonalPoints,
config.maxPolygonalPoints);
}
}
/**
* Checks to see if the specified radius is within bounds.
*

View File

@ -609,8 +609,12 @@ public class SelectionCommands {
selector = new ExtendingCuboidRegionSelector(oldSelector);
player.print("Cuboid: left click for a starting point, right click to extend");
} else if (typeName.equalsIgnoreCase("poly")) {
selector = new Polygonal2DRegionSelector(oldSelector);
int maxPoints = we.getMaximumPolygonalPoints(player);
selector = new Polygonal2DRegionSelector(oldSelector, maxPoints);
player.print("2D polygon selector: Left/right click to add a point.");
if (maxPoints > -1) {
player.print(maxPoints + " points maximum.");
}
} else if (typeName.equalsIgnoreCase("ellipsoid")) {
selector = new EllipsoidRegionSelector(oldSelector);
player.print("Ellipsoid selector: left click=center, right click to extend");

View File

@ -40,15 +40,25 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent;
* @author sk89q
*/
public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
private int maxPoints;
private BlockVector pos1;
private Polygonal2DRegion region;
public Polygonal2DRegionSelector(LocalWorld world) {
this(world, 20);
}
public Polygonal2DRegionSelector(LocalWorld world, int maxPoints) {
this.maxPoints = maxPoints;
region = new Polygonal2DRegion(world);
}
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(oldSelector.getIncompleteRegion().getWorld());
this(oldSelector, 20);
}
public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
this(oldSelector.getIncompleteRegion().getWorld(), maxPoints);
if (oldSelector instanceof Polygonal2DRegionSelector) {
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
@ -108,7 +118,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
return false;
}
if (points.size() >= 20) {
if (maxPoints > -1 && points.size() >= maxPoints) {
return false;
}
}

View File

@ -65,6 +65,10 @@ public class YAMLConfiguration extends LocalConfiguration {
"limits.max-blocks-changed.default", defaultChangeLimit));
maxChangeLimit = Math.max(-1,
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
defaultMaxPolygonalPoints = Math.max(-1,
config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints));
maxPolygonalPoints = Math.max(-1,
config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints));
maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
maxSuperPickaxeSize = Math.max(1, config.getInt(
"limits.max-super-pickaxe-size", maxSuperPickaxeSize));

View File

@ -19,6 +19,9 @@ limits:
max-blocks-changed:
default: -1
maximum: -1
max-polygonal-points:
default: -1
maximum: 20
max-radius: -1
max-super-pickaxe-size: 5
max-brush-radius: 5