the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1/*
2package net.minecraft.commands.common;
3
4import net.minecraft.commands.BaseCommand;
5import net.minecraft.commands.CommandSender;
6import net.minecraft.commands.exceptions.CommandException;
7import net.minecraft.commands.exceptions.UsageException;
8import net.minecraft.network.packet.LevelSoundPacket;
9import net.minecraft.server.level.ServerPlayer;
10import net.minecraft.world.entity.player.Player;
11
12public class PlaySoundCommand extends BaseCommand {
13 @Override
14 public String getName() {
15 return "playsound";
16 }
17
18 @Override
19 public int getPermissionLevel() {
20 return LEVEL_GAMEMASTERS;
21 }
22
23 @Override
24 public String getUsage(CommandSender source) {
25 return "commands.playsound.usage";
26 }
27
28 @Override
29 public void execute(CommandSender source, String[] args) {
30 if (args.length < 2) {
31 throw new UsageException(getUsage(source));
32 }
33
34 int index = 0;
35 String sound = args[index++];
36 ServerPlayer player = convertToPlayer(source, args[index++]);
37 double x = player.getCommandSenderWorldPosition().x;
38 double y = player.getCommandSenderWorldPosition().y;
39 double z = player.getCommandSenderWorldPosition().z;
40 double volume = 1;
41 double pitch = 1;
42 double minVolume = 0;
43
44 if (args.length > index) x = convertArgToCoordinate(source, x, args[index++]);
45 if (args.length > index) y = convertArgToCoordinate(source, y, args[index++], 0, 0);
46 if (args.length > index) z = convertArgToCoordinate(source, z, args[index++]);
47
48 if (args.length > index) volume = convertArgToDouble(source, args[index++], 0, Float.MAX_VALUE);
49 if (args.length > index) pitch = convertArgToDouble(source, args[index++], 0, 2);
50 if (args.length > index) minVolume = convertArgToDouble(source, args[index++], 0, 1);
51
52 double maxDist = volume > 1 ? volume * 16 : 16;
53 double dist = player.distanceTo(x, y, z);
54
55 if (dist > maxDist) {
56 if (minVolume > 0) {
57 double deltaX = x - player.x;
58 double deltaY = y - player.y;
59 double deltaZ = z - player.z;
60 double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
61 double soundX = player.x;
62 double soundY = player.y;
63 double soundZ = player.z;
64
65 if (length > 0) {
66 soundX += deltaX / length * 2;
67 soundY += deltaY / length * 2;
68 soundZ += deltaZ / length * 2;
69 }
70
71 player.connection.send(new LevelSoundPacket(sound, soundX, soundY, soundZ, (float) minVolume, (float) pitch));
72 } else {
73 throw new CommandException("commands.playsound.playerTooFar", player.getAName());
74 }
75 } else {
76 player.connection.send(new LevelSoundPacket(sound, x, y, z, (float) volume, (float) pitch));
77 }
78
79 logAdminAction(source, "commands.playsound.success", sound, player.getAName());
80 }
81
82 @Override
83 public boolean isValidWildcardPlayerArgument(String[] args, int argumentIndex) {
84 return argumentIndex == 1;
85 }
86}
87
88*/