-
-
Notifications
You must be signed in to change notification settings - Fork 148
Frequently Asked Questions
Below you may find one off bits of information that are too small to have their own page, or may be important enough to call out again even if it is mentioned elsewhere
For non Bukkit platforms, replace CommandSender/Player with the source command issuer of your platform in use.
Build tools commonly cache snapshot builds and only periodically check for new versions.
To force a version update check, use the following strategies:
Maven: Add -U
to your command, eg: mvn clean install -U
Gradle: Add --refresh-dependencies
to your command, eg: gradle build --refresh-dependencies
Gradle users can set the following config to adjust cache time:
configurations.all {
resolutionStrategy.cacheChangingModulesFor 30, 'minutes'
}
Create any command like so:
@Default
public void onDefault(CommandSender/Player player) {
// Command
}
Just like the above for @Default
, You may annotate the method @CatchUnknown
and it will receive all unknown commands.
You may even combine @Default
to make a single method handle unknown, no args, and even @Subcommand("help")
to have a catch all help response like so:
@Subcommand("help")
@CatchUnknown @Default
public void doHelp(CommandSender sender, String[] args) {
EmpireDocs.showAntiGrief(sender);
}
You may even leave off the String[] args if you do not need it
@Subcommand("help")
@CatchUnknown @Default
public void doHelp(CommandSender sender) {
EmpireDocs.showAntiGrief(sender);
}
Per Command Organization, it is recommended to simply keep your related subcommands in the same file, and only move distinctive groupings to another file. If you still wish to, see the Command Organization page for details.
You may add the
@Syntax("Anything here")
to the subcommand.
However, if you simply want to change the name of the parameter, the automatic syntax generation will use the parameter name as-is, so you could(should) just rename the parameter.
You missed the step about adding -parameters to the compiler. See the Maven/Gradle setup guides.
This is on the near term roadmap as part of a larger project to make the command system support I18N in a really professional way.
Register a IssuerAwareContextResolver. If you also want to use that class as a parameter for commands, use a @Flag
to differentiate between senders and params.
Example:
// command
public void tacoCommand(User sender, @Flags("other") User recipent)
// register the context
commandManager.getCommandContexts().registerIssuerAwareContext(User.class, c -> {
if ("false".equalsIgnoreCase(c.getFlagValue("other", "false"))) {
return userHandler.getUser(c.getSender().getName()).orElseThrow(() -> new UserException("Unknown user " + c.getSender().getName()));
} else {
return userHandler.getUser(c.getFirstArg()).orElseThrow(() -> new UserException("Unknown user " + c.getFirstArg()));
}
});