Remove chat-based WECUI protocol. Everybody running a modern (1.2.5 or newer) WECUI should be fine.

This has a bonus of allowing us to stay far far away from that smelly PlayerChatEvent guy who's always late (or early, or both).
This commit is contained in:
zml2008
2012-08-04 20:22:55 -07:00
parent ce20f33425
commit fe445a7ec9
13 changed files with 157 additions and 112 deletions

View File

@ -28,7 +28,7 @@ import java.util.Set;
/**
* Represents WorldEdit's configuration.
*
*
* @author sk89q
*/
public abstract class LocalConfiguration {
@ -78,7 +78,6 @@ public abstract class LocalConfiguration {
};
public boolean profile = false;
public boolean enableWECUI = true;
public Set<Integer> disallowedBlocks = new HashSet<Integer>();
public int defaultChangeLimit = -1;
public int maxChangeLimit = -1;
@ -113,7 +112,7 @@ public abstract class LocalConfiguration {
/**
* Get the working directory to work from.
*
*
* @return
*/
public File getWorkingDirectory() {

View File

@ -623,7 +623,9 @@ public abstract class LocalPlayer {
/**
* Send the CUI handshake.
* @deprecated Not used anymore; The CUI begins the handshake
*/
@Deprecated
public void dispatchCUIHandshake() {
}

View File

@ -602,6 +602,22 @@ public class LocalSession {
}
}
public void handleCUIInitializationMessage(String text) {
if (hasCUISupport()) {
return;
}
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) {
WorldEdit.logger.warning("Error while reading CUI init message: " + e.getMessage());
}
}
}
/**
* Gets the status of CUI support.
*
@ -617,7 +633,7 @@ public class LocalSession {
* @param support
*/
public void setCUISupport(boolean support) {
hasCUISupport = true;
hasCUISupport = support;
}
/**

View File

@ -133,22 +133,7 @@ public class BukkitPlayer extends LocalPlayer {
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
if (plugin.hasPluginChannelCUI(getName())) {
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
} else {
if (plugin.getLocalConfiguration().enableWECUI) {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + send);
}
}
}
@Override
public void dispatchCUIHandshake() {
if (!plugin.hasPluginChannelCUI(getName()) && plugin.getLocalConfiguration().enableWECUI) {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
}
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
}
public Player getPlayer() {

View File

@ -39,19 +39,11 @@ public class CUIChannelListener implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
LocalSession session = plugin.getSession(player);
if (session.hasCUISupport() && plugin.hasPluginChannelCUI(player.getName())) { // Already initialized
if (session.hasCUISupport()) { // Already initialized
return;
}
String[] text = new String(message, UTF_8_CHARSET).split("\\|");
if (text.length > 1 && text[0].equalsIgnoreCase("v")) { // enough fields and right message
plugin.setPluginChannelCUI(player.getName(), true);
session.setCUISupport(true);
try {
session.setCUIVersion(Integer.parseInt(text[1]));
} catch (NumberFormatException e) {
plugin.getLogger().warning("Error while reading CUI init message: " + e.getMessage());
}
}
String text = new String(message, UTF_8_CHARSET);
session.handleCUIInitializationMessage(text);
}
}

View File

@ -23,23 +23,18 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Handles all events thrown in relation to a Player
@ -48,7 +43,6 @@ public class WorldEditListener implements Listener {
private WorldEditPlugin plugin;
private boolean ignoreLeftClickAir = false;
private final static Pattern cuipattern = Pattern.compile("u00a74u00a75u00a73u00a74([^\\|]*)\\|?(.*)");
/**
* Called when a player plays an animation, such as an arm swing
@ -65,20 +59,6 @@ public class WorldEditListener implements Listener {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
plugin.wrapPlayer(player).dispatchCUIHandshake();
}
}
}, 20 * 2);
}
/**
* Called when a player leaves a server
*
@ -87,7 +67,6 @@ public class WorldEditListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
plugin.setPluginChannelCUI(event.getPlayer().getName(), false);
}
/**
@ -187,22 +166,4 @@ public class WorldEditListener implements Listener {
}
}
}
@EventHandler(ignoreCancelled = true) // TODO: Remove this in a bit
public void onPlayerChat(PlayerChatEvent event) {
Matcher matcher = cuipattern.matcher(event.getMessage());
if (matcher.find()) {
String type = matcher.group(1);
String args = matcher.group(2);
if( type.equals("v") ) {
try {
plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args));
event.setCancelled(true);
} catch(NumberFormatException ignore) {
}
}
}
}
}

View File

@ -70,11 +70,6 @@ public class WorldEditPlugin extends JavaPlugin {
*/
private BukkitConfiguration config;
/**
* Stores players who are using plugin channels for the cui
*/
private final Set<String> pluginChannelCui = new HashSet<String>();
/**
* Called on plugin enable.
*/
@ -389,16 +384,4 @@ public class WorldEditPlugin extends JavaPlugin {
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
public void setPluginChannelCUI(String name, boolean value) {
if (value) {
pluginChannelCui.add(name);
} else {
pluginChannelCui.remove(name);
}
}
public boolean hasPluginChannelCUI(String name) {
return pluginChannelCui.contains(name);
}
}

View File

@ -39,14 +39,6 @@ public class WorldEditCUIMessageHandler extends MessageHandler<WorldEditCUIMessa
return;
}
String[] text = message.getMessage().split("\\|");
if (text.length > 1 && text[0].equalsIgnoreCase("v")) { // enough fields and right message
localSession.setCUISupport(true);
try {
localSession.setCUIVersion(Integer.parseInt(text[1]));
} catch (NumberFormatException e) {
plugin.getLogger().warning("Error while reading CUI init message: " + e.getMessage());
}
}
localSession.handleCUIInitializationMessage(message.getMessage());
}
}

