Search in sources :

Example 1 with CommandDataVersions

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

the class Player method sendCommandData.

public void sendCommandData() {
    AvailableCommandsPacket pk = new AvailableCommandsPacket();
    Map<String, CommandDataVersions> data = new HashMap<>();
    int count = 0;
    for (Command command : this.server.getCommandMap().getCommands().values()) {
        if (!command.testPermissionSilent(this)) {
            continue;
        }
        ++count;
        CommandDataVersions data0 = command.generateCustomCommandData(this);
        data.put(command.getName(), data0);
    }
    if (count > 0) {
        // TODO: structure checking
        pk.commands = data;
        // We *need* ACK so we can be sure that the client received the packet or not
        int identifier = this.dataPacket(pk, true);
        Thread t = new Thread() {

            public void run() {
                // We are going to wait 3 seconds, if after 3 seconds we didn't receive a reply from the client, resend the packet.
                try {
                    Thread.sleep(3000);
                    Boolean status = needACK.get(identifier);
                    if ((status == null || !status) && isOnline()) {
                        sendCommandData();
                        return;
                    }
                } catch (InterruptedException e) {
                }
            }
        };
        t.start();
    }
}
Also used : Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) Command(cn.nukkit.command.Command) CommandDataVersions(cn.nukkit.command.data.CommandDataVersions)

Example 2 with CommandDataVersions

use of cn.nukkit.command.data.CommandDataVersions 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

CommandDataVersions (cn.nukkit.command.data.CommandDataVersions)2 Command (cn.nukkit.command.Command)1 CommandData (cn.nukkit.command.data.CommandData)1 CommandOverload (cn.nukkit.command.data.CommandOverload)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Long2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1