Command Replacements - aikar/commands GitHub Wiki
What would you use this for?
Replacements are variables for your commands, that replaces values in the annotation at runtime.
Examples of where command replacements will be useful:
- Permission nodes
Define common permission nodes to a descriptive 'role'. Abstract out the perm name and if the perm ever changes, you change it in 1 place. Or for those long permission nodes, so you don't have to look it up each time. - Dynamic
@Values
that are shared with@CommandCompletion
Say you have a server switcher, and you don't want to include the current server in the list. Build the list of static strings of allowed values as a replacement string, instead of it being a fixed value in the compiled jar. - Common
@Flags
Define repeated complicated flag setup as a replacement to avoid repetition and maintenance burden to update it. - Common
@Syntax
appendages
For example: " See more at help.mysite.com or type /help"
How to register them
First have your plugin setup for a Command Manager, by seeing: Using ACF
Then on your manager, do CommandReplacements replacements = manager.getCommandReplacements();
Then you may do stuff like:
replacements.addReplacements(
"test", "foobar", // %test -> foobar
"foo", "barbaz" // %foo -> barbaz
);
replacements.addReplacement("x", "y"); // %x -> y
Do this at plugin startup / manager creation. Preferably before registering commands.
Using Replacements
Simply use %ID in an annotations value, such as the above examples would be @CommandAlias("%test")
would result in @CommandAlias("foobar")