Skip to content

Commit

Permalink
stop_sound for specific sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 3, 2021
1 parent ba196b1 commit cb2c6bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Expand Up @@ -3377,19 +3377,28 @@ else if (split.length > 1) {
// @description
// Stops all sounds of the specified type for the player.
// Valid types are AMBIENT, BLOCKS, HOSTILE, MASTER, MUSIC, NEUTRAL, PLAYERS, RECORDS, VOICE, and WEATHER
// Instead of a type, you can specify a full sound key, which usually has the 'minecraft:' prefix.
// If no sound type is specified, all types will be stopped.
// -->
if (mechanism.matches("stop_sound")) {
SoundCategory category = SoundCategory.MASTER;
SoundCategory category = null;
String key = null;
if (mechanism.hasValue()) {
try {
category = SoundCategory.valueOf(mechanism.getValue().asString().toUpperCase());
if (mechanism.getValue().matchesEnum(SoundCategory.values())) {
category = SoundCategory.valueOf(mechanism.getValue().asString().toUpperCase());
}
else {
key = mechanism.getValue().asString();
}
}
catch (Exception e) {
Debug.echoError("Invalid SoundCategory. Must specify a valid name.");
}
}
NMSHandler.getPlayerHelper().stopSound(getPlayerEntity(), null, category);
else {
category = SoundCategory.MASTER;
}
NMSHandler.getPlayerHelper().stopSound(getPlayerEntity(), key, category);
}

if (mechanism.matches("action_bar")) {
Expand Down
Expand Up @@ -257,8 +257,8 @@ public void run() {
Vector newVel = v3.multiply(speed);
lastEntity.setVelocity(newVel);
// Check if the entity has collided with something using the most basic possible calculation
if (!ignoreCollision && (!isSafeBlock(lastEntity.getLocation().add(v3).add(expandForBoundingBox(lastEntity.getBukkitEntity(), v3)))
|| !isSafeBlock(lastEntity.getLocation().add(newVel)))) {
if (!ignoreCollision && (!isSafeBlock(lastEntity.getLocation().add(expandForBoundingBox(lastEntity.getBukkitEntity(), newVel)))
|| !isSafeBlock(lastEntity.getLocation().add(v3)))) {
runs = maxTicks;
}
if (no_damage && lastEntity.isLivingEntity()) {
Expand Down
Expand Up @@ -65,7 +65,8 @@ public class PlayerHelperImpl extends PlayerHelper {
@Override
public void stopSound(Player player, String sound, SoundCategory category) {
MinecraftKey soundKey = sound == null ? null : new MinecraftKey(sound);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(soundKey, net.minecraft.server.v1_16_R3.SoundCategory.valueOf(category.name())));
net.minecraft.server.v1_16_R3.SoundCategory nmsCategory = category == null ? null : net.minecraft.server.v1_16_R3.SoundCategory.valueOf(category.name());
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(soundKey, nmsCategory));
}

@Override
Expand Down

0 comments on commit cb2c6bd

Please sign in to comment.