| 1 | package net.minecraft.scoreboard;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Sets;
|
| 5 | import java.util.Arrays;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Set;
|
| 8 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 9 | import net.minecraft.network.Packet;
|
| 10 | import net.minecraft.network.play.server.S3BPacketScoreboardObjective;
|
| 11 | import net.minecraft.network.play.server.S3CPacketUpdateScore;
|
| 12 | import net.minecraft.network.play.server.S3DPacketDisplayScoreboard;
|
| 13 | import net.minecraft.network.play.server.S3EPacketTeams;
|
| 14 | import net.minecraft.server.MinecraftServer;
|
| 15 |
|
| 16 | public class ServerScoreboard extends Scoreboard
|
| 17 | {
|
| 18 | private final MinecraftServer scoreboardMCServer;
|
| 19 | private final Set<ScoreObjective> field_96553_b = Sets.<ScoreObjective>newHashSet();
|
| 20 | private ScoreboardSaveData scoreboardSaveData;
|
| 21 |
|
| 22 | public ServerScoreboard(MinecraftServer mcServer)
|
| 23 | {
|
| 24 | this.scoreboardMCServer = mcServer;
|
| 25 | }
|
| 26 |
|
| 27 | public void func_96536_a(Score p_96536_1_)
|
| 28 | {
|
| 29 | super.func_96536_a(p_96536_1_);
|
| 30 |
|
| 31 | if (this.field_96553_b.contains(p_96536_1_.getObjective()))
|
| 32 | {
|
| 33 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3CPacketUpdateScore(p_96536_1_));
|
| 34 | }
|
| 35 |
|
| 36 | this.markSaveDataDirty();
|
| 37 | }
|
| 38 |
|
| 39 | public void func_96516_a(String p_96516_1_)
|
| 40 | {
|
| 41 | super.func_96516_a(p_96516_1_);
|
| 42 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3CPacketUpdateScore(p_96516_1_));
|
| 43 | this.markSaveDataDirty();
|
| 44 | }
|
| 45 |
|
| 46 | public void func_178820_a(String p_178820_1_, ScoreObjective p_178820_2_)
|
| 47 | {
|
| 48 | super.func_178820_a(p_178820_1_, p_178820_2_);
|
| 49 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3CPacketUpdateScore(p_178820_1_, p_178820_2_));
|
| 50 | this.markSaveDataDirty();
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * 0 is tab menu, 1 is sidebar, 2 is below name
|
| 55 | */
|
| 56 | public void setObjectiveInDisplaySlot(int p_96530_1_, ScoreObjective p_96530_2_)
|
| 57 | {
|
| 58 | ScoreObjective scoreobjective = this.getObjectiveInDisplaySlot(p_96530_1_);
|
| 59 | super.setObjectiveInDisplaySlot(p_96530_1_, p_96530_2_);
|
| 60 |
|
| 61 | if (scoreobjective != p_96530_2_ && scoreobjective != null)
|
| 62 | {
|
| 63 | if (this.func_96552_h(scoreobjective) > 0)
|
| 64 | {
|
| 65 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3DPacketDisplayScoreboard(p_96530_1_, p_96530_2_));
|
| 66 | }
|
| 67 | else
|
| 68 | {
|
| 69 | this.sendDisplaySlotRemovalPackets(scoreobjective);
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | if (p_96530_2_ != null)
|
| 74 | {
|
| 75 | if (this.field_96553_b.contains(p_96530_2_))
|
| 76 | {
|
| 77 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3DPacketDisplayScoreboard(p_96530_1_, p_96530_2_));
|
| 78 | }
|
| 79 | else
|
| 80 | {
|
| 81 | this.func_96549_e(p_96530_2_);
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | this.markSaveDataDirty();
|
| 86 | }
|
| 87 |
|
| 88 | /**
|
| 89 | * Adds a player to the given team
|
| 90 | */
|
| 91 | public boolean addPlayerToTeam(String player, String newTeam)
|
| 92 | {
|
| 93 | if (super.addPlayerToTeam(player, newTeam))
|
| 94 | {
|
| 95 | ScorePlayerTeam scoreplayerteam = this.getTeam(newTeam);
|
| 96 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3EPacketTeams(scoreplayerteam, Arrays.asList(new String[] {player}), 3));
|
| 97 | this.markSaveDataDirty();
|
| 98 | return true;
|
| 99 | }
|
| 100 | else
|
| 101 | {
|
| 102 | return false;
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | /**
|
| 107 | * Removes the given username from the given ScorePlayerTeam. If the player is not on the team then an
|
| 108 | * IllegalStateException is thrown.
|
| 109 | */
|
| 110 | public void removePlayerFromTeam(String p_96512_1_, ScorePlayerTeam p_96512_2_)
|
| 111 | {
|
| 112 | super.removePlayerFromTeam(p_96512_1_, p_96512_2_);
|
| 113 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3EPacketTeams(p_96512_2_, Arrays.asList(new String[] {p_96512_1_}), 4));
|
| 114 | this.markSaveDataDirty();
|
| 115 | }
|
| 116 |
|
| 117 | /**
|
| 118 | * Called when a score objective is added
|
| 119 | */
|
| 120 | public void onScoreObjectiveAdded(ScoreObjective scoreObjectiveIn)
|
| 121 | {
|
| 122 | super.onScoreObjectiveAdded(scoreObjectiveIn);
|
| 123 | this.markSaveDataDirty();
|
| 124 | }
|
| 125 |
|
| 126 | public void onObjectiveDisplayNameChanged(ScoreObjective p_96532_1_)
|
| 127 | {
|
| 128 | super.onObjectiveDisplayNameChanged(p_96532_1_);
|
| 129 |
|
| 130 | if (this.field_96553_b.contains(p_96532_1_))
|
| 131 | {
|
| 132 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3BPacketScoreboardObjective(p_96532_1_, 2));
|
| 133 | }
|
| 134 |
|
| 135 | this.markSaveDataDirty();
|
| 136 | }
|
| 137 |
|
| 138 | public void onScoreObjectiveRemoved(ScoreObjective p_96533_1_)
|
| 139 | {
|
| 140 | super.onScoreObjectiveRemoved(p_96533_1_);
|
| 141 |
|
| 142 | if (this.field_96553_b.contains(p_96533_1_))
|
| 143 | {
|
| 144 | this.sendDisplaySlotRemovalPackets(p_96533_1_);
|
| 145 | }
|
| 146 |
|
| 147 | this.markSaveDataDirty();
|
| 148 | }
|
| 149 |
|
| 150 | /**
|
| 151 | * This packet will notify the players that this team is created, and that will register it on the client
|
| 152 | */
|
| 153 | public void broadcastTeamCreated(ScorePlayerTeam playerTeam)
|
| 154 | {
|
| 155 | super.broadcastTeamCreated(playerTeam);
|
| 156 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3EPacketTeams(playerTeam, 0));
|
| 157 | this.markSaveDataDirty();
|
| 158 | }
|
| 159 |
|
| 160 | /**
|
| 161 | * This packet will notify the players that this team is updated
|
| 162 | */
|
| 163 | public void sendTeamUpdate(ScorePlayerTeam playerTeam)
|
| 164 | {
|
| 165 | super.sendTeamUpdate(playerTeam);
|
| 166 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3EPacketTeams(playerTeam, 2));
|
| 167 | this.markSaveDataDirty();
|
| 168 | }
|
| 169 |
|
| 170 | public void func_96513_c(ScorePlayerTeam playerTeam)
|
| 171 | {
|
| 172 | super.func_96513_c(playerTeam);
|
| 173 | this.scoreboardMCServer.getConfigurationManager().sendPacketToAllPlayers(new S3EPacketTeams(playerTeam, 1));
|
| 174 | this.markSaveDataDirty();
|
| 175 | }
|
| 176 |
|
| 177 | public void func_96547_a(ScoreboardSaveData p_96547_1_)
|
| 178 | {
|
| 179 | this.scoreboardSaveData = p_96547_1_;
|
| 180 | }
|
| 181 |
|
| 182 | protected void markSaveDataDirty()
|
| 183 | {
|
| 184 | if (this.scoreboardSaveData != null)
|
| 185 | {
|
| 186 | this.scoreboardSaveData.markDirty();
|
| 187 | }
|
| 188 | }
|
| 189 |
|
| 190 | public List<Packet> func_96550_d(ScoreObjective p_96550_1_)
|
| 191 | {
|
| 192 | List<Packet> list = Lists.<Packet>newArrayList();
|
| 193 | list.add(new S3BPacketScoreboardObjective(p_96550_1_, 0));
|
| 194 |
|
| 195 | for (int i = 0; i < 19; ++i)
|
| 196 | {
|
| 197 | if (this.getObjectiveInDisplaySlot(i) == p_96550_1_)
|
| 198 | {
|
| 199 | list.add(new S3DPacketDisplayScoreboard(i, p_96550_1_));
|
| 200 | }
|
| 201 | }
|
| 202 |
|
| 203 | for (Score score : this.getSortedScores(p_96550_1_))
|
| 204 | {
|
| 205 | list.add(new S3CPacketUpdateScore(score));
|
| 206 | }
|
| 207 |
|
| 208 | return list;
|
| 209 | }
|
| 210 |
|
| 211 | public void func_96549_e(ScoreObjective p_96549_1_)
|
| 212 | {
|
| 213 | List<Packet> list = this.func_96550_d(p_96549_1_);
|
| 214 |
|
| 215 | for (EntityPlayerMP entityplayermp : this.scoreboardMCServer.getConfigurationManager().getPlayerList())
|
| 216 | {
|
| 217 | for (Packet packet : list)
|
| 218 | {
|
| 219 | entityplayermp.playerNetServerHandler.sendPacket(packet);
|
| 220 | }
|
| 221 | }
|
| 222 |
|
| 223 | this.field_96553_b.add(p_96549_1_);
|
| 224 | }
|
| 225 |
|
| 226 | public List<Packet> func_96548_f(ScoreObjective p_96548_1_)
|
| 227 | {
|
| 228 | List<Packet> list = Lists.<Packet>newArrayList();
|
| 229 | list.add(new S3BPacketScoreboardObjective(p_96548_1_, 1));
|
| 230 |
|
| 231 | for (int i = 0; i < 19; ++i)
|
| 232 | {
|
| 233 | if (this.getObjectiveInDisplaySlot(i) == p_96548_1_)
|
| 234 | {
|
| 235 | list.add(new S3DPacketDisplayScoreboard(i, p_96548_1_));
|
| 236 | }
|
| 237 | }
|
| 238 |
|
| 239 | return list;
|
| 240 | }
|
| 241 |
|
| 242 | public void sendDisplaySlotRemovalPackets(ScoreObjective p_96546_1_)
|
| 243 | {
|
| 244 | List<Packet> list = this.func_96548_f(p_96546_1_);
|
| 245 |
|
| 246 | for (EntityPlayerMP entityplayermp : this.scoreboardMCServer.getConfigurationManager().getPlayerList())
|
| 247 | {
|
| 248 | for (Packet packet : list)
|
| 249 | {
|
| 250 | entityplayermp.playerNetServerHandler.sendPacket(packet);
|
| 251 | }
|
| 252 | }
|
| 253 |
|
| 254 | this.field_96553_b.remove(p_96546_1_);
|
| 255 | }
|
| 256 |
|
| 257 | public int func_96552_h(ScoreObjective p_96552_1_)
|
| 258 | {
|
| 259 | int i = 0;
|
| 260 |
|
| 261 | for (int j = 0; j < 19; ++j)
|
| 262 | {
|
| 263 | if (this.getObjectiveInDisplaySlot(j) == p_96552_1_)
|
| 264 | {
|
| 265 | ++i;
|
| 266 | }
|
| 267 | }
|
| 268 |
|
| 269 | return i;
|
| 270 | }
|
| 271 | }
|
| 272 |
|