forked from GeyserMC/Geyser
Pull command descriptions from Bukkit and Sponge versions when listing commands
This allows the description of the commands to display when listing the commands in bedrock by tab-completing. This is currently only available on Sponge and Bukkit versions as there is no support in BungeeCord and Velocity to get these values. This data is also not sent in any packet, so we cannot retrieve that from standalone either.
This commit is contained in:
parent
672024c718
commit
bab2b4a420
22 changed files with 340 additions and 23 deletions
|
@ -35,7 +35,7 @@ import org.geysermc.common.AuthType;
|
|||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||
import org.geysermc.common.logger.IGeyserLogger;
|
||||
import org.geysermc.connector.command.GeyserCommandMap;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
import org.geysermc.connector.metrics.Metrics;
|
||||
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
||||
import org.geysermc.connector.network.remote.RemoteServer;
|
||||
|
@ -50,7 +50,6 @@ import java.text.DecimalFormat;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -70,8 +69,6 @@ public class GeyserConnector {
|
|||
private RemoteServer remoteServer;
|
||||
private AuthType authType;
|
||||
|
||||
private GeyserCommandMap commandMap;
|
||||
|
||||
private boolean shuttingDown = false;
|
||||
|
||||
private final ScheduledExecutorService generalThreadPool;
|
||||
|
@ -108,7 +105,6 @@ public class GeyserConnector {
|
|||
Toolbox.init();
|
||||
Translators.start();
|
||||
|
||||
commandMap = new GeyserCommandMap(this);
|
||||
remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort());
|
||||
authType = AuthType.getByName(config.getRemote().getAuthType());
|
||||
|
||||
|
@ -182,8 +178,7 @@ public class GeyserConnector {
|
|||
players.clear();
|
||||
remoteServer = null;
|
||||
authType = null;
|
||||
commandMap.getCommands().clear();
|
||||
commandMap = null;
|
||||
this.getCommandManager().getCommands().clear();
|
||||
|
||||
bootstrap.getGeyserLogger().info("Geyser shutdown successfully.");
|
||||
}
|
||||
|
@ -213,6 +208,10 @@ public class GeyserConnector {
|
|||
return bootstrap.getGeyserConfig();
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return (CommandManager) bootstrap.getGeyserCommandManager();
|
||||
}
|
||||
|
||||
public static GeyserConnector getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
package org.geysermc.connector.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.geysermc.common.command.ICommandManager;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.command.defaults.HelpCommand;
|
||||
import org.geysermc.connector.command.defaults.ReloadCommand;
|
||||
|
@ -35,14 +36,14 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeyserCommandMap {
|
||||
public abstract class CommandManager implements ICommandManager {
|
||||
|
||||
@Getter
|
||||
private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private GeyserConnector connector;
|
||||
|
||||
public GeyserCommandMap(GeyserConnector connector) {
|
||||
public CommandManager(GeyserConnector connector) {
|
||||
this.connector = connector;
|
||||
|
||||
registerCommand(new HelpCommand(connector, "help", "Shows help for all registered commands.", "geyser.command.help"));
|
|
@ -49,8 +49,8 @@ public class HelpCommand extends GeyserCommand {
|
|||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----");
|
||||
Map<String, GeyserCommand> cmds = connector.getCommandMap().getCommands();
|
||||
List<String> commands = connector.getCommandMap().getCommands().keySet().stream().sorted().collect(Collectors.toList());
|
||||
Map<String, GeyserCommand> cmds = connector.getCommandManager().getCommands();
|
||||
List<String> commands = connector.getCommandManager().getCommands().keySet().stream().sorted().collect(Collectors.toList());
|
||||
commands.forEach(cmd -> sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.bedrock;
|
|||
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.command.GeyserCommandMap;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
|
@ -42,9 +42,9 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
|
|||
@Override
|
||||
public void translate(CommandRequestPacket packet, GeyserSession session) {
|
||||
String command = packet.getCommand().replace("/", "");
|
||||
GeyserCommandMap commandMap = GeyserConnector.getInstance().getCommandMap();
|
||||
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandMap.getCommands().containsKey(command.split(" ")[1])) {
|
||||
commandMap.runCommand(session, command);
|
||||
CommandManager commandManager = GeyserConnector.getInstance().getCommandManager();
|
||||
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) {
|
||||
commandManager.runCommand(session, command);
|
||||
} else {
|
||||
String message = packet.getCommand().trim();
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator<Server
|
|||
CommandParamData[][] params = getParams(commandID, packet.getNodes()[commandID], packet.getNodes());
|
||||
|
||||
// Build the completed command and add it to the final list
|
||||
CommandData data = new CommandData(commandName, "A Java server command", flags, (byte) 0, aliases, params);
|
||||
CommandData data = new CommandData(commandName, session.getConnector().getCommandManager().getDescription(commandName), flags, (byte) 0, aliases, params);
|
||||
commandData.add(data);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue