From 6fc0a618ff1e1840d3b8282c5a2232db4878d50d Mon Sep 17 00:00:00 2001 From: William Date: Wed, 19 Jun 2024 12:41:23 +0100 Subject: [PATCH] feat: properly do the above --- .../net/william278/uniform/bukkit/BukkitCommand.java | 9 ++++++++- .../net/william278/uniform/paper/LegacyPaperCommand.java | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java index be8cc69..1e00580 100644 --- a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java @@ -38,6 +38,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.stream.Collectors; @SuppressWarnings("unused") public class BukkitCommand extends BaseCommand { @@ -78,12 +79,18 @@ public class BukkitCommand extends BaseCommand { // Setup command properties this.setDescription(command.getDescription()); this.setAliases(command.getAliases()); - this.setUsage(command.build().getUsageText()); + this.setUsage(getUsageText()); if (permission != null) { this.setPermission(permission.node()); } } + @NotNull + private String getUsageText() { + return dispatcher.getSmartUsage(dispatcher.getRoot(), null).values().stream() + .map("/%s"::formatted).collect(Collectors.joining("\n")); + } + @SuppressWarnings("deprecation") @Override public boolean execute(@NotNull CommandSender commandSender, @NotNull String alias, @NotNull String[] args) { diff --git a/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java b/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java index 0f749bf..5ce5b3a 100644 --- a/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java +++ b/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java @@ -34,6 +34,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; @SuppressWarnings("unused") public class LegacyPaperCommand extends BaseCommand { @@ -83,12 +84,18 @@ public class LegacyPaperCommand extends BaseCommand { // Setup command properties this.setDescription(command.getDescription()); this.setAliases(command.getAliases()); - this.setUsage(command.build().getUsageText()); + this.setUsage(getUsageText()); if (permission != null) { this.setPermission(permission.node()); } } + @NotNull + private String getUsageText() { + return dispatcher.getSmartUsage(dispatcher.getRoot(), null).values().stream() + .map("/%s"::formatted).collect(Collectors.joining("\n")); + } + @SuppressWarnings("deprecation") @Override public boolean execute(@NotNull CommandSender commandSender, @NotNull String alias, @NotNull String[] args) {