Fix for slashless commands triggering errors in CraftBukkit on rare occasions due to being run async

This commit is contained in:
Brettflan 2012-11-06 14:23:16 -06:00
parent 8288cfc44a
commit c11d9b03a3
2 changed files with 24 additions and 4 deletions

View File

@ -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<String> args = new ArrayList<String>(Arrays.asList(commandString.split("\\s+")));
final List<String> args = new ArrayList<String>(Arrays.asList(commandString.split("\\s+")));
args.remove(0);
if (testOnly) return true;
if (async)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
@Override
public void run()
{
command.execute(sender, args);
}
});
}
else
command.execute(sender, args);
return true;
}
}

View File

@ -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());