From 3f1dfc855e601fe70eae72219cfdd90b94d24a2e Mon Sep 17 00:00:00 2001 From: ASangarin Date: Thu, 17 Dec 2020 16:27:21 +0100 Subject: [PATCH] Some sounds can now use string values instead of just values from the Sound enum --- .../mmoitems/api/util/SoundReader.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/api/util/SoundReader.java b/src/main/java/net/Indyuce/mmoitems/api/util/SoundReader.java index 25c1ac5b..c1e884b6 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/util/SoundReader.java +++ b/src/main/java/net/Indyuce/mmoitems/api/util/SoundReader.java @@ -5,26 +5,45 @@ import org.bukkit.entity.Player; public class SoundReader { private final Sound sound; + private final String soundKey; public SoundReader(String tag, Sound defaultSound) { + if(tag.isEmpty()) { + this.sound = defaultSound; + this.soundKey = ""; + return; + } + Sound sound; + String soundKey; try { sound = Sound.valueOf(tag); + soundKey = ""; } catch (Exception e) { - sound = defaultSound; + sound = null; + soundKey = tag; } + this.sound = sound; + this.soundKey = soundKey; } public Sound getSound() { return sound; } + public String getSoundKey() { + return soundKey; + } + public void play(Player player) { play(player, 1, 1); } public void play(Player player, float vol, float pitch) { - player.playSound(player.getLocation(), sound, vol, pitch); + if(soundKey.isEmpty()) + player.playSound(player.getLocation(), sound, vol, pitch); + else + player.playSound(player.getLocation(), soundKey, vol, pitch); } }