geforkt von Mirrors/FastAsyncWorldEdit
Refactor RegionSelectors so limits are passed in during selection.
Dieser Commit ist enthalten in:
Ursprung
683bd670fe
Commit
c2a0f590b1
@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit.selections;
|
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.Vector;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
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 {
|
public class CuboidSelection extends RegionSelection {
|
||||||
|
|
||||||
@ -51,8 +52,8 @@ public class CuboidSelection extends RegionSelection {
|
|||||||
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
|
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
|
||||||
|
|
||||||
// set up selector
|
// set up selector
|
||||||
sel.selectPrimary(pt1);
|
sel.selectPrimary(pt1, PermissiveSelectorLimits.getInstance());
|
||||||
sel.selectSecondary(pt2);
|
sel.selectSecondary(pt2, PermissiveSelectorLimits.getInstance());
|
||||||
|
|
||||||
// set up CuboidSelection
|
// set up CuboidSelection
|
||||||
cuboid = sel.getIncompleteRegion();
|
cuboid = sel.getIncompleteRegion();
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
|
|||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
public abstract class ConvexPolyhedralRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
|
|||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
public abstract class CuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
|
|||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
public abstract class CylinderRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
|
|||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
public abstract class EllipsoidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions;
|
package com.sk89q.worldedit.regions;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
public abstract class ExtendingCuboidRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import com.sk89q.worldedit.internal.cui.CUIRegion;
|
|||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
public abstract class Polygonal2DRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of points.
|
* Get the number of points.
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions;
|
package com.sk89q.worldedit.regions;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated This class only exists as to not break binary compatibility
|
* @deprecated This class only exists as to not break binary compatibility
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract class SphereRegionSelector extends EllipsoidRegionSelector {
|
public abstract class SphereRegionSelector extends AbstractLegacyRegionSelector implements CUIRegion {
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* Checks to see if the specified radius is within bounds.
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
import com.sk89q.minecraft.util.commands.Command;
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||||
import com.sk89q.minecraft.util.commands.CommandException;
|
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.BaseBlock;
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
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.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||||
@ -93,7 +95,7 @@ public class SelectionCommands {
|
|||||||
pos = player.getBlockIn();
|
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.");
|
player.printError("Position already set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,7 +130,7 @@ public class SelectionCommands {
|
|||||||
pos = player.getBlockIn();
|
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.");
|
player.printError("Position already set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -150,8 +152,7 @@ public class SelectionCommands {
|
|||||||
Vector pos = player.getBlockTrace(300);
|
Vector pos = player.getBlockTrace(300);
|
||||||
|
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
if (!session.getRegionSelector(player.getWorld())
|
if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) {
|
||||||
.selectPrimary(pos)) {
|
|
||||||
player.printError("Position already set.");
|
player.printError("Position already set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -176,8 +177,7 @@ public class SelectionCommands {
|
|||||||
Vector pos = player.getBlockTrace(300);
|
Vector pos = player.getBlockTrace(300);
|
||||||
|
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
if (!session.getRegionSelector(player.getWorld())
|
if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) {
|
||||||
.selectSecondary(pos)) {
|
|
||||||
player.printError("Position already set.");
|
player.printError("Position already set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,6 @@ public class SelectionCommands {
|
|||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
@CommandPermissions("worldedit.selection.chunk")
|
@CommandPermissions("worldedit.selection.chunk")
|
||||||
public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||||
|
|
||||||
final Vector min;
|
final Vector min;
|
||||||
final Vector max;
|
final Vector max;
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
@ -254,8 +253,8 @@ public class SelectionCommands {
|
|||||||
} else {
|
} else {
|
||||||
selector = new CuboidRegionSelector(world);
|
selector = new CuboidRegionSelector(world);
|
||||||
}
|
}
|
||||||
selector.selectPrimary(min);
|
selector.selectPrimary(min, ActorSelectorLimits.forActor(player));
|
||||||
selector.selectSecondary(max);
|
selector.selectSecondary(max, ActorSelectorLimits.forActor(player));
|
||||||
session.setRegionSelector(world, selector);
|
session.setRegionSelector(world, selector);
|
||||||
|
|
||||||
session.dispatchCUISelection(player);
|
session.dispatchCUISelection(player);
|
||||||
@ -732,11 +731,11 @@ public class SelectionCommands {
|
|||||||
selector = new ExtendingCuboidRegionSelector(oldSelector);
|
selector = new ExtendingCuboidRegionSelector(oldSelector);
|
||||||
player.print("Cuboid: left click for a starting point, right click to extend");
|
player.print("Cuboid: left click for a starting point, right click to extend");
|
||||||
} else if (typeName.equalsIgnoreCase("poly")) {
|
} else if (typeName.equalsIgnoreCase("poly")) {
|
||||||
int maxPoints = we.getMaximumPolygonalPoints(player);
|
selector = new Polygonal2DRegionSelector(oldSelector);
|
||||||
selector = new Polygonal2DRegionSelector(oldSelector, maxPoints);
|
|
||||||
player.print("2D polygon selector: Left/right click to add a point.");
|
player.print("2D polygon selector: Left/right click to add a point.");
|
||||||
if (maxPoints > -1) {
|
Optional<Integer> limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit();
|
||||||
player.print(maxPoints + " points maximum.");
|
if (limit.isPresent()) {
|
||||||
|
player.print(limit.get() + " points maximum.");
|
||||||
}
|
}
|
||||||
} else if (typeName.equalsIgnoreCase("ellipsoid")) {
|
} else if (typeName.equalsIgnoreCase("ellipsoid")) {
|
||||||
selector = new EllipsoidRegionSelector(oldSelector);
|
selector = new EllipsoidRegionSelector(oldSelector);
|
||||||
@ -748,9 +747,12 @@ public class SelectionCommands {
|
|||||||
selector = new CylinderRegionSelector(oldSelector);
|
selector = new CylinderRegionSelector(oldSelector);
|
||||||
player.print("Cylindrical selector: Left click=center, right click to extend.");
|
player.print("Cylindrical selector: Left click=center, right click to extend.");
|
||||||
} else if (typeName.equalsIgnoreCase("convex") || typeName.equalsIgnoreCase("hull") || typeName.equalsIgnoreCase("polyhedron")) {
|
} else if (typeName.equalsIgnoreCase("convex") || typeName.equalsIgnoreCase("hull") || typeName.equalsIgnoreCase("polyhedron")) {
|
||||||
int maxVertices = we.getMaximumPolyhedronPoints(player);
|
selector = new ConvexPolyhedralRegionSelector(oldSelector);
|
||||||
selector = new ConvexPolyhedralRegionSelector(oldSelector, maxVertices);
|
|
||||||
player.print("Convex polyhedral selector: Left click=First vertex, right click to add more.");
|
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 {
|
} else {
|
||||||
player.printError("Only cuboid|extend|poly|ellipsoid|sphere|cyl|convex are accepted.");
|
player.printError("Only cuboid|extend|poly|ellipsoid|sphere|cyl|convex are accepted.");
|
||||||
return;
|
return;
|
||||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.*;
|
|||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extension.platform.Platform;
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
|
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +47,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
|
|||||||
if (target == null) return true;
|
if (target == null) return true;
|
||||||
|
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
if (selector.selectPrimary(target)) {
|
if (selector.selectPrimary(target, ActorSelectorLimits.forActor(player))) {
|
||||||
selector.explainPrimarySelection(player, session, target);
|
selector.explainPrimarySelection(player, session, target);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -63,7 +64,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
|
|||||||
if (target == null) return true;
|
if (target == null) return true;
|
||||||
|
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
if (selector.selectSecondary(target)) {
|
if (selector.selectSecondary(target, ActorSelectorLimits.forActor(player))) {
|
||||||
selector.explainSecondarySelection(player, session, target);
|
selector.explainSecondarySelection(player, session, target);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,6 +37,7 @@ import com.sk89q.worldedit.event.platform.Interaction;
|
|||||||
import com.sk89q.worldedit.event.platform.PlatformInitializeEvent;
|
import com.sk89q.worldedit.event.platform.PlatformInitializeEvent;
|
||||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||||
import com.sk89q.worldedit.event.platform.PlayerInputEvent;
|
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.internal.ServerInterfaceAdapter;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
@ -330,7 +331,7 @@ public class PlatformManager {
|
|||||||
|
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
|
|
||||||
if (selector.selectPrimary(location.toVector())) {
|
if (selector.selectPrimary(location.toVector(), ActorSelectorLimits.forActor(player))) {
|
||||||
selector.explainPrimarySelection(actor, session, vector);
|
selector.explainPrimarySelection(actor, session, vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +366,7 @@ public class PlatformManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
if (selector.selectSecondary(vector)) {
|
if (selector.selectSecondary(vector, ActorSelectorLimits.forActor(player))) {
|
||||||
selector.explainSecondarySelection(actor, session, vector);
|
selector.explainSecondarySelection(actor, session, vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,8 +19,12 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions;
|
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.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -37,7 +41,7 @@ public interface RegionSelector {
|
|||||||
* @param position the position
|
* @param position the position
|
||||||
* @return true if something changed
|
* @return true if something changed
|
||||||
*/
|
*/
|
||||||
public boolean selectPrimary(Vector position);
|
public boolean selectPrimary(Vector position, SelectorLimits limits);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the second point is selected.
|
* Called when the second point is selected.
|
||||||
@ -45,7 +49,7 @@ public interface RegionSelector {
|
|||||||
* @param position the position
|
* @param position the position
|
||||||
* @return true if something changed
|
* @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.
|
* 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);
|
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.
|
* 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);
|
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
|
* The the player information about the region's changes. This may resend
|
||||||
* all the defining region information if needed.
|
* all the defining region information if needed.
|
||||||
@ -80,9 +78,6 @@ public interface RegionSelector {
|
|||||||
*/
|
*/
|
||||||
public void explainRegionAdjust(Actor actor, LocalSession session);
|
public void explainRegionAdjust(Actor actor, LocalSession session);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the primary position.
|
* Get the primary position.
|
||||||
*
|
*
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions.selector;
|
package com.sk89q.worldedit.regions.selector;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.BlockVector2D;
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
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.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -46,30 +46,26 @@ import java.util.Map;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
||||||
|
|
||||||
private int maxVertices;
|
|
||||||
private final ConvexPolyhedralRegion region;
|
private final ConvexPolyhedralRegion region;
|
||||||
private BlockVector pos1;
|
private BlockVector pos1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated cast {@code world} to {@link World}
|
* Create a new selector with a {@code null} world.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public ConvexPolyhedralRegionSelector() {
|
||||||
public ConvexPolyhedralRegionSelector(@Nullable LocalWorld world, int maxVertices) {
|
this((World) null);
|
||||||
this((World) world, maxVertices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
* @param maxVertices the maximum number of vertices, where a number below 0 means unbounded
|
|
||||||
*/
|
*/
|
||||||
public ConvexPolyhedralRegionSelector(@Nullable World world, int maxVertices) {
|
public ConvexPolyhedralRegionSelector(@Nullable World world) {
|
||||||
this.maxVertices = maxVertices;
|
|
||||||
region = new ConvexPolyhedralRegion(world);
|
region = new ConvexPolyhedralRegion(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +73,10 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param oldSelector the old 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);
|
checkNotNull(oldSelector);
|
||||||
|
|
||||||
this.maxVertices = maxVertices;
|
|
||||||
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
|
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
|
||||||
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
|
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
|
||||||
|
|
||||||
@ -102,7 +96,7 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
|
|
||||||
region = new ConvexPolyhedralRegion(oldRegion.getWorld());
|
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(minY));
|
||||||
region.addVertex(pt.toVector(maxY));
|
region.addVertex(pt.toVector(maxY));
|
||||||
}
|
}
|
||||||
@ -112,19 +106,24 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
|
checkNotNull(position);
|
||||||
clear();
|
clear();
|
||||||
pos1 = pos.toBlockVector();
|
pos1 = position.toBlockVector();
|
||||||
return region.addVertex(pos);
|
return region.addVertex(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (maxVertices >= 0 && region.getVertices().size() > maxVertices) {
|
checkNotNull(position);
|
||||||
|
|
||||||
|
Optional<Integer> vertexLimit = limits.getPolyhedronVertexLimit();
|
||||||
|
|
||||||
|
if (vertexLimit.isPresent() && region.getVertices().size() > vertexLimit.get()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return region.addVertex(pos);
|
return region.addVertex(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -184,6 +183,10 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||||
|
checkNotNull(player);
|
||||||
|
checkNotNull(session);
|
||||||
|
checkNotNull(pos);
|
||||||
|
|
||||||
session.describeCUI(player);
|
session.describeCUI(player);
|
||||||
|
|
||||||
player.print("Started new selection with vertex "+pos+".");
|
player.print("Started new selection with vertex "+pos+".");
|
||||||
@ -191,17 +194,22 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||||
|
checkNotNull(player);
|
||||||
|
checkNotNull(session);
|
||||||
|
checkNotNull(pos);
|
||||||
|
|
||||||
session.describeCUI(player);
|
session.describeCUI(player);
|
||||||
|
|
||||||
player.print("Added vertex "+pos+" to the selection.");
|
player.print("Added vertex " + pos + " to the selection.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainRegionAdjust(Actor player, LocalSession session) {
|
public void explainRegionAdjust(Actor player, LocalSession session) {
|
||||||
|
checkNotNull(player);
|
||||||
|
checkNotNull(session);
|
||||||
session.describeCUI(player);
|
session.describeCUI(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProtocolVersion() {
|
public int getProtocolVersion() {
|
||||||
return 3;
|
return 3;
|
||||||
@ -214,6 +222,9 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeCUI(LocalSession session, Actor player) {
|
public void describeCUI(LocalSession session, Actor player) {
|
||||||
|
checkNotNull(player);
|
||||||
|
checkNotNull(session);
|
||||||
|
|
||||||
Collection<Vector> vertices = region.getVertices();
|
Collection<Vector> vertices = region.getVertices();
|
||||||
Collection<Triangle> triangles = region.getTriangles();
|
Collection<Triangle> triangles = region.getTriangles();
|
||||||
|
|
||||||
@ -240,25 +251,13 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeLegacyCUI(LocalSession session, Actor player) {
|
public void describeLegacyCUI(LocalSession session, Actor player) {
|
||||||
|
checkNotNull(player);
|
||||||
|
checkNotNull(session);
|
||||||
|
|
||||||
if (isDefined()) {
|
if (isDefined()) {
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
|||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -35,33 +36,25 @@ import java.util.List;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||||
|
|
||||||
protected BlockVector pos1;
|
protected BlockVector position1;
|
||||||
protected BlockVector pos2;
|
protected BlockVector position2;
|
||||||
protected CuboidRegion region;
|
protected CuboidRegion region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new region selector with no world.
|
* Create a new region selector with a {@code null} world.
|
||||||
*/
|
*/
|
||||||
public CuboidRegionSelector() {
|
public CuboidRegionSelector() {
|
||||||
this((World) null);
|
this((World) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated cast {@code world} to {@link World}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public CuboidRegionSelector(@Nullable LocalWorld world) {
|
|
||||||
this((World) world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new region selector.
|
* Create a new region selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
*/
|
*/
|
||||||
public CuboidRegionSelector(@Nullable World world) {
|
public CuboidRegionSelector(@Nullable World world) {
|
||||||
region = new CuboidRegion(world, new Vector(), new Vector());
|
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) {
|
public CuboidRegionSelector(RegionSelector oldSelector) {
|
||||||
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
|
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
|
||||||
|
|
||||||
if (oldSelector instanceof CuboidRegionSelector) {
|
if (oldSelector instanceof CuboidRegionSelector) {
|
||||||
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
|
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
|
||||||
|
|
||||||
pos1 = cuboidRegionSelector.pos1;
|
position1 = cuboidRegionSelector.position1;
|
||||||
pos2 = cuboidRegionSelector.pos2;
|
position2 = cuboidRegionSelector.position2;
|
||||||
} else {
|
} else {
|
||||||
final Region oldRegion;
|
final Region oldRegion;
|
||||||
try {
|
try {
|
||||||
@ -87,67 +81,67 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos1 = oldRegion.getMinimumPoint().toBlockVector();
|
position1 = oldRegion.getMinimumPoint().toBlockVector();
|
||||||
pos2 = oldRegion.getMaximumPoint().toBlockVector();
|
position2 = oldRegion.getMaximumPoint().toBlockVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated cast {@code world} to {@link World}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public CuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
|
|
||||||
this((World) world, pos1, pos2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new region selector with the given two positions.
|
* Create a new region selector with the given two positions.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world
|
||||||
* @param pos1 position 1
|
* @param position1 position 1
|
||||||
* @param pos2 position 2
|
* @param position2 position 2
|
||||||
*/
|
*/
|
||||||
public CuboidRegionSelector(@Nullable World world, Vector pos1, Vector pos2) {
|
public CuboidRegionSelector(@Nullable World world, Vector position1, Vector position2) {
|
||||||
this(world);
|
this(world);
|
||||||
checkNotNull(pos1);
|
checkNotNull(position1);
|
||||||
checkNotNull(pos2);
|
checkNotNull(position2);
|
||||||
this.pos1 = pos1.toBlockVector();
|
this.position1 = position1.toBlockVector();
|
||||||
this.pos2 = pos2.toBlockVector();
|
this.position2 = position2.toBlockVector();
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
if (pos1 != null && (pos.compareTo(pos1) == 0)) {
|
checkNotNull(position);
|
||||||
|
|
||||||
|
if (position1 != null && (position.compareTo(position1) == 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos1 = pos.toBlockVector();
|
position1 = position.toBlockVector();
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (pos2 != null && (pos.compareTo(pos2)) == 0) {
|
checkNotNull(position);
|
||||||
|
|
||||||
|
if (position2 != null && (position.compareTo(position2)) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos2 = pos.toBlockVector();
|
position2 = position.toBlockVector();
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) {
|
||||||
if (pos1 != null && pos2 != null) {
|
checkNotNull(player);
|
||||||
player.print("First position set to " + pos1 + " (" + region.getArea() + ").");
|
checkNotNull(session);
|
||||||
|
checkNotNull(pos);
|
||||||
|
|
||||||
|
if (position1 != null && position2 != null) {
|
||||||
|
player.print("First position set to " + position1 + " (" + region.getArea() + ").");
|
||||||
} else {
|
} else {
|
||||||
player.print("First position set to " + pos1 + ".");
|
player.print("First position set to " + position1 + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||||
@ -155,10 +149,14 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||||
if (pos1 != null && pos2 != null) {
|
checkNotNull(player);
|
||||||
player.print("Second position set to " + pos2 + " (" + region.getArea() + ").");
|
checkNotNull(session);
|
||||||
|
checkNotNull(pos);
|
||||||
|
|
||||||
|
if (position1 != null && position2 != null) {
|
||||||
|
player.print("Second position set to " + position2 + " (" + region.getArea() + ").");
|
||||||
} else {
|
} else {
|
||||||
player.print("Second position set to " + pos2 + ".");
|
player.print("Second position set to " + position2 + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||||
@ -166,32 +164,35 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void explainRegionAdjust(Actor player, LocalSession session) {
|
public void explainRegionAdjust(Actor player, LocalSession session) {
|
||||||
if (pos1 != null) {
|
checkNotNull(player);
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
checkNotNull(session);
|
||||||
|
|
||||||
|
if (position1 != null) {
|
||||||
|
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos2 != null) {
|
if (position2 != null) {
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||||
if (pos1 == null) {
|
if (position1 == null) {
|
||||||
throw new IncompleteRegionException();
|
throw new IncompleteRegionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos1;
|
return position1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefined() {
|
public boolean isDefined() {
|
||||||
return pos1 != null && pos2 != null;
|
return position1 != null && position2 != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CuboidRegion getRegion() throws IncompleteRegionException {
|
public CuboidRegion getRegion() throws IncompleteRegionException {
|
||||||
if (pos1 == null || pos2 == null) {
|
if (position1 == null || position2 == null) {
|
||||||
throw new IncompleteRegionException();
|
throw new IncompleteRegionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,14 +206,14 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void learnChanges() {
|
public void learnChanges() {
|
||||||
pos1 = region.getPos1().toBlockVector();
|
position1 = region.getPos1().toBlockVector();
|
||||||
pos2 = region.getPos2().toBlockVector();
|
position2 = region.getPos2().toBlockVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
pos1 = null;
|
position1 = null;
|
||||||
pos2 = null;
|
position2 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -224,12 +225,12 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
public List<String> getInformationLines() {
|
public List<String> getInformationLines() {
|
||||||
final List<String> lines = new ArrayList<String>();
|
final List<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
if (pos1 != null) {
|
if (position1 != null) {
|
||||||
lines.add("Position 1: " + pos1);
|
lines.add("Position 1: " + position1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos2 != null) {
|
if (position2 != null) {
|
||||||
lines.add("Position 2: " + pos2);
|
lines.add("Position 2: " + position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
@ -237,11 +238,11 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getArea() {
|
public int getArea() {
|
||||||
if (pos1 == null) {
|
if (position1 == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos2 == null) {
|
if (position2 == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,12 +251,12 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeCUI(LocalSession session, Actor player) {
|
public void describeCUI(LocalSession session, Actor player) {
|
||||||
if (pos1 != null) {
|
if (position1 != null) {
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos2 != null) {
|
if (position2 != null) {
|
||||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,20 +279,5 @@ public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegi
|
|||||||
public String getLegacyTypeID() {
|
public String getLegacyTypeID() {
|
||||||
return "cuboid";
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.internal.cui.*;
|
|||||||
import com.sk89q.worldedit.regions.CylinderRegion;
|
import com.sk89q.worldedit.regions.CylinderRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -35,7 +36,7 @@ import java.util.List;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
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() {
|
||||||
public CylinderRegionSelector(@Nullable LocalWorld world) {
|
this((World) null);
|
||||||
this((World) world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new region selector.
|
* Create a new region selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
*/
|
*/
|
||||||
public CylinderRegionSelector(@Nullable World world) {
|
public CylinderRegionSelector(@Nullable World world) {
|
||||||
region = new CylinderRegion(world);
|
region = new CylinderRegion(world);
|
||||||
@ -71,6 +71,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
|||||||
*/
|
*/
|
||||||
public CylinderRegionSelector(RegionSelector oldSelector) {
|
public CylinderRegionSelector(RegionSelector oldSelector) {
|
||||||
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
|
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
|
||||||
|
|
||||||
if (oldSelector instanceof CylinderRegionSelector) {
|
if (oldSelector instanceof CylinderRegionSelector) {
|
||||||
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
|
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
|||||||
* @param minY the minimum Y
|
* @param minY the minimum Y
|
||||||
* @param maxY the maximum 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);
|
this(world);
|
||||||
|
|
||||||
region.setCenter(center);
|
region.setCenter(center);
|
||||||
@ -115,30 +116,30 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) {
|
if (!region.getCenter().equals(Vector.ZERO) && position.compareTo(region.getCenter()) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
region = new CylinderRegion(region.getWorld());
|
region = new CylinderRegion(region.getWorld());
|
||||||
region.setCenter(pos.toVector2D());
|
region.setCenter(position.toVector2D());
|
||||||
region.setY(pos.getBlockY());
|
region.setY(position.getBlockY());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
Vector center = region.getCenter();
|
Vector center = region.getCenter();
|
||||||
if ((center.compareTo(Vector.ZERO)) == 0) {
|
if ((center.compareTo(Vector.ZERO)) == 0) {
|
||||||
return true;
|
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));
|
final Vector2D minRadius = Vector2D.getMaximum(diff, diff.multiply(-1.0));
|
||||||
region.extendRadius(minRadius);
|
region.extendRadius(minRadius);
|
||||||
|
|
||||||
region.setY(pos.getBlockY());
|
region.setY(position.getBlockY());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -153,6 +154,7 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
|||||||
@Override
|
@Override
|
||||||
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) {
|
||||||
Vector center = region.getCenter();
|
Vector center = region.getCenter();
|
||||||
|
|
||||||
if (!center.equals(Vector.ZERO)) {
|
if (!center.equals(Vector.ZERO)) {
|
||||||
player.print("Radius set to " + format.format(region.getRadius().getX()) + "/" + format.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ").");
|
player.print("Radius set to " + format.format(region.getRadius().getX()) + "/" + format.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ").");
|
||||||
} else {
|
} else {
|
||||||
@ -258,19 +260,4 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
|
|||||||
return "cuboid";
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
|||||||
import com.sk89q.worldedit.regions.EllipsoidRegion;
|
import com.sk89q.worldedit.regions.EllipsoidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -36,7 +37,7 @@ import java.util.List;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
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;
|
protected boolean started = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector with a {@code null} world.
|
||||||
*/
|
*/
|
||||||
public EllipsoidRegionSelector() {
|
public EllipsoidRegionSelector() {
|
||||||
this((World) null);
|
this((World) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated cast {@code world} to {@link World}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public EllipsoidRegionSelector(@Nullable LocalWorld world) {
|
|
||||||
this((World) world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
*/
|
*/
|
||||||
public EllipsoidRegionSelector(@Nullable World world) {
|
public EllipsoidRegionSelector(@Nullable World world) {
|
||||||
region = new EllipsoidRegion(world, new Vector(), new Vector());
|
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 center the center
|
||||||
* @param radius the radius
|
* @param radius the radius
|
||||||
*/
|
*/
|
||||||
public EllipsoidRegionSelector(@Nullable LocalWorld world, Vector center, Vector radius) {
|
public EllipsoidRegionSelector(@Nullable World world, Vector center, Vector radius) {
|
||||||
this(world);
|
this(world);
|
||||||
|
|
||||||
region.setCenter(center);
|
region.setCenter(center);
|
||||||
@ -110,12 +103,12 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
|
if (position.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
region.setCenter(pos.toBlockVector());
|
region.setCenter(position.toBlockVector());
|
||||||
region.setRadius(new Vector());
|
region.setRadius(new Vector());
|
||||||
started = true;
|
started = true;
|
||||||
|
|
||||||
@ -123,12 +116,12 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
return false;
|
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));
|
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
|
||||||
region.extendRadius(minRadius);
|
region.extendRadius(minRadius);
|
||||||
return true;
|
return true;
|
||||||
@ -249,19 +242,4 @@ public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.Ellipso
|
|||||||
return region.getCenter().toBlockVector();
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,29 +19,33 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions.selector;
|
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.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link RegionSelector} for {@link CuboidRegion}s that enlarges the
|
* Creates a {@code CuboidRegion} from a user's selections by expanding
|
||||||
* region with every secondary selection.
|
* the region on every right click.
|
||||||
*/
|
*/
|
||||||
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
public ExtendingCuboidRegionSelector(@Nullable LocalWorld world) {
|
* Create a new selector with a {@code null} world.
|
||||||
this((World) world);
|
*/
|
||||||
|
public ExtendingCuboidRegionSelector() {
|
||||||
|
super((World) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
*/
|
*/
|
||||||
public ExtendingCuboidRegionSelector(@Nullable World world) {
|
public ExtendingCuboidRegionSelector(@Nullable World world) {
|
||||||
super(world);
|
super(world);
|
||||||
@ -55,71 +59,71 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
|||||||
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
|
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
|
||||||
super(oldSelector);
|
super(oldSelector);
|
||||||
|
|
||||||
if (pos1 == null || pos2 == null) {
|
if (position1 == null || position2 == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos1 = region.getMinimumPoint().toBlockVector();
|
position1 = region.getMinimumPoint().toBlockVector();
|
||||||
pos2 = region.getMaximumPoint().toBlockVector();
|
position2 = region.getMaximumPoint().toBlockVector();
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world
|
||||||
* @param pos1 the first position
|
* @param position1 the first position
|
||||||
* @param pos2 the second 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);
|
this(world);
|
||||||
pos1 = Vector.getMinimum(pos1, pos2);
|
position1 = Vector.getMinimum(position1, position2);
|
||||||
pos2 = Vector.getMaximum(pos1, pos2);
|
position2 = Vector.getMaximum(position1, position2);
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
if (pos1 != null && pos2 != null && pos.compareTo(pos1) == 0 && pos.compareTo(pos2) == 0) {
|
if (position1 != null && position2 != null && position.compareTo(position1) == 0 && position.compareTo(position2) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos1 = pos2 = pos.toBlockVector();
|
position1 = position2 = position.toBlockVector();
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (pos1 == null || pos2 == null) {
|
if (position1 == null || position2 == null) {
|
||||||
return selectPrimary(pos);
|
return selectPrimary(position, limits);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region.contains(pos)) {
|
if (region.contains(position)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double x1 = Math.min(pos.getX(), pos1.getX());
|
double x1 = Math.min(position.getX(), position1.getX());
|
||||||
double y1 = Math.min(pos.getY(), pos1.getY());
|
double y1 = Math.min(position.getY(), position1.getY());
|
||||||
double z1 = Math.min(pos.getZ(), pos1.getZ());
|
double z1 = Math.min(position.getZ(), position1.getZ());
|
||||||
|
|
||||||
double x2 = Math.max(pos.getX(), pos2.getX());
|
double x2 = Math.max(position.getX(), position2.getX());
|
||||||
double y2 = Math.max(pos.getY(), pos2.getY());
|
double y2 = Math.max(position.getY(), position2.getY());
|
||||||
double z2 = Math.max(pos.getZ(), pos2.getZ());
|
double z2 = Math.max(position.getZ(), position2.getZ());
|
||||||
|
|
||||||
final BlockVector o1 = pos1;
|
final BlockVector o1 = position1;
|
||||||
final BlockVector o2 = pos2;
|
final BlockVector o2 = position2;
|
||||||
pos1 = new BlockVector(x1, y1, z1);
|
position1 = new BlockVector(x1, y1, z1);
|
||||||
pos2 = new BlockVector(x2, y2, z2);
|
position2 = new BlockVector(x2, y2, z2);
|
||||||
region.setPos1(pos1);
|
region.setPos1(position1);
|
||||||
region.setPos2(pos2);
|
region.setPos2(position2);
|
||||||
|
|
||||||
assert(region.contains(o1));
|
assert(region.contains(o1));
|
||||||
assert(region.contains(o2));
|
assert(region.contains(o2));
|
||||||
assert(region.contains(pos));
|
assert(region.contains(position));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -138,19 +142,4 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
|||||||
explainRegionAdjust(player, session);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions.selector;
|
package com.sk89q.worldedit.regions.selector;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
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.Polygonal2DRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -37,57 +39,37 @@ import java.util.List;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 {
|
public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||||
|
|
||||||
private int maxPoints;
|
|
||||||
private BlockVector pos1;
|
private BlockVector pos1;
|
||||||
private Polygonal2DRegion region;
|
private Polygonal2DRegion region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #Polygonal2DRegionSelector(LocalWorld, int)}
|
* Create a new selector with a {@code null} world.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public Polygonal2DRegionSelector() {
|
||||||
public Polygonal2DRegionSelector(@Nullable LocalWorld world) {
|
this((World) null);
|
||||||
this(world, 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated cast {@code world} to {@link World}
|
* Create a new selector with the given world.
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Polygonal2DRegionSelector(@Nullable LocalWorld world, int maxPoints) {
|
|
||||||
this((World) world, maxPoints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new selector.
|
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world
|
||||||
* @param maxPoints the maximum number of points
|
|
||||||
*/
|
*/
|
||||||
public Polygonal2DRegionSelector(@Nullable World world, int maxPoints) {
|
public Polygonal2DRegionSelector(@Nullable World world) {
|
||||||
this.maxPoints = maxPoints;
|
|
||||||
region = new Polygonal2DRegion(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.
|
* Create a new selector from another one.
|
||||||
*
|
*
|
||||||
* @param oldSelector the old selector
|
* @param oldSelector the old selector
|
||||||
* @param maxPoints the maximum number of points
|
|
||||||
*/
|
*/
|
||||||
public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
|
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
|
||||||
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld(), maxPoints);
|
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
|
||||||
|
|
||||||
if (oldSelector instanceof Polygonal2DRegionSelector) {
|
if (oldSelector instanceof Polygonal2DRegionSelector) {
|
||||||
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
|
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 minY = oldRegion.getMinimumPoint().getBlockY();
|
||||||
final int maxY = oldRegion.getMaximumPoint().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();
|
pos1 = points.get(0).toVector(minY).toBlockVector();
|
||||||
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
|
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
|
||||||
@ -136,36 +118,38 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectPrimary(Vector pos) {
|
public boolean selectPrimary(Vector position, SelectorLimits limits) {
|
||||||
if (pos.equals(pos1)) {
|
if (position.equals(pos1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos1 = pos.toBlockVector();
|
pos1 = position.toBlockVector();
|
||||||
region = new Polygonal2DRegion(region.getWorld());
|
region = new Polygonal2DRegion(region.getWorld());
|
||||||
region.addPoint(pos);
|
region.addPoint(position);
|
||||||
region.expandY(pos.getBlockY());
|
region.expandY(position.getBlockY());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (region.size() > 0) {
|
if (region.size() > 0) {
|
||||||
final List<BlockVector2D> points = region.getPoints();
|
final List<BlockVector2D> points = region.getPoints();
|
||||||
|
|
||||||
final BlockVector2D lastPoint = points.get(region.size() - 1);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxPoints >= 0 && points.size() > maxPoints) {
|
Optional<Integer> vertexLimit = limits.getPolygonVertexLimit();
|
||||||
|
|
||||||
|
if (vertexLimit.isPresent() && points.size() > vertexLimit.get()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
region.addPoint(pos);
|
region.addPoint(position);
|
||||||
region.expandY(pos.getBlockY());
|
region.expandY(position.getBlockY());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -288,19 +272,4 @@ public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polyg
|
|||||||
return "polygon2d";
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,42 +19,36 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.regions.selector;
|
package com.sk89q.worldedit.regions.selector;
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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 {
|
public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
public SphereRegionSelector(@Nullable LocalWorld world) {
|
* Create a new selector with a {@code null world}.
|
||||||
this((World) world);
|
*/
|
||||||
|
public SphereRegionSelector() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector.
|
* Create a new selector.
|
||||||
*
|
*
|
||||||
* @param world the world
|
* @param world the world, which may be {@code null}
|
||||||
*/
|
*/
|
||||||
public SphereRegionSelector(@Nullable World world) {
|
public SphereRegionSelector(@Nullable World world) {
|
||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new selector.
|
|
||||||
*/
|
|
||||||
public SphereRegionSelector() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new selector from another one
|
* Create a new selector from another one
|
||||||
*
|
*
|
||||||
@ -74,17 +68,17 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
|||||||
* @param center the center position
|
* @param center the center position
|
||||||
* @param radius the radius
|
* @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));
|
super(world, center, new Vector(radius, radius, radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean selectSecondary(Vector pos) {
|
public boolean selectSecondary(Vector position, SelectorLimits limits) {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
return false;
|
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));
|
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -106,19 +100,4 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
|||||||
return "sphere";
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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();
|
||||||
|
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren