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:
Ursprung
ca3d0512f3
Commit
07c98ea2a4
@ -13,7 +13,12 @@ public class ConsoleCommandHandler {
|
||||
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;
|
||||
ICommandListener icommandlistener = servercommand.b;
|
||||
String s1 = icommandlistener.c();
|
||||
@ -24,17 +29,17 @@ public class ConsoleCommandHandler {
|
||||
if (s.toLowerCase().startsWith("list")) {
|
||||
icommandlistener.b("Connected players: " + serverconfigurationmanager.c());
|
||||
} 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();
|
||||
} 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.a(s1, "Save complete.");
|
||||
this.notify(icommandlistener, "Save complete."); // CraftBukkit - notify command sender
|
||||
} 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;
|
||||
} 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;
|
||||
} else {
|
||||
String s2;
|
||||
@ -42,28 +47,28 @@ public class ConsoleCommandHandler {
|
||||
if (s.toLowerCase().startsWith("op ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
serverconfigurationmanager.e(s2);
|
||||
this.a(s1, "Opping " + s2);
|
||||
this.notify(icommandlistener, "Opping " + s2); // CraftBukkit - notify command sender
|
||||
serverconfigurationmanager.a(s2, "\u00A7eYou are now op!");
|
||||
} else if (s.toLowerCase().startsWith("deop ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
serverconfigurationmanager.f(s2);
|
||||
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 ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
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 ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
serverconfigurationmanager.d(s2);
|
||||
this.a(s1, "Pardoning ip " + s2);
|
||||
this.notify(icommandlistener, "Pardoning ip " + s2); // CraftBukkit - notify command sender
|
||||
} else {
|
||||
EntityPlayer entityplayer;
|
||||
|
||||
if (s.toLowerCase().startsWith("ban ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
serverconfigurationmanager.a(s2);
|
||||
this.a(s1, "Banning " + s2);
|
||||
this.notify(icommandlistener, "Banning " + s2); // CraftBukkit - notify command sender
|
||||
entityplayer = serverconfigurationmanager.i(s2);
|
||||
if (entityplayer != null) {
|
||||
entityplayer.a.a("Banned by admin");
|
||||
@ -71,12 +76,16 @@ public class ConsoleCommandHandler {
|
||||
} else if (s.toLowerCase().startsWith("pardon ")) {
|
||||
s2 = s.substring(s.indexOf(" ")).trim();
|
||||
serverconfigurationmanager.b(s2);
|
||||
this.a(s1, "Pardoning " + s2);
|
||||
this.notify(icommandlistener, "Pardoning " + s2); // CraftBukkit - notify command sender
|
||||
} else {
|
||||
int i;
|
||||
|
||||
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;
|
||||
|
||||
for (i = 0; i < serverconfigurationmanager.b.size(); ++i) {
|
||||
@ -89,7 +98,7 @@ public class ConsoleCommandHandler {
|
||||
|
||||
if (entityplayer != null) {
|
||||
entityplayer.a.a("Kicked by admin");
|
||||
this.a(s1, "Kicking " + entityplayer.name);
|
||||
this.notify(icommandlistener, "Kicking " + entityplayer.name); // CraftBukkit - notify command sender
|
||||
} else {
|
||||
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.");
|
||||
} else {
|
||||
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 {
|
||||
icommandlistener.b("Syntax error, please provice a source and a target.");
|
||||
@ -119,7 +128,7 @@ public class ConsoleCommandHandler {
|
||||
if (s.toLowerCase().startsWith("give ")) {
|
||||
astring = s.split(" ");
|
||||
if (astring.length != 3 && astring.length != 4) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
s3 = astring[1];
|
||||
@ -129,7 +138,7 @@ public class ConsoleCommandHandler {
|
||||
int j = Integer.parseInt(astring[2]);
|
||||
|
||||
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;
|
||||
|
||||
if (astring.length > 3) {
|
||||
@ -157,7 +166,7 @@ public class ConsoleCommandHandler {
|
||||
} else if (s.toLowerCase().startsWith("time ")) {
|
||||
astring = s.split(" ");
|
||||
if (astring.length != 3) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
s3 = astring[1];
|
||||
@ -166,10 +175,10 @@ public class ConsoleCommandHandler {
|
||||
i = Integer.parseInt(astring[2]);
|
||||
if ("add".equalsIgnoreCase(s3)) {
|
||||
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)) {
|
||||
worldserver.a((long) i);
|
||||
this.a(s1, "Set time to " + i);
|
||||
this.notify(icommandlistener, "Set time to " + i); // CraftBukkit - notify command sender
|
||||
} else {
|
||||
icommandlistener.b("Unknown method, use either \"add\" or \"set\"");
|
||||
}
|
||||
@ -195,7 +204,8 @@ public class ConsoleCommandHandler {
|
||||
} else if (s.toLowerCase().startsWith("whitelist ")) {
|
||||
this.a(s1, s, icommandlistener);
|
||||
} 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 {
|
||||
this.a(icommandlistener);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void a(String s, String s1, ICommandListener icommandlistener) {
|
||||
@ -214,10 +226,10 @@ public class ConsoleCommandHandler {
|
||||
String s2 = astring[1].toLowerCase();
|
||||
|
||||
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);
|
||||
} 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);
|
||||
} else if ("list".equals(s2)) {
|
||||
Set set = this.b.f.e();
|
||||
@ -236,14 +248,14 @@ public class ConsoleCommandHandler {
|
||||
if ("add".equals(s2) && astring.length == 3) {
|
||||
s5 = astring[2].toLowerCase();
|
||||
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) {
|
||||
s5 = astring[2].toLowerCase();
|
||||
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)) {
|
||||
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)");
|
||||
}
|
||||
|
||||
// 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) {
|
||||
String s2 = s + ": " + s1;
|
||||
|
||||
// CraftBukkit - This notifies ops and logs
|
||||
this.b.f.j("\u00A77(" + s2 + ")");
|
||||
a.info(s2);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
|
||||
public PropertyManager d;
|
||||
// public WorldServer e; // CraftBukkit - removed
|
||||
public ServerConfigurationManager f;
|
||||
private ConsoleCommandHandler o;
|
||||
public ConsoleCommandHandler o; // CraftBukkit - made public
|
||||
private boolean p = true;
|
||||
public boolean g = false;
|
||||
int h = 0;
|
||||
@ -377,13 +377,8 @@ public class MinecraftServer implements Runnable, ICommandListener {
|
||||
while (this.r.size() > 0) {
|
||||
ServerCommand servercommand = (ServerCommand) this.r.remove(0);
|
||||
|
||||
// CraftBukkit start
|
||||
if (server.dispatchCommand(console, servercommand.a)) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
this.o.a(servercommand);
|
||||
server.dispatchCommand(console, servercommand); // CraftBukkit
|
||||
// this.o.a(servercommand); // CraftBukkit - Removed its now called in server.displatchCommand
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ import net.minecraft.server.ServerNBTManager;
|
||||
import net.minecraft.server.WorldLoaderServer;
|
||||
import net.minecraft.server.WorldManager;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import net.minecraft.server.ServerCommand;
|
||||
import net.minecraft.server.ICommandListener;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -163,6 +165,33 @@ public final class CraftServer implements Server {
|
||||
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() {
|
||||
return pluginManager;
|
||||
}
|
||||
@ -179,8 +208,27 @@ public final class CraftServer implements 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) {
|
||||
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() {
|
||||
@ -207,7 +255,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
@ -301,4 +349,23 @@ public final class CraftServer implements Server {
|
||||
public void savePlayers() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren