Search in sources :

Example 1 with PlayerListPacket

use of org.dragonet.protocol.packets.PlayerListPacket in project DragonProxy by DragonetMC.

the class PCPlayerListItemPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerListEntryPacket packet) {
    PlayerListPacket pk = new PlayerListPacket();
    if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
        PlayerListEntry[] entries = packet.getEntries();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (PlayerListEntry entry : entries) {
            session.getPlayerInfoCache().put(entry.getProfile().getId(), entry);
            org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
            peEntry.uuid = entry.getProfile().getId();
            peEntry.eid = 1;
            peEntry.username = entry.getProfile().getName();
            peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
            peEntry.xboxUserId = entry.getProfile().getId().toString();
            peEntries.add(peEntry);
        }
        pk.type = PlayerListPacket.TYPE_ADD;
        pk.entries = (org.dragonet.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
    } else if (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER) {
        PlayerListEntry[] entries = packet.getEntries();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (PlayerListEntry entry : entries) {
            session.getPlayerInfoCache().remove(entry.getProfile().getId());
            org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
            peEntry.uuid = entry.getProfile().getId();
            peEntry.eid = 1;
            peEntry.username = entry.getProfile().getName();
            peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
            peEntry.xboxUserId = entry.getProfile().getId().toString();
            peEntries.add(peEntry);
        }
        pk.type = PlayerListPacket.TYPE_REMOVE;
        pk.entries = (org.dragonet.protocol.type.PlayerListEntry[]) peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
    }
    return new PEPacket[] { pk };
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PEPacket(org.dragonet.protocol.PEPacket) PlayerListPacket(org.dragonet.protocol.packets.PlayerListPacket) PlayerListEntry(com.github.steveice10.mc.protocol.data.game.PlayerListEntry) HashSet(java.util.HashSet)

Aggregations

PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PEPacket (org.dragonet.protocol.PEPacket)1 PlayerListPacket (org.dragonet.protocol.packets.PlayerListPacket)1