From 6ad274677f07d05d83d214974ee2532073699add Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 29 May 2019 23:15:00 -0400 Subject: [PATCH] Don't require command for CUI init. --- .../sk89q/worldedit/bukkit/CUIChannelListener.java | 5 +++-- .../main/java/com/sk89q/worldedit/LocalSession.java | 13 +++++++++---- .../forge/net/handler/WECUIPacketHandler.java | 6 ++++-- .../sk89q/worldedit/sponge/CUIChannelHandler.java | 6 ++++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java index 23b190616..8767e9fe9 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/CUIChannelListener.java @@ -41,8 +41,9 @@ public class CUIChannelListener implements PluginMessageListener { public void onPluginMessageReceived(String channel, Player player, byte[] message) { LocalSession session = plugin.getSession(player); String text = new String(message, UTF_8_CHARSET); - session.handleCUIInitializationMessage(text); - session.describeCUI(plugin.wrapPlayer(player)); + final BukkitPlayer actor = plugin.wrapPlayer(player); + session.handleCUIInitializationMessage(text, actor); + session.describeCUI(actor); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index b0c1ebd45..5dd9aabee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -782,9 +782,9 @@ public class LocalSession { * * @param text the message */ - public void handleCUIInitializationMessage(String text) { + public void handleCUIInitializationMessage(String text, Actor actor) { checkNotNull(text); - if (this.failedCuiAttempts > 3) { + if (this.hasCUISupport || this.failedCuiAttempts > 3) { return; } @@ -794,13 +794,18 @@ public class LocalSession { this.failedCuiAttempts ++; return; } - setCUISupport(true); + + int version; try { - setCUIVersion(Integer.parseInt(split[1])); + version = Integer.parseInt(split[1]); } catch (NumberFormatException e) { WorldEdit.logger.warn("Error while reading CUI init message: " + e.getMessage()); this.failedCuiAttempts ++; + return; } + setCUISupport(true); + setCUIVersion(version); + dispatchCUISelection(actor); } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/net/handler/WECUIPacketHandler.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/net/handler/WECUIPacketHandler.java index 541577e1f..5273887ea 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/net/handler/WECUIPacketHandler.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/net/handler/WECUIPacketHandler.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.forge.net.handler; import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.forge.ForgePlayer; import com.sk89q.worldedit.forge.ForgeWorldEdit; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; @@ -62,8 +63,9 @@ public final class WECUIPacketHandler { } String text = event.getPayload().toString(UTF_8_CHARSET); - session.handleCUIInitializationMessage(text); - session.describeCUI(adaptPlayer(player)); + final ForgePlayer actor = adaptPlayer(player); + session.handleCUIInitializationMessage(text, actor); + session.describeCUI(actor); } public static void callProcessPacket(ClientCustomPayloadEvent event) { diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java index 7be50e8d1..3e3fb44e1 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/CUIChannelHandler.java @@ -57,8 +57,10 @@ public class CUIChannelHandler implements RawDataListener { return; } - session.handleCUIInitializationMessage(new String(data.readBytes(data.available()), StandardCharsets.UTF_8)); - session.describeCUI(SpongeWorldEdit.inst().wrapPlayer(player)); + final SpongePlayer actor = SpongeWorldEdit.inst().wrapPlayer(player); + session.handleCUIInitializationMessage(new String(data.readBytes(data.available()), StandardCharsets.UTF_8), + actor); + session.describeCUI(actor); } } }