Skip to content

Frequently Asked Questions

MrPowerGamerBR edited this page Aug 3, 2018 · 12 revisions

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.

ACF supposively deployed an update to add something new, but I don't see it

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'
}

How do I handle commands with no arguments (The root command)

Create any command like so:

@Default
public void onDefault(CommandSender/Player player) { 
    // Command
}

How do I handle commands with arguments that do not match a subcommand

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);
    }

How do I put each of my subcommands in their own file

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.

How do I change the syntax message of the command

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.

My parameter names in syntax are "arg1" etc

You missed the step about adding -parameters to the compiler. See the Maven/Gradle setup guides.

How can I change the messages such as Permission Messages?

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.

How do I use my custom sender class?

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()));
  }
});