initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
54
java/src/game/packet/S38PacketPlayerListItem.java
Executable file
54
java/src/game/packet/S38PacketPlayerListItem.java
Executable file
|
@ -0,0 +1,54 @@
|
|||
package game.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import game.collect.Maps;
|
||||
import game.network.NetHandlerPlayClient;
|
||||
import game.network.NetHandlerPlayServer;
|
||||
import game.network.Packet;
|
||||
import game.network.PacketBuffer;
|
||||
|
||||
public class S38PacketPlayerListItem implements Packet<NetHandlerPlayClient> {
|
||||
private final Map<String, Integer> players = Maps.newHashMap();
|
||||
|
||||
public S38PacketPlayerListItem() {
|
||||
}
|
||||
|
||||
public S38PacketPlayerListItem(boolean remove, NetHandlerPlayServer... conns) {
|
||||
for(NetHandlerPlayServer conn : conns) {
|
||||
this.players.put(conn.getUser(), remove ? -1 : conn.getLatency());
|
||||
}
|
||||
}
|
||||
|
||||
public S38PacketPlayerListItem(Iterable<NetHandlerPlayServer> conns) {
|
||||
for(NetHandlerPlayServer conn : conns) {
|
||||
this.players.put(conn.getUser(), conn.getLatency());
|
||||
}
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||
int n = buf.readVarIntFromBuffer();
|
||||
for(int z = 0; z < n; z++) {
|
||||
this.players.put(buf.readStringFromBuffer(16), buf.readVarIntFromBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||
buf.writeVarIntToBuffer(this.players.size());
|
||||
for(Entry<String, Integer> data : this.players.entrySet()) {
|
||||
buf.writeString(data.getKey());
|
||||
buf.writeVarIntToBuffer(data.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void processPacket(NetHandlerPlayClient handler) {
|
||||
handler.handlePlayerListItem(this);
|
||||
}
|
||||
|
||||
public Collection<Entry<String, Integer>> getEntries() {
|
||||
return this.players.entrySet();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue