    001package net.minecraft.scoreboard;
    002
    003import java.util.ArrayList;
    004import java.util.Collection;
    005import java.util.Collections;
    006import java.util.HashMap;
    007import java.util.Iterator;
    008import java.util.List;
    009import java.util.Map;
    010
    011public class Scoreboard
    012{
    013    /** Map of objective names to ScoreObjective objects. */
    014    private final Map scoreObjectives = new HashMap();
    015    private final Map field_96543_b = new HashMap();
    016    private final Map field_96544_c = new HashMap();
    017    private final ScoreObjective[] field_96541_d = new ScoreObjective[3];
    018    private final Map field_96542_e = new HashMap();
    019    private final Map field_96540_f = new HashMap();
    020
    021    /**
    022     * Returns a ScoreObjective for the objective name
    023     */
    024    public ScoreObjective getObjective(String par1Str)
    025    {
    026        return (ScoreObjective)this.scoreObjectives.get(par1Str);
    027    }
    028
    029    public ScoreObjective func_96535_a(String par1Str, ScoreObjectiveCriteria par2ScoreObjectiveCriteria)
    030    {
    031        ScoreObjective scoreobjective = this.getObjective(par1Str);
    032
    033        if (scoreobjective != null)
    034        {
    035            throw new IllegalArgumentException("An objective with the name \'" + par1Str + "\' already exists!");
    036        }
    037        else
    038        {
    039            scoreobjective = new ScoreObjective(this, par1Str, par2ScoreObjectiveCriteria);
    040            Object object = (List)this.field_96543_b.get(par2ScoreObjectiveCriteria);
    041
    042            if (object == null)
    043            {
    044                object = new ArrayList();
    045                this.field_96543_b.put(par2ScoreObjectiveCriteria, object);
    046            }
    047
    048            ((List)object).add(scoreobjective);
    049            this.scoreObjectives.put(par1Str, scoreobjective);
    050            this.func_96522_a(scoreobjective);
    051            return scoreobjective;
    052        }
    053    }
    054
    055    public Collection func_96520_a(ScoreObjectiveCriteria par1ScoreObjectiveCriteria)
    056    {
    057        Collection collection = (Collection)this.field_96543_b.get(par1ScoreObjectiveCriteria);
    058        return collection == null ? new ArrayList() : new ArrayList(collection);
    059    }
    060
    061    public Score func_96529_a(String par1Str, ScoreObjective par2ScoreObjective)
    062    {
    063        Object object = (Map)this.field_96544_c.get(par1Str);
    064
    065        if (object == null)
    066        {
    067            object = new HashMap();
    068            this.field_96544_c.put(par1Str, object);
    069        }
    070
    071        Score score = (Score)((Map)object).get(par2ScoreObjective);
    072
    073        if (score == null)
    074        {
    075            score = new Score(this, par2ScoreObjective, par1Str);
    076            ((Map)object).put(par2ScoreObjective, score);
    077        }
    078
    079        return score;
    080    }
    081
    082    public Collection func_96534_i(ScoreObjective par1ScoreObjective)
    083    {
    084        ArrayList arraylist = new ArrayList();
    085        Iterator iterator = this.field_96544_c.values().iterator();
    086
    087        while (iterator.hasNext())
    088        {
    089            Map map = (Map)iterator.next();
    090            Score score = (Score)map.get(par1ScoreObjective);
    091
    092            if (score != null)
    093            {
    094                arraylist.add(score);
    095            }
    096        }
    097
    098        Collections.sort(arraylist, Score.field_96658_a);
    099        return arraylist;
    100    }
    101
    102    public Collection getScoreObjectives()
    103    {
    104        return this.scoreObjectives.values();
    105    }
    106
    107    public Collection getObjectiveNames()
    108    {
    109        return this.field_96544_c.keySet();
    110    }
    111
    112    public void func_96515_c(String par1Str)
    113    {
    114        Map map = (Map)this.field_96544_c.remove(par1Str);
    115
    116        if (map != null)
    117        {
    118            this.func_96516_a(par1Str);
    119        }
    120    }
    121
    122    public Collection func_96528_e()
    123    {
    124        Collection collection = this.field_96544_c.values();
    125        ArrayList arraylist = new ArrayList();
    126
    127        if (collection != null)
    128        {
    129            Iterator iterator = collection.iterator();
    130
    131            while (iterator.hasNext())
    132            {
    133                Map map = (Map)iterator.next();
    134                arraylist.addAll(map.values());
    135            }
    136        }
    137
    138        return arraylist;
    139    }
    140
    141    public Map func_96510_d(String par1Str)
    142    {
    143        Object object = (Map)this.field_96544_c.get(par1Str);
    144
    145        if (object == null)
    146        {
    147            object = new HashMap();
    148        }
    149
    150        return (Map)object;
    151    }
    152
    153    public void func_96519_k(ScoreObjective par1ScoreObjective)
    154    {
    155        this.scoreObjectives.remove(par1ScoreObjective.getName());
    156
    157        for (int i = 0; i < 3; ++i)
    158        {
    159            if (this.func_96539_a(i) == par1ScoreObjective)
    160            {
    161                this.func_96530_a(i, (ScoreObjective)null);
    162            }
    163        }
    164
    165        List list = (List)this.field_96543_b.get(par1ScoreObjective.getCriteria());
    166
    167        if (list != null)
    168        {
    169            list.remove(par1ScoreObjective);
    170        }
    171
    172        Iterator iterator = this.field_96544_c.values().iterator();
    173
    174        while (iterator.hasNext())
    175        {
    176            Map map = (Map)iterator.next();
    177            map.remove(par1ScoreObjective);
    178        }
    179
    180        this.func_96533_c(par1ScoreObjective);
    181    }
    182
    183    public void func_96530_a(int par1, ScoreObjective par2ScoreObjective)
    184    {
    185        this.field_96541_d[par1] = par2ScoreObjective;
    186    }
    187
    188    public ScoreObjective func_96539_a(int par1)
    189    {
    190        return this.field_96541_d[par1];
    191    }
    192
    193    public ScorePlayerTeam func_96508_e(String par1Str)
    194    {
    195        return (ScorePlayerTeam)this.field_96542_e.get(par1Str);
    196    }
    197
    198    public ScorePlayerTeam func_96527_f(String par1Str)
    199    {
    200        ScorePlayerTeam scoreplayerteam = this.func_96508_e(par1Str);
    201
    202        if (scoreplayerteam != null)
    203        {
    204            throw new IllegalArgumentException("An objective with the name \'" + par1Str + "\' already exists!");
    205        }
    206        else
    207        {
    208            scoreplayerteam = new ScorePlayerTeam(this, par1Str);
    209            this.field_96542_e.put(par1Str, scoreplayerteam);
    210            this.func_96523_a(scoreplayerteam);
    211            return scoreplayerteam;
    212        }
    213    }
    214
    215    public void func_96511_d(ScorePlayerTeam par1ScorePlayerTeam)
    216    {
    217        this.field_96542_e.remove(par1ScorePlayerTeam.func_96661_b());
    218        Iterator iterator = par1ScorePlayerTeam.func_96670_d().iterator();
    219
    220        while (iterator.hasNext())
    221        {
    222            String s = (String)iterator.next();
    223            this.field_96540_f.remove(s);
    224        }
    225
    226        this.func_96513_c(par1ScorePlayerTeam);
    227    }
    228
    229    public void func_96521_a(String par1Str, ScorePlayerTeam par2ScorePlayerTeam)
    230    {
    231        if (this.func_96509_i(par1Str) != null)
    232        {
    233            this.func_96524_g(par1Str);
    234        }
    235
    236        this.field_96540_f.put(par1Str, par2ScorePlayerTeam);
    237        par2ScorePlayerTeam.func_96670_d().add(par1Str);
    238    }
    239
    240    public boolean func_96524_g(String par1Str)
    241    {
    242        ScorePlayerTeam scoreplayerteam = this.func_96509_i(par1Str);
    243
    244        if (scoreplayerteam != null)
    245        {
    246            this.func_96512_b(par1Str, scoreplayerteam);
    247            return true;
    248        }
    249        else
    250        {
    251            return false;
    252        }
    253    }
    254
    255    public void func_96512_b(String par1Str, ScorePlayerTeam par2ScorePlayerTeam)
    256    {
    257        if (this.func_96509_i(par1Str) != par2ScorePlayerTeam)
    258        {
    259            throw new IllegalStateException("Player is either on another team or not on any team. Cannot remove from team \'" + par2ScorePlayerTeam.func_96661_b() + "\'.");
    260        }
    261        else
    262        {
    263            this.field_96540_f.remove(par1Str);
    264            par2ScorePlayerTeam.func_96670_d().remove(par1Str);
    265        }
    266    }
    267
    268    public Collection func_96531_f()
    269    {
    270        return this.field_96542_e.keySet();
    271    }
    272
    273    public Collection func_96525_g()
    274    {
    275        return this.field_96542_e.values();
    276    }
    277
    278    public ScorePlayerTeam func_96509_i(String par1Str)
    279    {
    280        return (ScorePlayerTeam)this.field_96540_f.get(par1Str);
    281    }
    282
    283    public void func_96522_a(ScoreObjective par1ScoreObjective) {}
    284
    285    public void func_96532_b(ScoreObjective par1ScoreObjective) {}
    286
    287    public void func_96533_c(ScoreObjective par1ScoreObjective) {}
    288
    289    public void func_96536_a(Score par1Score) {}
    290
    291    public void func_96516_a(String par1Str) {}
    292
    293    public void func_96523_a(ScorePlayerTeam par1ScorePlayerTeam) {}
    294
    295    public void func_96538_b(ScorePlayerTeam par1ScorePlayerTeam) {}
    296
    297    public void func_96513_c(ScorePlayerTeam par1ScorePlayerTeam) {}
    298
    299    /**
    300     * Returns 'list' for 0, 'sidebar' for 1, 'belowName for 2, otherwise null.
    301     */
    302    public static String getObjectiveDisplaySlot(int par0)
    303    {
    304        switch (par0)
    305        {
    306            case 0:
    307                return "list";
    308            case 1:
    309                return "sidebar";
    310            case 2:
    311                return "belowName";
    312            default:
    313                return null;
    314        }
    315    }
    316
    317    /**
    318     * Returns 0 for (case-insensitive) 'list', 1 for 'sidebar', 2 for 'belowName', otherwise -1.
    319     */
    320    public static int getObjectiveDisplaySlotNumber(String par0Str)
    321    {
    322        return par0Str.equalsIgnoreCase("list") ? 0 : (par0Str.equalsIgnoreCase("sidebar") ? 1 : (par0Str.equalsIgnoreCase("belowName") ? 2 : -1));
    323    }
    324}