Search in sources :

Example 1 with CommandParameter

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

the class AvailableCommandsPacket method encode.

@Override
public void encode() {
    this.reset();
    BinaryStream commandsStream = new BinaryStream();
    this.commands.forEach((name, versions) -> {
        if (name.equals("help"))
            return;
        ArrayList<String> aliases = new ArrayList<>();
        aliases.addAll(Arrays.asList(versions.versions.get(0).aliases));
        aliases.add(name);
        for (String alias : aliases) {
            commandsStream.putString(alias);
            commandsStream.putString(versions.versions.get(0).description);
            commandsStream.putByte((byte) 0);
            commandsStream.putByte((byte) 0);
            commandsStream.putLInt(-1);
            commandsStream.putUnsignedVarInt(versions.versions.get(0).overloads.size());
            for (CommandOverload overload : versions.versions.get(0).overloads.values()) {
                commandsStream.putUnsignedVarInt(overload.input.parameters.length);
                for (CommandParameter parameter : overload.input.parameters) {
                    commandsStream.putString(parameter.name);
                    commandsStream.putLInt(ARG_FLAG_VALID | getFlag(parameter.type));
                    commandsStream.putBoolean(parameter.optional);
                }
            }
        }
        aliasCommands += (aliases.size() - 1);
    });
    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(this.commands.size() + aliasCommands);
    this.put(commandsStream.getBuffer());
}
Also used : CommandParameter(cn.nukkit.command.data.CommandParameter) CommandOverload(cn.nukkit.command.data.CommandOverload) ArrayList(java.util.ArrayList) BinaryStream(cn.nukkit.utils.BinaryStream)

Aggregations

CommandOverload (cn.nukkit.command.data.CommandOverload)1 CommandParameter (cn.nukkit.command.data.CommandParameter)1 BinaryStream (cn.nukkit.utils.BinaryStream)1 ArrayList (java.util.ArrayList)1