CommandMessageRaw .java

net.minecraft.command.server.CommandMessageRaw (class): members: isUsernameIndex, addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage.

net.minecraft.command.serverclass83 linesserverextends CommandBase2.5 KB

API Surface (6)

String getCommandName()
int getRequiredPermissionLevel()
String getCommandUsage(ICommandSender sender)
void processCommand(ICommandSender sender, String[] args)
List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
boolean isUsernameIndex(String[] args, int index)

String literals (3)

"tellraw"
"commands.tellraw.usage"
"commands.tellraw.jsonException"

Full Source

CommandMessageRaw.java83 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command.server;
2
3
import com.google.gson.JsonParseException;
4
import java.util.List;
5
import net.minecraft.command.CommandBase;
6
import net.minecraft.command.CommandException;
7
import net.minecraft.command.ICommandSender;
8
import net.minecraft.command.SyntaxErrorException;
9
import net.minecraft.command.WrongUsageException;
10
import net.minecraft.entity.player.EntityPlayer;
11
import net.minecraft.server.MinecraftServer;
12
import net.minecraft.util.BlockPos;
13
import net.minecraft.util.ChatComponentProcessor;
14
import net.minecraft.util.IChatComponent;
15
import org.apache.commons.lang3.exception.ExceptionUtils;
16
17
public class CommandMessageRaw extends CommandBase
18
{
19
    /**
20
     * Gets the name of the command
21
     */
22
    public String getCommandName()
23
    {
24
        return "tellraw";
25
    }
26
27
    /**
28
     * Return the required permission level for this command.
29
     */
30
    public int getRequiredPermissionLevel()
31
    {
32
        return 2;
33
    }
34
35
    /**
36
     * Gets the usage string for the command.
37
     */
38
    public String getCommandUsage(ICommandSender sender)
39
    {
40
        return "commands.tellraw.usage";
41
    }
42
43
    /**
44
     * Callback when the command is invoked
45
     */
46
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
47
    {
48
        if (args.length < 2)
49
        {
50
            throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
51
        }
52
        else
53
        {
54
            EntityPlayer entityplayer = getPlayer(sender, args[0]);
55
            String s = buildString(args, 1);
56
57
            try
58
            {
59
                IChatComponent ichatcomponent = IChatComponent.Serializer.jsonToComponent(s);
60
                entityplayer.addChatMessage(ChatComponentProcessor.processComponent(sender, ichatcomponent, entityplayer));
61
            }
62
            catch (JsonParseException jsonparseexception)
63
            {
64
                Throwable throwable = ExceptionUtils.getRootCause(jsonparseexception);
65
                throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {throwable == null ? "" : throwable.getMessage()});
66
            }
67
        }
68
    }
69
70
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
71
    {
72
        return args.length == 1 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : null;
73
    }
74
75
    /**
76
     * Return whether the specified command parameter index is a username parameter.
77
     */
78
    public boolean isUsernameIndex(String[] args, int index)
79
    {
80
        return index == 0;
81
    }
82
}
83

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