diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index d7527ad590..7c72f0c9f1 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -383,14 +383,8 @@ default void clearHeaderAndFooter() { /** * {@inheritDoc} * - *

Note: This method is currently only implemented for players from version 1.19.3 and above. - *
A {@link ServerConnection} is required for this to function, so a {@link #getCurrentServer()}.isPresent() check should be made beforehand. - * - * @param sound the sound to play - * @throws IllegalArgumentException if the player is from a version lower than 1.19.3 - * @throws IllegalStateException if no server is connected - * @since 3.3.0 - * @sinceMinecraft 1.19.3 + * This method is not currently implemented in Velocity + * and will not perform any actions. */ @Override default void playSound(@NotNull Sound sound) { @@ -409,11 +403,16 @@ default void playSound(@NotNull Sound sound, double x, double y, double z) { /** * {@inheritDoc} * - * This method is not currently implemented in Velocity - * and will not perform any actions. + *

Note: This method is currently only implemented for players from version 1.19.3 and above + * and requires a present {@link #getCurrentServer}. Additionally, it only supports {@link Sound.Emitter#self()} for now. + * + * @param sound the sound to play + * @param emitter the emitter of the sound + * @since 3.4.0 + * @sinceMinecraft 1.19.3 */ @Override - default void playSound(@NotNull Sound sound, Sound.Emitter emitter) { + default void playSound(@NotNull Sound sound, @NotNull Sound.Emitter emitter) { } /** @@ -422,8 +421,7 @@ default void playSound(@NotNull Sound sound, Sound.Emitter emitter) { *

Note: This method is currently only implemented for players from version 1.19.3 and above. * * @param stop the sound and/or a sound source, to stop - * @throws IllegalArgumentException if the player is from a version lower than 1.19.3 - * @since 3.3.0 + * @since 3.4.0 * @sinceMinecraft 1.19.3 */ @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index c1e724c06b..93f75e028b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -1017,26 +1017,25 @@ void setClientBrand(final @Nullable String clientBrand) { } @Override - public void playSound(@NotNull Sound sound) { + public void playSound(@NotNull Sound sound, @NotNull Sound.Emitter emitter) { Preconditions.checkNotNull(sound, "sound"); - Preconditions.checkArgument( - getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3), - "Player version must be 1.19.3 to be able to interact with sounds"); - if (connection.getState() != StateRegistry.PLAY) { - throw new IllegalStateException("Can only interact with sounds in PLAY protocol"); + Preconditions.checkNotNull(emitter, "emitter"); + Preconditions.checkArgument(emitter.equals(Sound.Emitter.self()), "non-self emitter not supported"); + if (getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_19_3) + || connection.getState() != StateRegistry.PLAY + || getConnectedServer() == null) { + return; } - connection.write(new ClientboundSoundEntityPacket(sound, null, ensureAndGetCurrentServer().getEntityId())); + connection.write(new ClientboundSoundEntityPacket(sound, null, getConnectedServer().getEntityId())); } @Override public void stopSound(@NotNull SoundStop stop) { Preconditions.checkNotNull(stop, "stop"); - Preconditions.checkArgument( - getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3), - "Player version must be 1.19.3 to be able to interact with sounds"); - if (connection.getState() != StateRegistry.PLAY) { - throw new IllegalStateException("Can only interact with sounds in PLAY protocol"); + if (getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_19_3) + || connection.getState() != StateRegistry.PLAY) { + return; } connection.write(new ClientboundStopSoundPacket(stop));