9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 02:49:15 +00:00

新增模板缺少参数提示

This commit is contained in:
XiaoMoMi
2025-07-04 21:52:51 +08:00
parent 9209fdb33f
commit f7429eaed7
4 changed files with 12 additions and 5 deletions

View File

@@ -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