lucko / commodore

Utility for using Minecraft's 1.13 'brigadier' library in Bukkit plugins.
MIT License
176 stars 15 forks source link

Registering aliases? #7

Open adamtomi opened 4 years ago

adamtomi commented 4 years ago

I was wondering if it's possible to register aliases to certain commands using the commodore file format. Right now I have something like this:

InputStream is = //...
LiteralCommandNode<?> commandNode = CommodoreFileFormat.parse(is);
CommandNode hologramCmd = commandNode.getChild("hologram");
LiteralCommandNode child = LiteralArgumentBuilder.literal("holo")
               .redirect(hologramCmd)
               .build();

commandNode.addChild(child);
commodore.register(command, commandNode);

which is obviously not that great since I'd have to write something like shown above for all aliases. Is there a better solution for this?

lucko commented 4 years ago

Using Commodore#register(Command, LiteralCommandNode) will automatically register the data for all aliases of the command.

The code for that is here: https://github.com/lucko/commodore/blob/1c1b6287847cf66beea31efa5e293a5316ad92b3/src/main/java/me/lucko/commodore/CommodoreImpl.java#L166-L171

https://github.com/lucko/commodore/blob/1c1b6287847cf66beea31efa5e293a5316ad92b3/src/main/java/me/lucko/commodore/CommodoreImpl.java#L201-L207

So if you're using that, there should be no more effort required on your part. :)

adamtomi commented 4 years ago

Yeah, all the commands using Commodore#register. However, in my case I only have 1 root command, and some subcommands. What I'm trying to achieve is to have /rootcommand subcommand <some args> and /rootcommand sub <some args> where subcommand and sub are aliases, and the two would do the same. :C

marcbal commented 4 years ago

I think the suggestion here is to add the ability to define command redirection in the commodore file format.

A suggestion for the commodore file format including a redirection could look like this:

your_command {
  hologram {
    // some args
  }
  holo redirect your_command hologram;
}
adamtomi commented 4 years ago

That'd be cool!