Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Nameable;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
Expand Down Expand Up @@ -715,6 +716,14 @@ final class Holder {
@NotNull
public Sound getSwimHighSpeedSplashSound();

/**
* Get the {@link SoundCategory} this entity will use when playing its sounds.
*
* @return the sound category for this entity
*/
@NotNull
SoundCategory getSoundCategory();

/**
* Returns whether this entity is inside a vehicle.
*
Expand Down
24 changes: 24 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/LivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.World;
import org.bukkit.attribute.Attributable;
import org.bukkit.block.Block;
import org.bukkit.damage.DamageSource;
import org.bukkit.entity.memory.MemoryKey;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -1002,6 +1003,15 @@ default boolean addPotionEffect(@NotNull PotionEffect effect) {
@Nullable
public Sound getHurtSound();

/**
* Get the {@link Sound} this entity will make when damaged by the given {@link DamageSource}.
*
* @param damageSource the damage source to get the hurt sound of
* @return the hurt sound, or null if the entity does not make any sound for the given damage source
*/
@Nullable
public Sound getHurtSound(@NotNull DamageSource damageSource);

/**
* Get the {@link Sound} this entity will make on death.
*
Expand Down Expand Up @@ -1061,6 +1071,20 @@ default boolean addPotionEffect(@NotNull PotionEffect effect) {
@NotNull
public Sound getEatingSound(@NotNull ItemStack itemStack);

/**
* Get the sound volume at which this entity plays its sounds with
*
* @return the sound volume of this entity
*/
public float getSoundVolume();

/**
* Get the sound pitch at which this entity plays its sounds with
*
* @return the sound pitch of this entity
*/
public float getVoicePitch();

/**
* Returns true if this entity can breathe underwater and will not take
* suffocation damage when its air supply reaches zero.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
Expand Down Expand Up @@ -613,6 +614,11 @@ public Sound getSwimHighSpeedSplashSound() {
return CraftSound.minecraftToBukkit(this.getHandle().getSwimHighSpeedSplashSound());
}

@Override
public SoundCategory getSoundCategory() {
return SoundCategory.valueOf(this.getHandle().getSoundSource().name());
}

@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
this.server.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,14 @@ public Sound getHurtSound() {
return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null;
}

@Override
public Sound getHurtSound(org.bukkit.damage.DamageSource damageSource) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import and maybe add the Precondition for null

Copy link
Copy Markdown
Author

@LeonTG LeonTG May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both done now!

The import for that specific method was already taken by nms DamageSource class, which was being used a lot in the class

Preconditions.checkArgument(damageSource != null, "damageSource cannot be null");

SoundEvent sound = this.getHandle().getHurtSound(((CraftDamageSource) damageSource).getHandle());
return (sound != null) ? CraftSound.minecraftToBukkit(sound) : null;
}

@Override
public Sound getDeathSound() {
SoundEvent sound = this.getHandle().getDeathSound();
Expand All @@ -905,6 +913,16 @@ public Sound getDrinkingSound(ItemStack itemStack) {
return this.getEatingSound(itemStack);
}

@Override
public float getSoundVolume() {
return this.getHandle().getSoundVolume();
}

@Override
public float getVoicePitch() {
return this.getHandle().getVoicePitch();
}

@Override
public Sound getEatingSound(ItemStack itemStack) {
Preconditions.checkArgument(itemStack != null, "itemStack must not be null");
Expand Down
Loading