Example usage for com.google.common.io ByteArrayDataOutput writeBoolean

List of usage examples for com.google.common.io ByteArrayDataOutput writeBoolean

Introduction

In this page you can find the example usage for com.google.common.io ByteArrayDataOutput writeBoolean.

Prototype

@Override
    void writeBoolean(boolean v);

Source Link

Usage

From source file:de.mineformers.robots.network.packet.PacketFactoryController.java

@Override
public void write(ByteArrayDataOutput out) {
    super.write(out);
    out.writeInt(orientation);/*from   w w  w .j a v a  2 s .  c  om*/
    out.writeBoolean(validMultiblock);
    out.writeUTF(selectedModule);
}

From source file:com.fr3gu.letsmod.entity.EntitySpaceship.java

@Override
public void writeSpawnData(ByteArrayDataOutput data) {
    data.writeBoolean(charged);
}

From source file:de.mineformers.robots.network.packet.PacketFactoryEnergy.java

@Override
public void write(ByteArrayDataOutput out) {
    super.write(out);
    out.writeInt(energy);/*from   www  .ja  va  2 s.c om*/
    out.writeInt(currentRate);
    out.writeBoolean(controllerPos != null);
    if (controllerPos != null) {
        out.writeInt((int) controllerPos.x);
        out.writeInt((int) controllerPos.y);
        out.writeInt((int) controllerPos.z);
    }
}

From source file:nxminetilities.network.MultilightPacket.java

@Override
public void write(ByteArrayDataOutput out) {
    out.writeInt(x);//from   ww w. j a v a  2s.co  m
    out.writeInt(y);
    out.writeInt(z);
    out.writeDouble(lightColourRed);
    out.writeDouble(lightColourGreen);
    out.writeDouble(lightColourBlue);
    out.writeBoolean(lightEnabled);
}

From source file:com.xlogisticzz.learningModding.entities.EntitySpaceship.java

@Override
public void writeSpawnData(ByteArrayDataOutput data) {

    data.writeBoolean(this.charged);
}

From source file:codecrafter47.bungeetablistplus.managers.RedisPlayerManager.java

private <T> void updateData(UUID uuid, DataKey<T> key, T value) {
    try {/*from   w  w  w.j  a  va  2 s.c o m*/
        ByteArrayDataOutput data = ByteStreams.newDataOutput();
        DataStreamUtils.writeUUID(data, uuid);
        DataStreamUtils.writeDataKey(data, key);
        data.writeBoolean(value == null);
        if (value != null) {
            typeRegistry.getTypeAdapter(key.getType()).write(data, value);
        }
        RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_UPDATE,
                Base64.getEncoder().encodeToString(data.toByteArray()));
    } catch (RuntimeException ex) {
        BungeeTabListPlus.getInstance().getLogger().log(Level.WARNING, "RedisBungee Error", ex);
    } catch (Throwable th) {
        BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to send data", th);
    }
}

From source file:net.minecraftforge.gradle.patcher.TaskGenBinPatches.java

private void createBinPatches(HashMap<String, byte[]> patches, String root, File base, File target)
        throws Exception {
    JarFile cleanJ = new JarFile(base);
    JarFile dirtyJ = new JarFile(target);

    for (Map.Entry<String, String> entry : obfMapping.entrySet()) {
        String obf = entry.getKey();
        String srg = entry.getValue();

        if (!patchedFiles.contains(obf)) // Not in the list of patch files.. we didn't edit it.
        {//from w  ww. j  a  va2s  . c o  m
            continue;
        }

        JarEntry cleanE = cleanJ.getJarEntry(obf + ".class");
        JarEntry dirtyE = dirtyJ.getJarEntry(obf + ".class");

        if (dirtyE == null) //Something odd happened.. a base MC class wasn't in the obfed jar?
        {
            continue;
        }

        byte[] clean = (cleanE != null ? ByteStreams.toByteArray(cleanJ.getInputStream(cleanE)) : new byte[0]);
        byte[] dirty = ByteStreams.toByteArray(dirtyJ.getInputStream(dirtyE));

        byte[] diff = delta.compute(clean, dirty);

        ByteArrayDataOutput out = ByteStreams.newDataOutput(diff.length + 50);
        out.writeUTF(obf); // Clean name
        out.writeUTF(obf.replace('/', '.')); // Source Notch name
        out.writeUTF(srg.replace('/', '.')); // Source SRG Name
        out.writeBoolean(cleanE != null); // Exists in Clean
        if (cleanE != null) {
            out.writeInt(adlerHash(clean)); // Hash of Clean file
        }
        out.writeInt(diff.length); // Patch length
        out.write(diff); // Patch

        patches.put(root + srg.replace('/', '.') + ".binpatch", out.toByteArray());
    }

    cleanJ.close();
    dirtyJ.close();
}

