CommandEntityData .java

net.minecraft.command.CommandEntityData (class): members: isUsernameIndex, getRequiredPermissionLevel, getCommandUsage, getCommandName, processCommand.

net.minecraft.commandclass93 linescommonextends CommandBase2.8 KB

API Surface (5)

String getCommandName()
int getRequiredPermissionLevel()
String getCommandUsage(ICommandSender sender)
void processCommand(ICommandSender sender, String[] args)
boolean isUsernameIndex(String[] args, int index)

String literals (8)

"entitydata"
"commands.entitydata.usage"
"commands.entitydata.noPlayers"
"commands.entitydata.tagError"
"UUIDMost"
"UUIDLeast"
"commands.entitydata.failed"
"commands.entitydata.success"

Code Graph: Dependencies (7)

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

Full Source

CommandEntityData.java93 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.entity.player.EntityPlayer;
5
import net.minecraft.nbt.JsonToNBT;
6
import net.minecraft.nbt.NBTException;
7
import net.minecraft.nbt.NBTTagCompound;
8
9
public class CommandEntityData extends CommandBase
10
{
11
    /**
12
     * Gets the name of the command
13
     */
14
    public String getCommandName()
15
    {
16
        return "entitydata";
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.entitydata.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 < 2)
41
        {
42
            throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
43
        }
44
        else
45
        {
46
            Entity entity = getEntity(sender, args[0]);
47
48
            if (entity instanceof EntityPlayer)
49
            {
50
                throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
51
            }
52
            else
53
            {
54
                NBTTagCompound nbttagcompound = new NBTTagCompound();
55
                entity.writeToNBT(nbttagcompound);
56
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
57
                NBTTagCompound nbttagcompound2;
58
59
                try
60
                {
61
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 1).getUnformattedText());
62
                }
63
                catch (NBTException nbtexception)
64
                {
65
                    throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
66
                }
67
68
                nbttagcompound2.removeTag("UUIDMost");
69
                nbttagcompound2.removeTag("UUIDLeast");
70
                nbttagcompound.merge(nbttagcompound2);
71
72
                if (nbttagcompound.equals(nbttagcompound1))
73
                {
74
                    throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
75
                }
76
                else
77
                {
78
                    entity.readFromNBT(nbttagcompound);
79
                    notifyOperators(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
80
                }
81
            }
82
        }
83
    }
84
85
    /**
86
     * Return whether the specified command parameter index is a username parameter.
87
     */
88
    public boolean isUsernameIndex(String[] args, int index)
89
    {
90
        return index == 0;
91
    }
92
}
93

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