diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index f98312b64b..b4e765936a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -24,12 +24,14 @@ import java.util.stream.Collectors; import net.minecraft.core.BlockPosition; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect; +import net.minecraft.network.protocol.game.PacketPlayOutEntitySound; import net.minecraft.network.protocol.game.PacketPlayOutUpdateTime; import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent; import net.minecraft.resources.MinecraftKey; import net.minecraft.server.level.ChunkMapDistance; import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.PlayerChunk; +import net.minecraft.server.level.PlayerChunkMap; import net.minecraft.server.level.Ticket; import net.minecraft.server.level.TicketType; import net.minecraft.server.level.WorldServer; @@ -1514,6 +1516,22 @@ public class CraftWorld extends CraftRegionAccessor implements World { world.getServer().getPlayerList().broadcast(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.dimension(), packet); } + @Override + public void playSound(Entity entity, Sound sound, float volume, float pitch) { + playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch); + } + + @Override + public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { + if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; + + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.getSoundEffect(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch); + PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId()); + if (entityTracker != null) { + entityTracker.broadcastAndSend(packet); + } + } + private static Map> gamerules; public static synchronized Map> getGameRulesNMS() { if (gamerules != null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 44fcc736f9..f9a0af35b7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -44,6 +44,7 @@ import net.minecraft.network.protocol.game.PacketPlayOutChat; import net.minecraft.network.protocol.game.PacketPlayOutCustomPayload; import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect; import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; +import net.minecraft.network.protocol.game.PacketPlayOutEntitySound; import net.minecraft.network.protocol.game.PacketPlayOutExperience; import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; import net.minecraft.network.protocol.game.PacketPlayOutMap; @@ -501,6 +502,19 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().connection.send(packet); } + @Override + public void playSound(org.bukkit.entity.Entity entity, Sound sound, float volume, float pitch) { + playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch); + } + + @Override + public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { + if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return; + + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.getSoundEffect(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch); + getHandle().connection.send(packet); + } + @Override public void stopSound(Sound sound) { stopSound(sound, null);