CommandDifficulty .java

net.minecraft.command.CommandDifficulty (class): members: getDifficultyFromCommand, addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage.

net.minecraft.commandclass62 linescommonextends CommandBase2.2 KB

API Surface (6)

String getCommandName()
int getRequiredPermissionLevel()
String getCommandUsage(ICommandSender sender)
void processCommand(ICommandSender sender, String[] args)
EnumDifficulty getDifficultyFromCommand(String p_180531_1_)
List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)

String literals (7)

"difficulty"
"commands.difficulty.usage"
"commands.difficulty.success"
"peaceful"
"easy"
"normal"
"hard"

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CommandDifficulty.java62 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import java.util.List;
4
import net.minecraft.server.MinecraftServer;
5
import net.minecraft.util.BlockPos;
6
import net.minecraft.util.ChatComponentTranslation;
7
import net.minecraft.world.EnumDifficulty;
8
9
public class CommandDifficulty extends CommandBase
10
{
11
    /**
12
     * Gets the name of the command
13
     */
14
    public String getCommandName()
15
    {
16
        return "difficulty";
17
    }
18
19
    /**
20
     * Return the required permission level for this command.
21
     */
22
    public int getRequiredPermissionLevel()
23
    {
24
        return 2;
25
    }
26
27
    /**
28
     * Gets the usage string for the command.
29
     */
30
    public String getCommandUsage(ICommandSender sender)
31
    {
32
        return "commands.difficulty.usage";
33
    }
34
35
    /**
36
     * Callback when the command is invoked
37
     */
38
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
39
    {
40
        if (args.length <= 0)
41
        {
42
            throw new WrongUsageException("commands.difficulty.usage", new Object[0]);
43
        }
44
        else
45
        {
46
            EnumDifficulty enumdifficulty = this.getDifficultyFromCommand(args[0]);
47
            MinecraftServer.getServer().setDifficultyForAllWorlds(enumdifficulty);
48
            notifyOperators(sender, this, "commands.difficulty.success", new Object[] {new ChatComponentTranslation(enumdifficulty.getDifficultyResourceKey(), new Object[0])});
49
        }
50
    }
51
52
    protected EnumDifficulty getDifficultyFromCommand(String p_180531_1_) throws CommandException, NumberInvalidException
53
    {
54
        return !p_180531_1_.equalsIgnoreCase("peaceful") && !p_180531_1_.equalsIgnoreCase("p") ? (!p_180531_1_.equalsIgnoreCase("easy") && !p_180531_1_.equalsIgnoreCase("e") ? (!p_180531_1_.equalsIgnoreCase("normal") && !p_180531_1_.equalsIgnoreCase("n") ? (!p_180531_1_.equalsIgnoreCase("hard") && !p_180531_1_.equalsIgnoreCase("h") ? EnumDifficulty.getDifficultyEnum(parseInt(p_180531_1_, 0, 3)) : EnumDifficulty.HARD) : EnumDifficulty.NORMAL) : EnumDifficulty.EASY) : EnumDifficulty.PEACEFUL;
55
    }
56
57
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
58
    {
59
        return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"peaceful", "easy", "normal", "hard"}): null;
60
    }
61
}
62

Deobfuscated MCP 1.8.9 source of CommandDifficulty from Marcelektro/MavenMCP-1.8.9 (net/minecraft/command/CommandDifficulty.java), stored verbatim.