From f7429eaed787369310f69a0bc643f05877591f32 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Fri, 4 Jul 2025 21:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A8=A1=E6=9D=BF=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=E5=8F=82=E6=95=B0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/default/configuration/templates.yml | 6 +++--- common-files/src/main/resources/translations/en.yml | 1 + common-files/src/main/resources/translations/zh_cn.yml | 1 + .../core/plugin/config/template/TemplateManager.java | 9 +++++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common-files/src/main/resources/resources/default/configuration/templates.yml b/common-files/src/main/resources/resources/default/configuration/templates.yml index 9d6e1e4c4..5760c9c18 100644 --- a/common-files/src/main/resources/resources/default/configuration/templates.yml +++ b/common-files/src/main/resources/resources/default/configuration/templates.yml @@ -2150,17 +2150,17 @@ templates#block_states: state: ${base_block}[type=top,waterlogged=false] model: path: ${model_top_path} - generation: ${model_top_generation} + generation: ${model_top_generation:-null} type=bottom,waterlogged=false: state: ${base_block}[type=bottom,waterlogged=false] model: path: ${model_bottom_path} - generation: ${model_bottom_generation} + generation: ${model_bottom_generation:-null} type=double,waterlogged=false: state: ${base_block}[type=double,waterlogged=false] model: path: ${model_double_path} - generation: ${model_double_generation} + generation: ${model_double_generation:-null} type=top,waterlogged=true: state: ${base_block}[type=top,waterlogged=true] model: diff --git a/common-files/src/main/resources/translations/en.yml b/common-files/src/main/resources/translations/en.yml index 40c7c0b65..e7de0566e 100644 --- a/common-files/src/main/resources/translations/en.yml +++ b/common-files/src/main/resources/translations/en.yml @@ -139,6 +139,7 @@ warning.config.template.duplicate: "Issue found in file - Duplic warning.config.template.invalid: "Issue found in file - The config '' is using an invalid template ''." warning.config.template.argument.self_increase_int.invalid_range: "Issue found in file - The template '' is using a 'from' '' larger than 'to' '' in 'self_increase_int' argument." warning.config.template.argument.list.invalid_type: "Issue found in file - The template '' is using a 'list' argument which expects a 'List' as argument while the input argument is a(n) ''." +warning.config.template.argument.missing_value: "Issue found in file - The config '' is missing the template argument for ''. Please use the arguments option to configure or set a default value for this parameter." warning.config.vanilla_loot.missing_type: "Issue found in file - The vanilla loot '' is missing the required 'type' argument." warning.config.vanilla_loot.invalid_type: "Issue found in file - The vanilla loot '' is using an invalid type ''. Allowed types: []." warning.config.vanilla_loot.block.invalid_target: "Issue found in file - Invalid block target '' in vanilla loot ''." diff --git a/common-files/src/main/resources/translations/zh_cn.yml b/common-files/src/main/resources/translations/zh_cn.yml index 53a4041be..de5367bc2 100644 --- a/common-files/src/main/resources/translations/zh_cn.yml +++ b/common-files/src/main/resources/translations/zh_cn.yml @@ -139,6 +139,7 @@ warning.config.template.duplicate: "在文件 发现问题 - 重 warning.config.template.argument.self_increase_int.invalid_range: "在文件 发现问题 - 模板 '' 在 'self_increase_int' 参数中使用了一个起始值 '' 大于终止值 ''" warning.config.template.invalid: "在文件 发现问题 - 配置 '' 使用了无效的模板 ''." warning.config.template.argument.list.invalid_type: "在文件 发现问题 - 模板 '' 的 'list' 参数需要列表类型 但输入参数类型为 ''" +warning.config.template.argument.missing_value: "在文件 发现问题 - 配置 '' 缺少了 '' 必要的模板参数值. 请使用 arguments 选项进行配置或为此参数设定默认值." warning.config.vanilla_loot.missing_type: "在文件 发现问题 - 原版战利品 '' 缺少必需的 'type' 参数" warning.config.vanilla_loot.invalid_type: "在文件 发现问题 - 原版战利品 '' 使用了无效类型 '' 允许的类型: []" warning.config.vanilla_loot.block.invalid_target: "在文件 发现问题 - 原版战利品 '' 中存在无效的方块目标 ''" diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManager.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManager.java index 55fba96cb..86840c238 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManager.java @@ -65,6 +65,7 @@ public interface TemplateManager extends Manageable { private final String placeholder; private final String rawText; private final Object defaultValue; + private final boolean hasDefaultValue; public Placeholder(String placeholderContent) { this.rawText = "${" + placeholderContent + "}"; @@ -72,16 +73,17 @@ public interface TemplateManager extends Manageable { if (separatorIndex == -1) { this.placeholder = placeholderContent; this.defaultValue = null; + this.hasDefaultValue = false; } else { this.placeholder = placeholderContent.substring(0, separatorIndex); String defaultValueString = placeholderContent.substring(separatorIndex + 2); try { - // TODO 改进报错检测 this.defaultValue = new SNBTReader(defaultValueString).deserializeAsJava(); } catch (LocalizedResourceConfigException e) { e.appendTailArgument(this.placeholder); throw e; } + this.hasDefaultValue = true; } } @@ -95,7 +97,10 @@ public interface TemplateManager extends Manageable { if (replacement != null) { return replacement.get(arguments); } - return this.defaultValue; + if (this.hasDefaultValue) { + return this.defaultValue; + } + throw new LocalizedResourceConfigException("warning.config.template.argument.missing_value", this.rawText); } @Override