From b8aaeb1053b981966c41dff159e38f5cd5cc048b Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 6 Nov 2012 14:23:17 -0600 Subject: [PATCH] Fix for slashless commands triggering errors in CraftBukkit on rare occasions due to being run async --- .../massivecraft/factions/zcore/MPlugin.java | 26 ++++++++++++++++--- .../zcore/MPluginSecretPlayerListener.java | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/factions/zcore/MPlugin.java b/src/com/massivecraft/factions/zcore/MPlugin.java index e3a00fde..0531e4ff 100644 --- a/src/com/massivecraft/factions/zcore/MPlugin.java +++ b/src/com/massivecraft/factions/zcore/MPlugin.java @@ -185,6 +185,11 @@ public abstract class MPlugin extends JavaPlugin } public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) + { + return handleCommand(sender, commandString, testOnly, false); + } + + public boolean handleCommand(final CommandSender sender, String commandString, boolean testOnly, boolean async) { boolean noSlash = true; if (commandString.startsWith("/")) @@ -193,7 +198,7 @@ public abstract class MPlugin extends JavaPlugin commandString = commandString.substring(1); } - for (MCommand command : this.getBaseCommands()) + for (final MCommand command : this.getBaseCommands()) { if (noSlash && ! command.allowNoSlashAccess) continue; @@ -204,10 +209,25 @@ public abstract class MPlugin extends JavaPlugin if (commandString.startsWith(alias+" ") || commandString.equals(alias)) { - List args = new ArrayList(Arrays.asList(commandString.split("\\s+"))); + final List args = new ArrayList(Arrays.asList(commandString.split("\\s+"))); args.remove(0); + if (testOnly) return true; - command.execute(sender, args); + + if (async) + { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() + { + @Override + public void run() + { + command.execute(sender, args); + } + }); + } + else + command.execute(sender, args); + return true; } } diff --git a/src/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java b/src/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java index 3d4c0ef5..70942b61 100644 --- a/src/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java +++ b/src/com/massivecraft/factions/zcore/MPluginSecretPlayerListener.java @@ -39,7 +39,7 @@ public class MPluginSecretPlayerListener implements Listener { if (event.isCancelled()) return; - if (p.handleCommand(event.getPlayer(), event.getMessage())) + if (p.handleCommand(event.getPlayer(), event.getMessage(), false, true)) { if (p.logPlayerCommands()) Bukkit.getLogger().info("[PLAYER_COMMAND] "+event.getPlayer().getName()+": "+event.getMessage());