From e70c82c7c0609a5a95869c18b37b1c41e4480837 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 07:23:01 -0800 Subject: [PATCH 1/5] Don't send SelectionShapeEvent events in the describeCUI/describeLegacyCUI methods, that event is already sent in dispatchCUISelection in LocalSession --- .../worldedit/regions/ConvexPolyhedralRegionSelector.java | 6 +----- .../com/sk89q/worldedit/regions/CylinderRegionSelector.java | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java index ba4d941ea..6131c7435 100644 --- a/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java @@ -183,9 +183,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion public void describeCUI(LocalSession session, LocalPlayer player) { Collection vertices = region.getVertices(); Collection triangles = region.getTriangles(); - - player.dispatchCUIEvent(new SelectionShapeEvent(getTypeID())); - + Map vertexIds = new HashMap(vertices.size()); int lastVertexId = -1; for (Vector vertex : vertices) { @@ -212,8 +210,6 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion if (isDefined()) { session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea())); - } else { - session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID())); } } } diff --git a/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java index 54585f708..f33937240 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/CylinderRegionSelector.java @@ -199,8 +199,6 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { if (isDefined()) { session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea())); session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea())); - } else { - session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID())); } } From 747de4cab7b98170c9e613767c80a786d097b091 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 07:24:29 -0800 Subject: [PATCH 2/5] That check is also done in the LocalSession, let the LocalSession decide what to do with multiple packets. --- .../java/com/sk89q/worldedit/bukkit/CUIChannelListener.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java b/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java index e846e6d1c..f3cd85bf8 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java @@ -39,10 +39,6 @@ public class CUIChannelListener implements PluginMessageListener { @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { LocalSession session = plugin.getSession(player); - if (session.hasCUISupport()) { // Already initialized - return; - } - String text = new String(message, UTF_8_CHARSET); session.handleCUIInitializationMessage(text); } From e25e1bfe67aa747d2a8954757bd5ffb080aff72d Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 08:21:59 -0800 Subject: [PATCH 3/5] Let the handshake packet refresh the CUI protocol version (it happens that players join with another client before the previous session expires) and also send the current selection when receiving a handshake packet (for when the player joins and the previous session did not expire) --- src/main/java/com/sk89q/worldedit/LocalSession.java | 9 ++++----- .../com/sk89q/worldedit/bukkit/CUIChannelListener.java | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index 7e73d222d..72b744d8c 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -605,13 +605,12 @@ public class LocalSession { } public void handleCUIInitializationMessage(String text) { - if (hasCUISupport()) { - return; - } - + if(!hasCUISupport()) { + setCUISupport(true); + } + String[] split = text.split("\\|"); if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message - setCUISupport(true); try { setCUIVersion(Integer.parseInt(split[1])); } catch (NumberFormatException e) { diff --git a/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java b/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java index f3cd85bf8..03d9014a7 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java @@ -41,5 +41,6 @@ public class CUIChannelListener implements PluginMessageListener { LocalSession session = plugin.getSession(player); String text = new String(message, UTF_8_CHARSET); session.handleCUIInitializationMessage(text); + session.describeCUI(plugin.wrapPlayer(player)); } } From c47f50696dfa70837641528ad54dd851ab165852 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 08:25:43 -0800 Subject: [PATCH 4/5] Fix indentation --- src/main/java/com/sk89q/worldedit/LocalSession.java | 8 ++++---- .../worldedit/regions/ConvexPolyhedralRegionSelector.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index 72b744d8c..15b2c3153 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -605,10 +605,10 @@ public class LocalSession { } public void handleCUIInitializationMessage(String text) { - if(!hasCUISupport()) { - setCUISupport(true); - } - + if(!hasCUISupport()) { + setCUISupport(true); + } + String[] split = text.split("\\|"); if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message try { diff --git a/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java index 6131c7435..6dfab10b2 100644 --- a/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegionSelector.java @@ -183,7 +183,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion public void describeCUI(LocalSession session, LocalPlayer player) { Collection vertices = region.getVertices(); Collection triangles = region.getTriangles(); - + Map vertexIds = new HashMap(vertices.size()); int lastVertexId = -1; for (Vector vertex : vertices) { From be8bb784f8675ac0804b2668f387dbb6eb011197 Mon Sep 17 00:00:00 2001 From: ReneZeidler Date: Sat, 1 Feb 2014 08:30:40 -0800 Subject: [PATCH 5/5] Only enable CUI support when the message is valid. Also the check if support isn't already enabled is not really needed, as it will just overwrite the field with the same value. --- src/main/java/com/sk89q/worldedit/LocalSession.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index 15b2c3153..4c0ff68d1 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -605,12 +605,9 @@ public class LocalSession { } public void handleCUIInitializationMessage(String text) { - if(!hasCUISupport()) { - setCUISupport(true); - } - String[] split = text.split("\\|"); if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message + setCUISupport(true); try { setCUIVersion(Integer.parseInt(split[1])); } catch (NumberFormatException e) {