CommandMessage .java

net.minecraft.command.server.CommandMessage (class, 91 lines): members: getCommandAliases, isUsernameIndex, addTabCompletionOptions, getCommandUsage.

net.minecraft.command.serverclass91 linesserverextends CommandBase3.1 KB

API Surface (7)

List<String> getCommandAliases()
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 (5)

"tell"
"commands.message.usage"
"commands.message.sameTarget"
"commands.message.display.incoming"
"commands.message.display.outgoing"

Full Source

CommandMessage.java91 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command.server;
2
3
import java.util.Arrays;
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.PlayerNotFoundException;
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.ChatComponentTranslation;
14
import net.minecraft.util.EnumChatFormatting;
15
import net.minecraft.util.IChatComponent;
16
17
public class CommandMessage extends CommandBase
18
{
19
    public List<String> getCommandAliases()
20
    {
21
        return Arrays.<String>asList(new String[] {"w", "msg"});
22
    }
23
24
    /**
25
     * Gets the name of the command
26
     */
27
    public String getCommandName()
28
    {
29
        return "tell";
30
    }
31
32
    /**
33
     * Return the required permission level for this command.
34
     */
35
    public int getRequiredPermissionLevel()
36
    {
37
        return 0;
38
    }
39
40
    /**
41
     * Gets the usage string for the command.
42
     */
43
    public String getCommandUsage(ICommandSender sender)
44
    {
45
        return "commands.message.usage";
46
    }
47
48
    /**
49
     * Callback when the command is invoked
50
     */
51
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
52
    {
53
        if (args.length < 2)
54
        {
55
            throw new WrongUsageException("commands.message.usage", new Object[0]);
56
        }
57
        else
58
        {
59
            EntityPlayer entityplayer = getPlayer(sender, args[0]);
60
61
            if (entityplayer == sender)
62
            {
63
                throw new PlayerNotFoundException("commands.message.sameTarget", new Object[0]);
64
            }
65
            else
66
            {
67
                IChatComponent ichatcomponent = getChatComponentFromNthArg(sender, args, 1, !(sender instanceof EntityPlayer));
68
                ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("commands.message.display.incoming", new Object[] {sender.getDisplayName(), ichatcomponent.createCopy()});
69
                ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("commands.message.display.outgoing", new Object[] {entityplayer.getDisplayName(), ichatcomponent.createCopy()});
70
                chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(Boolean.valueOf(true));
71
                chatcomponenttranslation1.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(Boolean.valueOf(true));
72
                entityplayer.addChatMessage(chatcomponenttranslation);
73
                sender.addChatMessage(chatcomponenttranslation1);
74
            }
75
        }
76
    }
77
78
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
79
    {
80
        return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
81
    }
82
83
    /**
84
     * Return whether the specified command parameter index is a username parameter.
85
     */
86
    public boolean isUsernameIndex(String[] args, int index)
87
    {
88
        return index == 0;
89
    }
90
}
91

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