SPIGOT-7467: Add getAddress to RemoteConsoleCommandSender

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-08-26 18:19:22 +10:00
parent 6fdc83ddd9
commit a16df1b04c
6 changed files with 179 additions and 54 deletions

View File

@@ -17,7 +17,16 @@
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
static final Logger LOGGER = LogUtils.getLogger();
@@ -70,8 +80,10 @@
@@ -61,7 +71,7 @@
private final List<ServerCommand> consoleInput = Collections.synchronizedList(Lists.newArrayList());
@Nullable
private RemoteStatusListener queryThreadGs4;
- public final RemoteControlCommandListener rconConsoleSource;
+ // public final RemoteControlCommandListener rconConsoleSource; // CraftBukkit - remove field
@Nullable
private RemoteControlListener rconThread;
public DedicatedServerSettings settings;
@@ -70,10 +80,12 @@
@Nullable
private final TextFilter textFilterClient;
@@ -28,8 +37,11 @@
+ super(options, worldLoader, thread, convertable_conversionsession, resourcepackrepository, worldstem, Proxy.NO_PROXY, datafixer, services, worldloadlistenerfactory);
+ // CraftBukkit end
this.settings = dedicatedserversettings;
this.rconConsoleSource = new RemoteControlCommandListener(this);
- this.rconConsoleSource = new RemoteControlCommandListener(this);
+ // this.rconConsoleSource = new RemoteControlCommandListener(this); // CraftBukkit - remove field
this.textFilterClient = TextFilter.createFromConfig(dedicatedserversettings.getProperties().textFilteringConfig);
}
@@ -81,13 +93,44 @@
public boolean initServer() throws IOException {
Thread thread = new Thread("Server console handler") {
@@ -144,15 +156,7 @@
long j = SystemUtils.getNanos() - i;
String s = String.format(Locale.ROOT, "%.3fs", (double) j / 1.0E9D);
@@ -181,6 +251,7 @@
if (dedicatedserverproperties.enableRcon) {
DedicatedServer.LOGGER.info("Starting remote control listener");
this.rconThread = RemoteControlListener.create(this);
+ this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.rconConsoleSource); // CraftBukkit
}
if (this.getMaxTickLength() > 0L) {
@@ -296,6 +367,7 @@
@@ -296,6 +366,7 @@
this.queryThreadGs4.stop();
}
@@ -160,7 +164,7 @@
}
@Override
@@ -317,7 +389,15 @@
@@ -317,7 +388,15 @@
while (!this.consoleInput.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0);
@@ -177,7 +181,7 @@
}
}
@@ -539,14 +619,45 @@
@@ -539,16 +618,52 @@
@Override
public String getPluginNames() {
@@ -210,22 +214,31 @@
@Override
public String runCommand(String s) {
this.rconConsoleSource.prepareForCommand();
- this.rconConsoleSource.prepareForCommand();
+ // CraftBukkit start - fire RemoteServerCommandEvent
+ throw new UnsupportedOperationException("Not supported - remote source required.");
+ }
+
+ public String runCommand(RemoteControlCommandListener rconConsoleSource, String s) {
+ rconConsoleSource.prepareForCommand();
this.executeBlocking(() -> {
- this.getCommands().performPrefixedCommand(this.rconConsoleSource.createCommandSourceStack(), s);
+ // CraftBukkit start - fire RemoteServerCommandEvent
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, s);
+ CommandListenerWrapper wrapper = rconConsoleSource.createCommandSourceStack();
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(rconConsoleSource.getBukkitSender(wrapper), s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), rconConsoleSource.createCommandSourceStack());
+ server.dispatchServerCommand(remoteConsole, serverCommand);
+ // CraftBukkit end
+ ServerCommand serverCommand = new ServerCommand(event.getCommand(), wrapper);
+ server.dispatchServerCommand(event.getSender(), serverCommand);
});
return this.rconConsoleSource.getCommandResponse();
- return this.rconConsoleSource.getCommandResponse();
+ return rconConsoleSource.getCommandResponse();
+ // CraftBukkit end
}
@@ -599,4 +710,15 @@
public void storeUsingWhiteList(boolean flag) {
@@ -599,4 +714,15 @@
public Optional<MinecraftServer.ServerResourcePackInfo> getServerResourcePack() {
return this.settings.getProperties().serverResourcePackInfo;
}