CommandPlaySound .java

net.minecraft.command.CommandPlaySound (class, 136 lines): members: isUsernameIndex, addTabCompletionOptions, getRequiredPermissionLevel, getCommandUsage.

net.minecraft.commandclass136 linescommonextends CommandBase3.8 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)

String literals (4)

"playsound"
"commands.playsound.usage"
"commands.playsound.playerTooFar"
"commands.playsound.success"

Code Graph: Dependencies (7)

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

Full Source

CommandPlaySound.java136 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import java.util.List;
4
import net.minecraft.entity.player.EntityPlayerMP;
5
import net.minecraft.network.play.server.S29PacketSoundEffect;
6
import net.minecraft.server.MinecraftServer;
7
import net.minecraft.util.BlockPos;
8
import net.minecraft.util.Vec3;
9
10
public class CommandPlaySound extends CommandBase
11
{
12
    /**
13
     * Gets the name of the command
14
     */
15
    public String getCommandName()
16
    {
17
        return "playsound";
18
    }
19
20
    /**
21
     * Return the required permission level for this command.
22
     */
23
    public int getRequiredPermissionLevel()
24
    {
25
        return 2;
26
    }
27
28
    /**
29
     * Gets the usage string for the command.
30
     */
31
    public String getCommandUsage(ICommandSender sender)
32
    {
33
        return "commands.playsound.usage";
34
    }
35
36
    /**
37
     * Callback when the command is invoked
38
     */
39
    public void processCommand(ICommandSender sender, String[] args) throws CommandException
40
    {
41
        if (args.length < 2)
42
        {
43
            throw new WrongUsageException(this.getCommandUsage(sender), new Object[0]);
44
        }
45
        else
46
        {
47
            int i = 0;
48
            String s = args[i++];
49
            EntityPlayerMP entityplayermp = getPlayer(sender, args[i++]);
50
            Vec3 vec3 = sender.getPositionVector();
51
            double d0 = vec3.xCoord;
52
53
            if (args.length > i)
54
            {
55
                d0 = parseDouble(d0, args[i++], true);
56
            }
57
58
            double d1 = vec3.yCoord;
59
60
            if (args.length > i)
61
            {
62
                d1 = parseDouble(d1, args[i++], 0, 0, false);
63
            }
64
65
            double d2 = vec3.zCoord;
66
67
            if (args.length > i)
68
            {
69
                d2 = parseDouble(d2, args[i++], true);
70
            }
71
72
            double d3 = 1.0D;
73
74
            if (args.length > i)
75
            {
76
                d3 = parseDouble(args[i++], 0.0D, 3.4028234663852886E38D);
77
            }
78
79
            double d4 = 1.0D;
80
81
            if (args.length > i)
82
            {
83
                d4 = parseDouble(args[i++], 0.0D, 2.0D);
84
            }
85
86
            double d5 = 0.0D;
87
88
            if (args.length > i)
89
            {
90
                d5 = parseDouble(args[i], 0.0D, 1.0D);
91
            }
92
93
            double d6 = d3 > 1.0D ? d3 * 16.0D : 16.0D;
94
            double d7 = entityplayermp.getDistance(d0, d1, d2);
95
96
            if (d7 > d6)
97
            {
98
                if (d5 <= 0.0D)
99
                {
100
                    throw new CommandException("commands.playsound.playerTooFar", new Object[] {entityplayermp.getName()});
101
                }
102
103
                double d8 = d0 - entityplayermp.posX;
104
                double d9 = d1 - entityplayermp.posY;
105
                double d10 = d2 - entityplayermp.posZ;
106
                double d11 = Math.sqrt(d8 * d8 + d9 * d9 + d10 * d10);
107
108
                if (d11 > 0.0D)
109
                {
110
                    d0 = entityplayermp.posX + d8 / d11 * 2.0D;
111
                    d1 = entityplayermp.posY + d9 / d11 * 2.0D;
112
                    d2 = entityplayermp.posZ + d10 / d11 * 2.0D;
113
                }
114
115
                d3 = d5;
116
            }
117
118
            entityplayermp.playerNetServerHandler.sendPacket(new S29PacketSoundEffect(s, d0, d1, d2, (float)d3, (float)d4));
119
            notifyOperators(sender, this, "commands.playsound.success", new Object[] {s, entityplayermp.getName()});
120
        }
121
    }
122
123
    public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
124
    {
125
        return args.length == 2 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : (args.length > 2 && args.length <= 5 ? func_175771_a(args, 2, pos) : null);
126
    }
127
128
    /**
129
     * Return whether the specified command parameter index is a username parameter.
130
     */
131
    public boolean isUsernameIndex(String[] args, int index)
132
    {
133
        return index == 1;
134
    }
135
}
136

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