mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-14 08:38:35 +00:00
Added basic support for CUI.
This commit is contained in:
@ -24,14 +24,17 @@ 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.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
|
||||
/**
|
||||
* Selector for cuboids.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CuboidRegionSelector implements RegionSelector {
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
protected BlockVector pos1;
|
||||
protected BlockVector pos2;
|
||||
protected CuboidRegion region = new CuboidRegion(new Vector(), new Vector());
|
||||
@ -54,22 +57,30 @@ public class CuboidRegionSelector implements RegionSelector {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, Vector pos) {
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("First position set to " + pos1
|
||||
+ " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("First position set to " + pos1 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player,
|
||||
new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, Vector pos) {
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos) {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
player.print("Second position set to " + pos2
|
||||
+ " (" + region.getArea() + ").");
|
||||
} else {
|
||||
player.print("Second position set to " + pos2 + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player,
|
||||
new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
|
||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||
@ -119,4 +130,20 @@ public class CuboidRegionSelector implements RegionSelector {
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public Vector[] getCUIPoints() {
|
||||
return new Vector[] { pos1, pos2 };
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
if (pos1 != null && pos2 != null) {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ 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.Vector;
|
||||
|
||||
/**
|
||||
@ -66,11 +67,13 @@ public class Polygonal2DRegionSelector implements RegionSelector {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void explainPrimarySelection(LocalPlayer player, Vector pos) {
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos) {
|
||||
player.print("Starting a new polygon at " + pos + ".");
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, Vector pos) {
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos) {
|
||||
player.print("Added point #" + region.size() + " at " + pos + ".");
|
||||
}
|
||||
|
||||
@ -111,4 +114,12 @@ public class Polygonal2DRegionSelector implements RegionSelector {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ 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.Vector;
|
||||
|
||||
/**
|
||||
@ -51,17 +52,21 @@ public interface RegionSelector {
|
||||
* Tell the player information about his/her primary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainPrimarySelection(LocalPlayer player, Vector pos);
|
||||
public void explainPrimarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her secondary selection.
|
||||
*
|
||||
* @param player
|
||||
* @param session
|
||||
* @param pos
|
||||
*/
|
||||
public void explainSecondarySelection(LocalPlayer player, Vector pos);
|
||||
public void explainSecondarySelection(LocalPlayer player,
|
||||
LocalSession session, Vector pos);
|
||||
|
||||
/**
|
||||
* Get the primary position.
|
||||
@ -86,6 +91,13 @@ public interface RegionSelector {
|
||||
*/
|
||||
public boolean isDefined();
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks or -1 if undefined
|
||||
*/
|
||||
public int getArea();
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
*/
|
||||
@ -103,6 +115,13 @@ public interface RegionSelector {
|
||||
*/
|
||||
public String getTypeName();
|
||||
|
||||
/**
|
||||
* Get a lowecase space-less ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeId();
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
|
Reference in New Issue
Block a user