3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-10 05:20:04 +01:00

Added selection setting API.

Dieser Commit ist enthalten in:
sk89q 2011-04-03 11:03:57 -07:00
Ursprung fd2de1d264
Commit fc3531ce89
9 geänderte Dateien mit 177 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -353,6 +353,13 @@ public class WorldEditPlugin extends JavaPlugin {
* @return the selection or null if there was none * @return the selection or null if there was none
*/ */
public Selection getSelection(Player player) { public Selection getSelection(Player player) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player)); LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(); RegionSelector selector = session.getRegionSelector();
@ -361,9 +368,9 @@ public class WorldEditPlugin extends JavaPlugin {
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld(); World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
return new CuboidSelection(world, (CuboidRegion)region); return new CuboidSelection(world, selector, (CuboidRegion)region);
} else if (region instanceof Polygonal2DRegion) { } else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, (Polygonal2DRegion)region); return new Polygonal2DSelection(world, selector, (Polygonal2DRegion)region);
} else { } else {
return null; return null;
} }
@ -371,4 +378,27 @@ public class WorldEditPlugin extends JavaPlugin {
return null; return null;
} }
} }
/**
* Sets the region selection for a player.
*
* @param player
* @param selection
*/
public void setSelection(Player player, Selection selection) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(new BukkitWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
} }

Datei anzeigen

@ -19,16 +19,48 @@
package com.sk89q.worldedit.bukkit.selections; package com.sk89q.worldedit.bukkit.selections;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.regions.*;
public class CuboidSelection extends RegionSelection { public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid; protected CuboidRegion cuboid;
public CuboidSelection(World world, CuboidRegion region) { public CuboidSelection(World world, Location pt1, Location pt2) {
super(world, region); this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
this.world = world; }
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
CuboidRegionSelector sel = new CuboidRegionSelector();
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
try {
cuboid = sel.getRegion();
} catch (IncompleteRegionException e) {
throw new RuntimeException("IncompleteRegionException unexpectedly thrown");
}
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region; this.cuboid = region;
} }
} }

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit.selections; package com.sk89q.worldedit.bukkit.selections;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.BlockVector2D;
@ -28,13 +29,38 @@ public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d; protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, Polygonal2DRegion region) { public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, region); super(world, sel, region);
this.world = world;
this.poly2d = region; this.poly2d = region;
} }
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
minY = Math.min(Math.max(0, minY), 127);
maxY = Math.min(Math.max(0, maxY), 127);
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector();
poly2d = sel.getIncompleteRegion();
for (BlockVector2D pt : points) {
if (pt == null) {
throw new IllegalArgumentException("Null point not permitted");
}
poly2d.addPoint(pt);
}
poly2d.setMinimumY(minY);
poly2d.setMaximumY(maxY);
sel.learnChanges();
setRegionSelector(sel);
setRegion(poly2d);
}
public List<BlockVector2D> getNativePoints() { public List<BlockVector2D> getNativePoints() {
return poly2d.getPoints(); return Collections.unmodifiableList(poly2d.getPoints());
} }
} }

Datei anzeigen

@ -25,15 +25,38 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
public abstract class RegionSelection implements Selection { public abstract class RegionSelection implements Selection {
protected World world; private World world;
protected Region region; private RegionSelector selector;
private Region region;
public RegionSelection(World world, Region region) { public RegionSelection(World world) {
this.world = world;
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this.world = world; this.world = world;
this.region = region; this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return region;
}
protected void setRegion(Region region) {
this.region = region;
}
public RegionSelector getRegionSelector() {
return selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
} }
@Override @Override

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit.selections;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
public interface Selection { public interface Selection {
/** /**
@ -52,6 +53,13 @@ public interface Selection {
*/ */
public Vector getNativeMaximumPoint(); public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return
*/
public RegionSelector getRegionSelector();
/** /**
* Get the world. * Get the world.
* *

Datei anzeigen

@ -106,7 +106,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
return pos1 != null && pos2 != null; return pos1 != null && pos2 != null;
} }
public Region getRegion() throws IncompleteRegionException { public CuboidRegion getRegion() throws IncompleteRegionException {
if (pos1 == null || pos2 == null) { if (pos1 == null || pos2 == null) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
} }
@ -114,6 +114,10 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
return region; return region;
} }
public CuboidRegion getIncompleteRegion() {
return region;
}
public void learnChanges() { public void learnChanges() {
pos1 = region.getPos1().toBlockVector(); pos1 = region.getPos1().toBlockVector();
pos2 = region.getPos2().toBlockVector(); pos2 = region.getPos2().toBlockVector();

Datei anzeigen

@ -143,6 +143,28 @@ public class Polygonal2DRegion implements Region {
recalculate(); recalculate();
} }
/**
* Set the minimum Y.
*
* @param y
*/
public void setMinimumY(int y) {
hasY = true;
minY = y;
recalculate();
}
/**
* Se the maximum Y.
*
* @param y
*/
public void setMaximumY(int y) {
hasY = true;
maxY = y;
recalculate();
}
/** /**
* Get the lower point of a region. * Get the lower point of a region.
* *

Datei anzeigen

@ -87,7 +87,7 @@ public class Polygonal2DRegionSelector implements RegionSelector {
return pos1; return pos1;
} }
public Region getRegion() throws IncompleteRegionException { public Polygonal2DRegion getRegion() throws IncompleteRegionException {
if (!isDefined()) { if (!isDefined()) {
throw new IncompleteRegionException(); throw new IncompleteRegionException();
} }
@ -95,11 +95,18 @@ public class Polygonal2DRegionSelector implements RegionSelector {
return region; return region;
} }
public Polygonal2DRegion getIncompleteRegion() {
return region;
}
public boolean isDefined() { public boolean isDefined() {
return region.size() > 2; return region.size() > 2;
} }
public void learnChanges() { public void learnChanges() {
BlockVector2D pt = region.getPoints().get(0);
pos1 = new BlockVector(pt.getBlockX(),
region.getMinimumPoint().getBlockY(), pt.getBlockZ());
} }
public void clear() { public void clear() {
@ -125,4 +132,8 @@ public class Polygonal2DRegionSelector implements RegionSelector {
return region.getArea(); return region.getArea();
} }
public int getPointCount() {
return region.getPoints().size();
}
} }

Datei anzeigen

@ -93,6 +93,13 @@ public interface RegionSelector {
*/ */
public Region getRegion() throws IncompleteRegionException; public Region getRegion() throws IncompleteRegionException;
/**
* Get the region even if it's not fully defined.
*
* @return
*/
public Region getIncompleteRegion();
/** /**
* Returns whether the region has been fully defined. * Returns whether the region has been fully defined.
* *