Search in sources :

Example 1 with Value

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);
        }
    }
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) Value(de.dytanic.cloudnet.lib.Value) BukkitMobUpdateEvent(de.dytanic.cloudnet.bridge.event.bukkit.BukkitMobUpdateEvent) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with Value

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();
}
Also used : Value(de.dytanic.cloudnet.lib.Value) Document(de.dytanic.cloudnet.lib.utility.document.Document) Result(de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)

Aggregations

Value (de.dytanic.cloudnet.lib.Value)2 BukkitMobUpdateEvent (de.dytanic.cloudnet.bridge.event.bukkit.BukkitMobUpdateEvent)1 Result (de.dytanic.cloudnet.lib.network.protocol.packet.result.Result)1 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)1 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 ItemStack (org.bukkit.inventory.ItemStack)1