From cffb5b00200617565e57f2a5ac78651ca6d67ffb Mon Sep 17 00:00:00 2001 From: William Date: Sat, 15 Jun 2024 23:27:04 +0100 Subject: [PATCH] feat: fixup command aliases on legacy Paper --- .../net/william278/uniform/ExampleCommand.java | 3 +++ .../uniform/paper/LegacyPaperCommand.java | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java index 6f7f2da..81e447d 100644 --- a/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java +++ b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java @@ -24,6 +24,8 @@ package net.william278.uniform; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; +import java.util.List; + import static net.william278.uniform.BaseCommand.greedyString; public class ExampleCommand extends Command { @@ -31,6 +33,7 @@ public class ExampleCommand extends Command { public ExampleCommand() { super("example"); setDescription("An example command for Uniform"); + setAliases(List.of("helloworld")); } @Override 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 42910fc..43658d8 100644 --- a/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java +++ b/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java @@ -23,6 +23,7 @@ package net.william278.uniform.paper; import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent; +import com.google.common.collect.Sets; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; import lombok.AllArgsConstructor; @@ -35,6 +36,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Locale; import java.util.Set; @SuppressWarnings({"removal", "deprecation", "UnstableApiUsage"}) @@ -73,10 +75,20 @@ public class LegacyPaperCommand extends BaseCommand event) { commands.forEach(command -> { + // Register root command final LiteralCommandNode built = command.build(); event.getRoot().addChild(built); - command.getAliases().forEach(alias -> event.getRoot().addChild( - LiteralArgumentBuilder.literal(alias).redirect(built).build() + + // Register aliases + final Set aliases = Sets.newHashSet(command.getAliases()); + aliases.add("%s:%s".formatted( + plugin.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""), + command.getName()) + ); + aliases.forEach(alias -> event.getRoot().addChild( + LiteralArgumentBuilder.literal(alias) + .requires(built.getRequirement()).executes(built.getCommand()).redirect(built) + .build() )); }); commands.clear();