mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
Catch async usage of playsound (#10021)
This commit is contained in:
parent
7ecbd18f48
commit
fab261ae0b
2 changed files with 43 additions and 0 deletions
|
@ -3447,6 +3447,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // Paper start - adventure sounds
|
+ // Paper start - adventure sounds
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
||||||
|
+ if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
|
||||||
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
||||||
+ for (ServerPlayer player : this.playerList.getPlayers()) {
|
+ for (ServerPlayer player : this.playerList.getPlayers()) {
|
||||||
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
||||||
|
@ -3455,17 +3456,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong), this.playSound0(x, y, z, this.console.getAllLevels()));
|
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong), this.playSound0(x, y, z, this.console.getAllLevels()));
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
||||||
|
+ if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
|
||||||
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
||||||
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
||||||
+ for (ServerPlayer player : this.playerList.getPlayers()) {
|
+ for (ServerPlayer player : this.playerList.getPlayers()) {
|
||||||
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
|
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
|
||||||
+ }
|
+ }
|
||||||
+ } else if (emitter instanceof org.bukkit.craftbukkit.entity.CraftEntity craftEntity) {
|
+ } else if (emitter instanceof org.bukkit.craftbukkit.entity.CraftEntity craftEntity) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound; cannot use entity emitter"); // Paper
|
||||||
+ final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
|
+ final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
|
||||||
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ(), List.of((ServerLevel) entity.level())));
|
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ(), List.of((ServerLevel) entity.level())));
|
||||||
+ } else {
|
+ } else {
|
||||||
|
@ -3512,6 +3516,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // Paper start - Adventure
|
+ // Paper start - Adventure
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
+ final long seed = sound.seed().orElseGet(this.world.getRandom()::nextLong);
|
+ final long seed = sound.seed().orElseGet(this.world.getRandom()::nextLong);
|
||||||
+ for (ServerPlayer player : this.getHandle().players()) {
|
+ for (ServerPlayer player : this.getHandle().players()) {
|
||||||
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
||||||
|
@ -3520,11 +3525,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
|
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
+ final long seed = sound.seed().orElseGet(this.getHandle().getRandom()::nextLong);
|
+ final long seed = sound.seed().orElseGet(this.getHandle().getRandom()::nextLong);
|
||||||
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
||||||
+ for (ServerPlayer player : this.getHandle().players()) {
|
+ for (ServerPlayer player : this.getHandle().players()) {
|
||||||
|
|
|
@ -165,6 +165,42 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
if (!this.currentSection.remove(this.entity)) {
|
if (!this.currentSection.remove(this.entity)) {
|
||||||
PersistentEntitySectionManager.LOGGER.warn("Entity {} wasn't found in section {} (destroying due to {})", new Object[]{this.entity, SectionPos.of(this.currentSectionKey), reason});
|
PersistentEntitySectionManager.LOGGER.warn("Entity {} wasn't found in section {} (destroying due to {})", new Object[]{this.entity, SectionPos.of(this.currentSectionKey), reason});
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
|
if (loc == null || sound == null || category == null) return;
|
||||||
|
|
||||||
|
double x = loc.getX();
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
|
if (loc == null || sound == null || category == null) return;
|
||||||
|
|
||||||
|
double x = loc.getX();
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
|
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
|
||||||
|
|
||||||
|
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
|
||||||
|
+ org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||||
|
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
|
||||||
|
|
||||||
|
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(new ResourceLocation(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||||
|
|
Loading…
Reference in a new issue