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

The following examples show how to use io.netty.buffer.ByteBuf#writeBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppendEntriesRequestEncoder.java    From joyqueue with 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 2
Source File: PlayerListSerializer_v388.java    From Protocol with 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 3
Source File: PlayerListItemCodec.java    From Cleanstone with 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
Source File: StructureBlockUpdateSerializer_v332.java    From Protocol with 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 5
Source File: VoteResponseEncoder.java    From joyqueue with 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 6
Source File: OptionalChatData.java    From Cleanstone with 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 7
Source File: Chunk1_8Type.java    From ViaRewind with 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 8
Source File: TileSpaceLaser.java    From AdvancedRocketry with 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 9
Source File: LevelSoundEventSerializer_v291.java    From Protocol with 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 10
Source File: StructureTemplateDataExportResponseSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: BedrockUtils.java    From Protocol with 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 12
Source File: PacketPlaySound.java    From PneumaticCraft with 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 13
Source File: CraftingDataSerializer_v340.java    From Protocol with 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 14
Source File: CraftingDataSerializer_v332.java    From Protocol with 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 15
Source File: NoLimitPlayers.java    From ehacks-pro with 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 16
Source File: OptPosition1_14Type.java    From ViaVersion with 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);
}
 
Example 17
Source File: CommandRequestSerializer_v361.java    From Protocol with 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 18
Source File: ReplicateConsumePosResponseEncoder.java    From joyqueue with 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
Source File: SetSpawnPositionSerializer_v340.java    From Protocol with 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 20
Source File: ShowStoreOfferSerializer_v340.java    From Protocol with 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());
}