From 584c28b880be083bb44abe5b63bf5d1f85f469cc Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Mon, 9 Sep 2019 09:42:50 -0500 Subject: [PATCH] add play functions for sounds --- .../core/compatibility/CompatibleSound.java | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/core/compatibility/CompatibleSound.java b/src/main/java/com/songoda/core/compatibility/CompatibleSound.java index 2f2179cc..afa9e590 100644 --- a/src/main/java/com/songoda/core/compatibility/CompatibleSound.java +++ b/src/main/java/com/songoda/core/compatibility/CompatibleSound.java @@ -1,6 +1,9 @@ package com.songoda.core.compatibility; +import org.bukkit.Location; import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.Player; /** * Sounds that are compatible with server versions 1.7+
@@ -915,12 +918,67 @@ public enum CompatibleSound { return sound != null ? sound : UI_BUTTON_CLICK.sound; } + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + */ + public void play(Player sendTo) { + sendTo.playSound(sendTo.getLocation(), getSound(), 1F, 1F); + } + + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(Player sendTo, float volume, float pitch) { + sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); + } + + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + * @param location where the sound should come from + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(Player sendTo, Location location, float volume, float pitch) { + sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); + } + + /** + * Play a sound in a world + * + * @param sendTo world to send the sound to + * @param location where the sound should come from + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(World sendTo, Location location, float volume, float pitch) { + sendTo.playSound(location, getSound(), volume, pitch); + } + + /** + * Stop a currently active sound from playing for a player + * + * @param sendTo player to stop the sound for + */ + public void stop(Player sendTo) { + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) { + sendTo.stopSound(getSound()); + } + } + /** * Check to see if this sound is available on this server. * * @return Returns false if we are using a different sound. */ - public boolean isMatch() { + public boolean usesCompatibility() { return !compatibilityMode; }