Search in sources :

Example 1 with TabListAction

use of com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListAction in project DirtMultiversion by DirtPowered.

the class TabListEntryDataType method read.

@Override
public TabListEntry read(PacketInput packetInput) throws IOException {
    TabListAction action = TabListAction.fromId(packetInput.readVarInt());
    PlayerListEntry[] entries = new PlayerListEntry[packetInput.readVarInt()];
    for (int i = 0; i < entries.length; i++) {
        UUID uuid = V1_8RProtocol.UUID.read(packetInput);
        String username = V1_7_2RProtocol.STRING.read(packetInput);
        GameProfile profile = action == TabListAction.ADD_PLAYER ? new GameProfile(uuid, username) : new GameProfile(uuid, null);
        PlayerListEntry listEntry = null;
        String displayName = null;
        switch(action) {
            case ADD_PLAYER:
                Property[] properties = new Property[packetInput.readVarInt()];
                for (int j = 0; j < properties.length; j++) {
                    String property = V1_7_2RProtocol.STRING.read(packetInput);
                    String value = V1_7_2RProtocol.STRING.read(packetInput);
                    String signature = null;
                    if (packetInput.readBoolean()) {
                        signature = V1_7_2RProtocol.STRING.read(packetInput);
                    }
                    properties[j] = new Property(property, value, signature);
                }
                int gameMode = packetInput.readVarInt();
                int ping = packetInput.readVarInt();
                if (packetInput.readBoolean()) {
                    displayName = V1_7_2RProtocol.STRING.read(packetInput);
                }
                listEntry = new PlayerListEntry(profile, properties, gameMode, ping, displayName);
                break;
            case UPDATE_GAMEMODE:
                listEntry = new PlayerListEntry(profile, packetInput.readVarInt());
                break;
            case UPDATE_LATENCY:
                listEntry = new PlayerListEntry(profile, packetInput.readVarInt(), true);
                break;
            case UPDATE_DISPLAY_NAME:
                if (packetInput.readBoolean()) {
                    displayName = V1_7_2RProtocol.STRING.read(packetInput);
                }
                listEntry = new PlayerListEntry(profile, displayName);
                break;
            case REMOVE_PLAYER:
                listEntry = new PlayerListEntry(profile);
                break;
        }
        entries[i] = listEntry;
    }
    return new TabListEntry(action, entries);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) TabListEntry(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListEntry) PlayerListEntry(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.PlayerListEntry) UUID(java.util.UUID) Property(com.mojang.authlib.properties.Property) TabListAction(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListAction)

Example 2 with TabListAction

use of com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListAction in project DirtMultiversion by DirtPowered.

the class TabListEntryDataType method write.

@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
    TabListEntry tabListEntry = (TabListEntry) typeHolder.getObject();
    TabListAction action = tabListEntry.getAction();
    packetOutput.writeVarInt(action.getAction());
    PlayerListEntry[] entries = tabListEntry.getEntries();
    packetOutput.writeVarInt(entries.length);
    for (PlayerListEntry entry : entries) {
        V1_8RProtocol.UUID.write(new TypeHolder(Type.UUID, entry.getProfile().getId()), packetOutput);
        switch(action) {
            case ADD_PLAYER:
                V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, entry.getProfile().getName()), packetOutput);
                packetOutput.writeVarInt(entry.getProperties().length);
                for (Property property : entry.getProperties()) {
                    V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, property.getName()), packetOutput);
                    V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, property.getValue()), packetOutput);
                    packetOutput.writeBoolean(property.hasSignature());
                    if (property.hasSignature()) {
                        V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, property.getSignature()), packetOutput);
                    }
                }
                packetOutput.writeVarInt(entry.getGameMode());
                packetOutput.writeVarInt(entry.getPing());
                packetOutput.writeBoolean(entry.getDisplayName() != null);
                if (entry.getDisplayName() != null) {
                    V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, entry.getDisplayName()), packetOutput);
                }
                break;
            case UPDATE_GAMEMODE:
                packetOutput.writeVarInt(entry.getGameMode());
                break;
            case UPDATE_LATENCY:
                packetOutput.writeVarInt(entry.getPing());
                break;
            case UPDATE_DISPLAY_NAME:
                packetOutput.writeBoolean(entry.getDisplayName() != null);
                if (entry.getDisplayName() != null) {
                    V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, entry.getDisplayName()), packetOutput);
                }
                break;
            case REMOVE_PLAYER:
                break;
        }
    }
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) TabListEntry(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListEntry) PlayerListEntry(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.PlayerListEntry) Property(com.mojang.authlib.properties.Property) TabListAction(com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListAction)

Aggregations

PlayerListEntry (com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.PlayerListEntry)2 TabListAction (com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListAction)2 TabListEntry (com.github.dirtpowered.dirtmv.data.protocol.objects.tablist.TabListEntry)2 Property (com.mojang.authlib.properties.Property)2 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)1 GameProfile (com.mojang.authlib.GameProfile)1 UUID (java.util.UUID)1