Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow /help to work even if command suggestions are disabled #1703

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ 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.");

// Only send the `help` command so Bedrock doesn't override it with its own, built-in help command.
CommandEnumData aliases = new CommandEnumData("helpAliases", new String[] { "help" }, false);
CommandData helpCommand = new CommandData("help", "", Collections.emptyList(), (byte) 0, aliases, new CommandParamData[0][0]);

AvailableCommandsPacket helpPacket = new AvailableCommandsPacket();
helpPacket.getCommands().add(helpCommand);
session.sendUpstreamPacket(helpPacket);
return;
}

List<CommandData> commandData = new ArrayList<>();
Int2ObjectMap<String> commands = new Int2ObjectOpenHashMap<>();
Int2ObjectMap<List<CommandNode>> commandArgs = new Int2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -82,29 +91,24 @@ public void translate(ServerDeclareCommandsPacket packet, GeyserSession session)
commands.put(nodeIndex, node.getName());
}

// The command flags, not sure what these do apart from break things
List<CommandData.Flag> flags = new ArrayList<>();

// 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());

// Build the completed command and add it to the final list
CommandData data = new CommandData(commandName, session.getConnector().getCommandManager().getDescription(commandName), flags, (byte) 0, aliases, params);
CommandData data = new CommandData(commandName, session.getConnector().getCommandManager().getDescription(commandName), Collections.emptyList(), (byte) 0, aliases, params);
commandData.add(data);
}

// 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");

Expand Down