use of de.dytanic.cloudnet.lib.Value in project CloudNet by Dytanic.
the class MobSelector method handleUpdate.
public void handleUpdate(ServerInfo serverInfo) {
if (serverInfo.getServiceId().getGroup() == null)
return;
for (MobImpl mob : this.mobs.values()) if (mob.getMob().getTargetGroup().equals(serverInfo.getServiceId().getGroup())) {
mob.getEntity().setTicksLived(Integer.MAX_VALUE);
updateCustom(mob.getMob(), mob.getDisplayMessage());
Bukkit.getPluginManager().callEvent(new BukkitMobUpdateEvent(mob.getMob()));
mob.getServerPosition().clear();
filter(serverInfo.getServiceId().getGroup());
Collection<ServerInfo> serverInfos = filter(serverInfo.getServiceId().getGroup());
final Value<Integer> index = new Value<>(0);
for (ServerInfo server : serverInfos) {
if (server.isOnline() && server.getServerState().equals(ServerState.LOBBY) && !server.getServerConfig().isHideServer() && !server.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
while (mobConfig.getDefaultItemInventory().containsKey((index.getValue() + 1))) index.setValue(index.getValue() + 1);
if ((mobConfig.getInventorySize() - 1) <= index.getValue())
break;
final int value = index.getValue();
Bukkit.getScheduler().runTask(CloudServer.getInstance().getPlugin(), new Runnable() {
@Override
public void run() {
mob.getInventory().setItem(value, transform(mobConfig.getItemLayout(), server));
mob.getServerPosition().put(value, server.getServiceId().getServerId());
}
});
index.setValue(index.getValue() + 1);
}
}
while (index.getValue() < (mob.getInventory().getSize())) {
if (!mobConfig.getDefaultItemInventory().containsKey(index.getValue() + 1))
mob.getInventory().setItem(index.getValue(), new ItemStack(Material.AIR));
index.setValue(index.getValue() + 1);
}
}
}
use of de.dytanic.cloudnet.lib.Value in project CloudNet by Dytanic.
the class PacketManager method sendQuery.
public Result sendQuery(Packet packet, PacketSender packetSender) {
UUID uniq = UUID.randomUUID();
packet.uniqueId = uniq;
Value<Result> handled = new Value<>(null);
synchronizedHandlers.put(uniq, handled);
executorService.execute(new Runnable() {
@Override
public void run() {
packetSender.sendPacket(packet);
}
});
short i = 0;
while (synchronizedHandlers.get(uniq).getValue() == null && i++ < 5000) {
try {
Thread.sleep(0, 300000);
} catch (InterruptedException e) {
}
}
if (i >= 200) {
synchronizedHandlers.get(uniq).setValue(new Result(uniq, new Document()));
}
Value<Result> values = synchronizedHandlers.get(uniq);
synchronizedHandlers.remove(uniq);
return values.getValue();
}
Aggregations