From source file:shadowmage.ancient_warfare.common.vehicles.missiles.MissileBase.java

@Override
public void writeSpawnData(ByteArrayDataOutput data) {
    data.writeInt(missileType);/*from w w  w  .j av a  2  s.c om*/
    data.writeFloat(rotationYaw);
    data.writeFloat(rotationPitch);
    data.writeBoolean(inGround);
    data.writeInt(blockX);
    data.writeInt(blockY);
    data.writeInt(blockZ);
    data.writeInt(blockID);
    data.writeInt(blockMeta);
    data.writeInt(rocketBurnTime);
    data.writeBoolean(this.launcher != null);
    if (this.launcher != null) {
        data.writeInt(this.launcher.entityId);
    }
}

From source file:shadowmage.ancient_warfare.common.vehicles.VehicleBase.java

@Override
public void writeSpawnData(ByteArrayDataOutput data) {
    data.writeFloat(this.getHealth());
    data.writeInt(this.vehicleType.getGlobalVehicleType());
    data.writeInt(this.vehicleMaterialLevel);
    ByteTools.writeNBTTagCompound(upgradeHelper.getNBTTag(), data);
    ByteTools.writeNBTTagCompound(ammoHelper.getNBTTag(), data);
    ByteTools.writeNBTTagCompound(moveHelper.getNBTTag(), data);
    ByteTools.writeNBTTagCompound(firingHelper.getNBTTag(), data);
    ByteTools.writeNBTTagCompound(firingVarsHelper.getNBTTag(), data);
    data.writeFloat(localLaunchPower);//from  w  ww. java  2s  .  c  om
    data.writeFloat(localTurretPitch);
    data.writeFloat(localTurretRotation);
    data.writeFloat(localTurretDestPitch);
    data.writeFloat(localTurretDestRot);
    data.writeInt(teamNum);
    data.writeFloat(localTurretRotationHome);
    data.writeBoolean(this.isSettingUp);
    if (this.isSettingUp) {
        data.writeInt(this.setupTicks);
    }
}

From source file:codecrafter47.bungeetablistplus.bukkitbridge.BukkitBridge.java

