CommandEffect .java

net.minecraft.command.CommandEffect (class, 162 lines): members: getAllUsernames, isUsernameIndex, addTabCompletionOptions, getRequiredPermissionLevel.

net.minecraft.commandclass162 linescommonextends CommandBase5.4 KB

API Surface (7)

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

String literals (9)

"effect"
"commands.effect.usage"
"clear"
"commands.effect.failure.notActive.all"
"commands.effect.success.removed.all"
"commands.effect.success"
"commands.effect.success.removed"
"commands.effect.failure.notActive"
"commands.effect.notFound"

Full Source

CommandEffect.java162 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import java.util.List;
4
import net.minecraft.entity.EntityLivingBase;
5
import net.minecraft.potion.Potion;
6
import net.minecraft.potion.PotionEffect;
7
import net.minecraft.server.MinecraftServer;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.ChatComponentTranslation;
10
11
public class CommandEffect extends CommandBase
12
{
13
    /**
14
     * Gets the name of the command
15
     */
16
    public String getCommandName()
17
    {
18
        return "effect";
19
    }
20
21
    /**
22
     * Return the required permission level for this command.
23
     */
24
    public int getRequiredPermissionLevel()
25
    {
26
        return 2;
27
    }
28
29
    /**
30
     * Gets the usage string for the command.
31
     */
32
    public String getCommandUsage(ICommandSender sender)
33
    {
34
        return "commands.effect.usage";
35
    }
36
37
    /**
38
     * Callback when the command is invoked
39
     */
40
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
41
    {
42
        if (args.length < 2)
43
        {
44
            throw new WrongUsageException("commands.effect.usage", new Object[0]);
45
        }
46
        else
47
        {
48
            EntityLivingBase entitylivingbase = (EntityLivingBase)getEntity(sender, args[0], EntityLivingBase.class);
49
50
            if (args[1].equals("clear"))
51
            {
52
                if (entitylivingbase.getActivePotionEffects().isEmpty())
53
                {
54
                    throw new CommandException("commands.effect.failure.notActive.all", new Object[] {entitylivingbase.getName()});
55
                }
56
                else
57
                {
58
                    entitylivingbase.clearActivePotions();
59
                    notifyOperators(sender, this, "commands.effect.success.removed.all", new Object[] {entitylivingbase.getName()});
60
                }
61
            }
62
            else
63
            {
64
                int i;
65
66
                try
67
                {
68
                    i = parseInt(args[1], 1);
69
                }
70
                catch (NumberInvalidException numberinvalidexception)
71
                {
72
                    Potion potion = Potion.getPotionFromResourceLocation(args[1]);
73
74
                    if (potion == null)
75
                    {
76
                        throw numberinvalidexception;
77
                    }
78
79
                    i = potion.id;
80
                }
81
82
                int j = 600;
83
                int l = 30;
84
                int k = 0;
85
86
                if (i >= 0 && i < Potion.potionTypes.length && Potion.potionTypes[i] != null)
87
                {
88
                    Potion potion1 = Potion.potionTypes[i];
89
90
                    if (args.length >= 3)
91
                    {
92
                        l = parseInt(args[2], 0, 1000000);
93
94
                        if (potion1.isInstant())
95
                        {
96
                            j = l;
97
                        }
98
                        else
99
                        {
100
                            j = l * 20;
101
                        }
102
                    }
103
                    else if (potion1.isInstant())
104
                    {
105
                        j = 1;
106
                    }
107
108
                    if (args.length >= 4)
109
                    {
110
                        k = parseInt(args[3], 0, 255);
111
                    }
112
113
                    boolean flag = true;
114
115
                    if (args.length >= 5 && "true".equalsIgnoreCase(args[4]))
116
                    {
117
                        flag = false;
118
                    }
119
120
                    if (l > 0)
121
                    {
122
                        PotionEffect potioneffect = new PotionEffect(i, j, k, false, flag);
123
                        entitylivingbase.addPotionEffect(potioneffect);
124
                        notifyOperators(sender, this, "commands.effect.success", new Object[] {new ChatComponentTranslation(potioneffect.getEffectName(), new Object[0]), Integer.valueOf(i), Integer.valueOf(k), entitylivingbase.getName(), Integer.valueOf(l)});
125
                    }
126
                    else if (entitylivingbase.isPotionActive(i))
127
                    {
128
                        entitylivingbase.removePotionEffect(i);
129
                        notifyOperators(sender, this, "commands.effect.success.removed", new Object[] {new ChatComponentTranslation(potion1.getName(), new Object[0]), entitylivingbase.getName()});
130
                    }
131
                    else
132
                    {
133
                        throw new CommandException("commands.effect.failure.notActive", new Object[] {new ChatComponentTranslation(potion1.getName(), new Object[0]), entitylivingbase.getName()});
134
                    }
135
                }
136
                else
137
                {
138
                    throw new NumberInvalidException("commands.effect.notFound", new Object[] {Integer.valueOf(i)});
139
                }
140
            }
141
        }
142
    }
143
144
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
145
    {
146
        return args.length == 1 ? getListOfStringsMatchingLastWord(args, this.getAllUsernames()) : (args.length == 2 ? getListOfStringsMatchingLastWord(args, Potion.getPotionLocations()) : (args.length == 5 ? getListOfStringsMatchingLastWord(args, new String[] {"true", "false"}): null));
147
    }
148
149
    protected String[] getAllUsernames()
150
    {
151
        return MinecraftServer.getServer().getAllUsernames();
152
    }
153
154
    /**
155
     * Return whether the specified command parameter index is a username parameter.
156
     */
157
    public boolean isUsernameIndex(String[] args, int index)
158
    {
159
        return index == 0;
160
    }
161
}
162

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