3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-17 05:20:05 +01:00

Added methods to support RemoteBukkit

This means all commands even "default" server commands work within the command structure
returning output to the command sender

Updated default kick command to be compatible with kick + msg used by remote tools that work with hMod
Dieser Commit ist enthalten in:
stevenh 2011-03-12 18:23:57 +00:00
Ursprung ca3d0512f3
Commit 07c98ea2a4
3 geänderte Dateien mit 120 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -13,7 +13,12 @@ public class ConsoleCommandHandler {
this.b = minecraftserver; this.b = minecraftserver;
} }
public void a(ServerCommand servercommand) { // CraftBukkit - All calls to the following below:
// this.a( String s1, String msg );
// are changed to:
// this.notify( ICommandListener icommandlistener, String msg );
public boolean a(ServerCommand servercommand) { // CraftBukkit - returns boolean
String s = servercommand.a; String s = servercommand.a;
ICommandListener icommandlistener = servercommand.b; ICommandListener icommandlistener = servercommand.b;
String s1 = icommandlistener.c(); String s1 = icommandlistener.c();
@ -24,17 +29,17 @@ public class ConsoleCommandHandler {
if (s.toLowerCase().startsWith("list")) { if (s.toLowerCase().startsWith("list")) {
icommandlistener.b("Connected players: " + serverconfigurationmanager.c()); icommandlistener.b("Connected players: " + serverconfigurationmanager.c());
} else if (s.toLowerCase().startsWith("stop")) { } else if (s.toLowerCase().startsWith("stop")) {
this.a(s1, "Stopping the server.."); this.notify(icommandlistener, "Stopping the server.."); // CraftBukkit - notify command sender
this.b.a(); this.b.a();
} else if (s.toLowerCase().startsWith("save-all")) { } else if (s.toLowerCase().startsWith("save-all")) {
this.a(s1, "Forcing save.."); this.notify(icommandlistener, "Forcing save.."); // CraftBukkit - notify command sender
this.b.f(); // CraftBukkit - We should save all worlds on save-all. this.b.f(); // CraftBukkit - We should save all worlds on save-all.
this.a(s1, "Save complete."); this.notify(icommandlistener, "Save complete."); // CraftBukkit - notify command sender
} else if (s.toLowerCase().startsWith("save-off")) { } else if (s.toLowerCase().startsWith("save-off")) {
this.a(s1, "Disabling level saving.."); this.notify(icommandlistener, "Disabling level saving.."); // CraftBukkit - notify command sender
worldserver.w = true; worldserver.w = true;
} else if (s.toLowerCase().startsWith("save-on")) { } else if (s.toLowerCase().startsWith("save-on")) {
this.a(s1, "Enabling level saving.."); this.notify(icommandlistener, "Enabling level saving.."); // CraftBukkit - notify command sender
worldserver.w = false; worldserver.w = false;
} else { } else {
String s2; String s2;
@ -42,28 +47,28 @@ public class ConsoleCommandHandler {
if (s.toLowerCase().startsWith("op ")) { if (s.toLowerCase().startsWith("op ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.e(s2); serverconfigurationmanager.e(s2);
this.a(s1, "Opping " + s2); this.notify(icommandlistener, "Opping " + s2); // CraftBukkit - notify command sender
serverconfigurationmanager.a(s2, "\u00A7eYou are now op!"); serverconfigurationmanager.a(s2, "\u00A7eYou are now op!");
} else if (s.toLowerCase().startsWith("deop ")) { } else if (s.toLowerCase().startsWith("deop ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.f(s2); serverconfigurationmanager.f(s2);
serverconfigurationmanager.a(s2, "\u00A7eYou are no longer op!"); serverconfigurationmanager.a(s2, "\u00A7eYou are no longer op!");
this.a(s1, "De-opping " + s2); this.notify(icommandlistener, "De-opping " + s2); // CraftBukkit - notify command sender
} else if (s.toLowerCase().startsWith("ban-ip ")) { } else if (s.toLowerCase().startsWith("ban-ip ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.c(s2); serverconfigurationmanager.c(s2);
this.a(s1, "Banning ip " + s2); this.notify(icommandlistener, "Banning ip " + s2); // CraftBukkit - notify command sender
} else if (s.toLowerCase().startsWith("pardon-ip ")) { } else if (s.toLowerCase().startsWith("pardon-ip ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.d(s2); serverconfigurationmanager.d(s2);
this.a(s1, "Pardoning ip " + s2); this.notify(icommandlistener, "Pardoning ip " + s2); // CraftBukkit - notify command sender
} else { } else {
EntityPlayer entityplayer; EntityPlayer entityplayer;
if (s.toLowerCase().startsWith("ban ")) { if (s.toLowerCase().startsWith("ban ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.a(s2); serverconfigurationmanager.a(s2);
this.a(s1, "Banning " + s2); this.notify(icommandlistener, "Banning " + s2); // CraftBukkit - notify command sender
entityplayer = serverconfigurationmanager.i(s2); entityplayer = serverconfigurationmanager.i(s2);
if (entityplayer != null) { if (entityplayer != null) {
entityplayer.a.a("Banned by admin"); entityplayer.a.a("Banned by admin");
@ -71,12 +76,16 @@ public class ConsoleCommandHandler {
} else if (s.toLowerCase().startsWith("pardon ")) { } else if (s.toLowerCase().startsWith("pardon ")) {
s2 = s.substring(s.indexOf(" ")).trim(); s2 = s.substring(s.indexOf(" ")).trim();
serverconfigurationmanager.b(s2); serverconfigurationmanager.b(s2);
this.a(s1, "Pardoning " + s2); this.notify(icommandlistener, "Pardoning " + s2); // CraftBukkit - notify command sender
} else { } else {
int i; int i;
if (s.toLowerCase().startsWith("kick ")) { if (s.toLowerCase().startsWith("kick ")) {
s2 = s.substring(s.indexOf(" ")).trim(); // CraftBukkit - Start - Add kick message compatibility
String[] parts = s.split(" ");
s2 = ( parts.length >= 2 ) ? parts[1] : "";
// CraftBukkit - End
// s2 = s.substring(s.indexOf(" ")).trim(); // CraftBukkit - Removed
entityplayer = null; entityplayer = null;
for (i = 0; i < serverconfigurationmanager.b.size(); ++i) { for (i = 0; i < serverconfigurationmanager.b.size(); ++i) {
@ -89,7 +98,7 @@ public class ConsoleCommandHandler {
if (entityplayer != null) { if (entityplayer != null) {
entityplayer.a.a("Kicked by admin"); entityplayer.a.a("Kicked by admin");
this.a(s1, "Kicking " + entityplayer.name); this.notify(icommandlistener, "Kicking " + entityplayer.name); // CraftBukkit - notify command sender
} else { } else {
icommandlistener.b("Can\'t find user " + s2 + ". No kick."); icommandlistener.b("Can\'t find user " + s2 + ". No kick.");
} }
@ -108,7 +117,7 @@ public class ConsoleCommandHandler {
icommandlistener.b("Can\'t find user " + astring[2] + ". No tp."); icommandlistener.b("Can\'t find user " + astring[2] + ". No tp.");
} else { } else {
entityplayer.a.a(entityplayer2.locX, entityplayer2.locY, entityplayer2.locZ, entityplayer2.yaw, entityplayer2.pitch); entityplayer.a.a(entityplayer2.locX, entityplayer2.locY, entityplayer2.locZ, entityplayer2.yaw, entityplayer2.pitch);
this.a(s1, "Teleporting " + astring[1] + " to " + astring[2] + "."); this.notify(icommandlistener, "Teleporting " + astring[1] + " to " + astring[2] + "."); // CraftBukkit - notify command sender
} }
} else { } else {
icommandlistener.b("Syntax error, please provice a source and a target."); icommandlistener.b("Syntax error, please provice a source and a target.");
@ -119,7 +128,7 @@ public class ConsoleCommandHandler {
if (s.toLowerCase().startsWith("give ")) { if (s.toLowerCase().startsWith("give ")) {
astring = s.split(" "); astring = s.split(" ");
if (astring.length != 3 && astring.length != 4) { if (astring.length != 3 && astring.length != 4) {
return; return true;
} }
s3 = astring[1]; s3 = astring[1];
@ -129,7 +138,7 @@ public class ConsoleCommandHandler {
int j = Integer.parseInt(astring[2]); int j = Integer.parseInt(astring[2]);
if (Item.byId[j] != null) { if (Item.byId[j] != null) {
this.a(s1, "Giving " + entityplayer2.name + " some " + j); this.notify(icommandlistener, "Giving " + entityplayer2.name + " some " + j); // CraftBukkit - notify command sender
int k = 1; int k = 1;
if (astring.length > 3) { if (astring.length > 3) {
@ -157,7 +166,7 @@ public class ConsoleCommandHandler {
} else if (s.toLowerCase().startsWith("time ")) { } else if (s.toLowerCase().startsWith("time ")) {
astring = s.split(" "); astring = s.split(" ");
if (astring.length != 3) { if (astring.length != 3) {
return; return true;
} }
s3 = astring[1]; s3 = astring[1];
@ -166,10 +175,10 @@ public class ConsoleCommandHandler {
i = Integer.parseInt(astring[2]); i = Integer.parseInt(astring[2]);
if ("add".equalsIgnoreCase(s3)) { if ("add".equalsIgnoreCase(s3)) {
worldserver.a(worldserver.k() + (long) i); worldserver.a(worldserver.k() + (long) i);
this.a(s1, "Added " + i + " to time"); this.notify(icommandlistener, "Added " + i + " to time"); // CraftBukkit - notify command sender
} else if ("set".equalsIgnoreCase(s3)) { } else if ("set".equalsIgnoreCase(s3)) {
worldserver.a((long) i); worldserver.a((long) i);
this.a(s1, "Set time to " + i); this.notify(icommandlistener, "Set time to " + i); // CraftBukkit - notify command sender
} else { } else {
icommandlistener.b("Unknown method, use either \"add\" or \"set\""); icommandlistener.b("Unknown method, use either \"add\" or \"set\"");
} }
@ -195,7 +204,8 @@ public class ConsoleCommandHandler {
} else if (s.toLowerCase().startsWith("whitelist ")) { } else if (s.toLowerCase().startsWith("whitelist ")) {
this.a(s1, s, icommandlistener); this.a(s1, s, icommandlistener);
} else { } else {
a.info("Unknown console command. Type \"help\" for help."); icommandlistener.b("Unknown console command. Type \"help\" for help."); // CraftBukkit - Send to listener not log
return false;
} }
} }
} }
@ -205,6 +215,8 @@ public class ConsoleCommandHandler {
} else { } else {
this.a(icommandlistener); this.a(icommandlistener);
} }
return true;
} }
private void a(String s, String s1, ICommandListener icommandlistener) { private void a(String s, String s1, ICommandListener icommandlistener) {
@ -214,10 +226,10 @@ public class ConsoleCommandHandler {
String s2 = astring[1].toLowerCase(); String s2 = astring[1].toLowerCase();
if ("on".equals(s2)) { if ("on".equals(s2)) {
this.a(s, "Turned on white-listing"); this.notify(icommandlistener, "Turned on white-listing"); // CraftBukkit - notify command sender
this.b.d.b("white-list", true); this.b.d.b("white-list", true);
} else if ("off".equals(s2)) { } else if ("off".equals(s2)) {
this.a(s, "Turned off white-listing"); this.notify(icommandlistener, "Turned off white-listing"); // CraftBukkit - notify command sender
this.b.d.b("white-list", false); this.b.d.b("white-list", false);
} else if ("list".equals(s2)) { } else if ("list".equals(s2)) {
Set set = this.b.f.e(); Set set = this.b.f.e();
@ -236,14 +248,14 @@ public class ConsoleCommandHandler {
if ("add".equals(s2) && astring.length == 3) { if ("add".equals(s2) && astring.length == 3) {
s5 = astring[2].toLowerCase(); s5 = astring[2].toLowerCase();
this.b.f.k(s5); this.b.f.k(s5);
this.a(s, "Added " + s5 + " to white-list"); this.notify(icommandlistener, "Added " + s5 + " to white-list"); // CraftBukkit - notify command sender
} else if ("remove".equals(s2) && astring.length == 3) { } else if ("remove".equals(s2) && astring.length == 3) {
s5 = astring[2].toLowerCase(); s5 = astring[2].toLowerCase();
this.b.f.l(s5); this.b.f.l(s5);
this.a(s, "Removed " + s5 + " from white-list"); this.notify(icommandlistener, "Removed " + s5 + " from white-list"); // CraftBukkit - notify command sender
} else if ("reload".equals(s2)) { } else if ("reload".equals(s2)) {
this.b.f.f(); this.b.f.f();
this.a(s, "Reloaded white-list from file"); this.notify(icommandlistener, "Reloaded white-list from file"); // CraftBukkit - notify command sender
} }
} }
} }
@ -273,9 +285,18 @@ public class ConsoleCommandHandler {
icommandlistener.b(" time <add|set> <amount> adds to or sets the world time (0-24000)"); icommandlistener.b(" time <add|set> <amount> adds to or sets the world time (0-24000)");
} }
// CraftBukkit start
// Notify sender and ops / log
private void notify(ICommandListener commandListener, String msg ) {
commandListener.b( msg );
this.a( commandListener.c(), msg );
}
// CraftBukkit end
private void a(String s, String s1) { private void a(String s, String s1) {
String s2 = s + ": " + s1; String s2 = s + ": " + s1;
// CraftBukkit - This notifies ops and logs
this.b.f.j("\u00A77(" + s2 + ")"); this.b.f.j("\u00A77(" + s2 + ")");
a.info(s2); a.info(s2);
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
public PropertyManager d; public PropertyManager d;
// public WorldServer e; // CraftBukkit - removed // public WorldServer e; // CraftBukkit - removed
public ServerConfigurationManager f; public ServerConfigurationManager f;
private ConsoleCommandHandler o; public ConsoleCommandHandler o; // CraftBukkit - made public
private boolean p = true; private boolean p = true;
public boolean g = false; public boolean g = false;
int h = 0; int h = 0;
@ -377,13 +377,8 @@ public class MinecraftServer implements Runnable, ICommandListener {
while (this.r.size() > 0) { while (this.r.size() > 0) {
ServerCommand servercommand = (ServerCommand) this.r.remove(0); ServerCommand servercommand = (ServerCommand) this.r.remove(0);
// CraftBukkit start server.dispatchCommand(console, servercommand); // CraftBukkit
if (server.dispatchCommand(console, servercommand.a)) { // this.o.a(servercommand); // CraftBukkit - Removed its now called in server.displatchCommand
continue;
}
// CraftBukkit end
this.o.a(servercommand);
} }
} }

Datei anzeigen

@ -21,6 +21,8 @@ import net.minecraft.server.ServerNBTManager;
import net.minecraft.server.WorldLoaderServer; import net.minecraft.server.WorldLoaderServer;
import net.minecraft.server.WorldManager; import net.minecraft.server.WorldManager;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
import net.minecraft.server.ServerCommand;
import net.minecraft.server.ICommandListener;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -163,6 +165,33 @@ public final class CraftServer implements Server {
return server.e; return server.e;
} }
// NOTE: These are dependent on the corrisponding call in MinecraftServer
// so if that changes this will need to as well
public int getPort() {
return this.getConfigInt("server-port", 25565);
}
public String getIp() {
return this.getConfigString("server-ip", "");
}
public String getServerName()
{
return this.getConfigString("server-name", "Unknown Server");
}
// NOTE: Temporary calls through to server.properies until its replaced
private String getConfigString(String variable, String defaultValue)
{
return this.console.d.a(variable, defaultValue);
}
private int getConfigInt(String variable, int defaultValue)
{
return this.console.d.a(variable, defaultValue);
}
// End Temporary calls
public PluginManager getPluginManager() { public PluginManager getPluginManager() {
return pluginManager; return pluginManager;
} }
@ -179,8 +208,27 @@ public final class CraftServer implements Server {
return server; return server;
} }
// NOTE: Should only be called from MinecraftServer.b()
public boolean dispatchCommand(CommandSender sender, ServerCommand serverCommand) {
if ( commandMap.dispatch(sender, serverCommand.a) ) {
return true;
}
return console.o.a(serverCommand);
}
public boolean dispatchCommand(CommandSender sender, String commandLine) { public boolean dispatchCommand(CommandSender sender, String commandLine) {
return commandMap.dispatch(sender, commandLine); // CraftBukkit native commands
if (commandMap.dispatch(sender, commandLine)) {
return true;
}
if ( ! sender.isOp() ) {
return false;
}
// See if the server can process this command
return console.o.a(new ServerCommand(commandLine, new CommandListener(sender)));
} }
public void reload() { public void reload() {
@ -207,7 +255,7 @@ public final class CraftServer implements Server {
@Override @Override
public String toString() { public String toString() {
return "CraftServer{" + "serverName=" + serverName + "serverVersion=" + serverVersion + "protocolVersion=" + protocolVersion + '}'; return "CraftServer{" + "serverName=" + serverName + ",serverVersion=" + serverVersion + ",protocolVersion=" + protocolVersion + '}';
} }
public World createWorld(String name, World.Environment environment) { public World createWorld(String name, World.Environment environment) {
@ -217,7 +265,7 @@ public final class CraftServer implements Server {
if (world != null) { if (world != null) {
return world; return world;
} }
if ((folder.exists()) && (!folder.isDirectory())) { if ((folder.exists()) && (!folder.isDirectory())) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
} }
@ -301,4 +349,23 @@ public final class CraftServer implements Server {
public void savePlayers() { public void savePlayers() {
server.d(); server.d();
} }
// 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 b(String msg) {
this.commandSender.sendMessage(msg);
}
public String c() {
return this.prefix;
}
}
} }