    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandDifficulty extends CommandBase
    007    {
    008        private static final String[] difficulties = new String[] {"options.difficulty.peaceful", "options.difficulty.easy", "options.difficulty.normal", "options.difficulty.hard"};
    009
    010        public String getCommandName()
    011        {
    012            return "difficulty";
    013        }
    014
    015        /**
    016         * Return the required permission level for this command.
    017         */
    018        public int getRequiredPermissionLevel()
    019        {
    020            return 2;
    021        }
    022
    023        public String getCommandUsage(ICommandSender par1ICommandSender)
    024        {
    025            return par1ICommandSender.translateString("commands.difficulty.usage", new Object[0]);
    026        }
    027
    028        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    029        {
    030            if (par2ArrayOfStr.length > 0)
    031            {
    032                int var3 = this.getDifficultyForName(par1ICommandSender, par2ArrayOfStr[0]);
    033                MinecraftServer.getServer().setDifficultyForAllWorlds(var3);
    034                String var4 = StatCollector.translateToLocal(difficulties[var3]);
    035                notifyAdmins(par1ICommandSender, 1, "commands.difficulty.success", new Object[] {var4});
    036            }
    037            else
    038            {
    039                throw new WrongUsageException("commands.difficulty.usage", new Object[0]);
    040            }
    041        }
    042
    043        /**
    044         * Return the difficulty value for the specified string.
    045         */
    046        protected int getDifficultyForName(ICommandSender par1ICommandSender, String par2Str)
    047        {
    048            return !par2Str.equalsIgnoreCase("peaceful") && !par2Str.equalsIgnoreCase("p") ? (!par2Str.equalsIgnoreCase("easy") && !par2Str.equalsIgnoreCase("e") ? (!par2Str.equalsIgnoreCase("normal") && !par2Str.equalsIgnoreCase("n") ? (!par2Str.equalsIgnoreCase("hard") && !par2Str.equalsIgnoreCase("h") ? parseIntBounded(par1ICommandSender, par2Str, 0, 3) : 3) : 2) : 1) : 0;
    049        }
    050
    051        /**
    052         * Adds the strings available in this command to the given list of tab completion options.
    053         */
    054        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    055        {
    056            return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, new String[] {"peaceful", "easy", "normal", "hard"}): null;
    057        }
    058    }