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();
}
}
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;
}
Aggregations