3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-27 03:12:37 +01:00

Added back old region selector classes as deprecated.

Dieser Commit ist enthalten in:
sk89q 2014-04-04 13:57:27 -07:00
Ursprung 8722104565
Commit 3294431e00
15 geänderte Dateien mit 580 neuen und 162 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,29 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CuboidRegionSelector implements RegionSelector, CUIRegion {
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class CylinderRegionSelector implements RegionSelector, CUIRegion {
}

Datei anzeigen

@ -0,0 +1,29 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
}

Datei anzeigen

@ -0,0 +1,27 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.internal.cui.CUIRegion;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
/**
* Get the number of points.
*
* @return the number of points
*/
public abstract int getPointCount();
}

Datei anzeigen

@ -0,0 +1,27 @@
/*
* 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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.regions;
/**
* @deprecated This class only exists as to not break binary compatibility
*/
@Deprecated
public abstract class SphereRegionSelector extends EllipsoidRegionSelector {
}

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
@ -24,90 +24,89 @@ import com.sk89q.worldedit.*;
import java.util.List; import java.util.List;
/** /**
* Region selection factory. * Region selectors create {@link Region}s from a series of "selected points."
* * They are used, for example, to allow users to create a {@link CuboidRegion}
* @author sk89q * by selecting two corners of the cuboid.
*/ */
public interface RegionSelector { public interface RegionSelector {
/** /**
* Called when the first point is selected. * Called when the first point is selected.
* *
* @param pos * @param position the position
* @return true if something changed * @return true if something changed
*/ */
public boolean selectPrimary(Vector pos); public boolean selectPrimary(Vector position);
/** /**
* Called when the second point is selected. * Called when the second point is selected.
* *
* @param pos * @param position the position
* @return true if something changed * @return true if something changed
*/ */
public boolean selectSecondary(Vector pos); public boolean selectSecondary(Vector position);
/** /**
* Tell the player information about his/her primary selection. * Tell the player information about his/her primary selection.
* *
* @param player * @param player the player
* @param session * @param session the session
* @param pos * @param position position
*/ */
public void explainPrimarySelection(LocalPlayer player, public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector position);
LocalSession session, Vector pos);
/** /**
* Tell the player information about his/her secondary selection. * Tell the player information about his/her secondary selection.
* *
* @param player * @param player the player
* @param session * @param session the session
* @param pos * @param position position
*/ */
public void explainSecondarySelection(LocalPlayer player, public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector position);
LocalSession session, Vector pos);
/** /**
* 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.
* *
* @param player * @param player the player
* @param session * @param session the session
*/ */
public void explainRegionAdjust(LocalPlayer player, LocalSession session); public void explainRegionAdjust(LocalPlayer player, LocalSession session);
/** /**
* Get the primary position. * Get the primary position.
* *
* @return * @return the primary position
* @throws IncompleteRegionException * @throws IncompleteRegionException thrown if a region has not been fully defined
*/ */
public BlockVector getPrimaryPosition() throws IncompleteRegionException; public BlockVector getPrimaryPosition() throws IncompleteRegionException;
/** /**
* Get the selection. * Get the selection.
* *
* @return * @return the created region
* @throws IncompleteRegionException * @throws IncompleteRegionException thrown if a region has not been fully defined
*/ */
public Region getRegion() throws IncompleteRegionException; public Region getRegion() throws IncompleteRegionException;
/** /**
* Get the region even if it's not fully defined. * Get the region even if it's not fully defined.
* *
* @return * @return an incomplete region object that is incomplete
*/ */
public Region getIncompleteRegion(); public Region getIncompleteRegion();
/** /**
* Returns whether the region has been fully defined. * Returns whether the region has been fully defined.
* *
* @return * @return true if a selection is available
*/ */
public boolean isDefined(); public boolean isDefined();
/** /**
* Get the number of blocks inside the region. * Get the number of blocks inside the region.
* *
* @return number of blocks or -1 if undefined * @return number of blocks, or -1 if undefined
*/ */
public int getArea(); public int getArea();
@ -124,14 +123,15 @@ public interface RegionSelector {
/** /**
* Get a lowercase name of this region selector type. * Get a lowercase name of this region selector type.
* *
* @return * @return a lower case name of the type
*/ */
public String getTypeName(); public String getTypeName();
/** /**
* Get lines of information about the selection. * Get lines of information about the selection.
* *
* @return * @return a list of lines describing the region
*/ */
public List<String> getInformationLines(); public List<String> getInformationLines();
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,22 +15,11 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import java.util.ArrayList; import com.sk89q.worldedit.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent; import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
@ -41,17 +30,40 @@ 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;
public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion { import javax.annotation.Nullable;
import java.util.*;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A {@link RegionSelector} for {@link ConvexPolyhedralRegion}s.
*/
public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion {
private int maxVertices; private int maxVertices;
private final ConvexPolyhedralRegion region; private final ConvexPolyhedralRegion region;
private BlockVector pos1; private BlockVector pos1;
public ConvexPolyhedralRegionSelector(LocalWorld world, int maxVertices) { /**
* Create a new selector.
*
* @param world the world
* @param maxVertices the maximum number of vertices, where a number below 0 means unbounded
*/
public ConvexPolyhedralRegionSelector(@Nullable LocalWorld world, int maxVertices) {
this.maxVertices = maxVertices; this.maxVertices = maxVertices;
region = new ConvexPolyhedralRegion(world); region = new ConvexPolyhedralRegion(world);
} }
/**
* 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, int maxVertices) {
checkNotNull(oldSelector);
this.maxVertices = maxVertices; this.maxVertices = maxVertices;
if (oldSelector instanceof ConvexPolyhedralRegionSelector) { if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector; final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
@ -219,4 +231,5 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID())); session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
} }
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,44 +15,55 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import java.util.ArrayList; import com.sk89q.worldedit.*;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent; 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 javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Selector for cuboids. * A {@link RegionSelector} for {@link CuboidRegion}s.
*
* @author sk89q
*/ */
public class CuboidRegionSelector implements RegionSelector, CUIRegion { public class CuboidRegionSelector extends com.sk89q.worldedit.regions.CuboidRegionSelector implements RegionSelector, CUIRegion {
protected BlockVector pos1; protected BlockVector pos1;
protected BlockVector pos2; protected BlockVector pos2;
protected CuboidRegion region; protected CuboidRegion region;
public CuboidRegionSelector(LocalWorld world) { /**
region = new CuboidRegion(world, new Vector(), new Vector()); * Create a new region selector with no world.
} */
public CuboidRegionSelector() { public CuboidRegionSelector() {
this((LocalWorld) null); this((LocalWorld) null);
} }
/**
* Create a new region selector.
*
* @param world the world
*/
public CuboidRegionSelector(@Nullable LocalWorld world) {
region = new CuboidRegion(world, new Vector(), new Vector());
}
/**
* Create a copy of another selector.
*
* @param oldSelector another selector
*/
public CuboidRegionSelector(RegionSelector oldSelector) { public CuboidRegionSelector(RegionSelector oldSelector) {
this(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;
@ -74,14 +85,25 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
region.setPos2(pos2); region.setPos2(pos2);
} }
public CuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) { /**
* Create a new region selector with the given two positions.
*
* @param world the world
* @param pos1 position 1
* @param pos2 position 2
*/
public CuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
this(world); this(world);
checkNotNull(world);
checkNotNull(pos1);
checkNotNull(pos2);
this.pos1 = pos1.toBlockVector(); this.pos1 = pos1.toBlockVector();
this.pos2 = pos2.toBlockVector(); this.pos2 = pos2.toBlockVector();
region.setPos1(pos1); region.setPos1(pos1);
region.setPos2(pos2); region.setPos2(pos2);
} }
@Override
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos1 != null && (pos.compareTo(pos1) == 0)) { if (pos1 != null && (pos.compareTo(pos1) == 0)) {
return false; return false;
@ -92,6 +114,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
if (pos2 != null && (pos.compareTo(pos2)) == 0) { if (pos2 != null && (pos.compareTo(pos2)) == 0) {
return false; return false;
@ -102,6 +125,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
if (pos1 != null && pos2 != null) { if (pos1 != null && pos2 != null) {
player.print("First position set to " + pos1 + " (" + region.getArea() + ")."); player.print("First position set to " + pos1 + " (" + region.getArea() + ").");
@ -112,6 +136,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
} }
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
if (pos1 != null && pos2 != null) { if (pos1 != null && pos2 != null) {
player.print("Second position set to " + pos2 + " (" + region.getArea() + ")."); player.print("Second position set to " + pos2 + " (" + region.getArea() + ").");
@ -122,6 +147,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
} }
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) { public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
if (pos1 != null) { if (pos1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
@ -132,6 +158,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
} }
} }
@Override
public BlockVector getPrimaryPosition() throws IncompleteRegionException { public BlockVector getPrimaryPosition() throws IncompleteRegionException {
if (pos1 == null) { if (pos1 == null) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -140,10 +167,12 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return pos1; return pos1;
} }
@Override
public boolean isDefined() { public boolean isDefined() {
return pos1 != null && pos2 != null; return pos1 != null && pos2 != null;
} }
@Override
public CuboidRegion getRegion() throws IncompleteRegionException { public CuboidRegion getRegion() throws IncompleteRegionException {
if (pos1 == null || pos2 == null) { if (pos1 == null || pos2 == null) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -152,24 +181,29 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return region; return region;
} }
@Override
public CuboidRegion getIncompleteRegion() { public CuboidRegion getIncompleteRegion() {
return region; return region;
} }
@Override
public void learnChanges() { public void learnChanges() {
pos1 = region.getPos1().toBlockVector(); pos1 = region.getPos1().toBlockVector();
pos2 = region.getPos2().toBlockVector(); pos2 = region.getPos2().toBlockVector();
} }
@Override
public void clear() { public void clear() {
pos1 = null; pos1 = null;
pos2 = null; pos2 = null;
} }
@Override
public String getTypeName() { public String getTypeName() {
return "cuboid"; return "cuboid";
} }
@Override
public List<String> getInformationLines() { public List<String> getInformationLines() {
final List<String> lines = new ArrayList<String>(); final List<String> lines = new ArrayList<String>();
@ -184,6 +218,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return lines; return lines;
} }
@Override
public int getArea() { public int getArea() {
if (pos1 == null) { if (pos1 == null) {
return -1; return -1;
@ -196,6 +231,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
return region.getArea(); return region.getArea();
} }
@Override
public void describeCUI(LocalSession session, LocalPlayer player) { public void describeCUI(LocalSession session, LocalPlayer player) {
if (pos1 != null) { if (pos1 != null) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
@ -206,18 +242,22 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
} }
} }
@Override
public void describeLegacyCUI(LocalSession session, LocalPlayer player) { public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
describeCUI(session, player); describeCUI(session, player);
} }
@Override
public int getProtocolVersion() { public int getProtocolVersion() {
return 0; return 0;
} }
@Override
public String getTypeID() { public String getTypeID() {
return "cuboid"; return "cuboid";
} }
@Override
public String getLegacyTypeID() { public String getLegacyTypeID() {
return "cuboid"; return "cuboid";
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,36 +15,28 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import java.util.ArrayList; import com.sk89q.worldedit.*;
import java.util.List; import com.sk89q.worldedit.internal.cui.*;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionCylinderEvent;
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.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 javax.annotation.Nullable;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Selector for polygonal regions. * A {@link RegionSelector} for {@link CylinderRegion}s.
*
* @author sk89q
*/ */
public class CylinderRegionSelector implements RegionSelector, CUIRegion { public class CylinderRegionSelector extends com.sk89q.worldedit.regions.CylinderRegionSelector implements RegionSelector, CUIRegion {
protected CylinderRegion region; protected CylinderRegion region;
protected static final NumberFormat format; protected static final NumberFormat format;
@ -53,12 +45,22 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
format.setMaximumFractionDigits(3); format.setMaximumFractionDigits(3);
} }
public CylinderRegionSelector(LocalWorld world) { /**
* Create a new region selector.
*
* @param world the world
*/
public CylinderRegionSelector(@Nullable LocalWorld world) {
region = new CylinderRegion(world); region = new CylinderRegion(world);
} }
/**
* Create a new selector from the given one.
*
* @param oldSelector the old selector
*/
public CylinderRegionSelector(RegionSelector oldSelector) { public CylinderRegionSelector(RegionSelector oldSelector) {
this(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;
@ -83,7 +85,16 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public CylinderRegionSelector(LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) { /**
* Create a new selector.
*
* @param world the world
* @param center the center
* @param radius the radius
* @param minY the minimum Y
* @param maxY the maximum Y
*/
public CylinderRegionSelector(@Nullable LocalWorld world, Vector2D center, Vector2D radius, int minY, int maxY) {
this(world); this(world);
region.setCenter(center); region.setCenter(center);
@ -93,6 +104,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
region.setMaximumY(Math.max(minY, maxY)); region.setMaximumY(Math.max(minY, maxY));
} }
@Override
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) { if (!region.getCenter().equals(Vector.ZERO) && pos.compareTo(region.getCenter()) == 0) {
return false; return false;
@ -105,6 +117,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
Vector center = region.getCenter(); Vector center = region.getCenter();
if ((center.compareTo(Vector.ZERO)) == 0) { if ((center.compareTo(Vector.ZERO)) == 0) {
@ -120,12 +133,14 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
player.print("Starting a new cylindrical selection at " + pos + "."); player.print("Starting a new cylindrical selection at " + pos + ".");
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
Vector center = region.getCenter(); Vector center = region.getCenter();
if (!center.equals(Vector.ZERO)) { if (!center.equals(Vector.ZERO)) {
@ -138,10 +153,12 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) { public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public BlockVector getPrimaryPosition() throws IncompleteRegionException { public BlockVector getPrimaryPosition() throws IncompleteRegionException {
if (!isDefined()) { if (!isDefined()) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -150,6 +167,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
return region.getCenter().toBlockVector(); return region.getCenter().toBlockVector();
} }
@Override
public CylinderRegion getRegion() throws IncompleteRegionException { public CylinderRegion getRegion() throws IncompleteRegionException {
if (!isDefined()) { if (!isDefined()) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -158,25 +176,31 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
return region; return region;
} }
@Override
public CylinderRegion getIncompleteRegion() { public CylinderRegion getIncompleteRegion() {
return region; return region;
} }
@Override
public boolean isDefined() { public boolean isDefined() {
return !region.getRadius().equals(Vector2D.ZERO); return !region.getRadius().equals(Vector2D.ZERO);
} }
@Override
public void learnChanges() { public void learnChanges() {
} }
@Override
public void clear() { public void clear() {
region = new CylinderRegion(region.getWorld()); region = new CylinderRegion(region.getWorld());
} }
@Override
public String getTypeName() { public String getTypeName() {
return "Cylinder"; return "Cylinder";
} }
@Override
public List<String> getInformationLines() { public List<String> getInformationLines() {
final List<String> lines = new ArrayList<String>(); final List<String> lines = new ArrayList<String>();
@ -190,15 +214,18 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
return lines; return lines;
} }
@Override
public int getArea() { public int getArea() {
return region.getArea(); return region.getArea();
} }
@Override
public void describeCUI(LocalSession session, LocalPlayer player) { public void describeCUI(LocalSession session, LocalPlayer player) {
session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter(), region.getRadius())); session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter(), region.getRadius()));
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
} }
@Override
public void describeLegacyCUI(LocalSession session, LocalPlayer player) { public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
if (isDefined()) { if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
@ -208,15 +235,19 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
} }
} }
@Override
public int getProtocolVersion() { public int getProtocolVersion() {
return 1; return 1;
} }
@Override
public String getTypeID() { public String getTypeID() {
return "cylinder"; return "cylinder";
} }
@Override
public String getLegacyTypeID() { public String getLegacyTypeID() {
return "cuboid"; return "cuboid";
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,18 +15,11 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import java.util.ArrayList; import com.sk89q.worldedit.*;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent; import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent;
import com.sk89q.worldedit.internal.cui.SelectionPointEvent; import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
@ -34,24 +27,42 @@ 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 javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Selector for ellipsoids. * A {@link RegionSelector} for {@link EllipsoidRegion}s.
*
* @author TomyLobo
*/ */
public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { public class EllipsoidRegionSelector extends com.sk89q.worldedit.regions.EllipsoidRegionSelector implements RegionSelector, CUIRegion {
protected EllipsoidRegion region; protected EllipsoidRegion region;
public EllipsoidRegionSelector(LocalWorld world) { /**
* Create a new selector.
*
* @param world the world
*/
public EllipsoidRegionSelector(@Nullable LocalWorld world) {
region = new EllipsoidRegion(world, new Vector(), new Vector()); region = new EllipsoidRegion(world, new Vector(), new Vector());
} }
/**
* Create a new selector.
*/
public EllipsoidRegionSelector() { public EllipsoidRegionSelector() {
this((LocalWorld) null); this((LocalWorld) null);
} }
/**
* Create a new selector from the given selector.
*
* @param oldSelector the old selector
*/
public EllipsoidRegionSelector(RegionSelector oldSelector) { public EllipsoidRegionSelector(RegionSelector oldSelector) {
this(oldSelector.getIncompleteRegion().getWorld()); this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof EllipsoidRegionSelector) { if (oldSelector instanceof EllipsoidRegionSelector) {
final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector; final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;
@ -73,13 +84,21 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public EllipsoidRegionSelector(LocalWorld world, Vector center, Vector radius) { /**
* Create a new selector.
*
* @param world the world
* @param center the center
* @param radius the radius
*/
public EllipsoidRegionSelector(@Nullable LocalWorld world, Vector center, Vector radius) {
this(world); this(world);
region.setCenter(center); region.setCenter(center);
region.setRadius(radius); region.setRadius(radius);
} }
@Override
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) { if (pos.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
return false; return false;
@ -90,6 +109,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
final Vector diff = pos.subtract(region.getCenter()); final Vector diff = pos.subtract(region.getCenter());
final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0)); final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0));
@ -97,6 +117,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
if (isDefined()) { if (isDefined()) {
player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ")."); player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ").");
@ -107,6 +128,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
if (isDefined()) { if (isDefined()) {
player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ")."); player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ").");
@ -117,14 +139,17 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) { public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
session.describeCUI(player); session.describeCUI(player);
} }
@Override
public boolean isDefined() { public boolean isDefined() {
return region.getRadius().lengthSq() > 0; return region.getRadius().lengthSq() > 0;
} }
@Override
public EllipsoidRegion getRegion() throws IncompleteRegionException { public EllipsoidRegion getRegion() throws IncompleteRegionException {
if (!isDefined()) { if (!isDefined()) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -133,22 +158,27 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
return region; return region;
} }
@Override
public EllipsoidRegion getIncompleteRegion() { public EllipsoidRegion getIncompleteRegion() {
return region; return region;
} }
@Override
public void learnChanges() { public void learnChanges() {
} }
@Override
public void clear() { public void clear() {
region.setCenter(new Vector()); region.setCenter(new Vector());
region.setRadius(new Vector()); region.setRadius(new Vector());
} }
@Override
public String getTypeName() { public String getTypeName() {
return "ellipsoid"; return "ellipsoid";
} }
@Override
public List<String> getInformationLines() { public List<String> getInformationLines() {
final List<String> lines = new ArrayList<String>(); final List<String> lines = new ArrayList<String>();
@ -165,28 +195,34 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
return lines; return lines;
} }
@Override
public int getArea() { public int getArea() {
return region.getArea(); return region.getArea();
} }
@Override
public void describeCUI(LocalSession session, LocalPlayer player) { public void describeCUI(LocalSession session, LocalPlayer player) {
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter())); session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter()));
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius())); session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
} }
@Override
public void describeLegacyCUI(LocalSession session, LocalPlayer player) { public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
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 String getLegacyTypeID() { public String getLegacyTypeID() {
return "cuboid"; return "cuboid";
} }
@Override
public int getProtocolVersion() { public int getProtocolVersion() {
return 1; return 1;
} }
@Override
public String getTypeID() { public String getTypeID() {
return "ellipsoid"; return "ellipsoid";
} }
@ -195,4 +231,5 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
public BlockVector getPrimaryPosition() throws IncompleteRegionException { public BlockVector getPrimaryPosition() throws IncompleteRegionException {
return region.getCenter().toBlockVector(); return region.getCenter().toBlockVector();
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,27 +15,36 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import javax.annotation.Nullable;
/** /**
* Alternative selector for cuboids. * A {@link RegionSelector} for {@link CuboidRegion}s that enlarges the
* * region with every secondary selection.
* @author sk89q
*/ */
public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
public ExtendingCuboidRegionSelector(LocalWorld world) {
/**
* Create a new selector.
*
* @param world the world
*/
public ExtendingCuboidRegionSelector(@Nullable LocalWorld world) {
super(world); super(world);
} }
/**
* Create a new selector from another one.
*
* @param oldSelector the other selector
*/
public ExtendingCuboidRegionSelector(RegionSelector oldSelector) { public ExtendingCuboidRegionSelector(RegionSelector oldSelector) {
super(oldSelector); super(oldSelector);
@ -49,7 +58,14 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
region.setPos2(pos2); region.setPos2(pos2);
} }
public ExtendingCuboidRegionSelector(LocalWorld world, Vector pos1, Vector pos2) { /**
* Create a new selector.
*
* @param world the world
* @param pos1 the first position
* @param pos2 the second position
*/
public ExtendingCuboidRegionSelector(@Nullable LocalWorld world, Vector pos1, Vector pos2) {
this(world); this(world);
pos1 = Vector.getMinimum(pos1, pos2); pos1 = Vector.getMinimum(pos1, pos2);
pos2 = Vector.getMaximum(pos1, pos2); pos2 = Vector.getMaximum(pos1, pos2);
@ -114,4 +130,5 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
explainRegionAdjust(player, session); explainRegionAdjust(player, session);
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,19 +15,11 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
import java.util.Collections; import com.sk89q.worldedit.*;
import java.util.List;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent; import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent;
import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent; import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent;
@ -36,33 +28,56 @@ 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 javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Selector for polygonal regions. * A {@link RegionSelector} for {@link Polygonal2DRegion}s.
*
* @author sk89q
*/ */
public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { public class Polygonal2DRegionSelector extends com.sk89q.worldedit.regions.Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
private int maxPoints; private int maxPoints;
private BlockVector pos1; private BlockVector pos1;
private Polygonal2DRegion region; private Polygonal2DRegion region;
/**
* @deprecated Use {@link #Polygonal2DRegionSelector(LocalWorld, int)}
*/
@Deprecated @Deprecated
public Polygonal2DRegionSelector(LocalWorld world) { public Polygonal2DRegionSelector(@Nullable LocalWorld world) {
this(world, 50); this(world, 50);
} }
public Polygonal2DRegionSelector(LocalWorld world, int maxPoints) { /**
* Create a new selector.
*
* @param world the world
* @param maxPoints the maximum number of points
*/
public Polygonal2DRegionSelector(@Nullable LocalWorld world, int maxPoints) {
this.maxPoints = maxPoints; this.maxPoints = maxPoints;
region = new Polygonal2DRegion(world); region = new Polygonal2DRegion(world);
} }
/**
* @deprecated Use {@link #Polygonal2DRegionSelector(RegionSelector, int)}
*/
@Deprecated @Deprecated
public Polygonal2DRegionSelector(RegionSelector oldSelector) { public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(oldSelector, 50); 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) { public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) {
this(oldSelector.getIncompleteRegion().getWorld(), maxPoints); this(checkNotNull(oldSelector).getIncompleteRegion().getWorld(), maxPoints);
if (oldSelector instanceof Polygonal2DRegionSelector) { if (oldSelector instanceof Polygonal2DRegionSelector) {
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector; final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
@ -86,12 +101,23 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
} }
} }
public Polygonal2DRegionSelector(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) { /**
* Create a new selector.
*
* @param world the world
* @param points a list of points
* @param minY the minimum Y
* @param maxY the maximum Y
*/
public Polygonal2DRegionSelector(@Nullable LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
checkNotNull(points);
final BlockVector2D pos2D = points.get(0); final BlockVector2D pos2D = points.get(0);
pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ()); pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
region = new Polygonal2DRegion(world, points, minY, maxY); region = new Polygonal2DRegion(world, points, minY, maxY);
} }
@Override
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1)) { if (pos.equals(pos1)) {
return false; return false;
@ -105,6 +131,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public boolean selectSecondary(Vector pos) { public boolean selectSecondary(Vector pos) {
if (region.size() > 0) { if (region.size() > 0) {
final List<BlockVector2D> points = region.getPoints(); final List<BlockVector2D> points = region.getPoints();
@ -125,6 +152,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
return true; return true;
} }
@Override
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
player.print("Starting a new polygon at " + pos + "."); player.print("Starting a new polygon at " + pos + ".");
@ -133,6 +161,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
} }
@Override
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) { public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
player.print("Added point #" + region.size() + " at " + pos + "."); player.print("Added point #" + region.size() + " at " + pos + ".");
@ -140,11 +169,13 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
} }
@Override
public void explainRegionAdjust(LocalPlayer player, LocalSession session) { public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID())); session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
describeCUI(session, player); describeCUI(session, player);
} }
@Override
public BlockVector getPrimaryPosition() throws IncompleteRegionException { public BlockVector getPrimaryPosition() throws IncompleteRegionException {
if (pos1 == null) { if (pos1 == null) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -153,6 +184,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
return pos1; return pos1;
} }
@Override
public Polygonal2DRegion getRegion() throws IncompleteRegionException { public Polygonal2DRegion getRegion() throws IncompleteRegionException {
if (!isDefined()) { if (!isDefined()) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
@ -161,40 +193,54 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
return region; return region;
} }
@Override
public Polygonal2DRegion getIncompleteRegion() { public Polygonal2DRegion getIncompleteRegion() {
return region; return region;
} }
@Override
public boolean isDefined() { public boolean isDefined() {
return region.size() > 2; return region.size() > 2;
} }
@Override
public void learnChanges() { public void learnChanges() {
BlockVector2D pt = region.getPoints().get(0); BlockVector2D pt = region.getPoints().get(0);
pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ()); pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ());
} }
@Override
public void clear() { public void clear() {
pos1 = null; pos1 = null;
region = new Polygonal2DRegion(region.getWorld()); region = new Polygonal2DRegion(region.getWorld());
} }
@Override
public String getTypeName() { public String getTypeName() {
return "2Dx1D polygon"; return "2Dx1D polygon";
} }
@Override
public List<String> getInformationLines() { public List<String> getInformationLines() {
return Collections.singletonList("# points: " + region.size()); return Collections.singletonList("# points: " + region.size());
} }
@Override
public int getArea() { public int getArea() {
return region.getArea(); return region.getArea();
} }
/**
* Get the number of points.
*
* @return the number of points
*/
@Override
public int getPointCount() { public int getPointCount() {
return region.getPoints().size(); return region.getPoints().size();
} }
@Override
public void describeCUI(LocalSession session, LocalPlayer player) { public void describeCUI(LocalSession session, LocalPlayer player) {
final List<BlockVector2D> points = region.getPoints(); final List<BlockVector2D> points = region.getPoints();
for (int id = 0; id < points.size(); id++) { for (int id = 0; id < points.size(); id++) {
@ -204,19 +250,24 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
} }
@Override
public void describeLegacyCUI(LocalSession session, LocalPlayer player) { public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
describeCUI(session, player); describeCUI(session, player);
} }
@Override
public int getProtocolVersion() { public int getProtocolVersion() {
return 0; return 0;
} }
@Override
public String getTypeID() { public String getTypeID() {
return "polygon2d"; return "polygon2d";
} }
@Override
public String getLegacyTypeID() { public String getLegacyTypeID() {
return "polygon2d"; return "polygon2d";
} }
} }

Datei anzeigen

@ -1,7 +1,7 @@
// $Id$
/* /*
* WorldEdit * WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.regions.selector; package com.sk89q.worldedit.regions.selector;
@ -25,20 +25,34 @@ import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import javax.annotation.Nullable;
/** /**
* Selector for spheres. * A {@link RegionSelector} for {@link SphereRegionSelector}s.
*
* @author TomyLobo
*/ */
public class SphereRegionSelector extends EllipsoidRegionSelector { public class SphereRegionSelector extends EllipsoidRegionSelector {
public SphereRegionSelector(LocalWorld world) {
/**
* Create a new selector.
*
* @param world the world
*/
public SphereRegionSelector(@Nullable LocalWorld world) {
super(world); super(world);
} }
/**
* Create a new selector.
*/
public SphereRegionSelector() { public SphereRegionSelector() {
super(); super();
} }
/**
* Create a new selector from another one
*
* @param oldSelector the old selector
*/
public SphereRegionSelector(RegionSelector oldSelector) { public SphereRegionSelector(RegionSelector oldSelector) {
super(oldSelector); super(oldSelector);
final Vector radius = region.getRadius(); final Vector radius = region.getRadius();
@ -46,7 +60,14 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar));
} }
public SphereRegionSelector(LocalWorld world, Vector center, int radius) { /**
* Create a new selector.
*
* @param world the world
* @param center the center position
* @param radius the radius
*/
public SphereRegionSelector(@Nullable LocalWorld world, Vector center, int radius) {
super(world, center, new Vector(radius, radius, radius)); super(world, center, new Vector(radius, radius, radius));
} }
@ -73,4 +94,5 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
public String getTypeName() { public String getTypeName() {
return "sphere"; return "sphere";
} }
} }