Java Code Examples for io.netty.buffer.ByteBuf#writeBoolean()

The following examples show how to use io.netty.buffer.ByteBuf#writeBoolean() .
Example 1
Project: Protocol   File: PlayerListSerializer_v388.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayerListPacket packet) {
    buffer.writeByte(packet.getAction().ordinal());
    VarInts.writeUnsignedInt(buffer, packet.getEntries().size());

    for (Entry entry : packet.getEntries()) {
        BedrockUtils.writeUuid(buffer, entry.getUuid());

        if (packet.getAction() == Action.ADD) {
            VarInts.writeLong(buffer, entry.getEntityId());
            BedrockUtils.writeString(buffer, entry.getName());
            BedrockUtils.writeString(buffer, entry.getXuid());
            BedrockUtils.writeString(buffer, entry.getPlatformChatId());
            buffer.writeIntLE(entry.getBuildPlatform());
            BedrockUtils.writeSkin(buffer, entry.getSkin());
            buffer.writeBoolean(entry.isTeacher());
            buffer.writeBoolean(entry.isHost());
        }
    }
}
 
Example 2
Project: joyqueue   File: AppendEntriesRequestEncoder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void encode(final AppendEntriesRequest payload, ByteBuf buffer) throws Exception {
    Serializer.write(payload.getTopic(), buffer, Serializer.SHORT_SIZE);
    buffer.writeInt(payload.getPartitionGroup());
    buffer.writeInt(payload.getTerm());
    buffer.writeInt(payload.getLeaderId());

    buffer.writeInt(payload.getPrevTerm());
    buffer.writeLong(payload.getPrevPosition());

    buffer.writeLong(payload.getStartPosition());
    buffer.writeLong(payload.getCommitPosition());
    buffer.writeLong(payload.getLeftPosition());

    buffer.writeBoolean(payload.isMatch());

    ByteBuffer entries = payload.getEntries();
    if (entries == null) {
        buffer.writeInt(0);
        return;
    }
    buffer.writeInt(entries.remaining());
    entries.mark();
    buffer.writeBytes(entries);
    entries.reset();
}
 
Example 3
Project: Cleanstone   File: PlayerListItemCodec.java    License: MIT License 5 votes vote down vote up
private void writeUserProperty(ByteBuf byteBuf, UserProperty userProperty) throws IOException {
    writeUTF8(byteBuf, userProperty.getName());
    writeUTF8(byteBuf, userProperty.getValue());
    byteBuf.writeBoolean(userProperty.hasSignature());
    if (userProperty.hasSignature()) {
        writeUTF8(byteBuf, userProperty.getSignature());
    }
}
 
Example 4
Project: ehacks-pro   File: NoLimitPlayers.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void killEntity(int entityId) {
    int playerId = Wrapper.INSTANCE.player().getEntityId();
    int dimensionId = Wrapper.INSTANCE.player().dimension;
    ByteBuf buf = Unpooled.buffer(0);
    buf.writeByte(0);
    buf.writeInt(entityId);
    buf.writeInt(playerId);
    buf.writeInt(dimensionId);
    buf.writeFloat(Float.MAX_VALUE);
    buf.writeBoolean(false);
    C17PacketCustomPayload packet = new C17PacketCustomPayload("taintedmagic", buf);
    Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet);
}
 
Example 5
Project: Protocol   File: CraftingDataSerializer_v332.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example 6
Project: Protocol   File: CraftingDataSerializer_v340.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CraftingDataPacket packet) {
    BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> {
        VarInts.writeInt(buf, craftingData.getType().ordinal());
        switch (craftingData.getType()) {
            case SHAPELESS:
            case SHAPELESS_CHEMISTRY:
            case SHULKER_BOX:
                BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case SHAPED:
            case SHAPED_CHEMISTRY:
                VarInts.writeInt(buf, craftingData.getWidth());
                VarInts.writeInt(buf, craftingData.getHeight());
                int count = craftingData.getWidth() * craftingData.getHeight();
                ItemData[] inputs = craftingData.getInputs();
                for (int i = 0; i < count; i++) {
                    BedrockUtils.writeItemData(buf, inputs[i]);
                }
                BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData);
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
            case FURNACE:
            case FURNACE_DATA:
                VarInts.writeInt(buf, craftingData.getInputId());
                if (craftingData.getType() == CraftingType.FURNACE_DATA) {
                    VarInts.writeInt(buf, craftingData.getInputDamage());
                }
                BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]);
                break;
            case MULTI:
                BedrockUtils.writeUuid(buf, craftingData.getUuid());
                break;
        }
    });
    buffer.writeBoolean(packet.isCleanRecipes());
}
 
