9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 17:09:19 +00:00
This commit is contained in:
XiaoMoMi
2025-06-05 22:16:15 +08:00
parent fb49db6547
commit cb7548a193
2 changed files with 9 additions and 6 deletions

View File

@@ -20,8 +20,11 @@ public class SelfIncreaseIntTemplateArgument implements TemplateArgument {
@Override @Override
public String get() { public String get() {
String value = String.valueOf(current); String value = String.valueOf(this.current);
if (current < max) current += 1; if (this.current < this.max) this.current += 1;
else {
throw new IllegalStateException("SelfIncreaseInt " + this.current + " is already >= " + this.max);
}
return value; return value;
} }
@@ -31,15 +34,15 @@ public class SelfIncreaseIntTemplateArgument implements TemplateArgument {
} }
public int current() { public int current() {
return current; return this.current;
} }
public int min() { public int min() {
return min; return this.min;
} }
public int max() { public int max() {
return max; return this.max;
} }
public static class Factory implements TemplateArgumentFactory { public static class Factory implements TemplateArgumentFactory {

View File

@@ -452,7 +452,7 @@ public class TemplateManagerImpl implements TemplateManager {
String key = input.substring(1, input.length() - 1); String key = input.substring(1, input.length() - 1);
return Optional.ofNullable(arguments.get(key)) return Optional.ofNullable(arguments.get(key))
.map(TemplateArgument::get) .map(TemplateArgument::get)
.orElse(replacePlaceholders(input, arguments)); .orElseGet(() -> replacePlaceholders(input, arguments));
} }
return replacePlaceholders(input, arguments); return replacePlaceholders(input, arguments);
} }