From 30f9fb16ac0d55a2e6d159457f7746d3aa9a1870 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 29 Jul 2012 00:03:34 -0700 Subject: [PATCH] Updated for SpoutAPI changes --- .../spout/SpoutRawCommandExecutor.java | 17 +++++++--- .../worldedit/spout/WorldEditListener.java | 31 ++++++++++++++----- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutRawCommandExecutor.java b/src/main/java/com/sk89q/worldedit/spout/SpoutRawCommandExecutor.java index f9924a2c8..2ae23edd2 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutRawCommandExecutor.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutRawCommandExecutor.java @@ -18,11 +18,13 @@ package com.sk89q.worldedit.spout; +import org.spout.api.chat.ChatSection; import org.spout.api.command.Command; import org.spout.api.command.CommandSource; import org.spout.api.command.RawCommandExecutor; import org.spout.api.exception.CommandException; -import org.spout.api.util.MiscCompatibilityUtils; + +import java.util.List; /** * @author zml2008 @@ -36,10 +38,15 @@ public class SpoutRawCommandExecutor implements RawCommandExecutor { } @Override - public void execute(Command cmd, CommandSource source, String[] args, int baseIndex, boolean fuzzyLookup) throws CommandException { - args[baseIndex] = "/" + cmd.getPreferredName(); - if (!plugin.getWorldEdit().handleCommand(plugin.wrapCommandSender(source), MiscCompatibilityUtils.arrayCopyOfRange(args, baseIndex, args.length))) { - throw new CommandException("Unknown command: '" + args[baseIndex] + "'!"); + public void execute(Command cmd, CommandSource source, String name, List args, int baseIndex, boolean fuzzyLookup) throws CommandException { + String[] argArray = new String[args.size() - baseIndex + 1]; + argArray[0] = "/" + cmd.getPreferredName(); + for (int i = baseIndex; i < args.size(); ++i) { + argArray[i - baseIndex + 1] = args.get(i).getPlainString(); + } + + if (!plugin.getWorldEdit().handleCommand(plugin.wrapCommandSender(source), argArray)) { + throw new CommandException("Unknown command: '/" + name + "'!"); } } } diff --git a/src/main/java/com/sk89q/worldedit/spout/WorldEditListener.java b/src/main/java/com/sk89q/worldedit/spout/WorldEditListener.java index ce78441eb..c53f088fa 100644 --- a/src/main/java/com/sk89q/worldedit/spout/WorldEditListener.java +++ b/src/main/java/com/sk89q/worldedit/spout/WorldEditListener.java @@ -27,6 +27,8 @@ import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldVector; import org.spout.api.Spout; +import org.spout.api.chat.ChatArguments; +import org.spout.api.chat.ChatSection; import org.spout.api.event.EventHandler; import org.spout.api.event.Listener; import org.spout.api.event.Order; @@ -41,6 +43,8 @@ import org.spout.api.generator.biome.BiomeGenerator; import org.spout.api.geo.discrete.Point; import org.spout.api.scheduler.TaskPriority; +import java.util.Arrays; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -89,17 +93,28 @@ public class WorldEditListener implements Listener { @EventHandler(order = Order.EARLY) public void onPlayerCommandPreprocess(PreCommandEvent event) { - if (event.getMessage().startsWith("nowe:")) { - event.setMessage(event.getMessage().substring(5)); + if (event.getCommand().startsWith("nowe:")) { + event.setCommand(event.getCommand().substring(5)); return; } - String[] split = event.getMessage().split(" "); + List args = event.getArguments().toSections(ChatSection.SplitType.WORD); + if (args.size() > 0) { + String[] split = new String[args.size() + 1]; + split[0] = "/" + event.getCommand(); + for (int i = 0; i < args.size(); ++i) { + split[i + 1] = args.get(i).getPlainString(); + } - if (split.length > 0) { - split[0] = "/" + split[0]; - split = plugin.getWorldEdit().commandDetection(split); - event.setMessage(StringUtil.joinString(split, " ")); + String[] newSplit = plugin.getWorldEdit().commandDetection(split); + if (!Arrays.equals(split, newSplit)) { + event.setCommand(newSplit[0]); + ChatArguments newArgs = new ChatArguments(); + for (int i = 1; i < newSplit.length; ++i) { + newArgs.append(newSplit[i]); + } + event.setArguments(newArgs); + } } } @@ -170,7 +185,7 @@ public class WorldEditListener implements Listener { return; } - Matcher matcher = cuipattern.matcher(event.getMessage()); + Matcher matcher = cuipattern.matcher(event.getMessage().getPlainString()); if (matcher.find()) { String type = matcher.group(1); String args = matcher.group(2);