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:
Yetanotherx
2011-12-31 23:16:39 -05:00
committed by zml2008
parent 616f9a2360
commit 3b87953da0
12 changed files with 220 additions and 129 deletions

View File

@ -140,8 +140,8 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public void dispatchCUIHandshake() {
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
}
public Player getPlayer() {

View File

@ -24,6 +24,7 @@ import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
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.PlayerListener;
@ -32,15 +33,17 @@ 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
*/
public class WorldEditPlayerListener extends PlayerListener {
/**
* Plugin.
*/
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
@ -59,6 +62,7 @@ public class WorldEditPlayerListener extends PlayerListener {
plugin.registerEvent("PLAYER_QUIT", this);
plugin.registerEvent("PLAYER_INTERACT", this);
plugin.registerEvent("PLAYER_COMMAND_PREPROCESS", this, Event.Priority.Low);
plugin.registerEvent("PLAYER_CHAT", this);
}
/**
@ -92,8 +96,6 @@ public class WorldEditPlayerListener extends PlayerListener {
event.setMessage(StringUtil.joinString(split, " "));
}
private boolean ignoreLeftClickAir = false;
/**
* Called when a player interacts
*
@ -162,4 +164,26 @@ public class WorldEditPlayerListener extends PlayerListener {
}
}
}
@Override
public void onPlayerChat(PlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
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 e ) {
}
}
}
}
}