    001package net.minecraft.scoreboard;
    002
    003import java.util.Collection;
    004import java.util.Iterator;
    005import net.minecraft.nbt.NBTTagCompound;
    006import net.minecraft.nbt.NBTTagList;
    007import net.minecraft.nbt.NBTTagString;
    008import net.minecraft.server.MinecraftServer;
    009import net.minecraft.world.WorldSavedData;
    010
    011public class ScoreboardSaveData extends WorldSavedData
    012{
    013    private Scoreboard field_96507_a;
    014    private NBTTagCompound field_96506_b;
    015
    016    public ScoreboardSaveData()
    017    {
    018        this("scoreboard");
    019    }
    020
    021    public ScoreboardSaveData(String par1Str)
    022    {
    023        super(par1Str);
    024    }
    025
    026    public void func_96499_a(Scoreboard par1Scoreboard)
    027    {
    028        this.field_96507_a = par1Scoreboard;
    029
    030        if (this.field_96506_b != null)
    031        {
    032            this.readFromNBT(this.field_96506_b);
    033        }
    034    }
    035
    036    /**
    037     * reads in data from the NBTTagCompound into this MapDataBase
    038     */
    039    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    040    {
    041        if (this.field_96507_a == null)
    042        {
    043            this.field_96506_b = par1NBTTagCompound;
    044        }
    045        else
    046        {
    047            this.func_96501_b(par1NBTTagCompound.getTagList("Objectives"));
    048            this.func_96500_c(par1NBTTagCompound.getTagList("PlayerScores"));
    049
    050            if (par1NBTTagCompound.hasKey("DisplaySlots"))
    051            {
    052                this.func_96504_c(par1NBTTagCompound.getCompoundTag("DisplaySlots"));
    053            }
    054
    055            if (par1NBTTagCompound.hasKey("Teams"))
    056            {
    057                this.func_96498_a(par1NBTTagCompound.getTagList("Teams"));
    058            }
    059        }
    060    }
    061
    062    protected void func_96498_a(NBTTagList par1NBTTagList)
    063    {
    064        for (int i = 0; i < par1NBTTagList.tagCount(); ++i)
    065        {
    066            NBTTagCompound nbttagcompound = (NBTTagCompound)par1NBTTagList.tagAt(i);
    067            ScorePlayerTeam scoreplayerteam = this.field_96507_a.func_96527_f(nbttagcompound.getString("Name"));
    068            scoreplayerteam.func_96664_a(nbttagcompound.getString("DisplayName"));
    069            scoreplayerteam.func_96666_b(nbttagcompound.getString("Prefix"));
    070            scoreplayerteam.func_96662_c(nbttagcompound.getString("Suffix"));
    071
    072            if (nbttagcompound.hasKey("AllowFriendlyFire"))
    073            {
    074                scoreplayerteam.func_96660_a(nbttagcompound.getBoolean("AllowFriendlyFire"));
    075            }
    076
    077            if (nbttagcompound.hasKey("SeeFriendlyInvisibles"))
    078            {
    079                scoreplayerteam.func_98300_b(nbttagcompound.getBoolean("SeeFriendlyInvisibles"));
    080            }
    081
    082            this.func_96502_a(scoreplayerteam, nbttagcompound.getTagList("Players"));
    083        }
    084    }
    085
    086    protected void func_96502_a(ScorePlayerTeam par1ScorePlayerTeam, NBTTagList par2NBTTagList)
    087    {
    088        for (int i = 0; i < par2NBTTagList.tagCount(); ++i)
    089        {
    090            this.field_96507_a.func_96521_a(((NBTTagString)par2NBTTagList.tagAt(i)).data, par1ScorePlayerTeam);
    091        }
    092    }
    093
    094    protected void func_96504_c(NBTTagCompound par1NBTTagCompound)
    095    {
    096        for (int i = 0; i < 3; ++i)
    097        {
    098            if (par1NBTTagCompound.hasKey("slot_" + i))
    099            {
    100                String s = par1NBTTagCompound.getString("slot_" + i);
    101                ScoreObjective scoreobjective = this.field_96507_a.func_96518_b(s);
    102                this.field_96507_a.func_96530_a(i, scoreobjective);
    103            }
    104        }
    105    }
    106
    107    protected void func_96501_b(NBTTagList par1NBTTagList)
    108    {
    109        for (int i = 0; i < par1NBTTagList.tagCount(); ++i)
    110        {
    111            NBTTagCompound nbttagcompound = (NBTTagCompound)par1NBTTagList.tagAt(i);
    112            ScoreObjectiveCriteria scoreobjectivecriteria = (ScoreObjectiveCriteria)ScoreObjectiveCriteria.field_96643_a.get(nbttagcompound.getString("CriteriaName"));
    113            ScoreObjective scoreobjective = this.field_96507_a.func_96535_a(nbttagcompound.getString("Name"), scoreobjectivecriteria);
    114            scoreobjective.func_96681_a(nbttagcompound.getString("DisplayName"));
    115        }
    116    }
    117
    118    protected void func_96500_c(NBTTagList par1NBTTagList)
    119    {
    120        for (int i = 0; i < par1NBTTagList.tagCount(); ++i)
    121        {
    122            NBTTagCompound nbttagcompound = (NBTTagCompound)par1NBTTagList.tagAt(i);
    123            ScoreObjective scoreobjective = this.field_96507_a.func_96518_b(nbttagcompound.getString("Objective"));
    124            Score score = this.field_96507_a.func_96529_a(nbttagcompound.getString("Name"), scoreobjective);
    125            score.func_96647_c(nbttagcompound.getInteger("Score"));
    126        }
    127    }
    128
    129    /**
    130     * write data to NBTTagCompound from this MapDataBase, similar to Entities and TileEntities
    131     */
    132    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    133    {
    134        if (this.field_96507_a == null)
    135        {
    136            MinecraftServer.getServer().func_98033_al().func_98236_b("Tried to save scoreboard without having a scoreboard...");
    137        }
    138        else
    139        {
    140            par1NBTTagCompound.setTag("Objectives", this.func_96505_b());
    141            par1NBTTagCompound.setTag("PlayerScores", this.func_96503_e());
    142            par1NBTTagCompound.setTag("Teams", this.func_96496_a());
    143            this.func_96497_d(par1NBTTagCompound);
    144        }
    145    }
    146
    147    protected NBTTagList func_96496_a()
    148    {
    149        NBTTagList nbttaglist = new NBTTagList();
    150        Collection collection = this.field_96507_a.func_96525_g();
    151        Iterator iterator = collection.iterator();
    152
    153        while (iterator.hasNext())
    154        {
    155            ScorePlayerTeam scoreplayerteam = (ScorePlayerTeam)iterator.next();
    156            NBTTagCompound nbttagcompound = new NBTTagCompound();
    157            nbttagcompound.setString("Name", scoreplayerteam.func_96661_b());
    158            nbttagcompound.setString("DisplayName", scoreplayerteam.func_96669_c());
    159            nbttagcompound.setString("Prefix", scoreplayerteam.func_96668_e());
    160            nbttagcompound.setString("Suffix", scoreplayerteam.func_96663_f());
    161            nbttagcompound.setBoolean("AllowFriendlyFire", scoreplayerteam.func_96665_g());
    162            nbttagcompound.setBoolean("SeeFriendlyInvisibles", scoreplayerteam.func_98297_h());
    163            NBTTagList nbttaglist1 = new NBTTagList();
    164            Iterator iterator1 = scoreplayerteam.func_96670_d().iterator();
    165
    166            while (iterator1.hasNext())
    167            {
    168                String s = (String)iterator1.next();
    169                nbttaglist1.appendTag(new NBTTagString("", s));
    170            }
    171
    172            nbttagcompound.setTag("Players", nbttaglist1);
    173            nbttaglist.appendTag(nbttagcompound);
    174        }
    175
    176        return nbttaglist;
    177    }
    178
    179    protected void func_96497_d(NBTTagCompound par1NBTTagCompound)
    180    {
    181        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
    182        boolean flag = false;
    183
    184        for (int i = 0; i < 3; ++i)
    185        {
    186            ScoreObjective scoreobjective = this.field_96507_a.func_96539_a(i);
    187
    188            if (scoreobjective != null)
    189            {
    190                nbttagcompound1.setString("slot_" + i, scoreobjective.func_96679_b());
    191                flag = true;
    192            }
    193        }
    194
    195        if (flag)
    196        {
    197            par1NBTTagCompound.setCompoundTag("DisplaySlots", nbttagcompound1);
    198        }
    199    }
    200
    201    protected NBTTagList func_96505_b()
    202    {
    203        NBTTagList nbttaglist = new NBTTagList();
    204        Collection collection = this.field_96507_a.func_96514_c();
    205        Iterator iterator = collection.iterator();
    206
    207        while (iterator.hasNext())
    208        {
    209            ScoreObjective scoreobjective = (ScoreObjective)iterator.next();
    210            NBTTagCompound nbttagcompound = new NBTTagCompound();
    211            nbttagcompound.setString("Name", scoreobjective.func_96679_b());
    212            nbttagcompound.setString("CriteriaName", scoreobjective.func_96680_c().func_96636_a());
    213            nbttagcompound.setString("DisplayName", scoreobjective.func_96678_d());
    214            nbttaglist.appendTag(nbttagcompound);
    215        }
    216
    217        return nbttaglist;
    218    }
    219
    220    protected NBTTagList func_96503_e()
    221    {
    222        NBTTagList nbttaglist = new NBTTagList();
    223        Collection collection = this.field_96507_a.func_96528_e();
    224        Iterator iterator = collection.iterator();
    225
    226        while (iterator.hasNext())
    227        {
    228            Score score = (Score)iterator.next();
    229            NBTTagCompound nbttagcompound = new NBTTagCompound();
    230            nbttagcompound.setString("Name", score.func_96653_e());
    231            nbttagcompound.setString("Objective", score.func_96645_d().func_96679_b());
    232            nbttagcompound.setInteger("Score", score.func_96652_c());
    233            nbttaglist.appendTag(nbttagcompound);
    234        }
    235
    236        return nbttaglist;
    237    }
    238}