CommandTitle .java

net.minecraft.command.CommandTitle (class): members: LOGGER, isUsernameIndex, addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage.

net.minecraft.commandclass138 linescommonextends CommandBase5.0 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)

Fields & Constants (1)

LOGGER

String literals (7)

"commands.title.usage"
"subtitle"
"commands.title.usage.title"
"times"
"commands.title.usage.times"
"commands.title.success"
"commands.tellraw.jsonException"

Full Source

CommandTitle.java138 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import com.google.gson.JsonParseException;
4
import java.util.List;
5
import net.minecraft.entity.player.EntityPlayerMP;
6
import net.minecraft.network.play.server.S45PacketTitle;
7
import net.minecraft.server.MinecraftServer;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.ChatComponentProcessor;
10
import net.minecraft.util.IChatComponent;
11
import org.apache.commons.lang3.exception.ExceptionUtils;
12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14
15
public class CommandTitle extends CommandBase
16
{
17
    private static final Logger LOGGER = LogManager.getLogger();
18
19
    /**
20
     * Gets the name of the command
21
     */
22
    public String getCommandName()
23
    {
24
        return "title";
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.title.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.title.usage", new Object[0]);
51
        }
52
        else
53
        {
54
            if (args.length < 3)
55
            {
56
                if ("title".equals(args[1]) || "subtitle".equals(args[1]))
57
                {
58
                    throw new WrongUsageException("commands.title.usage.title", new Object[0]);
59
                }
60
61
                if ("times".equals(args[1]))
62
                {
63
                    throw new WrongUsageException("commands.title.usage.times", new Object[0]);
64
                }
65
            }
66
67
            EntityPlayerMP entityplayermp = getPlayer(sender, args[0]);
68
            S45PacketTitle.Type s45packettitle$type = S45PacketTitle.Type.byName(args[1]);
69
70
            if (s45packettitle$type != S45PacketTitle.Type.CLEAR && s45packettitle$type != S45PacketTitle.Type.RESET)
71
            {
72
                if (s45packettitle$type == S45PacketTitle.Type.TIMES)
73
                {
74
                    if (args.length != 5)
75
                    {
76
                        throw new WrongUsageException("commands.title.usage", new Object[0]);
77
                    }
78
                    else
79
                    {
80
                        int i = parseInt(args[2]);
81
                        int j = parseInt(args[3]);
82
                        int k = parseInt(args[4]);
83
                        S45PacketTitle s45packettitle2 = new S45PacketTitle(i, j, k);
84
                        entityplayermp.playerNetServerHandler.sendPacket(s45packettitle2);
85
                        notifyOperators(sender, this, "commands.title.success", new Object[0]);
86
                    }
87
                }
88
                else if (args.length < 3)
89
                {
90
                    throw new WrongUsageException("commands.title.usage", new Object[0]);
91
                }
92
                else
93
                {
94
                    String s = buildString(args, 2);
95
                    IChatComponent ichatcomponent;
96
97
                    try
98
                    {
99
                        ichatcomponent = IChatComponent.Serializer.jsonToComponent(s);
100
                    }
101
                    catch (JsonParseException jsonparseexception)
102
                    {
103
                        Throwable throwable = ExceptionUtils.getRootCause(jsonparseexception);
104
                        throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {throwable == null ? "" : throwable.getMessage()});
105
                    }
106
107
                    S45PacketTitle s45packettitle1 = new S45PacketTitle(s45packettitle$type, ChatComponentProcessor.processComponent(sender, ichatcomponent, entityplayermp));
108
                    entityplayermp.playerNetServerHandler.sendPacket(s45packettitle1);
109
                    notifyOperators(sender, this, "commands.title.success", new Object[0]);
110
                }
111
            }
112
            else if (args.length != 2)
113
            {
114
                throw new WrongUsageException("commands.title.usage", new Object[0]);
115
            }
116
            else
117
            {
118
                S45PacketTitle s45packettitle = new S45PacketTitle(s45packettitle$type, (IChatComponent)null);
119
                entityplayermp.playerNetServerHandler.sendPacket(s45packettitle);
120
                notifyOperators(sender, this, "commands.title.success", new Object[0]);
121
            }
122
        }
123
    }
124
125
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
126
    {
127
        return args.length == 1 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : (args.length == 2 ? getListOfStringsMatchingLastWord(args, S45PacketTitle.Type.getNames()) : null);
128
    }
129
130
    /**
131
     * Return whether the specified command parameter index is a username parameter.
132
     */
133
    public boolean isUsernameIndex(String[] args, int index)
134
    {
135
        return index == 0;
136
    }
137
}
138

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