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:
Camotoy 2020-12-17 14:10:58 -05:00 committed by GitHub
parent ce9cd92b2e
commit c92150013f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View file

@ -38,7 +38,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
@Override @Override
public void translate(TextPacket packet, GeyserSession session) { public void translate(TextPacket packet, GeyserSession session) {
String message = packet.getMessage().replaceAll("^\\.", "/").trim(); String message = packet.getMessage();
if (MessageTranslator.isTooLong(message, session)) { if (MessageTranslator.isTooLong(message, session)) {
return; return;

View file

@ -52,9 +52,14 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) { public void translate(ServerDeclareCommandsPacket packet, GeyserSession session) {
// Don't send command suggestions if they are disabled // Don't send command suggestions if they are disabled
if (!session.getConnector().getConfig().isCommandSuggestions()) { 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; return;
} }
List<CommandData> commandData = new ArrayList<>(); List<CommandData> commandData = new ArrayList<>();
Int2ObjectMap<String> commands = new Int2ObjectOpenHashMap<>(); Int2ObjectMap<String> commands = new Int2ObjectOpenHashMap<>();
Int2ObjectMap<List<CommandNode>> commandArgs = 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 // 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 // Loop through all the found commands
for (int commandID : commands.keySet()) { for (int commandID : commands.keySet()) {
String commandName = commands.get(commandID); String commandName = commands.get(commandID);
// Create a basic alias // 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 // Get and parse all params
CommandParamData[][] params = getParams(packet.getNodes()[commandID], packet.getNodes()); 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 // Add our commands to the AvailableCommandsPacket for the bedrock client
AvailableCommandsPacket availableCommandsPacket = new AvailableCommandsPacket(); AvailableCommandsPacket availableCommandsPacket = new AvailableCommandsPacket();
for (CommandData data : commandData) { availableCommandsPacket.getCommands().addAll(commandData);
availableCommandsPacket.getCommands().add(data);
}
GeyserConnector.getInstance().getLogger().debug("Sending command packet of " + commandData.size() + " commands"); GeyserConnector.getInstance().getLogger().debug("Sending command packet of " + commandData.size() + " commands");