Some sounds can now use string values instead of just values from the Sound enum

This commit is contained in:
ASangarin 2020-12-17 16:27:21 +01:00
parent ddd6a994ce
commit 3f1dfc855e

View File

@ -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);
}
}