forked from GeyserMC/Geyser
Allow /help to work even if command suggestions are disabled (#1703)
* Allow /help to work even if command suggestions are disabled This sends a minimal available commands packet to permit /help sending to the server. * Fix whitespace * Just send an empty packet * Change variable name
This commit is contained in:
parent
ce9cd92b2e
commit
c92150013f
2 changed files with 10 additions and 7 deletions
|
@ -38,7 +38,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
|
|||
|
||||
@Override
|
||||
public void translate(TextPacket packet, GeyserSession session) {
|
||||
String message = packet.getMessage().replaceAll("^\\.", "/").trim();
|
||||
String message = packet.getMessage();
|
||||
|
||||
if (MessageTranslator.isTooLong(message, session)) {
|
||||
return;
|
||||
|
|
|
@ -52,9 +52,14 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
|||
public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) {
|
||||
// Don't send command suggestions if they are disabled
|
||||
if (!session.getConnector().getConfig().isCommandSuggestions()) {
|
||||
session.getConnector().getLogger().debug("Not sending command suggestions as they are disabled.");
|
||||
session.getConnector().getLogger().debug("Not sending translated command suggestions as they are disabled.");
|
||||
|
||||
// Send an empty packet so Bedrock doesn't override /help with its own, built-in help command.
|
||||
AvailableCommandsPacket emptyPacket = new AvailableCommandsPacket();
|
||||
session.sendUpstreamPacket(emptyPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
List<CommandData> commandData = new ArrayList<>();
|
||||
Int2ObjectMap<String> commands = new Int2ObjectOpenHashMap<>();
|
||||
Int2ObjectMap<List<CommandNode>> commandArgs = new Int2ObjectOpenHashMap<>();
|
||||
|
@ -83,14 +88,14 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
|||
}
|
||||
|
||||
// The command flags, not sure what these do apart from break things
|
||||
List<CommandData.Flag> flags = new ArrayList<>();
|
||||
List<CommandData.Flag> flags = Collections.emptyList();
|
||||
|
||||
// Loop through all the found commands
|
||||
for (int commandID : commands.keySet()) {
|
||||
String commandName = commands.get(commandID);
|
||||
|
||||
// Create a basic alias
|
||||
CommandEnumData aliases = new CommandEnumData( commandName + "Aliases", new String[] { commandName.toLowerCase() }, false);
|
||||
CommandEnumData aliases = new CommandEnumData(commandName + "Aliases", new String[] { commandName.toLowerCase() }, false);
|
||||
|
||||
// Get and parse all params
|
||||
CommandParamData[][] params = getParams(packet.getNodes()[commandID], packet.getNodes());
|
||||
|
@ -102,9 +107,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
|
|||
|
||||
// Add our commands to the AvailableCommandsPacket for the bedrock client
|
||||
AvailableCommandsPacket availableCommandsPacket = new AvailableCommandsPacket();
|
||||
for (CommandData data : commandData) {
|
||||
availableCommandsPacket.getCommands().add(data);
|
||||
}
|
||||
availableCommandsPacket.getCommands().addAll(commandData);
|
||||
|
||||
GeyserConnector.getInstance().getLogger().debug("Sending command packet of " + commandData.size() + " commands");
|
||||
|
||||
|
|
Loading…
Reference in a new issue