Search in sources :

Example 1 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class RelativeEntityPositionMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(RelativeEntityPositionMessage packet) {
    Entity entity = this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.id);
    if (entity == null) {
        return null;
    }
    if (entity instanceof GlowPlayer) {
        boolean isTeleport = (packet.deltaX ^ 2 + packet.deltaY ^ 2 + packet.deltaZ ^ 2) > 4;
        MovePlayerPacket pkMovePlayer = new MovePlayerPacket(packet.id, (float) entity.getLocation().getX(), (float) entity.getLocation().getY(), (float) entity.getLocation().getZ(), entity.getLocation().getYaw(), entity.getLocation().getPitch(), entity.getLocation().getYaw(), isTeleport);
        return new PEPacket[] { pkMovePlayer };
    } else {
        MoveEntitiesPacket.MoveEntityData data = new MoveEntitiesPacket.MoveEntityData();
        data.eid = packet.id;
        data.x = (float) entity.getLocation().getX();
        data.y = (float) entity.getLocation().getY();
        data.z = (float) entity.getLocation().getZ();
        data.yaw = (float) entity.getLocation().getYaw();
        data.pitch = (float) entity.getLocation().getPitch();
        MoveEntitiesPacket pk = new MoveEntitiesPacket(new MoveEntitiesPacket.MoveEntityData[] { data });
        return new PEPacket[] { pk };
    }
}
Also used : Entity(org.bukkit.entity.Entity) MoveEntitiesPacket(org.dragonet.net.packet.minecraft.MoveEntitiesPacket) GlowPlayer(net.glowstone.entity.GlowPlayer) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) MovePlayerPacket(org.dragonet.net.packet.minecraft.MovePlayerPacket)

Example 2 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class RelativeEntityPositionRotationMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(RelativeEntityPositionRotationMessage packet) {
    Entity entity = this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.id);
    if (entity == null) {
        return null;
    }
    if (entity instanceof GlowPlayer) {
        boolean isTeleport = (packet.deltaX ^ 2 + packet.deltaY ^ 2 + packet.deltaZ ^ 2) > 4;
        MovePlayerPacket pkMovePlayer = new MovePlayerPacket(packet.id, (float) entity.getLocation().getX(), (float) entity.getLocation().getY(), (float) entity.getLocation().getZ(), (float) entity.getLocation().getYaw(), (float) entity.getLocation().getPitch(), (float) entity.getLocation().getYaw(), isTeleport);
        return new PEPacket[] { pkMovePlayer };
    } else {
        MoveEntitiesPacket.MoveEntityData data = new MoveEntitiesPacket.MoveEntityData();
        data.eid = packet.id;
        data.x = (float) entity.getLocation().getX();
        data.y = (float) entity.getLocation().getY();
        data.z = (float) entity.getLocation().getZ();
        data.yaw = (float) entity.getLocation().getYaw();
        data.pitch = (float) entity.getLocation().getPitch();
        MoveEntitiesPacket pk = new MoveEntitiesPacket(new MoveEntitiesPacket.MoveEntityData[] { data });
        return new PEPacket[] { pk };
    }
}
Also used : Entity(org.bukkit.entity.Entity) MoveEntitiesPacket(org.dragonet.net.packet.minecraft.MoveEntitiesPacket) GlowPlayer(net.glowstone.entity.GlowPlayer) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) MovePlayerPacket(org.dragonet.net.packet.minecraft.MovePlayerPacket)

