Skip to content

Commit

Permalink
only remove the namespace if it's actually ours.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Sep 27, 2023
1 parent f3f0fc9 commit 2770ead
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ final class PaperCommodore extends Commodore implements Listener {

private final Map<String, LiteralCommandNode<?>> 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);
}

Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions common/src/main/java/revxrsal/commands/util/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public static LinkedList<String> 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)
Expand Down

0 comments on commit 2770ead

Please sign in to comment.