8000 Let the server generate help topics · CommandAPI/CommandAPI@e58b0e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e58b0e1

Browse files
committed
Let the server generate help topics
1 parent 956d0f6 commit e58b0e1

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ This is the current roadmap for the CommandAPI (as of 30th April 2024):
421421
</ul>
422422
<b>Bug Fixes:</b>
423423
<ul>
424-
<li>https://github.com/CommandAPI/CommandAPI/issues/578, https://github.com/CommandAPI/CommandAPI/issues/583, https://github.com/CommandAPI/CommandAPI/pull/629 Fixes <code>Bukkit#dispatchCommand() not working after Paper's Brigadier API changes</code></li>
424+
<li>https://github.com/CommandAPI/CommandAPI/issues/578, https://github.com/CommandAPI/CommandAPI/issues/583, https://github.com/CommandAPI/CommandAPI/pull/629 Fixes <code>Bukkit#dispatchCommand()</code> not working after Paper's Brigadier API changes</li>
425+
<ul>
426+
<li>This also comes with a change to the <code>withUsage()</code> method which starting with this release does have no effect on servers with Paper's Brigadier API</li>
427+
</ul>
425428
<li>Fixes <code>PotionEffectArgument.NamespacedKey</code> not having suggestions in some versions</li>
426429
</ul>
427430
</td>

commandapi-core/src/main/java/dev/jorel/commandapi/ExecutableCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public Impl withFullDescription(String description) {
190190
/**
191191
* Sets the full usage for this command. This is the usage which is
192192
* shown in the specific /help page for this command (e.g. /help mycommand).
193+
* @apiNote This method has no effect on Paper servers that have Paper's Brigadier API
193194
* @param usage the full usage for this command
194195
* @return this command builder
195196
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ private String[] getUsageList(RegisteredCommand currentCommand) {
276276
}
277277

278278
void updateHelpForCommands(List<RegisteredCommand> commands) {
279+
if (getPaper().isPaperBrigAPI()) return;
279280
Map<String, HelpTopic> helpTopicsToAdd = new HashMap<>();
280281

281282
for (RegisteredCommand command : commands) {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
import com.mojang.brigadier.tree.LiteralCommandNode;
77
import com.mojang.brigadier.tree.RootCommandNode;
88
import io.papermc.paper.plugin.configuration.PluginMeta;
9+
import net.kyori.adventure.text.Component;
10+
import org.bukkit.Bukkit;
911
import org.bukkit.help.HelpTopic;
1012

1113
import java.lang.reflect.Constructor;
1214
import java.lang.reflect.Field;
1315
import java.lang.reflect.InvocationTargetException;
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
1418
import java.util.Collections;
19+
import java.util.HashSet;
1520
import java.util.List;
1621
import java.util.Optional;
22+
import java.util.Set;
1723
import java.util.function.Predicate;
1824
import java.util.function.Supplier;
1925

@@ -184,7 +190,7 @@ private void setPluginCommandMeta(LiteralCommandNode<Source> node) {
184190
metaField.set(node, pluginCommandNodeConstructor.newInstance(
185191
CommandAPIBukkit.getConfiguration().getPlugin().getPluginMeta(),
186192
getDescription(node.getLiteral()),
187-
Collections.emptyList()
193+
getAliasesForCommand(node.getLiteral())
188194
));
189195
} catch (NoSuchFieldException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
190196
// This doesn't happen
@@ -200,7 +206,7 @@ private String getDescription(String commandName) {
200206
} else {
201207
namespaceStripped = commandName;
202208
}
203-
if (command.commandName().equals(namespaceStripped)) {
209+
if (command.commandName().equals(namespaceStripped) || Arrays.asList(command.aliases()).contains(namespaceStripped)) {
204210
Object helpTopic = command.helpTopic().orElse(null);
205211
if (helpTopic != null) {
206212
description = ((HelpTopic) helpTopic).getShortText();
@@ -215,4 +221,14 @@ private String getDescription(String commandName) {
215221
return description;
216222
}
217223

224+
private List<String> getAliasesForCommand(String commandName) {
225+
Set<String> aliases = new HashSet<>();
226+
for (RegisteredCommand command : CommandAPI.getRegisteredCommands()) {
227+
if (command.commandName().equals(commandName)) {
228+
aliases.addAll(Arrays.asList(command.aliases()));
229+
}
230+
}
231+
return new ArrayList<>(aliases);
232+
}
233+
218234
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class PaperImplementations {
2020

2121
private final boolean isPaperPresent;
2222
private final boolean isFoliaPresent;
23+
private final boolean isPaperBrigAPI;
2324
private final NMS<?> nmsInstance;
2425
private final Class<? extends CommandSender> feedbackForwardingCommandSender;
2526
private final Class<? extends CommandSender> nullCommandSender;
@@ -54,6 +55,15 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS<
5455
}
5556

5657
this.nullCommandSender = tempNullCommandSender;
58+
59+
boolean paperCommandSourceStackPresent;
60+
try {
61+
Class.forName("io.papermc.paper.command.brigadier.CommandSourceStack");
62+
paperCommandSourceStackPresent = true;
63+
} catch (ClassNotFoundException e) {
64+
paperCommandSourceStackPresent = false;
65+
}
66+
this.isPaperBrigAPI = paperCommandSourceStackPresent;
5767
}
5868

5969
/**
@@ -110,6 +120,13 @@ public CommandMap getCommandMap() {
110120
public boolean isPaperPresent() {
111121
return this.isPaperPresent;
112122
}
123+
124+
/**
125+
* @return whether we're running a Paper server with the Paper Brigadier command API
126+
*/
127+
public boolean isPaperBrigAPI() {
128+
return this.isPaperBrigAPI;
129+
}
113130

114131
/**
115132
* @return whether we're using folia or not

0 commit comments

Comments
 (0)
0