Search in sources :

Example 1 with PlayerListPacket

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

the class DestroyEntitiesMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(DestroyEntitiesMessage packet) {
    // Remove from the list
    this.getTranslator().cachedEntityIDs.removeAll(packet.ids);
    int[] ids = ArrayUtils.toPrimitive(packet.ids.toArray(new Integer[0]));
    ArrayList<PEPacket> pkRemoveEntity = new ArrayList<>();
    for (int i = 0; i < ids.length; i++) {
        if (!this.getTranslator().cachedPlayerEntities.contains(ids[i])) {
            PEPacket tmp = new RemoveEntityPacket();
            ((RemoveEntityPacket) tmp).eid = ids[i];
            pkRemoveEntity.add(tmp);
        } else {
            GlowPlayer glow = ((GlowPlayer) this.getSession().getPlayer().getWorld().getEntityManager().getEntity(ids[i]));
            PEPacket tmp = new RemovePlayerPacket();
            ((RemovePlayerPacket) tmp).uuid = glow.getUniqueId();
            ((RemovePlayerPacket) tmp).eid = ids[i];
            this.getTranslator().cachedPlayerEntities.remove(new Integer(ids[i]));
            PlayerListPacket pl = new PlayerListPacket(new PlayerListPacket.PlayerInfo(glow.getUniqueId(), -1, null, true, true, null));
            pl.isAdding = false;
            pkRemoveEntity.add(tmp);
            pkRemoveEntity.add(pl);
        }
    }
    return pkRemoveEntity.toArray(new PEPacket[0]);
}
Also used : RemoveEntityPacket(org.dragonet.net.packet.minecraft.RemoveEntityPacket) GlowPlayer(net.glowstone.entity.GlowPlayer) RemovePlayerPacket(org.dragonet.net.packet.minecraft.RemovePlayerPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) ArrayList(java.util.ArrayList) PlayerListPacket(org.dragonet.net.packet.minecraft.PlayerListPacket)

Example 2 with PlayerListPacket

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

the class SpawnPlayerMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(SpawnPlayerMessage packet) {
    if (!this.getTranslator().cachedEntityIDs.contains(packet.id)) {
        // Add to the spawned entity list
        this.getTranslator().cachedEntityIDs.add(packet.id);
    }
    // Register this id as a player
    this.getTranslator().cachedPlayerEntities.add(packet.id);
    AddPlayerPacket pkAddPlayer = new AddPlayerPacket();
    pkAddPlayer.uuid = packet.getUuid();
    pkAddPlayer.eid = packet.getId();
    pkAddPlayer.username = this.getSession().getServer().getPlayer(packet.getUuid()).getDisplayName();
    pkAddPlayer.x = (float) packet.getX() / 32;
    pkAddPlayer.y = (float) packet.getY() / 32;
    pkAddPlayer.z = (float) packet.getZ() / 32;
    // return (int) (((loc.getYaw() % 360) / 360) * 256);
    pkAddPlayer.speedX = 0.0f;
    pkAddPlayer.speedY = 0.0f;
    pkAddPlayer.speedZ = 0.0f;
    pkAddPlayer.yaw = ((float) packet.getRotation() / 256) * 360;
    pkAddPlayer.pitch = ((float) packet.getPitch() / 256) * 360;
    // pkAddPlayer.metadata = EntityMetaData.getMetaDataFromPlayer((GlowPlayer) this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.getId())); TODO Fix the metadata, this one of the reasons why skins weren't working properly!
    PlayerListPacket lst = new PlayerListPacket(new PlayerListPacket.PlayerInfo(packet.getUuid(), packet.getId(), pkAddPlayer.username, true, false, DefaultSkin.getDefaultSkin()));
    return new PEPacket[] { pkAddPlayer, lst };
}
Also used : AddPlayerPacket(org.dragonet.net.packet.minecraft.AddPlayerPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) PlayerListPacket(org.dragonet.net.packet.minecraft.PlayerListPacket)

Aggregations

PEPacket (org.dragonet.net.packet.minecraft.PEPacket)2 PlayerListPacket (org.dragonet.net.packet.minecraft.PlayerListPacket)2 ArrayList (java.util.ArrayList)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 AddPlayerPacket (org.dragonet.net.packet.minecraft.AddPlayerPacket)1 RemoveEntityPacket (org.dragonet.net.packet.minecraft.RemoveEntityPacket)1 RemovePlayerPacket (org.dragonet.net.packet.minecraft.RemovePlayerPacket)1