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