    001package net.minecraft.network.packet;
    002
    003import java.io.DataInputStream;
    004import java.io.DataOutputStream;
    005import java.io.IOException;
    006import java.util.ArrayList;
    007import java.util.Collection;
    008import java.util.Iterator;
    009import net.minecraft.scoreboard.ScorePlayerTeam;
    010
    011public class Packet209SetPlayerTeam extends Packet
    012{
    013    public String field_96495_a = "";
    014    public String field_96493_b = "";
    015    public String field_96494_c = "";
    016    public String field_96491_d = "";
    017    public Collection field_96492_e = new ArrayList();
    018    public int field_96489_f = 0;
    019    public int field_98212_g;
    020
    021    public Packet209SetPlayerTeam() {}
    022
    023    public Packet209SetPlayerTeam(ScorePlayerTeam par1, int par2)
    024    {
    025        this.field_96495_a = par1.func_96661_b();
    026        this.field_96489_f = par2;
    027
    028        if (par2 == 0 || par2 == 2)
    029        {
    030            this.field_96493_b = par1.func_96669_c();
    031            this.field_96494_c = par1.func_96668_e();
    032            this.field_96491_d = par1.func_96663_f();
    033            this.field_98212_g = par1.func_98299_i();
    034        }
    035
    036        if (par2 == 0)
    037        {
    038            this.field_96492_e.addAll(par1.func_96670_d());
    039        }
    040    }
    041
    042    public Packet209SetPlayerTeam(ScorePlayerTeam par1, Collection par2, int par3)
    043    {
    044        if (par3 != 3 && par3 != 4)
    045        {
    046            throw new IllegalArgumentException("Method must be join or leave for player constructor");
    047        }
    048        else if (par2 != null && !par2.isEmpty())
    049        {
    050            this.field_96489_f = par3;
    051            this.field_96495_a = par1.func_96661_b();
    052            this.field_96492_e.addAll(par2);
    053        }
    054        else
    055        {
    056            throw new IllegalArgumentException("Players cannot be null/empty");
    057        }
    058    }
    059
    060    /**
    061     * Abstract. Reads the raw packet data from the data stream.
    062     */
    063    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    064    {
    065        this.field_96495_a = readString(par1DataInputStream, 16);
    066        this.field_96489_f = par1DataInputStream.readByte();
    067
    068        if (this.field_96489_f == 0 || this.field_96489_f == 2)
    069        {
    070            this.field_96493_b = readString(par1DataInputStream, 32);
    071            this.field_96494_c = readString(par1DataInputStream, 16);
    072            this.field_96491_d = readString(par1DataInputStream, 16);
    073            this.field_98212_g = par1DataInputStream.readByte();
    074        }
    075
    076        if (this.field_96489_f == 0 || this.field_96489_f == 3 || this.field_96489_f == 4)
    077        {
    078            short short1 = par1DataInputStream.readShort();
    079
    080            for (int i = 0; i < short1; ++i)
    081            {
    082                this.field_96492_e.add(readString(par1DataInputStream, 16));
    083            }
    084        }
    085    }
    086
    087    /**
    088     * Abstract. Writes the raw packet data to the data stream.
    089     */
    090    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    091    {
    092        writeString(this.field_96495_a, par1DataOutputStream);
    093        par1DataOutputStream.writeByte(this.field_96489_f);
    094
    095        if (this.field_96489_f == 0 || this.field_96489_f == 2)
    096        {
    097            writeString(this.field_96493_b, par1DataOutputStream);
    098            writeString(this.field_96494_c, par1DataOutputStream);
    099            writeString(this.field_96491_d, par1DataOutputStream);
    100            par1DataOutputStream.writeByte(this.field_98212_g);
    101        }
    102
    103        if (this.field_96489_f == 0 || this.field_96489_f == 3 || this.field_96489_f == 4)
    104        {
    105            par1DataOutputStream.writeShort(this.field_96492_e.size());
    106            Iterator iterator = this.field_96492_e.iterator();
    107
    108            while (iterator.hasNext())
    109            {
    110                String s = (String)iterator.next();
    111                writeString(s, par1DataOutputStream);
    112            }
    113        }
    114    }
    115
    116    /**
    117     * Passes this Packet on to the NetHandler for processing.
    118     */
    119    public void processPacket(NetHandler par1NetHandler)
    120    {
    121        par1NetHandler.func_96435_a(this);
    122    }
    123
    124    /**
    125     * Abstract. Return the size of the packet (not counting the header).
    126     */
    127    public int getPacketSize()
    128    {
    129        return 3 + this.field_96495_a.length();
    130    }
    131}