public void onEnable() {
    try {//  w  w  w  .  j  a  v  a2s.com
        Field field = BungeeTabListPlusBukkitAPI.class.getDeclaredField("instance");
        field.setAccessible(true);
        field.set(null, this);
    } catch (NoSuchFieldException | IllegalAccessException ex) {
        plugin.getLogger().log(Level.SEVERE, "Failed to initialize API", ex);
    }

    plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, BridgeProtocolConstants.CHANNEL);
    plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, BridgeProtocolConstants.CHANNEL,
            (string, player, bytes) -> {

                DataInput input = new DataInputStream(new ByteArrayInputStream(bytes));

                try {
                    int messageId = input.readUnsignedByte();

                    switch (messageId) {
                    case BridgeProtocolConstants.MESSAGE_ID_PROXY_HANDSHAKE:
                        UUID proxyId = DataStreamUtils.readUUID(input);
                        int protocolVersion = input.readInt();

                        if (protocolVersion > BridgeProtocolConstants.VERSION) {
                            rlExecutor.execute(() -> plugin.getLogger()
                                    .warning("BungeeTabListPlus_BukkitBridge is outdated."));
                        } else if (protocolVersion < BridgeProtocolConstants.VERSION) {
                            rlExecutor.execute(() -> plugin.getLogger()
                                    .warning("BungeeTabListPlus proxy plugin outdated."));
                        } else {
                            playerData.put(player, new PlayerBridgeData(proxyId));
                            serverData.computeIfAbsent(proxyId, uuid -> new ServerBridgeData());
                            ByteArrayDataOutput data = ByteStreams.newDataOutput();
                            data.writeByte(BridgeProtocolConstants.MESSAGE_ID_SERVER_HANDSHAKE);
                            player.sendPluginMessage(plugin, BridgeProtocolConstants.CHANNEL,
                                    data.toByteArray());
                        }

                        break;

                    case BridgeProtocolConstants.MESSAGE_ID_PROXY_REQUEST_DATA:
                        BridgeData bridgeData = playerData.get(player);
                        if (bridgeData != null) {
                            handleDataRequest(bridgeData, input);
                        }
                        break;

                    case BridgeProtocolConstants.MESSAGE_ID_PROXY_REQUEST_SERVER_DATA:
                        PlayerBridgeData playerBridgeData = playerData.get(player);
                        if (playerBridgeData != null) {
                            bridgeData = serverData.get(playerBridgeData.proxyId);
                            if (bridgeData != null) {
                                handleDataRequest(bridgeData, input);
                            }
                        }
                        break;

                    case BridgeProtocolConstants.MESSAGE_ID_PROXY_OUTDATED:
                        rlExecutor.execute(
                                () -> plugin.getLogger().warning("BungeeTabListPlus proxy plugin outdated."));
                        break;

                    case BridgeProtocolConstants.MESSAGE_ID_PROXY_REQUEST_RESET_SERVER_DATA:
                        playerBridgeData = playerData.get(player);
                        if (playerBridgeData != null) {
                            bridgeData = serverData.get(playerBridgeData.proxyId);
                            if (bridgeData != null) {
                                serverData.put(playerBridgeData.proxyId, new ServerBridgeData());
                            }
                        }
                        break;

                    default:
                        plugin.getLogger().warning("Received unknown message id " + messageId);
                        break;
                    }
                } catch (IOException ex) {
                    plugin.getLogger().log(Level.SEVERE,
                            "An unexpected error occurred while processing a plugin message.", ex);
                }
            });

    plugin.getServer().getPluginManager().registerEvents(this, plugin);

    updateDataHooks();

    // initialize bridge for players already on the server
    for (Player player : plugin.getServer().getOnlinePlayers()) {
        ByteArrayDataOutput data = ByteStreams.newDataOutput();
        data.writeByte(BridgeProtocolConstants.MESSAGE_ID_SERVER_ENABLE_CONNECTION);
        try {
            DataStreamUtils.writeUUID(data, serverId);
        } catch (IOException e) {
            throw new AssertionError(e);
        }
        player.sendPluginMessage(plugin, BridgeProtocolConstants.CHANNEL, data.toByteArray());
    }

    // start update task
    plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
        long now = System.currentTimeMillis();
        Map<UUID, Player> proxyIds = new HashMap<>();

        for (Map.Entry<Player, PlayerBridgeData> e : playerData.entrySet()) {
            Player player = e.getKey();
            PlayerBridgeData bridgeData = e.getValue();

            proxyIds.putIfAbsent(bridgeData.proxyId, player);

            int size = 0;

            for (CacheEntry entry : bridgeData.requestedData) {
                Object value = playerDataAccess.get(entry.key, player);
                entry.dirty = !Objects.equals(value, entry.value);
                entry.value = value;

                if (entry.dirty) {
                    size++;
                }
            }

            if (size != 0) {
                ByteArrayDataOutput data = ByteStreams.newDataOutput();
                data.writeByte(BridgeProtocolConstants.MESSAGE_ID_SERVER_UPDATE_DATA);
                data.writeInt(size);

                for (CacheEntry entry : bridgeData.requestedData) {
                    if (entry.dirty) {
                        data.writeInt(entry.netId);
                        data.writeBoolean(entry.value == null);
                        if (entry.value != null) {
                            try {
                                typeRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(data,
                                        entry.value);
                            } catch (java.io.IOException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                }

                player.sendPluginMessage(plugin, BridgeProtocolConstants.CHANNEL, data.toByteArray());
            }
        }

        for (Map.Entry<UUID, Player> e : proxyIds.entrySet()) {
            UUID proxyId = e.getKey();
            Player player = e.getValue();
            ServerBridgeData bridgeData = serverData.get(proxyId);

            if (bridgeData == null) {
                continue;
            }

            bridgeData.lastUpdate = now;

            int size = 0;

            for (CacheEntry entry : bridgeData.requestedData) {
                Object value = serverDataAccess.get(entry.key, plugin.getServer());
                entry.dirty = !Objects.equals(value, entry.value);
                entry.value = value;

                if (entry.dirty) {
                    size++;
                }
            }

            ByteArrayDataOutput data = ByteStreams.newDataOutput();
            data.writeByte(BridgeProtocolConstants.MESSAGE_ID_SERVER_UPDATE_SERVER_DATA);

            if (size > 0) {
                bridgeData.revision++;
            }

            data.writeInt(bridgeData.revision);
            data.writeInt(size);

            for (CacheEntry entry : bridgeData.requestedData) {
                if (entry.dirty) {
                    data.writeInt(entry.netId);
                    data.writeBoolean(entry.value == null);
                    if (entry.value != null) {
                        try {
                            typeRegistry.getTypeAdapter((TypeToken<Object>) entry.key.getType()).write(data,
                                    entry.value);
                        } catch (java.io.IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                }
            }

            player.sendPluginMessage(plugin, BridgeProtocolConstants.CHANNEL, data.toByteArray());
        }

        for (Iterator<ServerBridgeData> iterator = serverData.values().iterator(); iterator.hasNext();) {
            ServerBridgeData data = iterator.next();
            if (now - data.lastUpdate > 900000) {
                iterator.remove();
            }
        }

    }, 20, 20);
}