Example 7
Project: PneumaticCraft   File: PacketPlaySound.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buffer){
    super.toBytes(buffer);
    ByteBufUtils.writeUTF8String(buffer, sound);
    buffer.writeFloat(volume);
    buffer.writeFloat(pitch);
    buffer.writeBoolean(bool);
}
 
Example 8
Project: Protocol   File: BedrockUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void writePacksInfoEntries(ByteBuf buffer, Collection<ResourcePacksInfoPacket.Entry> packInfoEntries) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(packInfoEntries, "packInfoEntries");
    buffer.writeShortLE(packInfoEntries.size());
    for (ResourcePacksInfoPacket.Entry packInfoEntry : packInfoEntries) {
        writeString(buffer, packInfoEntry.getPackId());
        writeString(buffer, packInfoEntry.getPackVersion());
        buffer.writeLongLE(packInfoEntry.getPackSize());
        writeString(buffer, packInfoEntry.getEncryptionKey());
        writeString(buffer, packInfoEntry.getSubpackName());
        writeString(buffer, packInfoEntry.getContentId());
        buffer.writeBoolean(packInfoEntry.isScripting());
    }
}
 
Example 9
@Override
public void serialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) {
    BedrockUtils.writeString(buffer, packet.getName());
    boolean save = packet.isSave();
    buffer.writeBoolean(save);

    if (save) {
        try (NBTOutputStream writer = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) {
            writer.write(packet.getTag());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 10
Project: Protocol   File: LevelSoundEventSerializer_v291.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, LevelSoundEvent1Packet packet) {
    buffer.writeByte(sounds.get(packet.getSound()));
    BedrockUtils.writeVector3f(buffer, packet.getPosition());
    VarInts.writeInt(buffer, packet.getExtraData());
    VarInts.writeInt(buffer, packet.getPitch());
    buffer.writeBoolean(packet.isBabySound());
    buffer.writeBoolean(packet.isRelativeVolumeDisabled());
}
 
Example 11
Project: AdvancedRocketry   File: TileSpaceLaser.java    License: MIT License 5 votes vote down vote up
@Override
public void writeDataToNetwork(ByteBuf out, byte id) {
	super.writeDataToNetwork(out, id);
	if(id == 10)
		out.writeInt(this.laserX);
	else if(id == 11)
		out.writeInt(this.laserZ);
	else if(id == 12)
		out.writeBoolean(isRunning);
	else if(id == 13)
		out.writeInt(mode.ordinal());
}
 
Example 12
Project: ViaRewind   File: Chunk1_8Type.java    License: MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    ByteBuf buf = output.alloc().buffer();

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        CHUNK_SECTION_TYPE.write(buf, chunk.getSections()[i]);
    }

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        chunk.getSections()[i].writeBlockLight(buf);
    }

    boolean skyLight = world.getEnvironment() == Environment.NORMAL;
    if (skyLight) {
        for (int i = 0; i < chunk.getSections().length; i++) {
            if ((chunk.getBitmask() & 1 << i) == 0) continue;
            chunk.getSections()[i].writeSkyLight(buf);
        }
    }

    if (chunk.isGroundUp() && chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            buf.writeByte((byte) biome);
        }
    }

    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());
    output.writeBoolean(chunk.isGroundUp());
    output.writeShort(chunk.getBitmask());
    Type.VAR_INT.write(output, buf.readableBytes());
    output.writeBytes(buf, buf.readableBytes());
    buf.release();
}
 
