From 0d0fbe5d3e342d1220aa456f3c36025775e73906 Mon Sep 17 00:00:00 2001 From: Faceguy Date: Sun, 17 Apr 2022 15:24:28 -0400 Subject: [PATCH] fixing potential NPE --- .../bukkit/facecore/pojo/RandomSound.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/pojo/RandomSound.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/pojo/RandomSound.java index ea16f66..8929308 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/pojo/RandomSound.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/pojo/RandomSound.java @@ -24,6 +24,7 @@ import lombok.Data; import org.apache.commons.lang3.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -33,12 +34,15 @@ @Data public class RandomSound { - private float pitchRange; - private float pitchBase; - private float volume; + private final float pitchRange; + private final float pitchBase; + private final float volume; private final Sound sound; private final SoundCategory soundCategory; + private static RandomSound defaultSound = new RandomSound(SoundCategory.MASTER, + Sound.ENTITY_CHICKEN_DEATH, 1f, 0.9f, 0.2f); + public RandomSound(SoundCategory soundCategory, Sound sound, float volume, float pitchBase, float pitchRange) { this.soundCategory = soundCategory; @@ -49,6 +53,10 @@ public RandomSound(SoundCategory soundCategory, Sound sound, float volume, } public static RandomSound load(ConfigurationSection section) { + if (section == null) { + Bukkit.getLogger().warning("Failed to load sound - null config section - using default"); + return defaultSound; + } String soundString = section.getString("sound"); Sound sound = Sound.ENTITY_CHICKEN_DEATH; try {