Skip to content

Commit

Permalink
Merge pull request #537 from JorelAli/dev/literal-argument-help
Browse files Browse the repository at this point in the history
Updates help generation for literal arguments
  • Loading branch information
DerEchtePilz authored Apr 3, 2024
2 parents 4c48580 + ac1d8e4 commit 118704e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ This is the current roadmap for the CommandAPI (as of 11th May 2023):
<li>https://github.com/JorelAli/CommandAPI/issues/495 Adds a parameter to <code>EntitySelectorArgument</code> to allow failure when no entity lists are empty</li>
<li>https://github.com/JorelAli/CommandAPI/issues/367, https://github.com/JorelAli/CommandAPI/pull/509 Adds the ability to register commands with a custom namespace</li>
<li>https://github.com/JorelAli/CommandAPI/pull/523 Exposed more details of the <code>CommandPermission</code></li>
<li>https://github.com/JorelAli/CommandAPI/issues/526, https://github.com/JorelAli/CommandAPI/pull/527 Fix wrong help generation for literal arguments</li>
</ul>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ void register(CommandMetaData<CommandSender> meta, final Argument[] args,
for (Argument arg : args) {
argumentsString.add(arg.getNodeName() + ":" + arg.getClass().getSimpleName());
}
RegisteredCommand registeredCommandInformation = new RegisteredCommand(commandName, argumentsString, shortDescription,
RegisteredCommand registeredCommandInformation = new RegisteredCommand(commandName, argumentsString, List.of(args), shortDescription,
fullDescription, usageDescription, aliases, permission, namespace);
registeredCommands.add(registeredCommandInformation);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.jorel.commandapi;

import dev.jorel.commandapi.arguments.AbstractArgument;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand All @@ -26,6 +28,11 @@ public record RegisteredCommand(
*/
List<String> argsAsStr,

/**
* @return An unmodifiable list of arguments for this command
*/
List<AbstractArgument<?, ?, ?, ?>> arguments,

/**
* @return An {@link Optional} containing this command's help's short
* descriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ public void copyPermissionsAndRequirements(Argument argument) {
this.withPermission(argument.getArgumentPermission());
}

public String getHelpString() {
return "<" + this.getNodeName() + ">";
}

@Override
public String toString() {
return this.getNodeName() + "<" + this.getClass().getSimpleName() + ">";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import dev.jorel.commandapi.arguments.AbstractArgument;
import dev.jorel.commandapi.commandsenders.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -315,8 +316,8 @@ private String[] getUsageList(RegisteredCommand currentCommand) {
final RegisteredCommand command = commandsWithIdenticalNames.get(i);
StringBuilder usageString = new StringBuilder();
usageString.append("/").append(command.commandName()).append(" ");
for (String arg : command.argsAsStr()) {
usageString.append("<").append(arg.split(":")[0]).append("> ");
for (AbstractArgument<?, ?, ?, ?> arg : command.arguments()) {
usageString.append(arg.getHelpString()).append(" ");
}
usages[i] = usageString.toString().trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public CommandAPIArgumentType getArgumentType() {
return CommandAPIArgumentType.LITERAL;
}

@Override
public String getHelpString() {
return literal;
}

@Override
public <Source> String parseArgument(CommandContext<Source> cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException {
return literal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public CommandAPIArgumentType getArgumentType() {
return CommandAPIArgumentType.LITERAL;
}

@Override
public String getHelpString() {
return literal;
}

@Override
public <Source> String parseArgument(CommandContext<Source> cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException {
return literal;
Expand Down

0 comments on commit 118704e

Please sign in to comment.