Added selection setting API.

This commit is contained in:
sk89q
2011-04-03 11:03:57 -07:00
parent fd2de1d264
commit fc3531ce89
9 changed files with 177 additions and 14 deletions

View File

@@ -353,6 +353,13 @@ public class WorldEditPlugin extends JavaPlugin {
* @return the selection or null if there was none
*/
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));
RegionSelector selector = session.getRegionSelector();
@@ -361,9 +368,9 @@ public class WorldEditPlugin extends JavaPlugin {
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, (CuboidRegion)region);
return new CuboidSelection(world, selector, (CuboidRegion)region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, (Polygonal2DRegion)region);
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion)region);
} else {
return null;
}
@@ -371,4 +378,27 @@ public class WorldEditPlugin extends JavaPlugin {
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));
}
}