diff --git a/bukkit/src/main/java/revxrsal/commands/bukkit/brigadier/PaperCommodore.java b/bukkit/src/main/java/revxrsal/commands/bukkit/brigadier/PaperCommodore.java index 45d7428c..410e00a1 100644 --- a/bukkit/src/main/java/revxrsal/commands/bukkit/brigadier/PaperCommodore.java +++ b/bukkit/src/main/java/revxrsal/commands/bukkit/brigadier/PaperCommodore.java @@ -52,11 +52,12 @@ final class PaperCommodore extends Commodore implements Listener { private final Map> commands = new HashMap<>(); private final BukkitCommandHandler handler; + private final String fallbackPrefix; PaperCommodore(@NotNull BukkitCommandHandler handler) { this.handler = handler; - Plugin plugin = handler.getPlugin(); + fallbackPrefix = plugin.getName().toLowerCase().trim(); registerListener(plugin); } @@ -71,12 +72,14 @@ public final class UnknownCommandListener implements Listener { @EventHandler public void onUnknownCommand(UnknownCommandEvent event) { ArgumentStack args = ArgumentStack.parse( - stripNamespace(event.getCommandLine()) + stripNamespace(fallbackPrefix, event.getCommandLine()) ); - if (commands.containsKey(args.get(0))) { - BukkitCommandActor actor = BukkitCommandActor.wrap(event.getSender(), handler); + if (commands.containsKey(args.getFirst())) { event.message(null); + BukkitCommandActor actor = BukkitCommandActor.wrap(event.getSender(), handler); try { + // This will automatically fail, we can then easily get the + // exception message and overwrite it. handler.dispatch(actor, args); } catch (Throwable t) { handler.getExceptionHandler().handleException(t, actor); diff --git a/common/src/main/java/revxrsal/commands/util/Strings.java b/common/src/main/java/revxrsal/commands/util/Strings.java index e34753b8..26d5ed9b 100644 --- a/common/src/main/java/revxrsal/commands/util/Strings.java +++ b/common/src/main/java/revxrsal/commands/util/Strings.java @@ -91,6 +91,15 @@ public static LinkedList splitBySpace(String text) { return null; } + public static @NotNull String stripNamespace(String namespace, @NotNull String command) { + int colon = command.indexOf(namespace + ':'); + if (colon == -1) { + return command; + } + // +1 for the ':' + return command.substring(namespace.length() + 1); + } + public static @NotNull String stripNamespace(@NotNull String command) { int colon = command.indexOf(':'); if (colon == -1)