Search in sources :

Example 16 with PEBinaryWriter

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

the class AddPlayerPacket method encode.

@Override
public void encode() {
    setShouldSendImmidate(true);
    setChannel(NetworkChannel.CHANNEL_ENTITY_SPAWNING);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PEBinaryWriter writer = new PEBinaryWriter(bos);
    try {
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeUUID(uuid);
        writer.writeString(this.username);
        writer.writeLong(this.eid);
        writer.writeFloat(this.x);
        writer.writeFloat(this.y);
        writer.writeFloat(this.z);
        writer.writeFloat(this.speedX);
        writer.writeFloat(this.speedY);
        writer.writeFloat(this.speedZ);
        writer.writeFloat(this.yaw);
        //Head rotation
        writer.writeFloat(this.yaw);
        writer.writeFloat(this.pitch);
        PEInventorySlot.writeSlot(writer, this.item);
        // TODO Fix metadata, one of the reasons why skins didn't work properly!
        writer.writeByte((byte) 0x00);
        //writer.write(this.metadata.encode());
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 17 with PEBinaryWriter

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

the class ChatPacket 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));
        writer.writeByte((byte) (this.type.getType() & 0xFF));
        switch(this.type) {
            case POPUP:
            case CHAT:
                writer.writeString(this.source);
            case RAW:
            case TIP:
            case SYSTEM:
                writer.writeString(this.message);
                break;
            case TRANSLATION:
                writer.writeString(this.message);
                if (this.params == null) {
                    writer.writeByte((byte) 0);
                    break;
                }
                writer.writeByte((byte) (this.params.length & 0xFF));
                for (int i = 0; i < this.params.length; i++) {
                    writer.writeString(this.params[i]);
                }
                break;
        }
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 18 with PEBinaryWriter

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

the class LoginStatusPacket method encode.

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

Example 19 with PEBinaryWriter

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

the class MoveEntitiesPacket method encode.

@Override
public void encode() {
    try {
        setChannel(NetworkChannel.CHANNEL_WORLD_EVENTS);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PEBinaryWriter writer = new PEBinaryWriter(bos);
        writer.writeByte((byte) (this.pid() & 0xFF));
        writer.writeInt(this.entities.length);
        for (MoveEntityData d : this.entities) {
            writer.writeLong(d.eid);
            writer.writeFloat(d.x);
            writer.writeFloat(d.y);
            writer.writeFloat(d.z);
            writer.writeFloat(d.yaw);
            writer.writeFloat(d.pitch);
        }
        this.setData(bos.toByteArray());
    } catch (IOException e) {
    }
}
Also used : PEBinaryWriter(org.dragonet.utilities.io.PEBinaryWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 20 with PEBinaryWriter

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

the class PingPongPacket method encode.

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

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