All checks were successful
KnarCraft/Minstrel/pipeline/head This commit looks good
32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
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 <p>The player to check</p>
|
|
* @param minstrelTrait <p>The minstrel to check</p>
|
|
* @return <p>True if the player would hear the minstrel</p>
|
|
*/
|
|
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));
|
|
}
|
|
|
|
}
|