package net.knarcraft.minstrel.util; import net.knarcraft.minstrel.trait.MinstrelTrait; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; /** * A helper class for dealing with sound */ public class SoundHelper { /** * Checks whether the given player can hear the given minstrel * * @param player

The player to check

* @param minstrelTrait

The minstrel to check

* @return

True if the player would hear the minstrel

*/ public static boolean canHear(@NotNull Player player, @NotNull MinstrelTrait minstrelTrait) { // Minstrels cannot be heard across worlds! if (player.getLocation().getWorld() != null && minstrelTrait.getLocation().getWorld() != null && !player.getLocation().getWorld().equals(minstrelTrait.getLocation().getWorld())) { return false; } double distance = player.getLocation().distance(minstrelTrait.getNPC().getStoredLocation()); // A player can hear a minstrel 15 blocks away, but the distance increases if volume > 1 return distance < 15 * (Math.max(minstrelTrait.getVolume(), 1)); } }