| 1 | package net.minecraft.network.play.server;
|
| 2 |
|
| 3 | import com.google.common.base.Objects;
|
| 4 | import com.google.common.collect.Lists;
|
| 5 | import com.mojang.authlib.GameProfile;
|
| 6 | import com.mojang.authlib.properties.Property;
|
| 7 | import java.io.IOException;
|
| 8 | import java.util.List;
|
| 9 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 10 | import net.minecraft.network.Packet;
|
| 11 | import net.minecraft.network.PacketBuffer;
|
| 12 | import net.minecraft.network.play.INetHandlerPlayClient;
|
| 13 | import net.minecraft.util.IChatComponent;
|
| 14 | import net.minecraft.world.WorldSettings;
|
| 15 |
|
| 16 | public class S38PacketPlayerListItem implements Packet<INetHandlerPlayClient>
|
| 17 | {
|
| 18 | private S38PacketPlayerListItem.Action action;
|
| 19 | private final List<S38PacketPlayerListItem.AddPlayerData> players = Lists.<S38PacketPlayerListItem.AddPlayerData>newArrayList();
|
| 20 |
|
| 21 | public S38PacketPlayerListItem()
|
| 22 | {
|
| 23 | }
|
| 24 |
|
| 25 | public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, EntityPlayerMP... players)
|
| 26 | {
|
| 27 | this.action = actionIn;
|
| 28 |
|
| 29 | for (EntityPlayerMP entityplayermp : players)
|
| 30 | {
|
| 31 | this.players.add(new S38PacketPlayerListItem.AddPlayerData(entityplayermp.getGameProfile(), entityplayermp.ping, entityplayermp.theItemInWorldManager.getGameType(), entityplayermp.getTabListDisplayName()));
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, Iterable<EntityPlayerMP> players)
|
| 36 | {
|
| 37 | this.action = actionIn;
|
| 38 |
|
| 39 | for (EntityPlayerMP entityplayermp : players)
|
| 40 | {
|
| 41 | this.players.add(new S38PacketPlayerListItem.AddPlayerData(entityplayermp.getGameProfile(), entityplayermp.ping, entityplayermp.theItemInWorldManager.getGameType(), entityplayermp.getTabListDisplayName()));
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Reads the raw packet data from the data stream.
|
| 47 | */
|
| 48 | public void readPacketData(PacketBuffer buf) throws IOException
|
| 49 | {
|
| 50 | this.action = (S38PacketPlayerListItem.Action)buf.readEnumValue(S38PacketPlayerListItem.Action.class);
|
| 51 | int i = buf.readVarIntFromBuffer();
|
| 52 |
|
| 53 | for (int j = 0; j < i; ++j)
|
| 54 | {
|
| 55 | GameProfile gameprofile = null;
|
| 56 | int k = 0;
|
| 57 | WorldSettings.GameType worldsettings$gametype = null;
|
| 58 | IChatComponent ichatcomponent = null;
|
| 59 |
|
| 60 | switch (this.action)
|
| 61 | {
|
| 62 | case ADD_PLAYER:
|
| 63 | gameprofile = new GameProfile(buf.readUuid(), buf.readStringFromBuffer(16));
|
| 64 | int l = buf.readVarIntFromBuffer();
|
| 65 | int i1 = 0;
|
| 66 |
|
| 67 | for (; i1 < l; ++i1)
|
| 68 | {
|
| 69 | String s = buf.readStringFromBuffer(32767);
|
| 70 | String s1 = buf.readStringFromBuffer(32767);
|
| 71 |
|
| 72 | if (buf.readBoolean())
|
| 73 | {
|
| 74 | gameprofile.getProperties().put(s, new Property(s, s1, buf.readStringFromBuffer(32767)));
|
| 75 | }
|
| 76 | else
|
| 77 | {
|
| 78 | gameprofile.getProperties().put(s, new Property(s, s1));
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | worldsettings$gametype = WorldSettings.GameType.getByID(buf.readVarIntFromBuffer());
|
| 83 | k = buf.readVarIntFromBuffer();
|
| 84 |
|
| 85 | if (buf.readBoolean())
|
| 86 | {
|
| 87 | ichatcomponent = buf.readChatComponent();
|
| 88 | }
|
| 89 |
|
| 90 | break;
|
| 91 |
|
| 92 | case UPDATE_GAME_MODE:
|
| 93 | gameprofile = new GameProfile(buf.readUuid(), (String)null);
|
| 94 | worldsettings$gametype = WorldSettings.GameType.getByID(buf.readVarIntFromBuffer());
|
| 95 | break;
|
| 96 |
|
| 97 | case UPDATE_LATENCY:
|
| 98 | gameprofile = new GameProfile(buf.readUuid(), (String)null);
|
| 99 | k = buf.readVarIntFromBuffer();
|
| 100 | break;
|
| 101 |
|
| 102 | case UPDATE_DISPLAY_NAME:
|
| 103 | gameprofile = new GameProfile(buf.readUuid(), (String)null);
|
| 104 |
|
| 105 | if (buf.readBoolean())
|
| 106 | {
|
| 107 | ichatcomponent = buf.readChatComponent();
|
| 108 | }
|
| 109 |
|
| 110 | break;
|
| 111 |
|
| 112 | case REMOVE_PLAYER:
|
| 113 | gameprofile = new GameProfile(buf.readUuid(), (String)null);
|
| 114 | }
|
| 115 |
|
| 116 | this.players.add(new S38PacketPlayerListItem.AddPlayerData(gameprofile, k, worldsettings$gametype, ichatcomponent));
|
| 117 | }
|
| 118 | }
|
| 119 |
|
| 120 | /**
|
| 121 | * Writes the raw packet data to the data stream.
|
| 122 | */
|
| 123 | public void writePacketData(PacketBuffer buf) throws IOException
|
| 124 | {
|
| 125 | buf.writeEnumValue(this.action);
|
| 126 | buf.writeVarIntToBuffer(this.players.size());
|
| 127 |
|
| 128 | for (S38PacketPlayerListItem.AddPlayerData s38packetplayerlistitem$addplayerdata : this.players)
|
| 129 | {
|
| 130 | switch (this.action)
|
| 131 | {
|
| 132 | case ADD_PLAYER:
|
| 133 | buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId());
|
| 134 | buf.writeString(s38packetplayerlistitem$addplayerdata.getProfile().getName());
|
| 135 | buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getProfile().getProperties().size());
|
| 136 |
|
| 137 | for (Property property : s38packetplayerlistitem$addplayerdata.getProfile().getProperties().values())
|
| 138 | {
|
| 139 | buf.writeString(property.getName());
|
| 140 | buf.writeString(property.getValue());
|
| 141 |
|
| 142 | if (property.hasSignature())
|
| 143 | {
|
| 144 | buf.writeBoolean(true);
|
| 145 | buf.writeString(property.getSignature());
|
| 146 | }
|
| 147 | else
|
| 148 | {
|
| 149 | buf.writeBoolean(false);
|
| 150 | }
|
| 151 | }
|
| 152 |
|
| 153 | buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getGameMode().getID());
|
| 154 | buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getPing());
|
| 155 |
|
| 156 | if (s38packetplayerlistitem$addplayerdata.getDisplayName() == null)
|
| 157 | {
|
| 158 | buf.writeBoolean(false);
|
| 159 | }
|
| 160 | else
|
| 161 | {
|
| 162 | buf.writeBoolean(true);
|
| 163 | buf.writeChatComponent(s38packetplayerlistitem$addplayerdata.getDisplayName());
|
| 164 | }
|
| 165 |
|
| 166 | break;
|
| 167 |
|
| 168 | case UPDATE_GAME_MODE:
|
| 169 | buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId());
|
| 170 | buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getGameMode().getID());
|
| 171 | break;
|
| 172 |
|
| 173 | case UPDATE_LATENCY:
|
| 174 | buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId());
|
| 175 | buf.writeVarIntToBuffer(s38packetplayerlistitem$addplayerdata.getPing());
|
| 176 | break;
|
| 177 |
|
| 178 | case UPDATE_DISPLAY_NAME:
|
| 179 | buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId());
|
| 180 |
|
| 181 | if (s38packetplayerlistitem$addplayerdata.getDisplayName() == null)
|
| 182 | {
|
| 183 | buf.writeBoolean(false);
|
| 184 | }
|
| 185 | else
|
| 186 | {
|
| 187 | buf.writeBoolean(true);
|
| 188 | buf.writeChatComponent(s38packetplayerlistitem$addplayerdata.getDisplayName());
|
| 189 | }
|
| 190 |
|
| 191 | break;
|
| 192 |
|
| 193 | case REMOVE_PLAYER:
|
| 194 | buf.writeUuid(s38packetplayerlistitem$addplayerdata.getProfile().getId());
|
| 195 | }
|
| 196 | }
|
| 197 | }
|
| 198 |
|
| 199 | /**
|
| 200 | * Passes this Packet on to the NetHandler for processing.
|
| 201 | */
|
| 202 | public void processPacket(INetHandlerPlayClient handler)
|
| 203 | {
|
| 204 | handler.handlePlayerListItem(this);
|
| 205 | }
|
| 206 |
|
| 207 | public List<S38PacketPlayerListItem.AddPlayerData> getEntries()
|
| 208 | {
|
| 209 | return this.players;
|
| 210 | }
|
| 211 |
|
| 212 | public S38PacketPlayerListItem.Action getAction()
|
| 213 | {
|
| 214 | return this.action;
|
| 215 | }
|
| 216 |
|
| 217 | public String toString()
|
| 218 | {
|
| 219 | return Objects.toStringHelper(this).add("action", this.action).add("entries", this.players).toString();
|
| 220 | }
|
| 221 |
|
| 222 | public static enum Action
|
| 223 | {
|
| 224 | ADD_PLAYER,
|
| 225 | UPDATE_GAME_MODE,
|
| 226 | UPDATE_LATENCY,
|
| 227 | UPDATE_DISPLAY_NAME,
|
| 228 | REMOVE_PLAYER;
|
| 229 | }
|
| 230 |
|
| 231 | public class AddPlayerData
|
| 232 | {
|
| 233 | private final int ping;
|
| 234 | private final WorldSettings.GameType gamemode;
|
| 235 | private final GameProfile profile;
|
| 236 | private final IChatComponent displayName;
|
| 237 |
|
| 238 | public AddPlayerData(GameProfile profile, int pingIn, WorldSettings.GameType gamemodeIn, IChatComponent displayNameIn)
|
| 239 | {
|
| 240 | this.profile = profile;
|
| 241 | this.ping = pingIn;
|
| 242 | this.gamemode = gamemodeIn;
|
| 243 | this.displayName = displayNameIn;
|
| 244 | }
|
| 245 |
|
| 246 | public GameProfile getProfile()
|
| 247 | {
|
| 248 | return this.profile;
|
| 249 | }
|
| 250 |
|
| 251 | public int getPing()
|
| 252 | {
|
| 253 | return this.ping;
|
| 254 | }
|
| 255 |
|
| 256 | public WorldSettings.GameType getGameMode()
|
| 257 | {
|
| 258 | return this.gamemode;
|
| 259 | }
|
| 260 |
|
| 261 | public IChatComponent getDisplayName()
|
| 262 | {
|
| 263 | return this.displayName;
|
| 264 | }
|
| 265 |
|
| 266 | public String toString()
|
| 267 | {
|
| 268 | return Objects.toStringHelper(this).add("latency", this.ping).add("gameMode", this.gamemode).add("profile", this.profile).add("displayName", this.displayName == null ? null : IChatComponent.Serializer.componentToJson(this.displayName)).toString();
|
| 269 | }
|
| 270 | }
|
| 271 | }
|
| 272 |
|