Fixed duplicate console and player messages when built in server commands where used or an unknown command was issued

By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
CraftBukkit/Spigot 2011-05-22 20:24:44 +01:00
parent 5f5de88a00
commit 76ba24db30
2 changed files with 38 additions and 20 deletions

View File

@ -48,6 +48,7 @@ import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
import org.bukkit.craftbukkit.inventory.CraftRecipe;
import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
import org.bukkit.craftbukkit.command.ServerCommandListener;
import org.bukkit.scheduler.BukkitWorker;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
@ -284,7 +285,7 @@ public final class CraftServer implements Server {
}
// See if the server can process this command
return console.consoleCommandHandler.handle(new ServerCommand(commandLine, new CommandListener(sender)));
return console.consoleCommandHandler.handle(new ServerCommand(commandLine, new ServerCommandListener(sender)));
}
public void reload() {
@ -451,25 +452,6 @@ public final class CraftServer implements Server {
config.setDataSourceConfig(ds);
}
// Inner class to capture the output of default server commands
class CommandListener implements ICommandListener {
private final CommandSender commandSender;
private final String prefix;
CommandListener(CommandSender commandSender) {
this.commandSender = commandSender;
String[] parts = commandSender.getClass().getName().split("\\.");
this.prefix = parts[parts.length-1];
}
public void sendMessage(String msg) {
this.commandSender.sendMessage(msg);
}
public String getName() {
return this.prefix;
}
}
public boolean addRecipe(Recipe recipe) {
CraftRecipe toAdd;
if(recipe instanceof CraftRecipe) {

View File

@ -0,0 +1,36 @@
package org.bukkit.craftbukkit.command;
import java.lang.reflect.Method;
import net.minecraft.server.ICommandListener;
import org.bukkit.command.CommandSender;
public class ServerCommandListener implements ICommandListener {
private final CommandSender commandSender;
private final String prefix;
public ServerCommandListener(CommandSender commandSender) {
this.commandSender = commandSender;
String[] parts = commandSender.getClass().getName().split("\\.");
this.prefix = parts[parts.length-1];
}
public void sendMessage(String msg) {
this.commandSender.sendMessage(msg);
}
public CommandSender getSender() {
return commandSender;
}
public String getName() {
try {
Method getName = commandSender.getClass().getMethod( "getName" );
return (String) getName.invoke(commandSender);
} catch (Exception e) {
}
return this.prefix;
}
}