View File

@ -64,11 +64,6 @@ public class WorldEditListener implements Listener {
this.plugin = plugin;
}
@EventHandler(order = Order.EARLIEST)
public void onPlayerJoin(PlayerJoinEvent event) {
plugin.wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
}
/**
* Called when a player leaves a server
*

View File

@ -36,7 +36,7 @@ import com.sk89q.worldedit.snapshots.SnapshotRepository;
/**
* Simple LocalConfiguration that loads settings using
* <code>java.util.Properties</code>.
*
*
* @author sk89q
*/
public class PropertiesConfiguration extends LocalConfiguration {
@ -46,7 +46,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Construct the object. The configuration isn't loaded yet.
*
*
* @param path
*/
public PropertiesConfiguration(File path) {
@ -77,7 +77,6 @@ public class PropertiesConfiguration extends LocalConfiguration {
}
profile = getBool("profile", profile);
enableWECUI = getBool("enable-wecui-handshake", enableWECUI);
disallowedBlocks = getIntSet("disallowed-blocks", defaultDisallowedBlocks);
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);
@ -126,7 +125,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Get a string value.
*
*
* @param key
* @param def
* @return
@ -146,7 +145,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Get a boolean value.
*
*
* @param key
* @param def
* @return
@ -164,7 +163,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Get an integer value.
*
*
* @param key
* @param def
* @return
@ -186,7 +185,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Get a double value.
*
*
* @param key
* @param def
* @return
@ -208,7 +207,7 @@ public class PropertiesConfiguration extends LocalConfiguration {
/**
* Get a double value.
*
*
* @param key
* @param def
* @return

View File

@ -59,7 +59,6 @@ public class YAMLConfiguration extends LocalConfiguration {
showFirstUseVersion = false;
profile = config.getBoolean("debug", profile);
enableWECUI = config.getBoolean("enable-wecui-handshake", enableWECUI);
wandItem = config.getInt("wand-item", wandItem);
defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit));