Skip to content

ZenCommandTree

youyihj edited this page Nov 12, 2020 · 3 revisions

ZenCommandTree

This is command tree.

Importing the package

It might be required to import the class to avoid errors.

import mods.zenutils.command.ZenCommandTree;

Create the ZenCommandTree

Before you can add command tree, you need to create a ZenCommandTree instance, and set some properities of the command tree you want to add.

// Return a new ZenCommand instance
ZenCommandTree.create(String name, ZenCommand... subCommands);

ZenGetters

You can use name ZenGetter to get the name of ZenCommandTree.

ZenPropertities

name type default value required
requiredPermissionLevel int 0 No

Register

You need to call register method to register it, otherwise nothing will happen!

Example

import mods.zenutils.command.ZenCommand;
import mods.zenutils.command.CommandUtils;
import mods.zenutils.command.IGetTabCompletion;
import mods.zenutils.command.ZenCommandTree;

val statusMessage as ZenCommand = ZenCommand.create("statusmessage");
statusMessage.getCommandUsage = function(sender) {
    return "commands.statusmessage.usage";
};
statusMessage.requiredPermissionLevel = 2;
statusMessage.tabCompletionGetters = [IGetTabCompletion.player()];
statusMessage.execute = function(command, server, sender, args) {
    if (args.length == 1) {
        CommandUtils.getCommandSenderAsPlayer(sender).sendStatusMessage(args[0], true);
    } else if (args.length == 2) {
        CommandUtils.getPlayer(server, sender, args[0]).sendStatusMessage(args[1], true);
    } else {
        CommandUtils.notifyWrongUsage(command, sender);
    }
};

val helloWorld as ZenCommand = ZenCommand.create("helloworld");
helloWorld.getCommandUsage = function(sender) {
    return "commands.helloworld.usage";
}
helloWorld.requiredPermissionLevel = 0;
helloWorld.execute = function(command, server, sender, args) {
    sender.sendMessage("hello, world!");
};

ZenCommandTree.create("zenutils", statusMessage, helloWorld).register();
Clone this wiki locally