Skip to content

Commit bb043bb

Browse files
authored
Merge pull request CommandAPI#546 from JorelAli/dev/fix-help-topics
Fix help topic generation
2 parents 51b5d1e + 38f3a38 commit bb043bb

File tree

1 file changed

+17
-0
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi

1 file changed

+17
-0
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ private String generateCommandHelpPrefix(String command) {
299299
return (Bukkit.getPluginCommand(command) == null ? "/" : "/minecraft:") + command;
300300
}
301301

302+
private String generateCommandHelpPrefix(String command, String namespace) {
303+
return (Bukkit.getPluginCommand(command) == null ? "/" + namespace + ":" : "/minecraft:") + command;
304+
}
305+
302306
private void generateHelpUsage(StringBuilder sb, RegisteredCommand command) {
303307
// Generate usages
304308
String[] usages = getUsageList(command);
@@ -354,10 +358,15 @@ private String[] getUsageList(RegisteredCommand currentCommand) {
354358

355359
void updateHelpForCommands(List<RegisteredCommand> commands) {
356360
Map<String, HelpTopic> helpTopicsToAdd = new HashMap<>();
361+
Set<String> namespacedCommandNames = new HashSet<>();
357362

358363
for (RegisteredCommand command : commands) {
359364
// Don't override the plugin help topic
360365
String commandPrefix = generateCommandHelpPrefix(command.commandName());
366+
367+
// Namespaced commands shouldn't have a help topic, we should save the namespaced command name
368+
namespacedCommandNames.add(generateCommandHelpPrefix(command.commandName(), command.namespace()));
369+
361370
StringBuilder aliasSb = new StringBuilder();
362371
final String shortDescription;
363372

@@ -418,13 +427,21 @@ void updateHelpForCommands(List<RegisteredCommand> commands) {
418427
// Don't override the plugin help topic
419428
commandPrefix = generateCommandHelpPrefix(alias);
420429
helpTopic = generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission);
430+
431+
// Namespaced commands shouldn't have a help topic, we should save the namespaced alias name
432+
namespacedCommandNames.add(generateCommandHelpPrefix(alias, command.namespace()));
421433
}
422434
helpTopicsToAdd.put(commandPrefix, helpTopic);
423435
}
424436
}
425437

426438
// We have to use helpTopics.put (instead of .addTopic) because we're overwriting an existing help topic, not adding a new help topic
427439
getHelpMap().putAll(helpTopicsToAdd);
440+
441+
// We also have to remove help topics for namespaced command names
442+
for (String namespacedCommandName : namespacedCommandNames) {
443+
getHelpMap().remove(namespacedCommandName);
444+
}
428445
}
429446

430447
private void fixNamespaces() {

0 commit comments

Comments
 (0)