cn.nukkit.command.data.CommandDataVersions Java Examples

The following examples show how to use cn.nukkit.command.data.CommandDataVersions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Command.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: Command.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void sendCommandData() {
    if (!spawned) {
        return;
    }
    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;
        int identifier = this.dataPacket(pk, true); // We *need* ACK so we can be sure that the client received the packet or not
        Server.getInstance().getScheduler().scheduleDelayedTask(new Task() {
            @Override
            public void onRun(int currentTick) {
                Boolean status = needACK.get(identifier);
                if ((status == null || !status) && isOnline()) {
                    sendCommandData();
                }
            }
        }, 60, true);
    }
}
 
Example #4
Source File: SynapsePlayer.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
public void sendCommandData() {
    AvailableCommandsPacket pk = new AvailableCommandsPacket();
    Map<String, CommandDataVersions> data = new HashMap<>();
    for (Command command : this.server.getCommandMap().getCommands().values()) {
        if (!command.testPermissionSilent(this)) {
            continue;
        }
        CommandDataVersions data0 = command.generateCustomCommandData(this);
        data.put(command.getName(), data0);
    }
    pk.commands = data;
    this.dataPacket(pk, true);
}
 
Example #5
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
        int identifier = this.dataPacket(pk, true); // We *need* ACK so we can be sure that the client received the packet or not
        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();
    }
}