Skip to content

Commit

Permalink
fixing potential NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
UltraFaceguy committed Apr 17, 2022
1 parent 64a34b8 commit 0d0fbe5
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 0d0fbe5

Please sign in to comment.