CommandExecuteAt .java

net.minecraft.command.CommandExecuteAt (class, 152 lines): members: isUsernameIndex, addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage.

net.minecraft.commandclass152 linescommonextends CommandBase5.4 KB

API Surface (16)

String getCommandName()
int getRequiredPermissionLevel()
String getCommandUsage(ICommandSender sender)
void processCommand(final ICommandSender sender, String[] args)
String getName()
IChatComponent getDisplayName()
void addChatMessage(IChatComponent component)
boolean canCommandSenderUseCommand(int permLevel, String commandName)
BlockPos getPosition()
Vec3 getPositionVector()
World getEntityWorld()
Entity getCommandSenderEntity()
boolean sendCommandFeedback()
void setCommandStat(CommandResultStats.Type type, int amount)
List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
boolean isUsernameIndex(String[] args, int index)

String literals (6)

"execute"
"commands.execute.usage"
"detect"
"commands.execute.failed"
"commandBlockOutput"
"commands.execute.allInvocationsFailed"

Full Source

CommandExecuteAt.java152 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import java.util.List;
4
import net.minecraft.block.Block;
5
import net.minecraft.block.state.IBlockState;
6
import net.minecraft.entity.Entity;
7
import net.minecraft.server.MinecraftServer;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.IChatComponent;
10
import net.minecraft.util.Vec3;
11
import net.minecraft.world.World;
12
13
public class CommandExecuteAt extends CommandBase
14
{
15
    /**
16
     * Gets the name of the command
17
     */
18
    public String getCommandName()
19
    {
20
        return "execute";
21
    }
22
23
    /**
24
     * Return the required permission level for this command.
25
     */
26
    public int getRequiredPermissionLevel()
27
    {
28
        return 2;
29
    }
30
31
    /**
32
     * Gets the usage string for the command.
33
     */
34
    public String getCommandUsage(ICommandSender sender)
35
    {
36
        return "commands.execute.usage";
37
    }
38
39
    /**
40
     * Callback when the command is invoked
41
     */
42
    public void processCommand(final ICommandSender sender, String[] args) throws CommandException
43
    {
44
        if (args.length < 5)
45
        {
46
            throw new WrongUsageException("commands.execute.usage", new Object[0]);
47
        }
48
        else
49
        {
50
            final Entity entity = getEntity(sender, args[0], Entity.class);
51
            final double d0 = parseDouble(entity.posX, args[1], false);
52
            final double d1 = parseDouble(entity.posY, args[2], false);
53
            final double d2 = parseDouble(entity.posZ, args[3], false);
54
            final BlockPos blockpos = new BlockPos(d0, d1, d2);
55
            int i = 4;
56
57
            if ("detect".equals(args[4]) && args.length > 10)
58
            {
59
                World world = entity.getEntityWorld();
60
                double d3 = parseDouble(d0, args[5], false);
61
                double d4 = parseDouble(d1, args[6], false);
62
                double d5 = parseDouble(d2, args[7], false);
63
                Block block = getBlockByText(sender, args[8]);
64
                int k = parseInt(args[9], -1, 15);
65
                BlockPos blockpos1 = new BlockPos(d3, d4, d5);
66
                IBlockState iblockstate = world.getBlockState(blockpos1);
67
68
                if (iblockstate.getBlock() != block || k >= 0 && iblockstate.getBlock().getMetaFromState(iblockstate) != k)
69
                {
70
                    throw new CommandException("commands.execute.failed", new Object[] {"detect", entity.getName()});
71
                }
72
73
                i = 10;
74
            }
75
76
            String s = buildString(args, i);
77
            ICommandSender icommandsender = new ICommandSender()
78
            {
79
                public String getName()
80
                {
81
                    return entity.getName();
82
                }
83
                public IChatComponent getDisplayName()
84
                {
85
                    return entity.getDisplayName();
86
                }
87
                public void addChatMessage(IChatComponent component)
88
                {
89
                    sender.addChatMessage(component);
90
                }
91
                public boolean canCommandSenderUseCommand(int permLevel, String commandName)
92
                {
93
                    return sender.canCommandSenderUseCommand(permLevel, commandName);
94
                }
95
                public BlockPos getPosition()
96
                {
97
                    return blockpos;
98
                }
99
                public Vec3 getPositionVector()
100
                {
101
                    return new Vec3(d0, d1, d2);
102
                }
103
                public World getEntityWorld()
104
                {
105
                    return entity.worldObj;
106
                }
107
                public Entity getCommandSenderEntity()
108
                {
109
                    return entity;
110
                }
111
                public boolean sendCommandFeedback()
112
                {
113
                    MinecraftServer minecraftserver = MinecraftServer.getServer();
114
                    return minecraftserver == null || minecraftserver.worldServers[0].getGameRules().getBoolean("commandBlockOutput");
115
                }
116
                public void setCommandStat(CommandResultStats.Type type, int amount)
117
                {
118
                    entity.setCommandStat(type, amount);
119
                }
120
            };
121
            ICommandManager icommandmanager = MinecraftServer.getServer().getCommandManager();
122
123
            try
124
            {
125
                int j = icommandmanager.executeCommand(icommandsender, s);
126
127
                if (j < 1)
128
                {
129
                    throw new CommandException("commands.execute.allInvocationsFailed", new Object[] {s});
130
                }
131
            }
132
            catch (Throwable var23)
133
            {
134
                throw new CommandException("commands.execute.failed", new Object[] {s, entity.getName()});
135
            }
136
        }
137
    }
138
139
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
140
    {
141
        return args.length == 1 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : (args.length > 1 && args.length <= 4 ? func_175771_a(args, 1, pos) : (args.length > 5 && args.length <= 8 && "detect".equals(args[4]) ? func_175771_a(args, 5, pos) : (args.length == 9 && "detect".equals(args[4]) ? getListOfStringsMatchingLastWord(args, Block.blockRegistry.getKeys()) : null)));
142
    }
143
144
    /**
145
     * Return whether the specified command parameter index is a username parameter.
146
     */
147
    public boolean isUsernameIndex(String[] args, int index)
148
    {
149
        return index == 0;
150
    }
151
}
152

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