From 99bc0b31176f0ec7b8d3b6ec9a628d8544870bb2 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 27 Apr 2025 22:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=AE=B6=E5=85=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../loader/src/main/resources/translations/en.yml | 8 +++++++- .../entity/furniture/BukkitFurnitureManager.java | 13 ++++++++++++- .../core/loot/condition/LootConditions.java | 6 +++--- .../core/loot/entry/LootEntryContainers.java | 5 +++-- .../core/loot/function/LootFunctions.java | 5 +++-- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 423ad1448..7937c5b2b 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -151,9 +151,15 @@ warning.config.loot_table.wrong_pools_type: "Issue found in file warning.config.loot_table.wrong_conditions_type: "Issue found in file - '' has a misconfigured loot table, 'conditions' should be a map list, current type: ''." warning.config.loot_table.wrong_functions_type: "Issue found in file - '' has a misconfigured loot table, 'functions' should be a map list, current type: ''." warning.config.loot_table.wrong_entries_type: "Issue found in file - '' has a misconfigured loot table, 'entries' should be a map list, current type: ''." +warning.config.loot_table.function.lack_type: "Issue found in file - '' has a misconfigured loot table, one of the functions is missing the required argument 'type'." +warning.config.loot_table.function.invalid_type: "Issue found in file - '' has a misconfigured loot table, one of the functions is using an invalid function type ''." warning.config.loot_table.function.apply_bonus.lack_enchantment: "Issue found in file - '' has a misconfigured loot table, function 'apply_bonus' is missing the required argument 'enchantment'." warning.config.loot_table.function.apply_bonus.lack_formula: "Issue found in file - '' has a misconfigured loot table, function 'apply_bonus' is missing the required argument 'formula'." warning.config.loot_table.function.drop_exp.lack_count: "Issue found in file - '' has a misconfigured loot table, function 'drop_exp' is missing the required argument 'count'." warning.config.loot_table.function.set_count.lack_count: "Issue found in file - '' has a misconfigured loot table, function 'set_count' is missing the required argument 'count'." +warning.config.loot_table.entry.lack_type: "Issue found in file - '' has a misconfigured loot table, one of the entries is missing the required argument 'type'." +warning.config.loot_table.entry.invalid_type: "Issue found in file - '' has a misconfigured loot table, one of the entries is using an invalid entry type ''." warning.config.loot_table.entry.exp.lack_count: "Issue found in file - '' has a misconfigured loot table, entry 'exp' is missing the required argument 'count'." -warning.config.loot_table.entry.item.lack_item: "Issue found in file - '' has a misconfigured loot table, entry 'item' is missing the required argument 'item'." \ No newline at end of file +warning.config.loot_table.entry.item.lack_item: "Issue found in file - '' has a misconfigured loot table, entry 'item' is missing the required argument 'item'." +warning.config.loot_table.condition.lack_type: "Issue found in file - '' has a misconfigured loot table, one of the conditions is missing the required argument 'type'." +warning.config.loot_table.condition.invalid_type: "Issue found in file - '' has a misconfigured loot table, one of the conditions is using an invalid condition type ''." \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java index 753a37a89..a244727d0 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java @@ -22,6 +22,7 @@ import org.bukkit.*; import org.bukkit.entity.*; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import org.joml.Vector3f; @@ -205,7 +206,17 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager { e.setId(id); throw e; } - CustomFurniture furniture = new CustomFurniture(id, settings, placements, lootMap == null ? null : LootTable.fromMap(lootMap)); + + // get loot table + LootTable lootTable; + try { + lootTable = lootMap == null ? null : LootTable.fromMap(lootMap); + } catch (LocalizedResourceConfigException e) { + e.setPath(path); + e.setId(id); + throw e; + } + CustomFurniture furniture = new CustomFurniture(id, settings, placements, lootTable); byId.put(id, furniture); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java index 7fac12892..b3a3c0ef7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.loot.condition; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.Registries; @@ -89,14 +90,13 @@ public class LootConditions { public static LootCondition fromMap(Map map) { String type = (String) map.get("type"); if (type == null) { - throw new NullPointerException("condition type cannot be null"); + throw new LocalizedResourceConfigException("warning.config.loot_table.condition.lack_type", new NullPointerException("condition type cannot be null")); } Key key = Key.withDefaultNamespace(type, "craftengine"); LootConditionFactory factory = BuiltInRegistries.LOOT_CONDITION_FACTORY.getValue(key); if (factory == null) { - throw new IllegalArgumentException("Unknown loot condition type: " + type); + throw new LocalizedResourceConfigException("warning.config.loot_table.condition.invalid_type", new IllegalArgumentException("Unknown loot condition type: " + type), type); } return factory.create(map); } - } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java index 4c11af995..66e315c0d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.loot.entry; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.Registries; @@ -41,12 +42,12 @@ public class LootEntryContainers { public static LootEntryContainer fromMap(Map map) { String type = (String) map.get("type"); if (type == null) { - throw new NullPointerException("loot entry type cannot be null"); + throw new LocalizedResourceConfigException("warning.config.loot_table.entry.lack_type", new NullPointerException("loot entry type cannot be null")); } Key key = Key.withDefaultNamespace(type, "craftengine"); LootEntryContainerFactory factory = (LootEntryContainerFactory) BuiltInRegistries.LOOT_ENTRY_CONTAINER_FACTORY.getValue(key); if (factory == null) { - throw new IllegalArgumentException("Unknown loot entry type: " + type); + throw new LocalizedResourceConfigException("warning.config.loot_table.entry.invalid_type", new IllegalArgumentException("Unknown loot entry type: " + type), type); } return factory.create(map); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java index 0ab815f53..4d8441a89 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java @@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.Registries; @@ -69,12 +70,12 @@ public class LootFunctions { public static LootFunction fromMap(Map map) { String type = (String) map.get("type"); if (type == null) { - throw new NullPointerException("function type cannot be null"); + throw new LocalizedResourceConfigException("warning.config.loot_table.function.lack_type", new NullPointerException("function type cannot be null")); } Key key = Key.withDefaultNamespace(type, "craftengine"); LootFunctionFactory factory = (LootFunctionFactory) BuiltInRegistries.LOOT_FUNCTION_FACTORY.getValue(key); if (factory == null) { - throw new IllegalArgumentException("Unknown function type: " + type); + throw new LocalizedResourceConfigException("warning.config.loot_table.function.invalid_type", new IllegalArgumentException("Unknown function type: " + type), type); } return factory.create(map); }