Example 3 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class SetWindowContentsMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(SetWindowContentsMessage packet) {
    if (packet.id == 0) {
        //Inventory Items(Included hotbar)
        WindowItemsPacket pkInventory = new WindowItemsPacket();
        pkInventory.windowID = PEWindowConstantID.PLAYER_INVENTORY;
        pkInventory.slots = new PEInventorySlot[InventoryType.SlotSize.PLAYER];
        for (int i = 9; i <= 44; i++) {
            if (packet.items[i] != null) {
                pkInventory.slots[i - 9] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
            } else {
                pkInventory.slots[i - 9] = new PEInventorySlot();
            }
        }
        pkInventory.hotbar = new int[9];
        for (int i = 36; i <= 44; i++) {
            pkInventory.hotbar[i - 36] = i - 9;
        }
        //Armor
        WindowItemsPacket pkArmorInv = new WindowItemsPacket();
        pkArmorInv.windowID = PEWindowConstantID.PLAYER_ARMOR;
        pkArmorInv.slots = new PEInventorySlot[4];
        for (int i = 5; i <= 8; i++) {
            if (packet.items[i] != null) {
                pkArmorInv.slots[i - 5] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
            } else {
                pkArmorInv.slots[i - 5] = new PEInventorySlot();
            }
        }
        return new PEPacket[] { pkInventory, pkArmorInv };
    }
    //TODO: Implement other types of inventory
    //switch(this.getSession().getPlayer().)
    System.out.println("Updating window content for " + packet.id + ", which has " + packet.items.length + " slots. ");
    return null;
}
Also used : WindowItemsPacket(org.dragonet.net.packet.minecraft.WindowItemsPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) PEInventorySlot(org.dragonet.inventory.PEInventorySlot)

Example 4 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class StateChangeMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(StateChangeMessage packet) {
    if (packet.reason == StateChangeMessage.Reason.GAMEMODE.ordinal()) {
        if (this.getSession().getPlayer() == null) {
            return null;
        }
        StartGamePacket pkStartGame = new StartGamePacket();
        pkStartGame.eid = this.getSession().getPlayer().getEntityId();
        pkStartGame.gamemode = ((int) packet.value) & 0x1;
        pkStartGame.seed = 0;
        pkStartGame.generator = 1;
        pkStartGame.spawnX = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockX();
        pkStartGame.spawnY = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockY();
        pkStartGame.spawnZ = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockZ();
        pkStartGame.x = (float) this.getSession().getPlayer().getLocation().getX();
        pkStartGame.y = (float) this.getSession().getPlayer().getLocation().getY();
        pkStartGame.z = (float) this.getSession().getPlayer().getLocation().getZ();
        return new PEPacket[] { pkStartGame };
    }
    return null;
}
Also used : PEPacket(org.dragonet.net.packet.minecraft.PEPacket) StartGamePacket(org.dragonet.net.packet.minecraft.StartGamePacket)

Example 5 with PEPacket

use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.

the class CloseWindowMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(CloseWindowMessage packet) {
    if (packet.id != 0) {
        this.getTranslator().cachedWindowType[packet.id & 0xFF] = -1;
    }
    WindowClosePacket pkCloseWindow = new WindowClosePacket();
    pkCloseWindow.windowID = (byte) (packet.id & 0xFF);
    getSession().getOpenedWindows().remove(packet.id);
    return new PEPacket[] { pkCloseWindow };
}
Also used : WindowClosePacket(org.dragonet.net.packet.minecraft.WindowClosePacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket)

Aggregations

PEPacket (org.dragonet.net.packet.minecraft.PEPacket)22 MovePlayerPacket (org.dragonet.net.packet.minecraft.MovePlayerPacket)4 GlowPlayer (net.glowstone.entity.GlowPlayer)3 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)3 Entity (org.bukkit.entity.Entity)2 MoveEntitiesPacket (org.dragonet.net.packet.minecraft.MoveEntitiesPacket)2 PlayerListPacket (org.dragonet.net.packet.minecraft.PlayerListPacket)2 UpdateBlockPacket (org.dragonet.net.packet.minecraft.UpdateBlockPacket)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 PlayerProfile (net.glowstone.entity.meta.profile.PlayerProfile)1 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)1 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)1 MultiBlockChangeMessage (net.glowstone.net.message.play.game.MultiBlockChangeMessage)1 CloseWindowMessage (net.glowstone.net.message.play.inv.CloseWindowMessage)1 Player (org.bukkit.entity.Player)1 PocketPotionEffect (org.dragonet.PocketPotionEffect)1 AddItemEntityPacket (org.dragonet.net.packet.minecraft.AddItemEntityPacket)1 AddPlayerPacket (org.dragonet.net.packet.minecraft.AddPlayerPacket)1 AnimatePacket (org.dragonet.net.packet.minecraft.AnimatePacket)1