From c8060dd88d4af7520a361f4f405b36834189968d Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Tue, 29 Apr 2025 01:19:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E4=B8=80=E4=B8=AA=E5=A3=B0=E9=9F=B3?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/loader/src/main/resources/translations/en.yml | 1 + .../net/momirealms/craftengine/core/sound/Sound.java | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 71aa787b7..7b2ec3953 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -103,6 +103,7 @@ warning.config.vanilla_loot.type_not_exist: "Issue found in file warning.config.vanilla_loot.block.invalid_target: "Issue found in file - Invalid block target [] in vanilla loot ''." warning.config.sound.duplicated: "Issue found in file - Duplicated sound ''." warning.config.sound.lack_sounds: "Issue found in file - The sound '' is missing the required argument 'sounds'." +warning.config.sound.lack_name: "Issue found in file - The sound '' is missing the required argument 'name'." warning.config.jukebox_song.duplicated: "Issue found in file - Duplicated jukebox song ''." warning.config.jukebox_song.lack_sound: "Issue found in file - The jukebox song '' is missing the required 'sound' argument." warning.config.furniture.duplicated: "Issue found in file - Duplicated furniture ''." diff --git a/core/src/main/java/net/momirealms/craftengine/core/sound/Sound.java b/core/src/main/java/net/momirealms/craftengine/core/sound/Sound.java index 4fa034178..71e16f911 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/sound/Sound.java +++ b/core/src/main/java/net/momirealms/craftengine/core/sound/Sound.java @@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.sound; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils; @@ -51,13 +52,11 @@ public interface Sound extends Supplier { } public static SoundFile fromMap(Map map) { - String name = (String) map.get("name"); - if (name == null) throw new IllegalArgumentException("Missing 'name' for sound"); - Builder builder = file(name); + Object name = map.get("name"); + if (name == null) throw new LocalizedResourceConfigException("warning.config.sound.lack_name", new NullPointerException("Missing required property 'name'")); + Builder builder = file(name.toString()); for (Map.Entry entry : map.entrySet()) { - Optional.ofNullable(Builder.MODIFIERS.get(entry.getKey())).ifPresent(modifier -> { - modifier.apply(builder, entry.getValue()); - }); + Optional.ofNullable(Builder.MODIFIERS.get(entry.getKey())).ifPresent(modifier -> modifier.apply(builder, entry.getValue())); } return builder.build(); }