Removed uses of Sound.valueOf
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user