diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/entity/EntityGoalUseItem.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/entity/EntityGoalUseItem.java index d94087b3..17c77eaa 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/entity/EntityGoalUseItem.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/entity/EntityGoalUseItem.java @@ -6,6 +6,7 @@ import com.willfp.eco.core.entities.TestableEntity; import com.willfp.eco.core.entities.ai.EntityGoal; import com.willfp.eco.core.items.Items; import com.willfp.eco.core.serialization.KeyedDeserializer; +import com.willfp.eco.util.SoundUtils; import org.bukkit.NamespacedKey; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; @@ -50,9 +51,15 @@ public record EntityGoalUseItem( TestableEntity filter = Entities.lookup(config.getString("condition")); + Sound sound = SoundUtils.getSound(config.getString("sound")); + + if (sound == null) { + return null; + } + return new EntityGoalUseItem( Items.lookup(config.getString("item")).getItem(), - Sound.valueOf(config.getString("sound").toUpperCase()), + sound, filter::matches ); } diff --git a/eco-api/src/main/java/com/willfp/eco/core/sound/PlayableSound.java b/eco-api/src/main/java/com/willfp/eco/core/sound/PlayableSound.java index 4f1bf159..0842a3b5 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/sound/PlayableSound.java +++ b/eco-api/src/main/java/com/willfp/eco/core/sound/PlayableSound.java @@ -2,6 +2,7 @@ package com.willfp.eco.core.sound; import com.willfp.eco.core.config.interfaces.Config; import com.willfp.eco.core.serialization.ConfigDeserializer; +import com.willfp.eco.util.SoundUtils; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.World; @@ -82,20 +83,20 @@ public record PlayableSound(@NotNull Sound sound, return null; } - try { - Sound sound = Sound.valueOf(config.getString("sound").toUpperCase()); + Sound sound = SoundUtils.getSound(config.getString("sound")); - double pitch = Objects.requireNonNullElse(config.getDoubleOrNull("pitch"), 1.0); - double volume = Objects.requireNonNullElse(config.getDoubleOrNull("volume"), 1.0); - - return new PlayableSound( - sound, - pitch, - volume - ); - } catch (IllegalArgumentException e) { + if (sound == null) { return null; } + + double pitch = Objects.requireNonNullElse(config.getDoubleOrNull("pitch"), 1.0); + double volume = Objects.requireNonNullElse(config.getDoubleOrNull("volume"), 1.0); + + return new PlayableSound( + sound, + pitch, + volume + ); } } }