Skip to content

Commit

Permalink
change to fail silently
Browse files Browse the repository at this point in the history
fix: implement the correct playSound method
fix: bumped "since" version
  • Loading branch information
Timongcraft committed Dec 8, 2024
1 parent 87b0e57 commit e85d130
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
24 changes: 11 additions & 13 deletions api/src/main/java/com/velocitypowered/api/proxy/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,8 @@ default void clearHeaderAndFooter() {
/**
* {@inheritDoc}
*
* <p>Note: This method is currently only implemented for players from version 1.19.3 and above.
* <br>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
* <b>This method is not currently implemented in Velocity
* and will not perform any actions.</b>
*/
@Override
default void playSound(@NotNull Sound sound) {
Expand All @@ -409,11 +403,16 @@ default void playSound(@NotNull Sound sound, double x, double y, double z) {
/**
* {@inheritDoc}
*
* <b>This method is not currently implemented in Velocity
* and will not perform any actions.</b>
* <p>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) {
}

/**
Expand All @@ -422,8 +421,7 @@ default void playSound(@NotNull Sound sound, Sound.Emitter emitter) {
* <p>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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit e85d130

Please sign in to comment.