Skip to content

IGetTabCompletion

youyihj edited this page Dec 7, 2020 · 4 revisions

IGetTabCompletion

IGetTabCompletion function is used to get command's tab completion.

Importing the package

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import. import mods.zenutils.command.IGetTabCompletion;

Parameters

The IGetTabCompletion function is a function with the following parameters (in this order):

The function should return a StringList.

Pre-registered IGetTabCompletions

These below are pre-registered IGetTabCompletions by zenutils. You can call these method to get them. For example: IGetTabCompletion.item().

  • empty: Empty List
  • item: All items in the game
  • block: All blocks in the game
  • player: All online players in the server
  • potion: All potions in the game
  • x: the target position's X coordinate
  • y: the target position's Y coordinate
  • z: the target position's Z coordinate

In acutal combat

The example script needs GameStage to run.

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

val stageGetter as IGetTabCompletion = function(server, sender, pos) {
    return StringList.create([
        "one",
        "two",
        "three",
        "four",
        "five",
        "six",
        "alpha",
        "beta"
    ]);
};

val addGameStage as ZenCommand = ZenCommand.create("addstage");
addGameStage.getCommandUsage = function(sender) {
    return "commands.addstage.usage";
};
addGameStage.requiredPermissionLevel = 3;
addGameStage.tabCompletionGetters = [IGetTabCompletion.player(), stageGetter];
addGameStage.execute = function(command, server, sender, args) {
    if (args.length == 2) {
        CommandUtils.getPlayer(server, sender, args[0]).addGameStage(args[1]);
    } else {
        CommandUtils.notifyWrongUsage(command, sender);
    }
}
addGameStage.register();
Clone this wiki locally