Search in sources :

Example 1 with CommandData

use of cn.nukkit.command.data.CommandData in project Nukkit by Nukkit.

the class Command method generateCustomCommandData.

/**
 * Generates modified command data for the specified player
 * for AvailableCommandsPacket.
 *
 * @return CommandData|null
 */
public CommandDataVersions generateCustomCommandData(Player player) {
    if (!this.testPermission(player)) {
        return null;
    }
    CommandData customData = this.commandData.clone();
    customData.aliases = this.getAliases();
    customData.description = player.getServer().getLanguage().translateString(this.getDescription());
    customData.permission = player.hasPermission(this.getPermission()) ? "any" : "false";
    this.commandParameters.forEach((key, par) -> {
        CommandOverload overload = new CommandOverload();
        overload.input.parameters = par;
        customData.overloads.put(key, overload);
    });
    if (customData.overloads.size() == 0)
        customData.overloads.put("default", new CommandOverload());
    CommandDataVersions versions = new CommandDataVersions();
    versions.versions.add(customData);
    return versions;
}
Also used : CommandOverload(cn.nukkit.command.data.CommandOverload) CommandDataVersions(cn.nukkit.command.data.CommandDataVersions) CommandData(cn.nukkit.command.data.CommandData)

Aggregations

CommandData (cn.nukkit.command.data.CommandData)1 CommandDataVersions (cn.nukkit.command.data.CommandDataVersions)1 CommandOverload (cn.nukkit.command.data.CommandOverload)1