Add cuiVersion to LocalSession and set it via incoming CUI event
Refactor region selectors to handle legacy versions a bit better. Because chat doesn't allow the section sign to be sent, I have to send non-color codes. Meh. closes #158
This commit is contained in:
@@ -27,7 +27,7 @@ import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected BlockVector pos1;
|
||||
protected BlockVector pos2;
|
||||
protected CuboidRegion region;
|
||||
@@ -173,24 +173,6 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public String getLegacyTypeId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void describeCUI(LocalPlayer player) {
|
||||
if (pos1 != null) {
|
||||
player.dispatchCUIEvent(new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
player.dispatchCUIEvent(new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
if (pos1 == null) {
|
||||
return -1;
|
||||
@@ -202,4 +184,32 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
|
||||
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
if (pos1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos1, getArea()));
|
||||
}
|
||||
|
||||
if (pos2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionEllipsoidPointEvent;
|
||||
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||
*
|
||||
* @author TomyLobo
|
||||
*/
|
||||
public class EllipsoidRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected EllipsoidRegion region;
|
||||
|
||||
public EllipsoidRegionSelector(LocalWorld world) {
|
||||
@@ -93,9 +93,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIPointBasedReg
|
||||
player.print("Center position set to " + region.getCenter() + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter()));
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
legacyDescribeCUI(player, session);
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
@@ -105,12 +103,11 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIPointBasedReg
|
||||
player.print("Radius set to " + region.getRadius() + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
legacyDescribeCUI(player, session);
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public void explainRegionAdjust(LocalPlayer player, LocalSession session) {
|
||||
legacyDescribeCUI(player, session);
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
@@ -157,35 +154,30 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIPointBasedReg
|
||||
return lines;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "ellipsoid";
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
public String getLegacyTypeId() {
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter()));
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
public void describeCUI(LocalPlayer player) {
|
||||
player.dispatchCUIEvent(new SelectionEllipsoidPointEvent(0, region.getCenter()));
|
||||
player.dispatchCUIEvent(new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
legacyDescribeCUI(player);
|
||||
public int getProtocolVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected void legacyDescribeCUI(LocalPlayer player, LocalSession session) {
|
||||
if (!session.hasCUISupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
legacyDescribeCUI(player);
|
||||
}
|
||||
|
||||
private void legacyDescribeCUI(LocalPlayer player) {
|
||||
player.dispatchCUIEvent(new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
player.dispatchCUIEvent(new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
public String getTypeID() {
|
||||
return "ellipsoid";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||
import com.sk89q.worldedit.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.cui.SelectionMinMaxEvent;
|
||||
import com.sk89q.worldedit.cui.SelectionPoint2DEvent;
|
||||
import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||
@@ -39,7 +39,7 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||
public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
protected BlockVector pos1;
|
||||
protected Polygonal2DRegion region;
|
||||
|
||||
@@ -116,7 +116,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos) {
|
||||
player.print("Starting a new polygon at " + pos + ".");
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeId()));
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.minY, region.maxY));
|
||||
}
|
||||
@@ -174,14 +174,6 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
return Collections.singletonList("# points: " + region.size());
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public String getLegacyTypeId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
@@ -190,12 +182,30 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR
|
||||
return region.getPoints().size();
|
||||
}
|
||||
|
||||
public void describeCUI(LocalPlayer player) {
|
||||
public void describeCUI(LocalSession session, LocalPlayer player) {
|
||||
final List<BlockVector2D> points = region.getPoints();
|
||||
for (int id = 0; id < points.size(); id++) {
|
||||
player.dispatchCUIEvent(new SelectionPoint2DEvent(id, points.get(id), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
|
||||
}
|
||||
|
||||
player.dispatchCUIEvent(new SelectionMinMaxEvent(region.minY, region.maxY));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.minY, region.maxY));
|
||||
}
|
||||
|
||||
public void describeLegacyCUI(LocalSession session, LocalPlayer player) {
|
||||
describeCUI(session, player);
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
public String getLegacyTypeID() {
|
||||
return "polygon2d";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -131,20 +131,6 @@ public interface RegionSelector {
|
||||
*/
|
||||
public String getTypeName();
|
||||
|
||||
/**
|
||||
* Get a lowercase space-less ID.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTypeId();
|
||||
|
||||
/**
|
||||
* Gets an alternative ID, for which this region selector also sends data.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getLegacyTypeId();
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.cui.SelectionEllipsoidPointEvent;
|
||||
|
||||
/**
|
||||
* Selector for spheres.
|
||||
@@ -65,8 +64,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
player.print("Radius set to " + region.getRadius().getX() + ".");
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius()));
|
||||
legacyDescribeCUI(player, session);
|
||||
session.describeCUI(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user