From 8845712881b341d8b6184c6de14f1612aded8309 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Sat, 5 Jun 2021 01:05:38 -0400 Subject: [PATCH] Fix SoundEvent + move handler to CraftEventFactory Fixes ProjectEdenGG/Issues#690 --- patches/server/0010-Add-SoundEvent.patch | 212 ++++++++++++----------- 1 file changed, 112 insertions(+), 100 deletions(-) diff --git a/patches/server/0010-Add-SoundEvent.patch b/patches/server/0010-Add-SoundEvent.patch index 9686e5e..47c120e 100644 --- a/patches/server/0010-Add-SoundEvent.patch +++ b/patches/server/0010-Add-SoundEvent.patch @@ -1,63 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lexikiq -Date: Mon, 31 May 2021 18:13:00 -0400 +Date: Sat, 5 Jun 2021 01:04:44 -0400 Subject: [PATCH] Add SoundEvent -diff --git a/src/main/java/me/lexikiq/CraftSoundEvent.java b/src/main/java/me/lexikiq/CraftSoundEvent.java -new file mode 100644 -index 0000000000000000000000000000000000000000..bcef4b18f5a710f9216cab917f3478a43827ace3 ---- /dev/null -+++ b/src/main/java/me/lexikiq/CraftSoundEvent.java -@@ -0,0 +1,43 @@ -+package me.lexikiq; -+ -+import me.lexikiq.event.sound.EntitySoundEvent; -+import me.lexikiq.event.sound.LocationCustomSoundEvent; -+import me.lexikiq.event.sound.LocationNamedSoundEvent; -+import me.lexikiq.event.sound.SoundEvent; -+import net.minecraft.network.protocol.Packet; -+import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect; -+import net.minecraft.network.protocol.game.PacketPlayOutEntitySound; -+import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect; -+import net.minecraft.sounds.SoundCategory; -+import org.bukkit.craftbukkit.CraftSound; -+import org.bukkit.craftbukkit.entity.CraftEntity; -+import org.bukkit.craftbukkit.util.CraftNamespacedKey; -+import org.bukkit.craftbukkit.util.CraftVector; -+import org.bukkit.util.Vector; -+import org.jetbrains.annotations.Nullable; -+ -+public class CraftSoundEvent { -+ private CraftSoundEvent() { -+ throw new IllegalArgumentException("This class is a utility class and should not be instantiated"); -+ } -+ -+ public static @Nullable Packet getPacket(SoundEvent _event) { -+ if (!_event.callEvent()) -+ return null; -+ float volume = _event.getVolume(); -+ float pitch = _event.getPitch(); -+ if (_event instanceof LocationNamedSoundEvent) { -+ LocationNamedSoundEvent event = (LocationNamedSoundEvent) _event; -+ Vector pos = event.getVector(); -+ return new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), pos.getX(), pos.getY(), pos.getZ(), volume, pitch); -+ } else if (_event instanceof LocationCustomSoundEvent) { -+ LocationCustomSoundEvent event = (LocationCustomSoundEvent) _event; -+ Vector pos = event.getVector(); -+ return new PacketPlayOutCustomSoundEffect(CraftNamespacedKey.toMinecraft(event.getKey()), SoundCategory.valueOf(event.getCategory().name()), CraftVector.toNMS(pos), volume, pitch); -+ } else if (_event instanceof EntitySoundEvent) { -+ EntitySoundEvent event = (EntitySoundEvent) _event; -+ return new PacketPlayOutEntitySound(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), ((CraftEntity) event.getOrigin()).getHandle(), volume, pitch); -+ } -+ throw new IllegalArgumentException("A matching sound packet could not be found"); -+ } -+} diff --git a/src/main/java/net/minecraft/server/commands/CommandPlaySound.java b/src/main/java/net/minecraft/server/commands/CommandPlaySound.java -index f896dd7447d8a8fbc6e3c1abad0c3da5448273c1..4463ca8e24808673fd259e0e5d8fe8156c68c0b8 100644 +index f896dd7447d8a8fbc6e3c1abad0c3da5448273c1..e61b9bc82641174e935516fc7c54d2f46ffd397c 100644 --- a/src/main/java/net/minecraft/server/commands/CommandPlaySound.java +++ b/src/main/java/net/minecraft/server/commands/CommandPlaySound.java -@@ -15,12 +15,16 @@ import net.minecraft.commands.arguments.ArgumentMinecraftKeyRegistered; +@@ -15,12 +15,15 @@ import net.minecraft.commands.arguments.ArgumentMinecraftKeyRegistered; import net.minecraft.commands.arguments.coordinates.ArgumentVec3; import net.minecraft.commands.synchronization.CompletionProviders; import net.minecraft.network.chat.ChatMessage; @@ -68,20 +19,19 @@ index f896dd7447d8a8fbc6e3c1abad0c3da5448273c1..4463ca8e24808673fd259e0e5d8fe815 import net.minecraft.util.MathHelper; import net.minecraft.world.phys.Vec3D; +// Parchment start -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationCustomSoundEvent; +import net.minecraft.network.protocol.Packet; +// Parchment end public class CommandPlaySound { -@@ -81,7 +85,17 @@ public class CommandPlaySound { +@@ -81,7 +84,17 @@ public class CommandPlaySound { f3 = f2; } - entityplayer.playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(minecraftkey, soundcategory, vec3d1, f3, f1)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationCustomSoundEvent( ++ Packet packet = org.bukkit.craftbukkit.event.CraftEventFactory.handleSoundEvent(new LocationCustomSoundEvent( + entityplayer.getBukkitEntity(), + entityplayer.getWorldServer().getWorld(), + org.bukkit.craftbukkit.util.CraftVector.toBukkit(vec3d1), @@ -95,7 +45,7 @@ index f896dd7447d8a8fbc6e3c1abad0c3da5448273c1..4463ca8e24808673fd259e0e5d8fe815 } diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java -index 10e9e5328f783832b957113a8672f45f90ace813..ff7afbb3a6d30c86eaec775e4e48f7b1f1282e7b 100644 +index 10e9e5328f783832b957113a8672f45f90ace813..89440aec276d919c784f0a43f8f398b84571cb1c 100644 --- a/src/main/java/net/minecraft/server/level/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java @@ -53,7 +53,6 @@ import net.minecraft.network.protocol.game.PacketPlayOutExperience; @@ -106,26 +56,25 @@ index 10e9e5328f783832b957113a8672f45f90ace813..ff7afbb3a6d30c86eaec775e4e48f7b1 import net.minecraft.network.protocol.game.PacketPlayOutOpenBook; import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor; import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; -@@ -173,6 +172,12 @@ import org.bukkit.event.player.PlayerTeleportEvent; +@@ -173,6 +172,11 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.MainHand; // CraftBukkit end +// Parchment start +import org.bukkit.craftbukkit.CraftSound; +import org.bukkit.craftbukkit.util.CraftVector; -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +// Parchment end public class EntityPlayer extends EntityHuman implements ICrafting { -@@ -2132,7 +2137,11 @@ public class EntityPlayer extends EntityHuman implements ICrafting { +@@ -2132,7 +2136,11 @@ public class EntityPlayer extends EntityHuman implements ICrafting { @Override public void a(SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) { - this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, this.locX(), this.locY(), this.locZ(), f, f1)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(this.getBukkitEntity(), this.getWorld().getWorld(), CraftVector.toBukkit(this.getPositionVector()), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(this.getBukkitEntity(), this.getWorld().getWorld(), CraftVector.toBukkit(this.getPositionVector()), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); + if (packet != null) + this.playerConnection.sendPacket(packet); + // Parchment end @@ -133,7 +82,7 @@ index 10e9e5328f783832b957113a8672f45f90ace813..ff7afbb3a6d30c86eaec775e4e48f7b1 @Override diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java -index 7e032845fe9a46d33236444d62405a41e29daa17..cfb5d2f716fe9181b721ee2b6364fba3eaa1313a 100644 +index 7e032845fe9a46d33236444d62405a41e29daa17..80801c60dd902d19d9c08f0692c96f0ee9612098 100644 --- a/src/main/java/net/minecraft/server/level/WorldServer.java +++ b/src/main/java/net/minecraft/server/level/WorldServer.java @@ -58,11 +58,9 @@ import net.minecraft.network.protocol.Packet; @@ -148,12 +97,11 @@ index 7e032845fe9a46d33236444d62405a41e29daa17..cfb5d2f716fe9181b721ee2b6364fba3 import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition; import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent; import net.minecraft.network.protocol.game.PacketPlayOutWorldParticles; -@@ -168,6 +166,13 @@ import org.bukkit.event.server.MapInitializeEvent; +@@ -168,6 +166,12 @@ import org.bukkit.event.server.MapInitializeEvent; import org.bukkit.event.weather.LightningStrikeEvent; import org.bukkit.event.world.TimeSkipEvent; // CraftBukkit end +// Parchment start -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.EntitySoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +import org.bukkit.craftbukkit.CraftSound; @@ -162,13 +110,13 @@ index 7e032845fe9a46d33236444d62405a41e29daa17..cfb5d2f716fe9181b721ee2b6364fba3 public class WorldServer extends World implements GeneratorAccessSeed { -@@ -1663,12 +1668,20 @@ public class WorldServer extends World implements GeneratorAccessSeed { +@@ -1663,12 +1667,20 @@ public class WorldServer extends World implements GeneratorAccessSeed { @Override public void playSound(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) { - this.server.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), getWorld(), new Vector(d0, d1, d2), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), getWorld(), new Vector(d0, d1, d2), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); + if (packet != null) + this.server.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), packet); + // Parchment end @@ -178,7 +126,7 @@ index 7e032845fe9a46d33236444d62405a41e29daa17..cfb5d2f716fe9181b721ee2b6364fba3 public void playSound(@Nullable EntityHuman entityhuman, Entity entity, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) { - this.server.getPlayerList().sendPacketNearby(entityhuman, entity.locX(), entity.locY(), entity.locZ(), f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), new PacketPlayOutEntitySound(soundeffect, soundcategory, entity, f, f1)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new EntitySoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), entity.getBukkitEntity(), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new EntitySoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), entity.getBukkitEntity(), CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1)); + if (packet != null) + this.server.getPlayerList().sendPacketNearby(entityhuman, entity.locX(), entity.locY(), entity.locZ(), f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), packet); + // Parchment end @@ -186,7 +134,7 @@ index 7e032845fe9a46d33236444d62405a41e29daa17..cfb5d2f716fe9181b721ee2b6364fba3 @Override diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 2a76c3624c64e93509a96579f48c507e29901625..4d908e13dae49e21f9c1001f0c225549bb529c2b 100644 +index 2a76c3624c64e93509a96579f48c507e29901625..9b76349d960b2d5a4d934dc2814f10c4a56e54b0 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -43,7 +43,6 @@ import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange; @@ -206,12 +154,11 @@ index 2a76c3624c64e93509a96579f48c507e29901625..4d908e13dae49e21f9c1001f0c225549 import net.minecraft.stats.ServerStatisticManager; import net.minecraft.stats.StatisticList; import net.minecraft.tags.Tag; -@@ -123,6 +120,12 @@ import org.bukkit.event.player.PlayerLoginEvent; +@@ -123,6 +120,11 @@ import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; // CraftBukkit end +// Parchment start -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +import org.bukkit.craftbukkit.util.CraftVector; +import org.bukkit.Sound; @@ -219,13 +166,13 @@ index 2a76c3624c64e93509a96579f48c507e29901625..4d908e13dae49e21f9c1001f0c225549 public abstract class PlayerList { -@@ -981,7 +984,11 @@ public abstract class PlayerList { +@@ -981,7 +983,11 @@ public abstract class PlayerList { if (flag2 && !isLocAltered) { IBlockData data = worldserver1.getType(blockposition); worldserver1.setTypeAndData(blockposition, data.set(BlockRespawnAnchor.a, data.get(BlockRespawnAnchor.a) - 1), 3); - entityplayer1.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.BLOCK_RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) location.getX(), (double) location.getY(), (double) location.getZ(), 1.0F, 1.0F)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(entityplayer1.getBukkitEntity(), entityplayer1.getWorld().getWorld(), CraftVector.toBukkit(entityplayer1.getPositionVector()), Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, org.bukkit.SoundCategory.BLOCKS, 1.0F, 1.0F)); ++ Packet packet = org.bukkit.craftbukkit.event.CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(entityplayer1.getBukkitEntity(), entityplayer1.getWorld().getWorld(), CraftVector.toBukkit(entityplayer1.getPositionVector()), Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, org.bukkit.SoundCategory.BLOCKS, 1.0F, 1.0F)); + if (packet != null) + entityplayer1.playerConnection.sendPacket(packet); + // Parchment end @@ -233,7 +180,7 @@ index 2a76c3624c64e93509a96579f48c507e29901625..4d908e13dae49e21f9c1001f0c225549 } // Added from changeDimension diff --git a/src/main/java/net/minecraft/world/entity/EntityLightning.java b/src/main/java/net/minecraft/world/entity/EntityLightning.java -index 85f571a791bce63989890f277857bc7bdeec0cb5..9172c6000174c53519b96e51819baa3066f51d04 100644 +index 85f571a791bce63989890f277857bc7bdeec0cb5..684d8128868390b74b1dce70b1c91608f83b75da 100644 --- a/src/main/java/net/minecraft/world/entity/EntityLightning.java +++ b/src/main/java/net/minecraft/world/entity/EntityLightning.java @@ -12,9 +12,7 @@ import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; @@ -246,7 +193,7 @@ index 85f571a791bce63989890f277857bc7bdeec0cb5..9172c6000174c53519b96e51819baa30 import net.minecraft.world.level.GameRules; import net.minecraft.world.level.IBlockAccess; import net.minecraft.world.level.World; -@@ -23,9 +21,14 @@ import net.minecraft.world.level.block.state.IBlockData; +@@ -23,9 +21,13 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.AxisAlignedBB; // CraftBukkit start @@ -256,27 +203,26 @@ index 85f571a791bce63989890f277857bc7bdeec0cb5..9172c6000174c53519b96e51819baa30 +// Parchment start +import org.bukkit.Sound; +import org.bukkit.util.Vector; -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +// Parchment end public class EntityLightning extends Entity { -@@ -88,8 +91,11 @@ public class EntityLightning extends Entity { +@@ -88,8 +90,11 @@ public class EntityLightning extends Entity { double distanceSquared = deltaX * deltaX + deltaZ * deltaZ; // Paper start - Limit lightning strike effect distance if (distanceSquared <= this.world.paperConfig.sqrMaxLightningImpactSoundDistance) { - player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, - SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 2.0f, 0.5F + this.random.nextFloat() * 0.2F)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new Vector(this.locX(), this.locY(), this.locZ()), Sound.ENTITY_LIGHTNING_BOLT_IMPACT, org.bukkit.SoundCategory.WEATHER, 2f, 0.5F + this.random.nextFloat() * 0.2F)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new Vector(this.locX(), this.locY(), this.locZ()), Sound.ENTITY_LIGHTNING_BOLT_IMPACT, org.bukkit.SoundCategory.WEATHER, 2f, 0.5F + this.random.nextFloat() * 0.2F)); + if (packet != null) + player.playerConnection.sendPacket(packet); + // Parchment end } if (world.paperConfig.sqrMaxThunderDistance != -1 && distanceSquared >= world.paperConfig.sqrMaxThunderDistance) { -@@ -97,14 +103,18 @@ public class EntityLightning extends Entity { +@@ -97,14 +102,18 @@ public class EntityLightning extends Entity { } // Paper end @@ -293,7 +239,7 @@ index 85f571a791bce63989890f277857bc7bdeec0cb5..9172c6000174c53519b96e51819baa30 + relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance; // Parchment - sound event } + // Parchment start - sound event -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new Vector(relativeX, this.locY(), relativeZ), Sound.ENTITY_LIGHTNING_BOLT_THUNDER, org.bukkit.SoundCategory.WEATHER, 10000.0F, pitch)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new Vector(relativeX, this.locY(), relativeZ), Sound.ENTITY_LIGHTNING_BOLT_THUNDER, org.bukkit.SoundCategory.WEATHER, 10000.0F, pitch)); + if (packet != null) + player.playerConnection.sendPacket(packet); + // Parchment end - sound event @@ -301,7 +247,7 @@ index 85f571a791bce63989890f277857bc7bdeec0cb5..9172c6000174c53519b96e51819baa30 // CraftBukkit end // this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F); // Paper - Limit lightning strike effect distance (the packet is now sent from inside the loop) diff --git a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java -index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..32eb3e96ab357a29d5f5e61351d088a22250e907 100644 +index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..7d85882184111392ee6086b579bb3e86214dd3f2 100644 --- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java +++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java @@ -28,7 +28,6 @@ import net.minecraft.network.chat.ChatMessage; @@ -312,7 +258,7 @@ index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..32eb3e96ab357a29d5f5e61351d088a2 import net.minecraft.network.syncher.DataWatcher; import net.minecraft.network.syncher.DataWatcherObject; import net.minecraft.network.syncher.DataWatcherRegistry; -@@ -125,6 +124,13 @@ import org.bukkit.event.entity.EntityExhaustionEvent; +@@ -125,6 +124,12 @@ import org.bukkit.event.entity.EntityExhaustionEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerVelocityEvent; // CraftBukkit end @@ -320,19 +266,18 @@ index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..32eb3e96ab357a29d5f5e61351d088a2 +import org.bukkit.craftbukkit.CraftSound; +import org.bukkit.util.Vector; +import net.minecraft.network.protocol.Packet; -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +// Parchment end public abstract class EntityHuman extends EntityLiving { -@@ -1755,7 +1761,11 @@ public abstract class EntityHuman extends EntityLiving { +@@ -1755,7 +1760,11 @@ public abstract class EntityHuman extends EntityLiving { private static void sendSoundEffect(EntityHuman fromEntity, double x, double y, double z, SoundEffect soundEffect, SoundCategory soundCategory, float volume, float pitch) { fromEntity.world.playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself if (fromEntity instanceof EntityPlayer) { - ((EntityPlayer) fromEntity).playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(soundEffect, soundCategory, x, y, z, volume, pitch)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(((EntityPlayer) fromEntity).getBukkitEntity(), fromEntity.getWorld().getWorld(), new Vector(x, y, z), CraftSound.getBukkit(soundEffect), org.bukkit.SoundCategory.valueOf(soundCategory.name()), volume, pitch)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(((EntityPlayer) fromEntity).getBukkitEntity(), fromEntity.getWorld().getWorld(), new Vector(x, y, z), CraftSound.getBukkit(soundEffect), org.bukkit.SoundCategory.valueOf(soundCategory.name()), volume, pitch)); + if (packet != null) + ((EntityPlayer) fromEntity).playerConnection.sendPacket(packet); + // Parchment end @@ -340,7 +285,7 @@ index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..32eb3e96ab357a29d5f5e61351d088a2 } // Paper end diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java -index 457cbdab3fa96fdf7fad1b0206bec9c0aa7847d8..e3ba6dbe6afdfbba299be5b50ff299cd18320ada 100644 +index 457cbdab3fa96fdf7fad1b0206bec9c0aa7847d8..ce854033e098888c468d2c632fd6a877bbd62c96 100644 --- a/src/main/java/net/minecraft/world/entity/raid/Raid.java +++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java @@ -26,12 +26,9 @@ import net.minecraft.nbt.NBTTagCompound; @@ -356,27 +301,26 @@ index 457cbdab3fa96fdf7fad1b0206bec9c0aa7847d8..e3ba6dbe6afdfbba299be5b50ff299cd import net.minecraft.stats.StatisticList; import net.minecraft.util.MathHelper; import net.minecraft.world.BossBattle; -@@ -58,6 +55,13 @@ import net.minecraft.world.level.block.Blocks; +@@ -58,6 +55,12 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.EnumBannerPatternType; import net.minecraft.world.level.levelgen.HeightMap; import net.minecraft.world.phys.Vec3D; +// Parchment start +import org.bukkit.Sound; +import org.bukkit.util.Vector; -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +import net.minecraft.network.protocol.Packet; +// Parchment end public class Raid { -@@ -495,7 +499,11 @@ public class Raid { +@@ -495,7 +498,11 @@ public class Raid { double d1 = vec3d.z + (double) (13.0F / f1) * (vec3d1.z - vec3d.z); if (f1 <= 64.0F || collection.contains(entityplayer)) { - entityplayer.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.EVENT_RAID_HORN, SoundCategory.NEUTRAL, d0, entityplayer.locY(), d1, 64.0F, 1.0F)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(entityplayer.getBukkitEntity(), world.getWorld(), new Vector(d0, entityplayer.locY(), d1), Sound.EVENT_RAID_HORN, org.bukkit.SoundCategory.NEUTRAL, 64.0F, 1.0F)); ++ Packet packet = org.bukkit.craftbukkit.event.CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(entityplayer.getBukkitEntity(), world.getWorld(), new Vector(d0, entityplayer.locY(), d1), Sound.EVENT_RAID_HORN, org.bukkit.SoundCategory.NEUTRAL, 64.0F, 1.0F)); + if (packet != null) + entityplayer.playerConnection.sendPacket(packet); + // Parchment end @@ -384,7 +328,7 @@ index 457cbdab3fa96fdf7fad1b0206bec9c0aa7847d8..e3ba6dbe6afdfbba299be5b50ff299cd } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 3b3eda95c0ff8b129adedbae6561bba2d01c2f3a..57ceffdc0df05e4024da307a8cde77965c67ddfd 100644 +index 3b3eda95c0ff8b129adedbae6561bba2d01c2f3a..c5d211806cff0d7053a4fd41088e357a184e22d1 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -26,7 +26,6 @@ import net.minecraft.core.BlockPosition; @@ -395,26 +339,25 @@ index 3b3eda95c0ff8b129adedbae6561bba2d01c2f3a..57ceffdc0df05e4024da307a8cde7796 import net.minecraft.network.protocol.game.PacketPlayOutUpdateTime; import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent; import net.minecraft.resources.MinecraftKey; -@@ -268,6 +267,11 @@ import org.bukkit.util.BoundingBox; +@@ -268,6 +267,10 @@ import org.bukkit.util.BoundingBox; import org.bukkit.util.Consumer; import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; +// Parchment start -+import me.lexikiq.CraftSoundEvent; +import me.lexikiq.event.sound.LocationCustomSoundEvent; +import net.minecraft.network.protocol.Packet; +// Parchment end public class CraftWorld implements World { public static final int CUSTOM_DIMENSION_OFFSET = 10; -@@ -2308,8 +2312,11 @@ public class CraftWorld implements World { +@@ -2308,8 +2311,11 @@ public class CraftWorld implements World { double y = loc.getY(); double z = loc.getZ(); - PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), SoundCategory.valueOf(category.name()), new Vec3D(x, y, z), volume, pitch); - world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.getDimensionKey(), packet); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationCustomSoundEvent(null, this, new Vector(x, y, z), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromString(sound), category, volume, pitch)); ++ Packet packet = org.bukkit.craftbukkit.event.CraftEventFactory.handleSoundEvent(new LocationCustomSoundEvent(null, this, new Vector(x, y, z), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromString(sound), category, volume, pitch)); + if (packet != null) + world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.getDimensionKey(), packet); + // Parchment end @@ -422,7 +365,7 @@ index 3b3eda95c0ff8b129adedbae6561bba2d01c2f3a..57ceffdc0df05e4024da307a8cde7796 private static Map> gamerules; diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe85f7a34ca 100644 +index 05248f560d643080a3eac581c01aa89fb3709e6c..7ccf0619cafe3c1bf83333ac2235d1fd2c6fb7e2 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -41,10 +41,8 @@ import net.minecraft.network.protocol.game.PacketPlayOutBlockBreakAnimation; @@ -442,7 +385,7 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 import org.bukkit.scoreboard.Scoreboard; +// Parchment start +import org.bukkit.util.Vector; -+import me.lexikiq.CraftSoundEvent; ++import org.bukkit.craftbukkit.event.CraftEventFactory; +import me.lexikiq.event.sound.LocationNamedSoundEvent; +import net.minecraft.network.protocol.Packet; +import me.lexikiq.event.sound.LocationCustomSoundEvent; @@ -457,7 +400,7 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D); - getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(this, getWorld(), new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(this, getWorld(), new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f)); + if (packet != null) + getHandle().playerConnection.sendPacket(packet); + // Parchment end @@ -470,7 +413,7 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); - getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f)); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(this, getWorld(), new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(this, getWorld(), new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f)); + if (packet != null) + getHandle().playerConnection.sendPacket(packet); + // Parchment end @@ -485,7 +428,7 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 - PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch); - getHandle().playerConnection.sendPacket(packet); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationNamedSoundEvent(this, getWorld(), loc.toVector(), sound, category, volume, pitch)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationNamedSoundEvent(this, getWorld(), loc.toVector(), sound, category, volume, pitch)); + if (packet != null) + getHandle().playerConnection.sendPacket(packet); + // Parchment end @@ -498,7 +441,7 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 - PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), new Vec3D(loc.getX(), loc.getY(), loc.getZ()), volume, pitch); - getHandle().playerConnection.sendPacket(packet); + // Parchment start -+ Packet packet = CraftSoundEvent.getPacket(new LocationCustomSoundEvent(this, getWorld(), loc.toVector(), CraftNamespacedKey.fromString(sound), category, volume, pitch)); ++ Packet packet = CraftEventFactory.handleSoundEvent(new LocationCustomSoundEvent(this, getWorld(), loc.toVector(), CraftNamespacedKey.fromString(sound), category, volume, pitch)); + if (packet != null) + getHandle().playerConnection.sendPacket(packet); + // Parchment end @@ -520,10 +463,79 @@ index 05248f560d643080a3eac581c01aa89fb3709e6c..f652cdb1813e23a38d0cff0a9ae23fe8 - this.getHandle().playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), new Vec3D(x, y, z), sound.volume(), sound.pitch())); + soundEvent = new LocationCustomSoundEvent(this, getWorld(), pos, CraftNamespacedKey.fromMinecraft(name), category, sound.volume(), sound.pitch()); } -+ Packet packet = CraftSoundEvent.getPacket(soundEvent); ++ Packet packet = CraftEventFactory.handleSoundEvent(soundEvent); + if (packet != null) + this.getHandle().playerConnection.sendPacket(packet); + // Parchment end } @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +index f0bd5b57ffd7e55299180b382551afe06bd764f8..e914674250bc8032bff56721992b9bdba4f2da79 100644 +--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +@@ -228,6 +228,19 @@ import org.bukkit.inventory.meta.BookMeta; + import org.bukkit.potion.PotionEffect; + + import org.bukkit.event.entity.SpawnerSpawnEvent; // Spigot ++// Parchment start ++import org.bukkit.util.Vector; ++import org.bukkit.craftbukkit.util.CraftVector; ++import org.bukkit.craftbukkit.CraftSound; ++import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect; ++import net.minecraft.network.protocol.game.PacketPlayOutEntitySound; ++import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect; ++import net.minecraft.network.protocol.Packet; ++import me.lexikiq.event.sound.EntitySoundEvent; ++import me.lexikiq.event.sound.LocationCustomSoundEvent; ++import me.lexikiq.event.sound.LocationNamedSoundEvent; ++import me.lexikiq.event.sound.SoundEvent; ++// Parchment end + + public class CraftEventFactory { + public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN); +@@ -1832,4 +1845,44 @@ public class CraftEventFactory { + return event.callEvent(); + } + // Paper end ++ ++ // Parchment start ++ public static @org.jetbrains.annotations.Nullable Packet handleSoundEvent(SoundEvent _event) { ++ org.bukkit.World world; ++ if (_event instanceof LocationNamedSoundEvent) ++ world = ((LocationNamedSoundEvent) _event).getWorld(); ++ else if (_event instanceof LocationCustomSoundEvent) ++ world = ((LocationCustomSoundEvent) _event).getWorld(); ++ else if (_event instanceof EntitySoundEvent) ++ world = ((EntitySoundEvent) _event).getOrigin().getWorld(); ++ else ++ throw new IllegalArgumentException("Could not find world"); ++ ++ if (!(world instanceof CraftWorld)) // mostly just ensuring the world isn't null ++ throw new IllegalArgumentException("World was not a CraftWorld as expected"); ++ ++ java.util.concurrent.CompletableFuture failure = java.util.concurrent.CompletableFuture.supplyAsync(_event::callEvent, ((CraftWorld) world).getHandle().getMinecraftServer()); ++ try { ++ if (failure.get()) ++ return null; ++ } catch (InterruptedException | java.util.concurrent.ExecutionException e) { ++ return null; ++ } ++ ++ float volume = _event.getVolume(); ++ float pitch = _event.getPitch(); ++ if (_event instanceof LocationNamedSoundEvent) { ++ LocationNamedSoundEvent event = (LocationNamedSoundEvent) _event; ++ Vector pos = event.getVector(); ++ return new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), pos.getX(), pos.getY(), pos.getZ(), volume, pitch); ++ } else if (_event instanceof LocationCustomSoundEvent) { ++ LocationCustomSoundEvent event = (LocationCustomSoundEvent) _event; ++ Vector pos = event.getVector(); ++ return new PacketPlayOutCustomSoundEffect(CraftNamespacedKey.toMinecraft(event.getKey()), SoundCategory.valueOf(event.getCategory().name()), CraftVector.toNMS(pos), volume, pitch); ++ } else { // EntitySoundEvent ++ EntitySoundEvent event = (EntitySoundEvent) _event; ++ return new PacketPlayOutEntitySound(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), ((CraftEntity) event.getOrigin()).getHandle(), volume, pitch); ++ } ++ } ++ // Parchment end + }