Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add primitive support for sound api #1422

Open
wants to merge 2 commits into
base: dev/3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
change to fail silently
fix: implement the correct playSound method
fix: bumped "since" version
  • Loading branch information
Timongcraft committed Dec 8, 2024
commit e85d13029b16dcf51cef345367e8a0c34007b5ad
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