    001package net.minecraft.scoreboard;
    002
    003import java.util.ArrayList;
    004import java.util.Arrays;
    005import java.util.Collection;
    006import java.util.HashSet;
    007import java.util.Iterator;
    008import java.util.List;
    009import java.util.Map;
    010import net.minecraft.command.CommandBase;
    011import net.minecraft.command.CommandException;
    012import net.minecraft.command.ICommandSender;
    013import net.minecraft.command.SyntaxErrorException;
    014import net.minecraft.command.WrongUsageException;
    015import net.minecraft.entity.player.EntityPlayer;
    016import net.minecraft.server.MinecraftServer;
    017import net.minecraft.util.EnumChatFormatting;
    018
    019public class ServerCommandScoreboard extends CommandBase
    020{
    021    public String getCommandName()
    022    {
    023        return "scoreboard";
    024    }
    025
    026    /**
    027     * Return the required permission level for this command.
    028     */
    029    public int getRequiredPermissionLevel()
    030    {
    031        return 2;
    032    }
    033
    034    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    035    {
    036        if (par2ArrayOfStr.length >= 1)
    037        {
    038            if (par2ArrayOfStr[0].equalsIgnoreCase("objectives"))
    039            {
    040                if (par2ArrayOfStr.length == 1)
    041                {
    042                    throw new WrongUsageException("commands.scoreboard.objectives.usage", new Object[0]);
    043                }
    044
    045                if (par2ArrayOfStr[1].equalsIgnoreCase("list"))
    046                {
    047                    this.getObjectivesList(par1ICommandSender);
    048                }
    049                else if (par2ArrayOfStr[1].equalsIgnoreCase("add"))
    050                {
    051                    if (par2ArrayOfStr.length < 4)
    052                    {
    053                        throw new WrongUsageException("commands.scoreboard.objectives.add.usage", new Object[0]);
    054                    }
    055
    056                    this.addObjective(par1ICommandSender, par2ArrayOfStr, 2);
    057                }
    058                else if (par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    059                {
    060                    if (par2ArrayOfStr.length != 3)
    061                    {
    062                        throw new WrongUsageException("commands.scoreboard.objectives.remove.usage", new Object[0]);
    063                    }
    064
    065                    this.removeObjective(par1ICommandSender, par2ArrayOfStr[2]);
    066                }
    067                else
    068                {
    069                    if (!par2ArrayOfStr[1].equalsIgnoreCase("setdisplay"))
    070                    {
    071                        throw new WrongUsageException("commands.scoreboard.objectives.usage", new Object[0]);
    072                    }
    073
    074                    if (par2ArrayOfStr.length != 3 && par2ArrayOfStr.length != 4)
    075                    {
    076                        throw new WrongUsageException("commands.scoreboard.objectives.setdisplay.usage", new Object[0]);
    077                    }
    078
    079                    this.setObjectivesDisplay(par1ICommandSender, par2ArrayOfStr, 2);
    080                }
    081
    082                return;
    083            }
    084
    085            if (par2ArrayOfStr[0].equalsIgnoreCase("players"))
    086            {
    087                if (par2ArrayOfStr.length == 1)
    088                {
    089                    throw new WrongUsageException("commands.scoreboard.players.usage", new Object[0]);
    090                }
    091
    092                if (par2ArrayOfStr[1].equalsIgnoreCase("list"))
    093                {
    094                    if (par2ArrayOfStr.length > 3)
    095                    {
    096                        throw new WrongUsageException("commands.scoreboard.players.list.usage", new Object[0]);
    097                    }
    098
    099                    this.listPlayers(par1ICommandSender, par2ArrayOfStr, 2);
    100                }
    101                else if (par2ArrayOfStr[1].equalsIgnoreCase("add"))
    102                {
    103                    if (par2ArrayOfStr.length != 5)
    104                    {
    105                        throw new WrongUsageException("commands.scoreboard.players.add.usage", new Object[0]);
    106                    }
    107
    108                    this.setPlayerScore(par1ICommandSender, par2ArrayOfStr, 2);
    109                }
    110                else if (par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    111                {
    112                    if (par2ArrayOfStr.length != 5)
    113                    {
    114                        throw new WrongUsageException("commands.scoreboard.players.remove.usage", new Object[0]);
    115                    }
    116
    117                    this.setPlayerScore(par1ICommandSender, par2ArrayOfStr, 2);
    118                }
    119                else if (par2ArrayOfStr[1].equalsIgnoreCase("set"))
    120                {
    121                    if (par2ArrayOfStr.length != 5)
    122                    {
    123                        throw new WrongUsageException("commands.scoreboard.players.set.usage", new Object[0]);
    124                    }
    125
    126                    this.setPlayerScore(par1ICommandSender, par2ArrayOfStr, 2);
    127                }
    128                else
    129                {
    130                    if (!par2ArrayOfStr[1].equalsIgnoreCase("reset"))
    131                    {
    132                        throw new WrongUsageException("commands.scoreboard.players.usage", new Object[0]);
    133                    }
    134
    135                    if (par2ArrayOfStr.length != 3)
    136                    {
    137                        throw new WrongUsageException("commands.scoreboard.players.reset.usage", new Object[0]);
    138                    }
    139
    140                    this.resetPlayerScore(par1ICommandSender, par2ArrayOfStr, 2);
    141                }
    142
    143                return;
    144            }
    145
    146            if (par2ArrayOfStr[0].equalsIgnoreCase("teams"))
    147            {
    148                if (par2ArrayOfStr.length == 1)
    149                {
    150                    throw new WrongUsageException("commands.scoreboard.teams.usage", new Object[0]);
    151                }
    152
    153                if (par2ArrayOfStr[1].equalsIgnoreCase("list"))
    154                {
    155                    if (par2ArrayOfStr.length > 3)
    156                    {
    157                        throw new WrongUsageException("commands.scoreboard.teams.list.usage", new Object[0]);
    158                    }
    159
    160                    this.getTeamList(par1ICommandSender, par2ArrayOfStr, 2);
    161                }
    162                else if (par2ArrayOfStr[1].equalsIgnoreCase("add"))
    163                {
    164                    if (par2ArrayOfStr.length < 3)
    165                    {
    166                        throw new WrongUsageException("commands.scoreboard.teams.add.usage", new Object[0]);
    167                    }
    168
    169                    this.addTeam(par1ICommandSender, par2ArrayOfStr, 2);
    170                }
    171                else if (par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    172                {
    173                    if (par2ArrayOfStr.length != 3)
    174                    {
    175                        throw new WrongUsageException("commands.scoreboard.teams.remove.usage", new Object[0]);
    176                    }
    177
    178                    this.removeTeam(par1ICommandSender, par2ArrayOfStr, 2);
    179                }
    180                else if (par2ArrayOfStr[1].equalsIgnoreCase("empty"))
    181                {
    182                    if (par2ArrayOfStr.length != 3)
    183                    {
    184                        throw new WrongUsageException("commands.scoreboard.teams.empty.usage", new Object[0]);
    185                    }
    186
    187                    this.emptyTeam(par1ICommandSender, par2ArrayOfStr, 2);
    188                }
    189                else if (par2ArrayOfStr[1].equalsIgnoreCase("join"))
    190                {
    191                    if (par2ArrayOfStr.length < 4 && (par2ArrayOfStr.length != 3 || !(par1ICommandSender instanceof EntityPlayer)))
    192                    {
    193                        throw new WrongUsageException("commands.scoreboard.teams.join.usage", new Object[0]);
    194                    }
    195
    196                    this.joinTeam(par1ICommandSender, par2ArrayOfStr, 2);
    197                }
    198                else if (par2ArrayOfStr[1].equalsIgnoreCase("leave"))
    199                {
    200                    if (par2ArrayOfStr.length < 3 && !(par1ICommandSender instanceof EntityPlayer))
    201                    {
    202                        throw new WrongUsageException("commands.scoreboard.teams.leave.usage", new Object[0]);
    203                    }
    204
    205                    this.leaveTeam(par1ICommandSender, par2ArrayOfStr, 2);
    206                }
    207                else
    208                {
    209                    if (!par2ArrayOfStr[1].equalsIgnoreCase("option"))
    210                    {
    211                        throw new WrongUsageException("commands.scoreboard.teams.usage", new Object[0]);
    212                    }
    213
    214                    if (par2ArrayOfStr.length != 4 && par2ArrayOfStr.length != 5)
    215                    {
    216                        throw new WrongUsageException("commands.scoreboard.teams.option.usage", new Object[0]);
    217                    }
    218
    219                    this.setTeamOption(par1ICommandSender, par2ArrayOfStr, 2);
    220                }
    221
    222                return;
    223            }
    224        }
    225
    226        throw new WrongUsageException("commands.scoreboard.usage", new Object[0]);
    227    }
    228
    229    protected Scoreboard getScoreboardFromWorldServer()
    230    {
    231        return MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
    232    }
    233
    234    /**
    235     * User-safe version of Scoreboard.getObjective, does checks against the objective not being found and whether it's
    236     * read-only or not. If true, the second parameter makes the function throw an exception if the objective is read-
    237     * only.
    238     */
    239    protected ScoreObjective getScoreObjective(String par1Str, boolean par2)
    240    {
    241        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    242        ScoreObjective scoreobjective = scoreboard.getObjective(par1Str);
    243
    244        if (scoreobjective == null)
    245        {
    246            throw new CommandException("commands.scoreboard.objectiveNotFound", new Object[] {par1Str});
    247        }
    248        else if (par2 && scoreobjective.getCriteria().isReadOnly())
    249        {
    250            throw new CommandException("commands.scoreboard.objectiveReadOnly", new Object[] {par1Str});
    251        }
    252        else
    253        {
    254            return scoreobjective;
    255        }
    256    }
    257
    258    /**
    259     * Returns the ScorePlayerTeam for the given team name.
    260     */
    261    protected ScorePlayerTeam getTeam(String par1Str)
    262    {
    263        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    264        ScorePlayerTeam scoreplayerteam = scoreboard.func_96508_e(par1Str);
    265
    266        if (scoreplayerteam == null)
    267        {
    268            throw new CommandException("commands.scoreboard.teamNotFound", new Object[] {par1Str});
    269        }
    270        else
    271        {
    272            return scoreplayerteam;
    273        }
    274    }
    275
    276    /**
    277     * Handler for the 'scoreboard objectives add' command.
    278     */
    279    protected void addObjective(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    280    {
    281        String s = par2ArrayOfStr[par3++];
    282        String s1 = par2ArrayOfStr[par3++];
    283        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    284        ScoreObjectiveCriteria scoreobjectivecriteria = (ScoreObjectiveCriteria)ScoreObjectiveCriteria.field_96643_a.get(s1);
    285
    286        if (scoreobjectivecriteria == null)
    287        {
    288            String[] astring1 = (String[])ScoreObjectiveCriteria.field_96643_a.keySet().toArray(new String[0]);
    289            throw new WrongUsageException("commands.scoreboard.objectives.add.wrongType", new Object[] {joinNiceString(astring1)});
    290        }
    291        else if (scoreboard.getObjective(s) != null)
    292        {
    293            throw new CommandException("commands.scoreboard.objectives.add.alreadyExists", new Object[] {s});
    294        }
    295        else if (s.length() > 16)
    296        {
    297            throw new SyntaxErrorException("commands.scoreboard.objectives.add.tooLong", new Object[] {s, Integer.valueOf(16)});
    298        }
    299        else
    300        {
    301            ScoreObjective scoreobjective = scoreboard.func_96535_a(s, scoreobjectivecriteria);
    302
    303            if (par2ArrayOfStr.length > par3)
    304            {
    305                String s2 = func_82360_a(par1ICommandSender, par2ArrayOfStr, par3);
    306
    307                if (s2.length() > 32)
    308                {
    309                    throw new SyntaxErrorException("commands.scoreboard.objectives.add.displayTooLong", new Object[] {s2, Integer.valueOf(32)});
    310                }
    311
    312                if (s2.length() > 0)
    313                {
    314                    scoreobjective.setDisplayName(s2);
    315                }
    316            }
    317
    318            notifyAdmins(par1ICommandSender, "commands.scoreboard.objectives.add.success", new Object[] {s});
    319        }
    320    }
    321
    322    /**
    323     * Handler for the 'scoreboard teams add' command.
    324     */
    325    protected void addTeam(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    326    {
    327        String s = par2ArrayOfStr[par3++];
    328        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    329
    330        if (scoreboard.func_96508_e(s) != null)
    331        {
    332            throw new CommandException("commands.scoreboard.teams.add.alreadyExists", new Object[] {s});
    333        }
    334        else if (s.length() > 16)
    335        {
    336            throw new SyntaxErrorException("commands.scoreboard.teams.add.tooLong", new Object[] {s, Integer.valueOf(16)});
    337        }
    338        else
    339        {
    340            ScorePlayerTeam scoreplayerteam = scoreboard.func_96527_f(s);
    341
    342            if (par2ArrayOfStr.length > par3)
    343            {
    344                String s1 = func_82360_a(par1ICommandSender, par2ArrayOfStr, par3);
    345
    346                if (s1.length() > 32)
    347                {
    348                    throw new SyntaxErrorException("commands.scoreboard.teams.add.displayTooLong", new Object[] {s1, Integer.valueOf(32)});
    349                }
    350
    351                if (s1.length() > 0)
    352                {
    353                    scoreplayerteam.func_96664_a(s1);
    354                }
    355            }
    356
    357            notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.add.success", new Object[] {s});
    358        }
    359    }
    360
    361    /**
    362     * Handler for the 'scoreboard teams option' command.
    363     */
    364    protected void setTeamOption(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    365    {
    366        ScorePlayerTeam scoreplayerteam = this.getTeam(par2ArrayOfStr[par3++]);
    367        String s = par2ArrayOfStr[par3++].toLowerCase();
    368
    369        if (!s.equalsIgnoreCase("color") && !s.equalsIgnoreCase("friendlyfire") && !s.equalsIgnoreCase("seeFriendlyInvisibles"))
    370        {
    371            throw new WrongUsageException("commands.scoreboard.teams.option.usage", new Object[0]);
    372        }
    373        else if (par2ArrayOfStr.length == 4)
    374        {
    375            if (s.equalsIgnoreCase("color"))
    376            {
    377                throw new WrongUsageException("commands.scoreboard.teams.option.noValue", new Object[] {s, func_96333_a(EnumChatFormatting.func_96296_a(true, false))});
    378            }
    379            else if (!s.equalsIgnoreCase("friendlyfire") && !s.equalsIgnoreCase("seeFriendlyInvisibles"))
    380            {
    381                throw new WrongUsageException("commands.scoreboard.teams.option.usage", new Object[0]);
    382            }
    383            else
    384            {
    385                throw new WrongUsageException("commands.scoreboard.teams.option.noValue", new Object[] {s, func_96333_a(Arrays.asList(new String[]{"true", "false"}))});
    386            }
    387        }
    388        else
    389        {
    390            String s1 = par2ArrayOfStr[par3++];
    391
    392            if (s.equalsIgnoreCase("color"))
    393            {
    394                EnumChatFormatting enumchatformatting = EnumChatFormatting.func_96300_b(s1);
    395
    396                if (s1 == null)
    397                {
    398                    throw new WrongUsageException("commands.scoreboard.teams.option.noValue", new Object[] {s, func_96333_a(EnumChatFormatting.func_96296_a(true, false))});
    399                }
    400
    401                scoreplayerteam.func_96666_b(enumchatformatting.toString());
    402                scoreplayerteam.func_96662_c(EnumChatFormatting.RESET.toString());
    403            }
    404            else if (s.equalsIgnoreCase("friendlyfire"))
    405            {
    406                if (!s1.equalsIgnoreCase("true") && !s1.equalsIgnoreCase("false"))
    407                {
    408                    throw new WrongUsageException("commands.scoreboard.teams.option.noValue", new Object[] {s, func_96333_a(Arrays.asList(new String[]{"true", "false"}))});
    409                }
    410
    411                scoreplayerteam.func_96660_a(s1.equalsIgnoreCase("true"));
    412            }
    413            else if (s.equalsIgnoreCase("seeFriendlyInvisibles"))
    414            {
    415                if (!s1.equalsIgnoreCase("true") && !s1.equalsIgnoreCase("false"))
    416                {
    417                    throw new WrongUsageException("commands.scoreboard.teams.option.noValue", new Object[] {s, func_96333_a(Arrays.asList(new String[]{"true", "false"}))});
    418                }
    419
    420                scoreplayerteam.func_98300_b(s1.equalsIgnoreCase("true"));
    421            }
    422
    423            notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.option.success", new Object[] {s, scoreplayerteam.func_96661_b(), s1});
    424        }
    425    }
    426
    427    /**
    428     * Handler for the 'scoreboard teams remove' command.
    429     */
    430    protected void removeTeam(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    431    {
    432        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    433        ScorePlayerTeam scoreplayerteam = this.getTeam(par2ArrayOfStr[par3++]);
    434        scoreboard.func_96511_d(scoreplayerteam);
    435        notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.remove.success", new Object[] {scoreplayerteam.func_96661_b()});
    436    }
    437
    438    /**
    439     * Handler for the 'scoreboard teams list' command.
    440     */
    441    protected void getTeamList(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    442    {
    443        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    444
    445        if (par2ArrayOfStr.length > par3)
    446        {
    447            ScorePlayerTeam scoreplayerteam = this.getTeam(par2ArrayOfStr[par3++]);
    448            Collection collection = scoreplayerteam.func_96670_d();
    449
    450            if (collection.size() <= 0)
    451            {
    452                throw new CommandException("commands.scoreboard.teams.list.player.empty", new Object[] {scoreplayerteam.func_96661_b()});
    453            }
    454
    455            par1ICommandSender.sendChatToPlayer(EnumChatFormatting.DARK_GREEN + par1ICommandSender.translateString("commands.scoreboard.teams.list.player.count", new Object[] {Integer.valueOf(collection.size()), scoreplayerteam.func_96661_b()}));
    456            par1ICommandSender.sendChatToPlayer(joinNiceString(collection.toArray()));
    457        }
    458        else
    459        {
    460            Collection collection1 = scoreboard.func_96525_g();
    461
    462            if (collection1.size() <= 0)
    463            {
    464                throw new CommandException("commands.scoreboard.teams.list.empty", new Object[0]);
    465            }
    466
    467            par1ICommandSender.sendChatToPlayer(EnumChatFormatting.DARK_GREEN + par1ICommandSender.translateString("commands.scoreboard.teams.list.count", new Object[] {Integer.valueOf(collection1.size())}));
    468            Iterator iterator = collection1.iterator();
    469
    470            while (iterator.hasNext())
    471            {
    472                ScorePlayerTeam scoreplayerteam1 = (ScorePlayerTeam)iterator.next();
    473                par1ICommandSender.sendChatToPlayer(par1ICommandSender.translateString("commands.scoreboard.teams.list.entry", new Object[] {scoreplayerteam1.func_96661_b(), scoreplayerteam1.func_96669_c(), Integer.valueOf(scoreplayerteam1.func_96670_d().size())}));
    474            }
    475        }
    476    }
    477
    478    /**
    479     * Handler for the 'scoreboard teams join' command.
    480     */
    481    protected void joinTeam(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    482    {
    483        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    484        ScorePlayerTeam scoreplayerteam = scoreboard.func_96508_e(par2ArrayOfStr[par3++]);
    485        HashSet hashset = new HashSet();
    486        String s;
    487
    488        if (par1ICommandSender instanceof EntityPlayer && par3 == par2ArrayOfStr.length)
    489        {
    490            s = getCommandSenderAsPlayer(par1ICommandSender).getEntityName();
    491            scoreboard.func_96521_a(s, scoreplayerteam);
    492            hashset.add(s);
    493        }
    494        else
    495        {
    496            while (par3 < par2ArrayOfStr.length)
    497            {
    498                s = func_96332_d(par1ICommandSender, par2ArrayOfStr[par3++]);
    499                scoreboard.func_96521_a(s, scoreplayerteam);
    500                hashset.add(s);
    501            }
    502        }
    503
    504        if (!hashset.isEmpty())
    505        {
    506            notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.join.success", new Object[] {Integer.valueOf(hashset.size()), scoreplayerteam.func_96661_b(), joinNiceString(hashset.toArray(new String[0]))});
    507        }
    508    }
    509
    510    /**
    511     * Handler for the 'scoreboard teams leave' command.
    512     */
    513    protected void leaveTeam(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    514    {
    515        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    516        HashSet hashset = new HashSet();
    517        HashSet hashset1 = new HashSet();
    518        String s;
    519
    520        if (par1ICommandSender instanceof EntityPlayer && par3 == par2ArrayOfStr.length)
    521        {
    522            s = getCommandSenderAsPlayer(par1ICommandSender).getEntityName();
    523
    524            if (scoreboard.func_96524_g(s))
    525            {
    526                hashset.add(s);
    527            }
    528            else
    529            {
    530                hashset1.add(s);
    531            }
    532        }
    533        else
    534        {
    535            while (par3 < par2ArrayOfStr.length)
    536            {
    537                s = func_96332_d(par1ICommandSender, par2ArrayOfStr[par3++]);
    538
    539                if (scoreboard.func_96524_g(s))
    540                {
    541                    hashset.add(s);
    542                }
    543                else
    544                {
    545                    hashset1.add(s);
    546                }
    547            }
    548        }
    549
    550        if (!hashset.isEmpty())
    551        {
    552            notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.leave.success", new Object[] {Integer.valueOf(hashset.size()), joinNiceString(hashset.toArray(new String[0]))});
    553        }
    554
    555        if (!hashset1.isEmpty())
    556        {
    557            throw new CommandException("commands.scoreboard.teams.leave.failure", new Object[] {Integer.valueOf(hashset1.size()), joinNiceString(hashset1.toArray(new String[0]))});
    558        }
    559    }
    560
    561    /**
    562     * Handler for the 'scoreboard teams empty' command.
    563     */
    564    protected void emptyTeam(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    565    {
    566        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    567        ScorePlayerTeam scoreplayerteam = this.getTeam(par2ArrayOfStr[par3++]);
    568        ArrayList arraylist = new ArrayList(scoreplayerteam.func_96670_d());
    569
    570        if (arraylist.isEmpty())
    571        {
    572            throw new CommandException("commands.scoreboard.teams.empty.alreadyEmpty", new Object[] {scoreplayerteam.func_96661_b()});
    573        }
    574        else
    575        {
    576            Iterator iterator = arraylist.iterator();
    577
    578            while (iterator.hasNext())
    579            {
    580                String s = (String)iterator.next();
    581                scoreboard.func_96512_b(s, scoreplayerteam);
    582            }
    583
    584            notifyAdmins(par1ICommandSender, "commands.scoreboard.teams.empty.success", new Object[] {Integer.valueOf(arraylist.size()), scoreplayerteam.func_96661_b()});
    585        }
    586    }
    587
    588    /**
    589     * Handler for the 'scoreboard objectives remove' command.
    590     */
    591    protected void removeObjective(ICommandSender par1ICommandSender, String par2Str)
    592    {
    593        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    594        ScoreObjective scoreobjective = this.getScoreObjective(par2Str, false);
    595        scoreboard.func_96519_k(scoreobjective);
    596        notifyAdmins(par1ICommandSender, "commands.scoreboard.objectives.remove.success", new Object[] {par2Str});
    597    }
    598
    599    /**
    600     * Handler for the 'scoreboard objectives list' command.
    601     */
    602    protected void getObjectivesList(ICommandSender par1ICommandSender)
    603    {
    604        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    605        Collection collection = scoreboard.getScoreObjectives();
    606
    607        if (collection.size() <= 0)
    608        {
    609            throw new CommandException("commands.scoreboard.objectives.list.empty", new Object[0]);
    610        }
    611        else
    612        {
    613            par1ICommandSender.sendChatToPlayer(EnumChatFormatting.DARK_GREEN + par1ICommandSender.translateString("commands.scoreboard.objectives.list.count", new Object[] {Integer.valueOf(collection.size())}));
    614            Iterator iterator = collection.iterator();
    615
    616            while (iterator.hasNext())
    617            {
    618                ScoreObjective scoreobjective = (ScoreObjective)iterator.next();
    619                par1ICommandSender.sendChatToPlayer(par1ICommandSender.translateString("commands.scoreboard.objectives.list.entry", new Object[] {scoreobjective.getName(), scoreobjective.getDisplayName(), scoreobjective.getCriteria().func_96636_a()}));
    620            }
    621        }
    622    }
    623
    624    /**
    625     * Handler for the 'scoreboard objectives setdisplay' command.
    626     */
    627    protected void setObjectivesDisplay(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    628    {
    629        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    630        String s = par2ArrayOfStr[par3++];
    631        int j = Scoreboard.getObjectiveDisplaySlotNumber(s);
    632        ScoreObjective scoreobjective = null;
    633
    634        if (par2ArrayOfStr.length == 4)
    635        {
    636            scoreobjective = this.getScoreObjective(par2ArrayOfStr[par3++], false);
    637        }
    638
    639        if (j < 0)
    640        {
    641            throw new CommandException("commands.scoreboard.objectives.setdisplay.invalidSlot", new Object[] {s});
    642        }
    643        else
    644        {
    645            scoreboard.func_96530_a(j, scoreobjective);
    646
    647            if (scoreobjective != null)
    648            {
    649                notifyAdmins(par1ICommandSender, "commands.scoreboard.objectives.setdisplay.successSet", new Object[] {Scoreboard.getObjectiveDisplaySlot(j), scoreobjective.getName()});
    650            }
    651            else
    652            {
    653                notifyAdmins(par1ICommandSender, "commands.scoreboard.objectives.setdisplay.successCleared", new Object[] {Scoreboard.getObjectiveDisplaySlot(j)});
    654            }
    655        }
    656    }
    657
    658    /**
    659     * Handler for the 'scoreboard players list' command.
    660     */
    661    protected void listPlayers(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    662    {
    663        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    664
    665        if (par2ArrayOfStr.length > par3)
    666        {
    667            String s = func_96332_d(par1ICommandSender, par2ArrayOfStr[par3++]);
    668            Map map = scoreboard.func_96510_d(s);
    669
    670            if (map.size() <= 0)
    671            {
    672                throw new CommandException("commands.scoreboard.players.list.player.empty", new Object[] {s});
    673            }
    674
    675            par1ICommandSender.sendChatToPlayer(EnumChatFormatting.DARK_GREEN + par1ICommandSender.translateString("commands.scoreboard.players.list.player.count", new Object[] {Integer.valueOf(map.size()), s}));
    676            Iterator iterator = map.values().iterator();
    677
    678            while (iterator.hasNext())
    679            {
    680                Score score = (Score)iterator.next();
    681                par1ICommandSender.sendChatToPlayer(par1ICommandSender.translateString("commands.scoreboard.players.list.player.entry", new Object[] {Integer.valueOf(score.func_96652_c()), score.func_96645_d().getDisplayName(), score.func_96645_d().getName()}));
    682            }
    683        }
    684        else
    685        {
    686            Collection collection = scoreboard.getObjectiveNames();
    687
    688            if (collection.size() <= 0)
    689            {
    690                throw new CommandException("commands.scoreboard.players.list.empty", new Object[0]);
    691            }
    692
    693            par1ICommandSender.sendChatToPlayer(EnumChatFormatting.DARK_GREEN + par1ICommandSender.translateString("commands.scoreboard.players.list.count", new Object[] {Integer.valueOf(collection.size())}));
    694            par1ICommandSender.sendChatToPlayer(joinNiceString(collection.toArray()));
    695        }
    696    }
    697
    698    /**
    699     * Handler for the 'scoreboard players [add|remove|set]' commands.
    700     */
    701    protected void setPlayerScore(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    702    {
    703        String s = par2ArrayOfStr[par3 - 1];
    704        String s1 = func_96332_d(par1ICommandSender, par2ArrayOfStr[par3++]);
    705        ScoreObjective scoreobjective = this.getScoreObjective(par2ArrayOfStr[par3++], true);
    706        int j = s.equalsIgnoreCase("set") ? parseInt(par1ICommandSender, par2ArrayOfStr[par3++]) : parseIntWithMin(par1ICommandSender, par2ArrayOfStr[par3++], 1);
    707        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    708        Score score = scoreboard.func_96529_a(s1, scoreobjective);
    709
    710        if (s.equalsIgnoreCase("set"))
    711        {
    712            score.func_96647_c(j);
    713        }
    714        else if (s.equalsIgnoreCase("add"))
    715        {
    716            score.func_96649_a(j);
    717        }
    718        else
    719        {
    720            score.func_96646_b(j);
    721        }
    722
    723        notifyAdmins(par1ICommandSender, "commands.scoreboard.players.set.success", new Object[] {scoreobjective.getName(), s1, Integer.valueOf(score.func_96652_c())});
    724    }
    725
    726    /**
    727     * Handler for the 'scoreboard players reset' command.
    728     */
    729    protected void resetPlayerScore(ICommandSender par1ICommandSender, String[] par2ArrayOfStr, int par3)
    730    {
    731        Scoreboard scoreboard = this.getScoreboardFromWorldServer();
    732        String s = func_96332_d(par1ICommandSender, par2ArrayOfStr[par3++]);
    733        scoreboard.func_96515_c(s);
    734        notifyAdmins(par1ICommandSender, "commands.scoreboard.players.reset.success", new Object[] {s});
    735    }
    736
    737    /**
    738     * Adds the strings available in this command to the given list of tab completion options.
    739     */
    740    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    741    {
    742        if (par2ArrayOfStr.length == 1)
    743        {
    744            return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"objectives", "players", "teams"});
    745        }
    746        else
    747        {
    748            if (par2ArrayOfStr[0].equalsIgnoreCase("objectives"))
    749            {
    750                if (par2ArrayOfStr.length == 2)
    751                {
    752                    return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"list", "add", "remove", "setdisplay"});
    753                }
    754
    755                if (par2ArrayOfStr[1].equalsIgnoreCase("add"))
    756                {
    757                    if (par2ArrayOfStr.length == 4)
    758                    {
    759                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, ScoreObjectiveCriteria.field_96643_a.keySet());
    760                    }
    761                }
    762                else if (par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    763                {
    764                    if (par2ArrayOfStr.length == 3)
    765                    {
    766                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreObjectivesList(false));
    767                    }
    768                }
    769                else if (par2ArrayOfStr[1].equalsIgnoreCase("setdisplay"))
    770                {
    771                    if (par2ArrayOfStr.length == 3)
    772                    {
    773                        return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"list", "sidebar", "belowName"});
    774                    }
    775
    776                    if (par2ArrayOfStr.length == 4)
    777                    {
    778                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreObjectivesList(false));
    779                    }
    780                }
    781            }
    782            else if (par2ArrayOfStr[0].equalsIgnoreCase("players"))
    783            {
    784                if (par2ArrayOfStr.length == 2)
    785                {
    786                    return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"set", "add", "remove", "reset", "list"});
    787                }
    788
    789                if (!par2ArrayOfStr[1].equalsIgnoreCase("set") && !par2ArrayOfStr[1].equalsIgnoreCase("add") && !par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    790                {
    791                    if ((par2ArrayOfStr[1].equalsIgnoreCase("reset") || par2ArrayOfStr[1].equalsIgnoreCase("list")) && par2ArrayOfStr.length == 3)
    792                    {
    793                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreboardFromWorldServer().getObjectiveNames());
    794                    }
    795                }
    796                else
    797                {
    798                    if (par2ArrayOfStr.length == 3)
    799                    {
    800                        return getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    801                    }
    802
    803                    if (par2ArrayOfStr.length == 4)
    804                    {
    805                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreObjectivesList(true));
    806                    }
    807                }
    808            }
    809            else if (par2ArrayOfStr[0].equalsIgnoreCase("teams"))
    810            {
    811                if (par2ArrayOfStr.length == 2)
    812                {
    813                    return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"add", "remove", "join", "leave", "empty", "list", "option"});
    814                }
    815
    816                if (par2ArrayOfStr[1].equalsIgnoreCase("join"))
    817                {
    818                    if (par2ArrayOfStr.length == 3)
    819                    {
    820                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreboardFromWorldServer().func_96531_f());
    821                    }
    822
    823                    if (par2ArrayOfStr.length >= 4)
    824                    {
    825                        return getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    826                    }
    827                }
    828                else
    829                {
    830                    if (par2ArrayOfStr[1].equalsIgnoreCase("leave"))
    831                    {
    832                        return getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    833                    }
    834
    835                    if (!par2ArrayOfStr[1].equalsIgnoreCase("empty") && !par2ArrayOfStr[1].equalsIgnoreCase("list") && !par2ArrayOfStr[1].equalsIgnoreCase("remove"))
    836                    {
    837                        if (par2ArrayOfStr[1].equalsIgnoreCase("option"))
    838                        {
    839                            if (par2ArrayOfStr.length == 3)
    840                            {
    841                                return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreboardFromWorldServer().func_96531_f());
    842                            }
    843
    844                            if (par2ArrayOfStr.length == 4)
    845                            {
    846                                return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"color", "friendlyfire", "seeFriendlyInvisibles"});
    847                            }
    848
    849                            if (par2ArrayOfStr.length == 5)
    850                            {
    851                                if (par2ArrayOfStr[3].equalsIgnoreCase("color"))
    852                                {
    853                                    return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, EnumChatFormatting.func_96296_a(true, false));
    854                                }
    855
    856                                if (par2ArrayOfStr[3].equalsIgnoreCase("friendlyfire") || par2ArrayOfStr[3].equalsIgnoreCase("seeFriendlyInvisibles"))
    857                                {
    858                                    return getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"true", "false"});
    859                                }
    860                            }
    861                        }
    862                    }
    863                    else if (par2ArrayOfStr.length == 3)
    864                    {
    865                        return getListOfStringsFromIterableMatchingLastWord(par2ArrayOfStr, this.getScoreboardFromWorldServer().func_96531_f());
    866                    }
    867                }
    868            }
    869
    870            return null;
    871        }
    872    }
    873
    874    /**
    875     * If the parameter is true, does not return read-only entries.
    876     */
    877    protected List getScoreObjectivesList(boolean par1)
    878    {
    879        Collection collection = this.getScoreboardFromWorldServer().getScoreObjectives();
    880        ArrayList arraylist = new ArrayList();
    881        Iterator iterator = collection.iterator();
    882
    883        while (iterator.hasNext())
    884        {
    885            ScoreObjective scoreobjective = (ScoreObjective)iterator.next();
    886
    887            if (!par1 || !scoreobjective.getCriteria().isReadOnly())
    888            {
    889                arraylist.add(scoreobjective.getName());
    890            }
    891        }
    892
    893        return arraylist;
    894    }
    895
    896    /**
    897     * Return whether the specified command parameter index is a username parameter.
    898     */
    899    public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
    900    {
    901        return par1ArrayOfStr[0].equalsIgnoreCase("players") ? par2 == 2 : (!par1ArrayOfStr[0].equalsIgnoreCase("teams") ? false : par2 == 2 || par2 == 3);
    902    }
    903}