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 /** A unique name for the team. */ 014 public String teamName = ""; 015 016 /** Only if mode = 0 or 2. */ 017 public String teamDisplayName = ""; 018 019 /** 020 * Only if mode = 0 or 2. Displayed before the players' name that are part of this team. 021 */ 022 public String teamPrefix = ""; 023 024 /** 025 * Only if mode = 0 or 2. Displayed after the players' name that are part of this team. 026 */ 027 public String teamSuffix = ""; 028 029 /** Only if mode = 0 or 3 or 4. Players to be added/remove from the team. */ 030 public Collection playerNames = new ArrayList(); 031 032 /** 033 * If 0 then the team is created. If 1 then the team is removed. If 2 the team team information is updated. If 3 034 * then new players are added to the team. If 4 then players are removed from the team. 035 */ 036 public int mode = 0; 037 038 /** Only if mode = 0 or 2. */ 039 public int friendlyFire; 040 041 public Packet209SetPlayerTeam() {} 042 043 public Packet209SetPlayerTeam(ScorePlayerTeam par1, int par2) 044 { 045 this.teamName = par1.func_96661_b(); 046 this.mode = par2; 047 048 if (par2 == 0 || par2 == 2) 049 { 050 this.teamDisplayName = par1.func_96669_c(); 051 this.teamPrefix = par1.func_96668_e(); 052 this.teamSuffix = par1.func_96663_f(); 053 this.friendlyFire = par1.func_98299_i(); 054 } 055 056 if (par2 == 0) 057 { 058 this.playerNames.addAll(par1.func_96670_d()); 059 } 060 } 061 062 public Packet209SetPlayerTeam(ScorePlayerTeam par1, Collection par2, int par3) 063 { 064 if (par3 != 3 && par3 != 4) 065 { 066 throw new IllegalArgumentException("Method must be join or leave for player constructor"); 067 } 068 else if (par2 != null && !par2.isEmpty()) 069 { 070 this.mode = par3; 071 this.teamName = par1.func_96661_b(); 072 this.playerNames.addAll(par2); 073 } 074 else 075 { 076 throw new IllegalArgumentException("Players cannot be null/empty"); 077 } 078 } 079 080 /** 081 * Abstract. Reads the raw packet data from the data stream. 082 */ 083 public void readPacketData(DataInputStream par1DataInputStream) throws IOException 084 { 085 this.teamName = readString(par1DataInputStream, 16); 086 this.mode = par1DataInputStream.readByte(); 087 088 if (this.mode == 0 || this.mode == 2) 089 { 090 this.teamDisplayName = readString(par1DataInputStream, 32); 091 this.teamPrefix = readString(par1DataInputStream, 16); 092 this.teamSuffix = readString(par1DataInputStream, 16); 093 this.friendlyFire = par1DataInputStream.readByte(); 094 } 095 096 if (this.mode == 0 || this.mode == 3 || this.mode == 4) 097 { 098 short short1 = par1DataInputStream.readShort(); 099 100 for (int i = 0; i < short1; ++i) 101 { 102 this.playerNames.add(readString(par1DataInputStream, 16)); 103 } 104 } 105 } 106 107 /** 108 * Abstract. Writes the raw packet data to the data stream. 109 */ 110 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException 111 { 112 writeString(this.teamName, par1DataOutputStream); 113 par1DataOutputStream.writeByte(this.mode); 114 115 if (this.mode == 0 || this.mode == 2) 116 { 117 writeString(this.teamDisplayName, par1DataOutputStream); 118 writeString(this.teamPrefix, par1DataOutputStream); 119 writeString(this.teamSuffix, par1DataOutputStream); 120 par1DataOutputStream.writeByte(this.friendlyFire); 121 } 122 123 if (this.mode == 0 || this.mode == 3 || this.mode == 4) 124 { 125 par1DataOutputStream.writeShort(this.playerNames.size()); 126 Iterator iterator = this.playerNames.iterator(); 127 128 while (iterator.hasNext()) 129 { 130 String s = (String)iterator.next(); 131 writeString(s, par1DataOutputStream); 132 } 133 } 134 } 135 136 /** 137 * Passes this Packet on to the NetHandler for processing. 138 */ 139 public void processPacket(NetHandler par1NetHandler) 140 { 141 par1NetHandler.handleSetPlayerTeam(this); 142 } 143 144 /** 145 * Abstract. Return the size of the packet (not counting the header). 146 */ 147 public int getPacketSize() 148 { 149 return 3 + this.teamName.length(); 150 } 151}