Example 13
Project: Cleanstone   File: OptionalChatData.java    License: MIT License 5 votes vote down vote up
@Override
public ByteBuf serialize() {
    ByteBuf byteBuf = Unpooled.buffer();
    byteBuf.writeBoolean(text != null);
    if (text != null) {
        ByteBuf chatData = ChatData.of(text).serialize();
        byteBuf.writeBytes(chatData);
        chatData.release();
    }
    return byteBuf;
}
 
Example 14
Project: joyqueue   File: VoteResponseEncoder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final VoteResponse voteResponse, ByteBuf buffer) {
    buffer.writeInt(voteResponse.getTerm());
    buffer.writeInt(voteResponse.getCandidateId());
    buffer.writeInt(voteResponse.getVoteNodeId());
    buffer.writeBoolean(voteResponse.isVoteGranted());
}
 
Example 15
Project: Protocol   File: StructureBlockUpdateSerializer_v332.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    StructureEditorData editorData = packet.getEditorData();
    StructureSettings settings = editorData.getStructureSettings();

    BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition());
    VarInts.writeUnsignedInt(buffer, editorData.getStructureBlockType());
    // Structure Editor Data start
    BedrockUtils.writeString(buffer, editorData.getName());
    BedrockUtils.writeString(buffer, editorData.getStructureDataField());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureOffset());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureSize());
    buffer.writeBoolean(!settings.isIgnoreEntities());
    buffer.writeBoolean(settings.isIgnoreBlocks());
    buffer.writeBoolean(editorData.isIncludePlayers());
    buffer.writeBoolean(false); // show air
    // Structure Settings start
    buffer.writeFloatLE(settings.getIntegrityValue());
    VarInts.writeUnsignedInt(buffer, settings.getIntegritySeed());
    VarInts.writeUnsignedInt(buffer, settings.getMirror());
    VarInts.writeUnsignedInt(buffer, settings.getRotation());
    buffer.writeBoolean(settings.isIgnoreEntities());
    buffer.writeBoolean(true); // ignore structure blocks
    Vector3i min = packet.getBlockPosition().add(settings.getStructureOffset());
    BedrockUtils.writeVector3i(buffer, min);
    Vector3i max = min.add(settings.getStructureSize());
    BedrockUtils.writeVector3i(buffer, max);
    // Structure Settings end
    // Structure Editor Data end
    buffer.writeBoolean(editorData.isShowBoundingBox());
    buffer.writeBoolean(packet.isPowered());
}
 
Example 16
Project: Protocol   File: ShowStoreOfferSerializer_v340.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, ShowStoreOfferPacket packet) {
    BedrockUtils.writeString(buffer, packet.getOfferId());
    buffer.writeBoolean(packet.isShownToAll());
}
 
Example 17
Project: Protocol   File: SetSpawnPositionSerializer_v340.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetSpawnPositionPacket packet) {
    VarInts.writeInt(buffer, packet.getSpawnType().ordinal());
    BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition());
    buffer.writeBoolean(packet.isSpawnForced());
}
 
Example 18
Project: joyqueue   File: ReplicateConsumePosResponseEncoder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void encode(final ReplicateConsumePosResponse response, ByteBuf buffer) {
    buffer.writeBoolean(response.isSuccess());
}
 
Example 19
Project: Protocol   File: CommandRequestSerializer_v361.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, CommandRequestPacket packet) {
    BedrockUtils.writeString(buffer, packet.getCommand());
    BedrockUtils.writeCommandOriginData(buffer, packet.getCommandOriginData());
    buffer.writeBoolean(packet.isInternal());
}
 
Example 20
Project: ViaVersion   File: OptPosition1_14Type.java    License: MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf buffer, Position object) throws Exception {
    buffer.writeBoolean(object != null);
    if (object != null)
        Type.POSITION1_14.write(buffer, object);
}