mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 12:57:41 +01:00
Fixed duplicate console and player messages when built in server commands where used or an unknown command was issued
This commit is contained in:
parent
6319a19073
commit
8b0924bbb4
@ -3,6 +3,12 @@ package net.minecraft.server;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
// Craftbukkit start
|
||||
import java.util.List;
|
||||
import org.bukkit.craftbukkit.command.ServerCommandListener;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
// Craftbukkit end
|
||||
|
||||
public class ConsoleCommandHandler {
|
||||
|
||||
@ -286,13 +292,38 @@ public class ConsoleCommandHandler {
|
||||
}
|
||||
|
||||
private void print(String s, String s1) {
|
||||
listener.sendMessage(s1); // CraftBukkit
|
||||
String s2 = s + ": " + s1;
|
||||
|
||||
this.server.serverConfigurationManager.j("\u00A77(" + s2 + ")");
|
||||
// CraftBukkit start
|
||||
listener.sendMessage(s1);
|
||||
informOps("\u00A77(" + s2 + ")");
|
||||
if (listener instanceof MinecraftServer) {
|
||||
return; // Already logged so don't call a.info()
|
||||
}
|
||||
// CraftBukkit end
|
||||
a.info(s2);
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
private void informOps(String msg) {
|
||||
Packet3Chat packet3chat = new Packet3Chat(msg);
|
||||
EntityPlayer sender = null;
|
||||
if (listener instanceof ServerCommandListener) {
|
||||
CommandSender commandSender = ((ServerCommandListener) listener).getSender();
|
||||
if (commandSender instanceof CraftPlayer) {
|
||||
sender = ((CraftPlayer) commandSender).getHandle();
|
||||
}
|
||||
}
|
||||
List<EntityPlayer> players = server.serverConfigurationManager.players;
|
||||
for (int i = 0; i < players.size(); ++i) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) players.get(i);
|
||||
if (sender != entityPlayer && server.serverConfigurationManager.isOp(entityPlayer.name)) {
|
||||
entityPlayer.netServerHandler.sendPacket(packet3chat);
|
||||
}
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
private int a(String s, int i) {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
|
@ -695,19 +695,15 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean targetPluginFound = false;
|
||||
|
||||
try {
|
||||
targetPluginFound = server.dispatchCommand(player, s.substring(1));
|
||||
if (server.dispatchCommand(player, s.substring(1))) {
|
||||
return;
|
||||
}
|
||||
} catch (CommandException ex) {
|
||||
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command");
|
||||
Logger.getLogger(NetServerHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetPluginFound) {
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
if (s.toLowerCase().startsWith("/me ")) {
|
||||
@ -728,9 +724,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
this.sendPacket(new Packet3Chat("\u00A7cThere\'s no player by that name online."));
|
||||
}
|
||||
}
|
||||
|
||||
/* CraftBukkit start - No longer neaded as we have already handled it server.dispatchCommand above.
|
||||
} else {
|
||||
String s1;
|
||||
|
||||
if (this.minecraftServer.serverConfigurationManager.isOp(this.player.name)) {
|
||||
s1 = s.substring(1);
|
||||
a.info(this.player.name + " issued server command: " + s1);
|
||||
@ -739,6 +736,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
||||
s1 = s.substring(1);
|
||||
a.info(this.player.name + " tried command: " + s1);
|
||||
}
|
||||
*/ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user