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);
}
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;
}
}
}
Aggregations