Venusanticheat docs

Subcommands interface

Plugins add commands under /venus through this registry. Registration is live: a subcommand registered after the plugin started is immediately runnable.

api.subcommands()
SignatureDescription
void register(Subcommand subcommand)Registers a subcommand, replacing any existing command with the same label.
Optional<Subcommand> unregister(String label)Removes a subcommand and returns it when it existed.
Optional<Subcommand> byLabel(String label)Looks a subcommand up; labels are matched case-insensitively. See Subcommand.
List<Subcommand> registered()Everything currently registered, in no particular order.

Registering one

MyPlugin.java
api.subcommands().register(new Subcommand("mystats", false, "myplugin.venus.mystats") {

    @Override
    public void execute(Player player, String label, String[] args) {
        api.users().queryUserByUuid(player.getUniqueId()).ifPresent(user -> {
            long flags = api.checks().of(user).stream()
                    .filter(check -> check.violationLevel() > 0)
                    .count();
            player.sendMessage("Checks with a violation level: " + flags);
        });
    }

    @Override
    public List<String> onTabComplete(Player player, String[] args) {
        return List.of();
    }
});

On a Bukkit server the subcommand is immediately runnable as /venus mystats, appears in tab completion unless hidden is set, and honours the permission node.

Labels and conflicts

  • Labels are compared without case sensitivity, so MyStats and mystats are the same command.
  • Registering a label that already exists replaces it. That is what makes re-registering safe for a plugin that re-registers on config reload.
  • A label that collides with a built-in command shadows it for as long as it is registered, so pick something specific.

Lifecycle

Unregister in your plugin's onDisable:

java
@Override
public void onDisable() {
    if (VenusAPIProvider.isLoaded()) {
        VenusAPIProvider.get().subcommands().unregister("mystats");
    }
}