Search in sources :

Example 31 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class MovePlayerPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_MOVEMENT);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeLong(this.eid);
        writer.writeFloat(this.x);
        writer.writeFloat(this.y + 1.62f);
        writer.writeFloat(this.z);
        writer.writeFloat(this.yaw);
        writer.writeFloat(this.bodyYaw);
        writer.writeFloat(this.pitch);
        writer.writeByte(this.mode);
        writer.writeByte((byte) (this.teleport ? 0x80 : 0x00));
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 32 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class PickUpItemPacket method encode.

@Override
public void encode() {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeInt(target);
        writer.writeInt(eid);
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 33 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class PlayerEquipmentPacket method encode.

@Override
public void encode() {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeLong(eid);
        PEInventorySlot.writeSlot(writer, item);
        writer.writeByte((byte) (slot & 0xFF));
        writer.writeByte((byte) (selectedSlot & 0xFF));
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 34 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class PlayerListPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_TEXT);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        if (isAdding) {
            writer.writeByte((byte) 0x00);
        } else {
            writer.writeByte((byte) 0x01);
        }
        writer.writeInt(players.size());
        for (PlayerInfo info : players) {
            info.encode(writer, isAdding);
        }
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 35 with PEBinaryWriter

use of org.dragonet.utilities.io.PEBinaryWriter in project Dragonet-Legacy by DragonetMC.

the class EntityMetaData method encode.

public byte[] encode() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PEBinaryWriter writer = new PEBinaryWriter(bos);
    try {
        for (Map.Entry<Integer, EntityMetaDataObject> entry : this.map.entrySet()) {
            writer.writeByte(((byte) (((entry.getValue().type() & 0xFF) << 5) | (entry.getKey() & 0x1F))));
            writer.write(entry.getValue().encode());
        }
        writer.writeByte((byte) 0x7F);
        return bos.toByteArray();
    } catch (IOException e) {
    }
    return null;
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)39 IOException (java.io.IOException)39 PEBinaryWriter (org.dragonet.utilities.io.PEBinaryWriter)39 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Deflater (java.util.zip.Deflater)1 Enchantment (org.bukkit.enchantments.Enchantment)1 FurnaceRecipe (org.bukkit.inventory.FurnaceRecipe)1 ItemStack (org.bukkit.inventory.ItemStack)1 Recipe (org.bukkit.inventory.Recipe)1 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)1 ShapelessRecipe (org.bukkit.inventory.ShapelessRecipe)1 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)1