    001package net.minecraft.scoreboard;
    002
    003import java.util.ArrayList;
    004import java.util.Arrays;
    005import java.util.HashSet;
    006import java.util.Iterator;
    007import java.util.List;
    008import java.util.Set;
    009import net.minecraft.entity.player.EntityPlayerMP;
    010import net.minecraft.network.packet.Packet;
    011import net.minecraft.network.packet.Packet206SetObjective;
    012import net.minecraft.network.packet.Packet207SetScore;
    013import net.minecraft.network.packet.Packet208SetDisplayObjective;
    014import net.minecraft.network.packet.Packet209SetPlayerTeam;
    015import net.minecraft.server.MinecraftServer;
    016
    017public class ServerScoreboard extends Scoreboard
    018{
    019    private final MinecraftServer field_96555_a;
    020    private final Set field_96553_b = new HashSet();
    021    private ScoreboardSaveData field_96554_c;
    022
    023    public ServerScoreboard(MinecraftServer par1MinecraftServer)
    024    {
    025        this.field_96555_a = par1MinecraftServer;
    026    }
    027
    028    public void func_96536_a(Score par1Score)
    029    {
    030        super.func_96536_a(par1Score);
    031
    032        if (this.field_96553_b.contains(par1Score.func_96645_d()))
    033        {
    034            this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet207SetScore(par1Score, 0));
    035        }
    036
    037        this.func_96551_b();
    038    }
    039
    040    public void func_96516_a(String par1Str)
    041    {
    042        super.func_96516_a(par1Str);
    043        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet207SetScore(par1Str));
    044        this.func_96551_b();
    045    }
    046
    047    public void func_96530_a(int par1, ScoreObjective par2ScoreObjective)
    048    {
    049        ScoreObjective scoreobjective1 = this.func_96539_a(par1);
    050        super.func_96530_a(par1, par2ScoreObjective);
    051
    052        if (scoreobjective1 != par2ScoreObjective && scoreobjective1 != null)
    053        {
    054            if (this.func_96552_h(scoreobjective1) > 0)
    055            {
    056                this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet208SetDisplayObjective(par1, par2ScoreObjective));
    057            }
    058            else
    059            {
    060                this.func_96546_g(scoreobjective1);
    061            }
    062        }
    063
    064        if (par2ScoreObjective != null)
    065        {
    066            if (this.field_96553_b.contains(par2ScoreObjective))
    067            {
    068                this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet208SetDisplayObjective(par1, par2ScoreObjective));
    069            }
    070            else
    071            {
    072                this.func_96549_e(par2ScoreObjective);
    073            }
    074        }
    075
    076        this.func_96551_b();
    077    }
    078
    079    public void func_96521_a(String par1Str, ScorePlayerTeam par2ScorePlayerTeam)
    080    {
    081        super.func_96521_a(par1Str, par2ScorePlayerTeam);
    082        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet209SetPlayerTeam(par2ScorePlayerTeam, Arrays.asList(new String[] {par1Str}), 3));
    083        this.func_96551_b();
    084    }
    085
    086    public void func_96512_b(String par1Str, ScorePlayerTeam par2ScorePlayerTeam)
    087    {
    088        super.func_96512_b(par1Str, par2ScorePlayerTeam);
    089        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet209SetPlayerTeam(par2ScorePlayerTeam, Arrays.asList(new String[] {par1Str}), 4));
    090        this.func_96551_b();
    091    }
    092
    093    public void func_96522_a(ScoreObjective par1ScoreObjective)
    094    {
    095        super.func_96522_a(par1ScoreObjective);
    096        this.func_96551_b();
    097    }
    098
    099    public void func_96532_b(ScoreObjective par1ScoreObjective)
    100    {
    101        super.func_96532_b(par1ScoreObjective);
    102
    103        if (this.field_96553_b.contains(par1ScoreObjective))
    104        {
    105            this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet206SetObjective(par1ScoreObjective, 2));
    106        }
    107
    108        this.func_96551_b();
    109    }
    110
    111    public void func_96533_c(ScoreObjective par1ScoreObjective)
    112    {
    113        super.func_96533_c(par1ScoreObjective);
    114
    115        if (this.field_96553_b.contains(par1ScoreObjective))
    116        {
    117            this.func_96546_g(par1ScoreObjective);
    118        }
    119
    120        this.func_96551_b();
    121    }
    122
    123    public void func_96523_a(ScorePlayerTeam par1ScorePlayerTeam)
    124    {
    125        super.func_96523_a(par1ScorePlayerTeam);
    126        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet209SetPlayerTeam(par1ScorePlayerTeam, 0));
    127        this.func_96551_b();
    128    }
    129
    130    public void func_96538_b(ScorePlayerTeam par1ScorePlayerTeam)
    131    {
    132        super.func_96538_b(par1ScorePlayerTeam);
    133        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet209SetPlayerTeam(par1ScorePlayerTeam, 2));
    134        this.func_96551_b();
    135    }
    136
    137    public void func_96513_c(ScorePlayerTeam par1ScorePlayerTeam)
    138    {
    139        super.func_96513_c(par1ScorePlayerTeam);
    140        this.field_96555_a.getConfigurationManager().sendPacketToAllPlayers(new Packet209SetPlayerTeam(par1ScorePlayerTeam, 1));
    141        this.func_96551_b();
    142    }
    143
    144    public void func_96547_a(ScoreboardSaveData par1ScoreboardSaveData)
    145    {
    146        this.field_96554_c = par1ScoreboardSaveData;
    147    }
    148
    149    protected void func_96551_b()
    150    {
    151        if (this.field_96554_c != null)
    152        {
    153            this.field_96554_c.markDirty();
    154        }
    155    }
    156
    157    public List func_96550_d(ScoreObjective par1ScoreObjective)
    158    {
    159        ArrayList arraylist = new ArrayList();
    160        arraylist.add(new Packet206SetObjective(par1ScoreObjective, 0));
    161
    162        for (int i = 0; i < 3; ++i)
    163        {
    164            if (this.func_96539_a(i) == par1ScoreObjective)
    165            {
    166                arraylist.add(new Packet208SetDisplayObjective(i, par1ScoreObjective));
    167            }
    168        }
    169
    170        Iterator iterator = this.func_96534_i(par1ScoreObjective).iterator();
    171
    172        while (iterator.hasNext())
    173        {
    174            Score score = (Score)iterator.next();
    175            arraylist.add(new Packet207SetScore(score, 0));
    176        }
    177
    178        return arraylist;
    179    }
    180
    181    public void func_96549_e(ScoreObjective par1ScoreObjective)
    182    {
    183        List list = this.func_96550_d(par1ScoreObjective);
    184        Iterator iterator = this.field_96555_a.getConfigurationManager().playerEntityList.iterator();
    185
    186        while (iterator.hasNext())
    187        {
    188            EntityPlayerMP entityplayermp = (EntityPlayerMP)iterator.next();
    189            Iterator iterator1 = list.iterator();
    190
    191            while (iterator1.hasNext())
    192            {
    193                Packet packet = (Packet)iterator1.next();
    194                entityplayermp.playerNetServerHandler.sendPacketToPlayer(packet);
    195            }
    196        }
    197
    198        this.field_96553_b.add(par1ScoreObjective);
    199    }
    200
    201    public List func_96548_f(ScoreObjective par1ScoreObjective)
    202    {
    203        ArrayList arraylist = new ArrayList();
    204        arraylist.add(new Packet206SetObjective(par1ScoreObjective, 1));
    205
    206        for (int i = 0; i < 3; ++i)
    207        {
    208            if (this.func_96539_a(i) == par1ScoreObjective)
    209            {
    210                arraylist.add(new Packet208SetDisplayObjective(i, par1ScoreObjective));
    211            }
    212        }
    213
    214        return arraylist;
    215    }
    216
    217    public void func_96546_g(ScoreObjective par1ScoreObjective)
    218    {
    219        List list = this.func_96548_f(par1ScoreObjective);
    220        Iterator iterator = this.field_96555_a.getConfigurationManager().playerEntityList.iterator();
    221
    222        while (iterator.hasNext())
    223        {
    224            EntityPlayerMP entityplayermp = (EntityPlayerMP)iterator.next();
    225            Iterator iterator1 = list.iterator();
    226
    227            while (iterator1.hasNext())
    228            {
    229                Packet packet = (Packet)iterator1.next();
    230                entityplayermp.playerNetServerHandler.sendPacketToPlayer(packet);
    231            }
    232        }
    233
    234        this.field_96553_b.remove(par1ScoreObjective);
    235    }
    236
    237    public int func_96552_h(ScoreObjective par1ScoreObjective)
    238    {
    239        int i = 0;
    240
    241        for (int j = 0; j < 3; ++j)
    242        {
    243            if (this.func_96539_a(j) == par1ScoreObjective)
    244            {
    245                ++i;
    246            }
    247        }
    248
    249        return i;
    250    }
    251}