Removed uses of Sound.valueOf

This commit is contained in:
Will FP
2025-01-21 14:23:45 +00:00
parent e1849fe307
commit 5e4ae1f932
2 changed files with 20 additions and 12 deletions

View File

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

View File

@@ -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,8 +83,11 @@ public record PlayableSound(@NotNull Sound sound,
return null;
}
try {
Sound sound = Sound.valueOf(config.getString("sound").toUpperCase());
Sound sound = SoundUtils.getSound(config.getString("sound"));
if (sound == null) {
return null;
}
double pitch = Objects.requireNonNullElse(config.getDoubleOrNull("pitch"), 1.0);
double volume = Objects.requireNonNullElse(config.getDoubleOrNull("volume"), 1.0);
@@ -93,9 +97,6 @@ public record PlayableSound(@NotNull Sound sound,
pitch,
volume
);
} catch (IllegalArgumentException e) {
return null;
}
}
}
}