Refactor RegionSelectors so limits are passed in during selection.

Dieser Commit ist enthalten in:
sk89q 2014-07-28 19:50:01 -07:00
Ursprung 683bd670fe
Commit c2a0f590b1
25 geänderte Dateien mit 528 neuen und 400 gelöschten Zeilen

Datei anzeigen

@ -19,13 +19,14 @@
package com.sk89q.worldedit.bukkit.selections;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits;
import org.bukkit.Location;
import org.bukkit.World;
public class CuboidSelection extends RegionSelection {
@ -51,8 +52,8 @@ public class CuboidSelection extends RegionSelection {
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
sel.selectPrimary(pt1, PermissiveSelectorLimits.getInstance());
sel.selectSecondary(pt2, PermissiveSelectorLimits.getInstance());
// set up CuboidSelection
cuboid = sel.getIncompleteRegion();

Datei anzeigen

@ -0,0 +1,44 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser 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.Vector;
import com.sk89q.worldedit.extension.platform.Actor;
abstract class AbstractLegacyRegionSelector implements RegionSelector {
@Deprecated
public final void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Deprecated
public final void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Deprecated
public final void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
public abstract class ConvexPolyhedralRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CuboidRegionSelector implements RegionSelector, CUIRegion {
public abstract class CuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CylinderRegionSelector implements RegionSelector, CUIRegion {
public abstract class CylinderRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
public abstract class EllipsoidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -19,9 +19,11 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
public abstract class ExtendingCuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -25,7 +25,7 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
public abstract class Polygonal2DRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
/**
* Get the number of points.

Datei anzeigen

@ -19,9 +19,11 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class SphereRegionSelector extends EllipsoidRegionSelector {
public abstract class SphereRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
}

Datei anzeigen

@ -412,30 +412,6 @@ public class WorldEdit {
}
}
public int getMaximumPolygonalPoints(Player player) {
if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolygonalPoints < 0) {
return getConfiguration().defaultMaxPolygonalPoints;
}
if (getConfiguration().defaultMaxPolygonalPoints < 0) {
return getConfiguration().maxPolygonalPoints;
}
return Math.min(getConfiguration().defaultMaxPolygonalPoints, getConfiguration().maxPolygonalPoints);
}
public int getMaximumPolyhedronPoints(Player player) {
if (player.hasPermission("worldedit.limit.unrestricted") || getConfiguration().maxPolyhedronPoints < 0) {
return getConfiguration().defaultMaxPolyhedronPoints;
}
if (getConfiguration().defaultMaxPolyhedronPoints < 0) {
return getConfiguration().maxPolyhedronPoints;
}
return Math.min(getConfiguration().defaultMaxPolyhedronPoints, getConfiguration().maxPolyhedronPoints);
}
/**
* Checks to see if the specified radius is within bounds.
*

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.command;
import com.google.common.base.Optional;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
@ -33,6 +34,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
@ -93,7 +95,7 @@ public class SelectionCommands {
pos = player.getBlockIn();
}
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos)) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
return;
}
@ -128,7 +130,7 @@ public class SelectionCommands {
pos = player.getBlockIn();
}
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos)) {
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
return;
}
@ -150,8 +152,7 @@ public class SelectionCommands {
Vector pos = player.getBlockTrace(300);
if (pos != null) {
if (!session.getRegionSelector(player.getWorld())
.selectPrimary(pos)) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
return;
}
@ -176,8 +177,7 @@ public class SelectionCommands {
Vector pos = player.getBlockTrace(300);
if (pos != null) {
if (!session.getRegionSelector(player.getWorld())
.selectSecondary(pos)) {
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
return;
}
@ -208,7 +208,6 @@ public class SelectionCommands {
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
final Vector min;
final Vector max;
final World world = player.getWorld();
@ -254,8 +253,8 @@ public class SelectionCommands {
} else {
selector = new CuboidRegionSelector(world);
}
selector.selectPrimary(min);
selector.selectSecondary(max);
selector.selectPrimary(min, ActorSelectorLimits.forActor(player));
selector.selectSecondary(max, ActorSelectorLimits.forActor(player));
session.setRegionSelector(world, selector);
session.dispatchCUISelection(player);
@ -732,11 +731,11 @@ 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")) {
int maxPoints = we.getMaximumPolygonalPoints(player);
selector = new Polygonal2DRegionSelector(oldSelector, maxPoints);
selector = new Polygonal2DRegionSelector(oldSelector);
player.print("2D polygon selector: Left/right click to add a point.");
if (maxPoints > -1) {
player.print(maxPoints + " points maximum.");
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit();
if (limit.isPresent()) {
player.print(limit.get() + " points maximum.");
}
} else if (typeName.equalsIgnoreCase("ellipsoid")) {
selector = new EllipsoidRegionSelector(oldSelector);
@ -748,9 +747,12 @@ public class SelectionCommands {
selector = new CylinderRegionSelector(oldSelector);
player.print("Cylindrical selector: Left click=center, right click to extend.");
} else if (typeName.equalsIgnoreCase("convex") || typeName.equalsIgnoreCase("hull") || typeName.equalsIgnoreCase("polyhedron")) {
int maxVertices = we.getMaximumPolyhedronPoints(player);
selector = new ConvexPolyhedralRegionSelector(oldSelector, maxVertices);
selector = new ConvexPolyhedralRegionSelector(oldSelector);
player.print("Convex polyhedral selector: Left click=First vertex, right click to add more.");
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit();
if (limit.isPresent()) {
player.print(limit.get() + " points maximum.");
}
} else {
player.printError("Only cuboid|extend|poly|ellipsoid|sphere|cyl|convex are accepted.");
return;

Datei anzeigen

@ -23,6 +23,7 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.regions.RegionSelector;
/**
@ -46,7 +47,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(target)) {
if (selector.selectPrimary(target, ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(player, session, target);
}
return true;
@ -63,7 +64,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
if (target == null) return true;
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(target)) {
if (selector.selectSecondary(target, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(player, session, target);
}
return true;

Datei anzeigen

@ -37,6 +37,7 @@ import com.sk89q.worldedit.event.platform.Interaction;
import com.sk89q.worldedit.event.platform.PlatformInitializeEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.internal.ServerInterfaceAdapter;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.util.Location;
@ -330,7 +331,7 @@ public class PlatformManager {
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectPrimary(location.toVector())) {
if (selector.selectPrimary(location.toVector(), ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(actor, session, vector);
}
@ -365,7 +366,7 @@ public class PlatformManager {
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
if (selector.selectSecondary(vector)) {
if (selector.selectSecondary(vector, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(actor, session, vector);
}

Datei anzeigen

@ -0,0 +1,85 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.platform.permission;
import com.google.common.base.Optional;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import static com.google.common.base.Preconditions.checkNotNull;
public class ActorSelectorLimits implements SelectorLimits {
private final LocalConfiguration configuration;
private final Actor actor;
public ActorSelectorLimits(LocalConfiguration configuration, Actor actor) {
checkNotNull(configuration);
checkNotNull(actor);
this.configuration = configuration;
this.actor = actor;
}
@Override
public Optional<Integer> getPolygonVertexLimit() {
int limit;
if (actor.hasPermission(OverridePermissions.NO_LIMITS) || configuration.maxPolygonalPoints < 0) {
limit = configuration.defaultMaxPolygonalPoints;
} else if (configuration.defaultMaxPolygonalPoints < 0) {
limit = configuration.maxPolygonalPoints;
} else {
limit = Math.min(configuration.defaultMaxPolygonalPoints, configuration.maxPolygonalPoints);
}
if (limit > 0) {
return Optional.of(limit);
} else {
return Optional.absent();
}
}
@Override
public Optional<Integer> getPolyhedronVertexLimit() {
int limit;
if (actor.hasPermission(OverridePermissions.NO_LIMITS) || configuration.maxPolyhedronPoints < 0) {
limit = configuration.defaultMaxPolyhedronPoints;
} else if (configuration.defaultMaxPolyhedronPoints < 0) {
limit = configuration.maxPolyhedronPoints;
} else {
limit = Math.min(configuration.defaultMaxPolyhedronPoints, configuration.maxPolyhedronPoints);
}
if (limit > 0) {
return Optional.of(limit);
} else {
return Optional.absent();
}
}
public static ActorSelectorLimits forActor(Actor actor) {
return new ActorSelectorLimits(WorldEdit.getInstance().getConfiguration(), actor);
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.platform.permission;
/**
* Standard override permissions.
*/
public final class OverridePermissions {
public static final String NO_LIMITS = "worldedit.limit.unrestricted";
private OverridePermissions() {
}
}

Datei anzeigen

@ -19,8 +19,12 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import java.util.List;
@ -37,7 +41,7 @@ public interface RegionSelector {
* @param position the position
* @return true if something changed
*/
public boolean selectPrimary(Vector position);
public boolean selectPrimary(Vector position, SelectorLimits limits);
/**
* Called when the second point is selected.
@ -45,7 +49,7 @@ public interface RegionSelector {
* @param position the position
* @return true if something changed
*/
public boolean selectSecondary(Vector position);
public boolean selectSecondary(Vector position, SelectorLimits limits);
/**
* Tell the player information about his/her primary selection.
@ -56,9 +60,6 @@ public interface RegionSelector {
*/
public void explainPrimarySelection(Actor actor, LocalSession session, Vector position);
@Deprecated
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position);
/**
* Tell the player information about his/her secondary selection.
*
@ -68,9 +69,6 @@ public interface RegionSelector {
*/
public void explainSecondarySelection(Actor actor, LocalSession session, Vector position);
@Deprecated
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position);
/**
* The the player information about the region's changes. This may resend
* all the defining region information if needed.
@ -80,9 +78,6 @@ public interface RegionSelector {
*/
public void explainRegionAdjust(Actor actor, LocalSession session);
@Deprecated
public void explainRegionAdjust(LocalPlayer player, LocalSession session);
/**
* Get the primary position.
*

Datei anzeigen

@ -19,12 +19,11 @@
package com.sk89q.worldedit.regions.selector;
import com.google.common.base.Optional;
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.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIRegion;
@ -34,6 +33,7 @@ import com.sk89q.worldedit.regions.ConvexPolyhedralRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.polyhedron.Triangle;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@ -46,30 +46,26 @@ import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link ConvexPolyhedralRegion}s.
* Creates a {@code ConvexPolyhedralRegion} from a user's selections.
*/
public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
private int maxVertices;
private final ConvexPolyhedralRegion region;
private BlockVector pos1;
/**
* @deprecated cast {@code world} to {@link World}
* Create a new selector with a {@code null} world.
*/
@Deprecated
public ConvexPolyhedralRegionSelector(@Nullable LocalWorld world, int maxVertices) {
this((World) world, maxVertices);
public ConvexPolyhedralRegionSelector() {
this((World) null);
}
/**
* Create a new selector.
*
* @param world the world
* @param maxVertices the maximum number of vertices, where a number below 0 means unbounded
* @param world the world, which may be {@code null}
*/
public ConvexPolyhedralRegionSelector(@Nullable World world, int maxVertices) {
this.maxVertices = maxVertices;
public ConvexPolyhedralRegionSelector(@Nullable World world) {
region = new ConvexPolyhedralRegion(world);
}
@ -77,12 +73,10 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
* Create a new selector.
*
* @param oldSelector the old selector
* @param maxVertices the maximum number of vertices, where a number below 0 means unbounded
*/
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector, int maxVertices) {
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector) {
checkNotNull(oldSelector);
this.maxVertices = maxVertices;
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
@ -102,7 +96,7 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
region = new ConvexPolyhedralRegion(oldRegion.getWorld());
for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(maxVertices < 0 ? maxVertices : maxVertices / 2))) {
for (final BlockVector2D pt : new ArrayList<BlockVector2D>(oldRegion.polygonize(Integer.MAX_VALUE))) {
region.addVertex(pt.toVector(minY));
region.addVertex(pt.toVector(maxY));
}
@ -112,19 +106,24 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
}
@Override
public boolean selectPrimary(Vector pos) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
checkNotNull(position);
clear();
pos1 = pos.toBlockVector();
return region.addVertex(pos);
pos1 = position.toBlockVector();
return region.addVertex(position);
}
@Override
public boolean selectSecondary(Vector pos) {
if (maxVertices >= 0 && region.getVertices().size() > maxVertices) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
checkNotNull(position);
Optional<Integer> vertexLimit = limits.getPolyhedronVertexLimit();
if (vertexLimit.isPresent() && region.getVertices().size() > vertexLimit.get()) {
return false;
}
return region.addVertex(pos);
return region.addVertex(position);
}
@Override
@ -184,6 +183,10 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
@Override
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
checkNotNull(player);
checkNotNull(session);
checkNotNull(pos);
session.describeCUI(player);
player.print("Started new selection with vertex "+pos+".");
@ -191,6 +194,10 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
@Override
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
checkNotNull(player);
checkNotNull(session);
checkNotNull(pos);
session.describeCUI(player);
player.print("Added vertex " + pos + " to the selection.");
@ -198,10 +205,11 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
@Override
public void explainRegionAdjust(Actor player, LocalSession session) {
checkNotNull(player);
checkNotNull(session);
session.describeCUI(player);
}
@Override
public int getProtocolVersion() {
return 3;
@ -214,6 +222,9 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
@Override
public void describeCUI(LocalSession session, Actor player) {
checkNotNull(player);
checkNotNull(session);
Collection<Vector> vertices = region.getVertices();
Collection<Triangle> triangles = region.getTriangles();
@ -240,25 +251,13 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
@Override
public void describeLegacyCUI(LocalSession session, Actor player) {
checkNotNull(player);
checkNotNull(session);
if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
}
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@ -35,33 +36,25 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link CuboidRegion}s.
* Creates a {@code CuboidRegion} from a user's selections.
*/
public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegionSelector implements RegionSelector, CUIRegion {
protected BlockVector pos1;
protected BlockVector pos2;
protected BlockVector position1;
protected BlockVector position2;
protected CuboidRegion region;
/**
* Create a new region selector with no world.
* Create a new region selector with a {@code null} world.
*/
public CuboidRegionSelector() {
this((World) null);
}
/**
* @deprecated cast {@code world} to {@link World}
*/
@Deprecated
public CuboidRegionSelector(@Nullable LocalWorld world) {
this((World) world);
}
/**
* Create a new region selector.
*
* @param world the world
* @param world the world, which may be {@code null}
*/
public CuboidRegionSelector(@Nullable World world) {
region = new CuboidRegion(world, new Vector(), new Vector());
@ -74,11 +67,12 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
*/
public CuboidRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof CuboidRegionSelector) {
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
pos1 = cuboidRegionSelector.pos1;
pos2 = cuboidRegionSelector.pos2;
position1 = cuboidRegionSelector.position1;
position2 = cuboidRegionSelector.position2;
} else {
final Region oldRegion;
try {
@ -87,67 +81,67 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
return;
}
pos1 = oldRegion.getMinimumPoint().toBlockVector();
pos2 = oldRegion.getMaximumPoint().toBlockVector();
position1 = oldRegion.getMinimumPoint().toBlockVector();
position2 = oldRegion.getMaximumPoint().toBlockVector();
}
region.setPos1(pos1);
region.setPos2(pos2);
}
/**
* @deprecated cast {@code world} to {@link World}
*/
@Deprecated
public CuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
this((World) world, pos1, pos2);
region.setPos1(position1);
region.setPos2(position2);
}
/**
* Create a new region selector with the given two positions.
*
* @param world the world
* @param pos1 position 1
* @param pos2 position 2
* @param position1 position 1
* @param position2 position 2
*/
public CuboidRegionSelector(@Nullable World world, Vector pos1, Vector pos2) {
public CuboidRegionSelector(@Nullable World world, Vector position1, Vector position2) {
this(world);
checkNotNull(pos1);
checkNotNull(pos2);
this.pos1 = pos1.toBlockVector();
this.pos2 = pos2.toBlockVector();
region.setPos1(pos1);
region.setPos2(pos2);
checkNotNull(position1);
checkNotNull(position2);
this.position1 = position1.toBlockVector();
this.position2 = position2.toBlockVector();
region.setPos1(position1);
region.setPos2(position2);
}
@Override
public boolean selectPrimary(Vector pos) {
if (pos1 != null && (pos.compareTo(pos1) == 0)) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
checkNotNull(position);
if (position1 != null && (position.compareTo(position1) == 0)) {
return false;
}
pos1 = pos.toBlockVector();
region.setPos1(pos1);
position1 = position.toBlockVector();
region.setPos1(position1);
return true;
}
@Override
public boolean selectSecondary(Vector pos) {
if (pos2 != null && (pos.compareTo(pos2)) == 0) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
checkNotNull(position);
if (position2 != null && (position.compareTo(position2)) == 0) {
return false;
}
pos2 = pos.toBlockVector();
region.setPos2(pos2);
position2 = position.toBlockVector();
region.setPos2(position2);
return true;
}
@Override
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
if (pos1 != null && pos2 != null) {
player.print("First position set to " + pos1 + " (" + region.getArea() + ").");
checkNotNull(player);
checkNotNull(session);
checkNotNull(pos);
if (position1 != null && position2 != null) {
player.print("First position set to " + position1 + " (" + region.getArea() + ").");
} else {
player.print("First position set to " + pos1 + ".");
player.print("First position set to " + position1 + ".");
}
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
@ -155,10 +149,14 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
@Override
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
if (pos1 != null && pos2 != null) {
player.print("Second position set to " + pos2 + " (" + region.getArea() + ").");
checkNotNull(player);
checkNotNull(session);
checkNotNull(pos);
if (position1 != null && position2 != null) {
player.print("Second position set to " + position2 + " (" + region.getArea() + ").");
} else {
player.print("Second position set to " + pos2 + ".");
player.print("Second position set to " + position2 + ".");
}
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
@ -166,32 +164,35 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
@Override
public void explainRegionAdjust(Actor player, LocalSession session) {
if (pos1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
checkNotNull(player);
checkNotNull(session);
if (position1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
}
if (pos2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
if (position2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
}
}
@Override
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
if (pos1 == null) {
if (position1 == null) {
throw new IncompleteRegionException();
}
return pos1;
return position1;
}
@Override
public boolean isDefined() {
return pos1 != null && pos2 != null;
return position1 != null && position2 != null;
}
@Override
public CuboidRegion getRegion() throws IncompleteRegionException {
if (pos1 == null || pos2 == null) {
if (position1 == null || position2 == null) {
throw new IncompleteRegionException();
}
@ -205,14 +206,14 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
@Override
public void learnChanges() {
pos1 = region.getPos1().toBlockVector();
pos2 = region.getPos2().toBlockVector();
position1 = region.getPos1().toBlockVector();
position2 = region.getPos2().toBlockVector();
}
@Override
public void clear() {
pos1 = null;
pos2 = null;
position1 = null;
position2 = null;
}
@Override
@ -224,12 +225,12 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
public List<String> getInformationLines() {
final List<String> lines = new ArrayList<String>();
if (pos1 != null) {
lines.add("Position 1: " + pos1);
if (position1 != null) {
lines.add("Position 1: " + position1);
}
if (pos2 != null) {
lines.add("Position 2: " + pos2);
if (position2 != null) {
lines.add("Position 2: " + position2);
}
return lines;
@ -237,11 +238,11 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
@Override
public int getArea() {
if (pos1 == null) {
if (position1 == null) {
return -1;
}
if (pos2 == null) {
if (position2 == null) {
return -1;
}
@ -250,12 +251,12 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
@Override
public void describeCUI(LocalSession session, Actor player) {
if (pos1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
if (position1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
}
if (pos2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
if (position2 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
}
}
@ -279,19 +280,4 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
return "cuboid";
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -25,6 +25,7 @@ import com.sk89q.worldedit.internal.cui.*;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@ -35,7 +36,7 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link CylinderRegion}s.
* Creates a {@code CylinderRegionSelector} from a user's selections.
*/
public class CylinderRegionSelector extends com.sk89q.worldedit.regions.CylinderRegionSelector implements RegionSelector, CUIRegion {
@ -48,17 +49,16 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
}
/**
* @deprecated cast {@code world} to {@link World}
* Create a new region selector with a {@code null} world.
*/
@Deprecated
public CylinderRegionSelector(@Nullable LocalWorld world) {
this((World) world);
public CylinderRegionSelector() {
this((World) null);
}
/**
* Create a new region selector.
*
* @param world the world
* @param world the world, which may be {@code null}
*/
public CylinderRegionSelector(@Nullable World world) {
region = new CylinderRegion(world);
@ -71,6 +71,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
*/
public CylinderRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof CylinderRegionSelector) {
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
@ -104,7 +105,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
* @param minY the minimum Y
* @param maxY the maximum Y
*/
public CylinderRegionSelector(@Nullable LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) {
public CylinderRegionSelector(@Nullable World world, Vector2D center, Vector2D radius, int minY, int maxY) {
this(world);
region.setCenter(center);
@ -115,30 +116,30 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
}
@Override
public boolean selectPrimary(Vector pos) {
if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
if (!region.getCenter().equals(Vector.ZERO) && position.compareTo(region.getCenter()) == 0) {
return false;
}
region = new CylinderRegion(region.getWorld());
region.setCenter(pos.toVector2D());
region.setY(pos.getBlockY());
region.setCenter(position.toVector2D());
region.setY(position.getBlockY());
return true;
}
@Override
public boolean selectSecondary(Vector pos) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
Vector center = region.getCenter();
if ((center.compareTo(Vector.ZERO)) == 0) {
return true;
}
final Vector2D diff = pos.subtract(center).toVector2D();
final Vector2D diff = position.subtract(center).toVector2D();
final Vector2D minRadius = Vector2D.getMaximum(diff, diff.multiply(-1.0));
region.extendRadius(minRadius);
region.setY(pos.getBlockY());
region.setY(position.getBlockY());
return true;
}
@ -153,6 +154,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
@Override
public void explainSecondarySelection(Actor 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 {
@ -258,19 +260,4 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
return "cuboid";
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.regions.EllipsoidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@ -36,7 +37,7 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link EllipsoidRegion}s.
* Creates a {@code EllipsoidRegionSelector} from a user's selections.
*/
public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.EllipsoidRegionSelector implements RegionSelector, CUIRegion {
@ -44,24 +45,16 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
protected boolean started = false;
/**
* Create a new selector.
* Create a new selector with a {@code null} world.
*/
public EllipsoidRegionSelector() {
this((World) null);
}
/**
* @deprecated cast {@code world} to {@link World}
*/
@Deprecated
public EllipsoidRegionSelector(@Nullable LocalWorld world) {
this((World) world);
}
/**
* Create a new selector.
*
* @param world the world
* @param world the world, which may be {@code null}
*/
public EllipsoidRegionSelector(@Nullable World world) {
region = new EllipsoidRegion(world, new Vector(), new Vector());
@ -102,7 +95,7 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
* @param center the center
* @param radius the radius
*/
public EllipsoidRegionSelector(@Nullable LocalWorld world, Vector center, Vector radius) {
public EllipsoidRegionSelector(@Nullable World world, Vector center, Vector radius) {
this(world);
region.setCenter(center);
@ -110,12 +103,12 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
}
@Override
public boolean selectPrimary(Vector pos) {
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
if (position.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
return false;
}
region.setCenter(pos.toBlockVector());
region.setCenter(position.toBlockVector());
region.setRadius(new Vector());
started = true;
@ -123,12 +116,12 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
}
@Override
public boolean selectSecondary(Vector pos) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
if (!started) {
return false;
}
final Vector diff = pos.subtract(region.getCenter());
final Vector diff = position.subtract(region.getCenter());
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
region.extendRadius(minRadius);
return true;
@ -249,19 +242,4 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
return region.getCenter().toBlockVector();
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -19,29 +19,33 @@
package com.sk89q.worldedit.regions.selector;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
/**
* A {@link RegionSelector} for {@link CuboidRegion}s that enlarges the
* region with every secondary selection.
* Creates a {@code CuboidRegion} from a user's selections by expanding
* the region on every right click.
*/
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
@Deprecated
public ExtendingCuboidRegionSelector(@Nullable LocalWorld world) {
this((World) world);
/**
* Create a new selector with a {@code null} world.
*/
public ExtendingCuboidRegionSelector() {
super((World) null);
}
/**
* Create a new selector.
*
* @param world the world
* @param world the world, which may be {@code null}
*/
public ExtendingCuboidRegionSelector(@Nullable World world) {
super(world);
@ -55,71 +59,71 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
super(oldSelector);
if (pos1 == null || pos2 == null) {
if (position1 == null || position2 == null) {
return;
}
pos1 = region.getMinimumPoint().toBlockVector();
pos2 = region.getMaximumPoint().toBlockVector();
region.setPos1(pos1);
region.setPos2(pos2);
position1 = region.getMinimumPoint().toBlockVector();
position2 = region.getMaximumPoint().toBlockVector();
region.setPos1(position1);
region.setPos2(position2);
}
/**
* Create a new selector.
*
* @param world the world
* @param pos1 the first position
* @param pos2 the second position
* @param position1 the first position
* @param position2 the second position
*/
public ExtendingCuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
public ExtendingCuboidRegionSelector(@Nullable World world, Vector position1, Vector position2) {
this(world);
pos1 = Vector.getMinimum(pos1, pos2);
pos2 = Vector.getMaximum(pos1, pos2);
region.setPos1(pos1);
region.setPos2(pos2);
position1 = Vector.getMinimum(position1, position2);
position2 = Vector.getMaximum(position1, position2);
region.setPos1(position1);
region.setPos2(position2);
}
@Override
public boolean selectPrimary(Vector pos) {
if (pos1 != null && pos2 != null && pos.compareTo(pos1) == 0 && pos.compareTo(pos2) == 0) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
if (position1 != null && position2 != null && position.compareTo(position1) == 0 && position.compareTo(position2) == 0) {
return false;
}
pos1 = pos2 = pos.toBlockVector();
region.setPos1(pos1);
region.setPos2(pos2);
position1 = position2 = position.toBlockVector();
region.setPos1(position1);
region.setPos2(position2);
return true;
}
@Override
public boolean selectSecondary(Vector pos) {
if (pos1 == null || pos2 == null) {
return selectPrimary(pos);
public boolean selectSecondary(Vector position, SelectorLimits limits) {
if (position1 == null || position2 == null) {
return selectPrimary(position, limits);
}
if (region.contains(pos)) {
if (region.contains(position)) {
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 x1 = Math.min(position.getX(), position1.getX());
double y1 = Math.min(position.getY(), position1.getY());
double z1 = Math.min(position.getZ(), position1.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());
double x2 = Math.max(position.getX(), position2.getX());
double y2 = Math.max(position.getY(), position2.getY());
double z2 = Math.max(position.getZ(), position2.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);
final BlockVector o1 = position1;
final BlockVector o2 = position2;
position1 = new BlockVector(x1, y1, z1);
position2 = new BlockVector(x2, y2, z2);
region.setPos1(position1);
region.setPos2(position2);
assert(region.contains(o1));
assert(region.contains(o2));
assert(region.contains(pos));
assert(region.contains(position));
return true;
}
@ -138,19 +142,4 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
explainRegionAdjust(player, session);
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.regions.selector;
import com.google.common.base.Optional;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIRegion;
@ -28,6 +29,7 @@ import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
@ -37,57 +39,37 @@ import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link Polygonal2DRegion}s.
* Creates a {@code Polygonal2DRegion} from a user's selections.
*/
public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
private int maxPoints;
private BlockVector pos1;
private Polygonal2DRegion region;
/**
* @deprecated Use {@link #Polygonal2DRegionSelector(LocalWorld, int)}
* Create a new selector with a {@code null} world.
*/
@Deprecated
public Polygonal2DRegionSelector(@Nullable LocalWorld world) {
this(world, 50);
public Polygonal2DRegionSelector() {
this((World) null);
}
/**
* @deprecated cast {@code world} to {@link World}
*/
@Deprecated
public Polygonal2DRegionSelector(@Nullable LocalWorld world, int maxPoints) {
this((World) world, maxPoints);
}
/**
* Create a new selector.
* Create a new selector with the given world.
*
* @param world the world
* @param maxPoints the maximum number of points
*/
public Polygonal2DRegionSelector(@Nullable World world, int maxPoints) {
this.maxPoints = maxPoints;
public Polygonal2DRegionSelector(@Nullable World world) {
region = new Polygonal2DRegion(world);
}
/**
* @deprecated Use {@link #Polygonal2DRegionSelector(RegionSelector, int)}
*/
@Deprecated
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(oldSelector, 50);
}
/**
* Create a new selector from another one.
*
* @param oldSelector the old selector
* @param maxPoints the maximum number of points
*/
public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld(), maxPoints);
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof Polygonal2DRegionSelector) {
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
@ -104,7 +86,7 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
final int minY = oldRegion.getMinimumPoint().getBlockY();
final int maxY = oldRegion.getMaximumPoint().getBlockY();
List<BlockVector2D> points = oldRegion.polygonize(maxPoints);
List<BlockVector2D> points = oldRegion.polygonize(Integer.MAX_VALUE);
pos1 = points.get(0).toVector(minY).toBlockVector();
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
@ -136,36 +118,38 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
}
@Override
public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1)) {
public boolean selectPrimary(Vector position, SelectorLimits limits) {
if (position.equals(pos1)) {
return false;
}
pos1 = pos.toBlockVector();
pos1 = position.toBlockVector();
region = new Polygonal2DRegion(region.getWorld());
region.addPoint(pos);
region.expandY(pos.getBlockY());
region.addPoint(position);
region.expandY(position.getBlockY());
return true;
}
@Override
public boolean selectSecondary(Vector pos) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
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()) {
if (lastPoint.getBlockX() == position.getBlockX() && lastPoint.getBlockZ() == position.getBlockZ()) {
return false;
}
if (maxPoints >= 0 && points.size() > maxPoints) {
Optional<Integer> vertexLimit = limits.getPolygonVertexLimit();
if (vertexLimit.isPresent() && points.size() > vertexLimit.get()) {
return false;
}
}
region.addPoint(pos);
region.expandY(pos.getBlockY());
region.addPoint(position);
region.expandY(position.getBlockY());
return true;
}
@ -288,19 +272,4 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
return "polygon2d";
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -19,42 +19,36 @@
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;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
/**
* A {@link RegionSelector} for {@link SphereRegionSelector}s.
* Creates a {@code SphereRegion} from a user's selections.
*/
public class SphereRegionSelector extends EllipsoidRegionSelector {
@Deprecated
public SphereRegionSelector(@Nullable LocalWorld world) {
this((World) world);
/**
* Create a new selector with a {@code null world}.
*/
public SphereRegionSelector() {
super();
}
/**
* Create a new selector.
*
* @param world the world
* @param world the world, which may be {@code null}
*/
public SphereRegionSelector(@Nullable World world) {
super(world);
}
/**
* Create a new selector.
*/
public SphereRegionSelector() {
super();
}
/**
* Create a new selector from another one
*
@ -74,17 +68,17 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
* @param center the center position
* @param radius the radius
*/
public SphereRegionSelector(@Nullable LocalWorld world, Vector center, int radius) {
public SphereRegionSelector(@Nullable World world, Vector center, int radius) {
super(world, center, new Vector(radius, radius, radius));
}
@Override
public boolean selectSecondary(Vector pos) {
public boolean selectSecondary(Vector position, SelectorLimits limits) {
if (!started) {
return false;
}
final double radiusScalar = Math.ceil(pos.distance(region.getCenter()));
final double radiusScalar = Math.ceil(position.distance(region.getCenter()));
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
return true;
@ -106,19 +100,4 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
return "sphere";
}
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainPrimarySelection((Actor) player, session, position);
}
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position) {
explainSecondarySelection((Actor) player, session, position);
}
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
explainRegionAdjust((Actor) player, session);
}
}

Datei anzeigen

@ -0,0 +1,53 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector.limit;
import com.google.common.base.Optional;
/**
* No limits at all.
*/
public class PermissiveSelectorLimits implements SelectorLimits {
private static final PermissiveSelectorLimits INSTANCE = new PermissiveSelectorLimits();
private PermissiveSelectorLimits() {
}
@Override
public Optional<Integer> getPolygonVertexLimit() {
return Optional.absent();
}
@Override
public Optional<Integer> getPolyhedronVertexLimit() {
return Optional.absent();
}
/**
* Get a static instance.
*
* @return an instance
*/
public static PermissiveSelectorLimits getInstance() {
return INSTANCE;
}
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions.selector.limit;
import com.google.common.base.Optional;
/**
* Defines limits for selections.
*/
public interface SelectorLimits {
/**
* Get the optionally defined vertex limit for polygons.
*
* <p>If one is not present, then there is no limitation.</p>
*
* @return an optional vertex limit
*/
Optional<Integer> getPolygonVertexLimit();
/**
* Get the optionally defined vertex limit for polyhedrons.
*
* <p>If one is not present, then there is no limitation.</p>
*
* @return an optional vertex limit
*/
Optional<Integer> getPolyhedronVertexLimit();
}