diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/properties/EnumProperty.java b/core/src/main/java/net/momirealms/craftengine/core/block/properties/EnumProperty.java index 49ac95204..ddff9c1be 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/properties/EnumProperty.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/properties/EnumProperty.java @@ -13,7 +13,7 @@ public final class EnumProperty> extends Property { private final int[] ordinalToIndex; private final int[] idLookupTable; - public EnumProperty(String name, Class type, List values, T defaultValue) { + private EnumProperty(String name, Class type, List values, T defaultValue) { super(name, type, defaultValue); this.values = List.copyOf(values); T[] enums = type.getEnumConstants(); diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/properties/StringProperty.java b/core/src/main/java/net/momirealms/craftengine/core/block/properties/StringProperty.java index 445d00b17..5be437023 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/properties/StringProperty.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/properties/StringProperty.java @@ -16,7 +16,7 @@ public final class StringProperty extends Property { private final List values; private final ImmutableMap names; - public StringProperty(String name, List values, String defaultValue) { + private StringProperty(String name, List values, String defaultValue) { super(name, String.class, defaultValue); this.values = List.copyOf(values); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManagerImpl.java index cfe45b6ca..a0a2511e0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateManagerImpl.java @@ -311,9 +311,9 @@ public class TemplateManagerImpl implements TemplateManager { Object processedPlaceholderValue = processUnknownValue(argumentEntry.getValue(), result); switch (processedPlaceholderValue) { case Map map -> result.put(placeholder, TemplateArguments.fromMap(MiscUtils.castToMap(map, false))); - case List listArgument -> result.put(placeholder, new ListTemplateArgument((List) listArgument)); + case List listArgument -> result.put(placeholder, ListTemplateArgument.list((List) listArgument)); case null -> result.put(placeholder, NullTemplateArgument.INSTANCE); - default -> result.put(placeholder, new ObjectTemplateArgument(processedPlaceholderValue)); + default -> result.put(placeholder, ObjectTemplateArgument.object(processedPlaceholderValue)); } } return result; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ConditionTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ConditionTemplateArgument.java index f8f3c72be..d58c1b8de 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ConditionTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ConditionTemplateArgument.java @@ -5,17 +5,21 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class ConditionTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class ConditionTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:condition"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final TemplateArgument result; private ConditionTemplateArgument(TemplateArgument result) { this.result = result; } - @Override - public Key type() { - return TemplateArguments.CONDITION; + public TemplateArgument result() { + return this.result; + } + + public static ConditionTemplateArgument condition(final TemplateArgument result) { + return new ConditionTemplateArgument(result); } @Override @@ -23,7 +27,7 @@ public class ConditionTemplateArgument implements TemplateArgument { return this.result.get(arguments); } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ExpressionTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ExpressionTemplateArgument.java index cf02eeb46..92d56c5d9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ExpressionTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ExpressionTemplateArgument.java @@ -10,12 +10,13 @@ import java.util.Map; import java.util.Optional; import java.util.function.Function; -public class ExpressionTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class ExpressionTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:expression"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final ArgumentString expression; private final ValueType valueType; - protected ExpressionTemplateArgument(String expression, ValueType valueType) { + private ExpressionTemplateArgument(String expression, ValueType valueType) { this.expression = ArgumentString.preParse(expression); this.valueType = valueType; } @@ -31,11 +32,6 @@ public class ExpressionTemplateArgument implements TemplateArgument { } } - @Override - public Key type() { - return TemplateArguments.EXPRESSION; - } - protected enum ValueType { INT(e -> e.getNumberValue().intValue()), LONG(e -> e.getNumberValue().longValue()), @@ -56,7 +52,8 @@ public class ExpressionTemplateArgument implements TemplateArgument { } } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { + @Override public TemplateArgument create(Map arguments) { return new ExpressionTemplateArgument( diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ListTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ListTemplateArgument.java index 3863b7841..b456dbf58 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ListTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ListTemplateArgument.java @@ -7,25 +7,25 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; -public class ListTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class ListTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:list"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final List value; - public ListTemplateArgument(List value) { + private ListTemplateArgument(List value) { this.value = value; } + public static ListTemplateArgument list(List value) { + return new ListTemplateArgument(value); + } + @Override public List get(Map arguments) { - return value; + return this.value; } - @Override - public Key type() { - return TemplateArguments.LIST; - } - - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/MapTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/MapTemplateArgument.java index b77c47bb0..6b1c557c8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/MapTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/MapTemplateArgument.java @@ -5,25 +5,29 @@ import net.momirealms.craftengine.core.util.MiscUtils; import java.util.Map; -public class MapTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class MapTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:map"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final Map value; - public MapTemplateArgument(Map value) { + private MapTemplateArgument(Map value) { this.value = value; } + public static MapTemplateArgument map(Map value) { + return new MapTemplateArgument(value); + } + + public Map value() { + return this.value; + } + @Override public Map get(Map arguments) { - return value; + return this.value; } - @Override - public Key type() { - return TemplateArguments.MAP; - } - - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/NullTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/NullTemplateArgument.java index 51a0af576..723a18a7c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/NullTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/NullTemplateArgument.java @@ -4,24 +4,20 @@ import net.momirealms.craftengine.core.util.Key; import java.util.Map; -public class NullTemplateArgument implements TemplateArgument { +public final class NullTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:null"); public static final NullTemplateArgument INSTANCE = new NullTemplateArgument(); - public static final Factory FACTORY = new Factory(); + public static final TemplateArgumentFactory FACTORY = new Factory(); private NullTemplateArgument() { } - @Override - public Key type() { - return TemplateArguments.NULL; - } - @Override public Object get(Map arguments) { return null; } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ObjectTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ObjectTemplateArgument.java index 980eadef6..da36cfaa9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ObjectTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ObjectTemplateArgument.java @@ -4,24 +4,28 @@ import net.momirealms.craftengine.core.util.Key; import java.util.Map; -public class ObjectTemplateArgument implements TemplateArgument { +public final class ObjectTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:object"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final Object value; - public ObjectTemplateArgument(Object value) { + private ObjectTemplateArgument(Object value) { this.value = value; } - public static ObjectTemplateArgument of(Object value) { + public static ObjectTemplateArgument object(Object value) { return new ObjectTemplateArgument(value); } - @Override - public Key type() { - return TemplateArguments.OBJECT; - } - @Override public Object get(Map arguments) { return this.value; } + + private static class Factory implements TemplateArgumentFactory { + @Override + public TemplateArgument create(Map arguments) { + return new ObjectTemplateArgument(arguments.get("value")); + } + } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/PlainStringTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/PlainStringTemplateArgument.java index 3305ac5c5..814a2be8c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/PlainStringTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/PlainStringTemplateArgument.java @@ -4,29 +4,29 @@ import net.momirealms.craftengine.core.util.Key; import java.util.Map; -public class PlainStringTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class PlainStringTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:plain"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final String value; - public PlainStringTemplateArgument(String value) { + private PlainStringTemplateArgument(String value) { this.value = value; } + public String value() { + return this.value; + } + public static PlainStringTemplateArgument plain(final String value) { return new PlainStringTemplateArgument(value); } @Override public String get(Map arguments) { - return value; + return this.value; } - @Override - public Key type() { - return TemplateArguments.PLAIN; - } - - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { return new PlainStringTemplateArgument(arguments.getOrDefault("value", "").toString()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/SelfIncreaseIntTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/SelfIncreaseIntTemplateArgument.java index b117622f4..325d00369 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/SelfIncreaseIntTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/SelfIncreaseIntTemplateArgument.java @@ -6,8 +6,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class SelfIncreaseIntTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class SelfIncreaseIntTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:self_increase_int"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final int min; private final int max; private int current; @@ -38,15 +39,6 @@ public class SelfIncreaseIntTemplateArgument implements TemplateArgument { return value; } - @Override - public Key type() { - return TemplateArguments.SELF_INCREASE_INT; - } - - public int current() { - return this.current; - } - public int min() { return this.min; } @@ -55,6 +47,10 @@ public class SelfIncreaseIntTemplateArgument implements TemplateArgument { return this.max; } + public int current() { + return this.current; + } + public int step() { return this.step; } @@ -67,7 +63,8 @@ public class SelfIncreaseIntTemplateArgument implements TemplateArgument { return this.callCount; } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { + @Override public TemplateArgument create(Map arguments) { int from = ResourceConfigUtils.getAsInt(arguments.get("from"), "from"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgument.java index 6e029e88c..71c6f0c23 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgument.java @@ -1,12 +1,8 @@ package net.momirealms.craftengine.core.plugin.config.template.argument; -import net.momirealms.craftengine.core.util.Key; - import java.util.Map; public interface TemplateArgument { - Key type(); - Object get(Map arguments); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgumentType.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgumentType.java new file mode 100644 index 000000000..047e662d3 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArgumentType.java @@ -0,0 +1,6 @@ +package net.momirealms.craftengine.core.plugin.config.template.argument; + +import net.momirealms.craftengine.core.util.Key; + +public record TemplateArgumentType(Key id, TemplateArgumentFactory factory) { +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArguments.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArguments.java index 9b1a8ef91..6e7e24dcb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArguments.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/TemplateArguments.java @@ -9,58 +9,49 @@ import net.momirealms.craftengine.core.util.ResourceKey; import java.util.List; import java.util.Map; -public class TemplateArguments { - public static final Key PLAIN = Key.of("craftengine:plain"); - public static final Key SELF_INCREASE_INT = Key.of("craftengine:self_increase_int"); - public static final Key MAP = Key.of("craftengine:map"); - public static final Key LIST = Key.of("craftengine:list"); - public static final Key NULL = Key.of("craftengine:null"); - public static final Key CONDITION = Key.of("craftengine:condition"); - public static final Key EXPRESSION = Key.of("craftengine:expression"); - public static final Key OBJECT = Key.of("craftengine:object"); // No Factory, internal use - public static final Key TO_UPPER_CASE = Key.of("craftengine:to_upper_case"); - public static final Key TO_LOWER_CASE = Key.of("craftengine:to_lower_case"); - public static final Key WHEN = Key.of("craftengine:when"); +public final class TemplateArguments { + public static final TemplateArgumentType PLAIN = register(PlainStringTemplateArgument.ID, PlainStringTemplateArgument.FACTORY); + public static final TemplateArgumentType SELF_INCREASE_INT = register(SelfIncreaseIntTemplateArgument.ID, SelfIncreaseIntTemplateArgument.FACTORY); + public static final TemplateArgumentType MAP = register(MapTemplateArgument.ID, MapTemplateArgument.FACTORY); + public static final TemplateArgumentType LIST = register(ListTemplateArgument.ID, ListTemplateArgument.FACTORY); + public static final TemplateArgumentType NULL = register(NullTemplateArgument.ID, NullTemplateArgument.FACTORY); + public static final TemplateArgumentType EXPRESSION = register(ExpressionTemplateArgument.ID, ExpressionTemplateArgument.FACTORY); + public static final TemplateArgumentType CONDITION = register(ConditionTemplateArgument.ID, ConditionTemplateArgument.FACTORY); + public static final TemplateArgumentType TO_UPPER_CASE = register(ToUpperCaseTemplateArgument.ID, ToUpperCaseTemplateArgument.FACTORY); + public static final TemplateArgumentType TO_LOWER_CASE = register(ToLowerCaseTemplateArgument.ID, ToLowerCaseTemplateArgument.FACTORY); + public static final TemplateArgumentType OBJECT = register(ObjectTemplateArgument.ID, ObjectTemplateArgument.FACTORY); + public static final TemplateArgumentType WHEN = register(WhenTemplateArgument.ID, WhenTemplateArgument.FACTORY); - public static void register(Key key, TemplateArgumentFactory factory) { - ((WritableRegistry) BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY) - .register(ResourceKey.create(Registries.TEMPLATE_ARGUMENT_FACTORY.location(), key), factory); - } + private TemplateArguments() {} - static { - register(PLAIN, PlainStringTemplateArgument.FACTORY); - register(SELF_INCREASE_INT, SelfIncreaseIntTemplateArgument.FACTORY); - register(MAP, MapTemplateArgument.FACTORY); - register(LIST, ListTemplateArgument.FACTORY); - register(NULL, NullTemplateArgument.FACTORY); - register(EXPRESSION, ExpressionTemplateArgument.FACTORY); - register(CONDITION, ConditionTemplateArgument.FACTORY); - register(TO_UPPER_CASE, ToUpperCaseTemplateArgument.FACTORY); - register(TO_LOWER_CASE, ToLowerCaseTemplateArgument.FACTORY); - register(WHEN, WhenTemplateArgument.FACTORY); + public static TemplateArgumentType register(Key key, TemplateArgumentFactory factory) { + TemplateArgumentType type = new TemplateArgumentType(key, factory); + ((WritableRegistry) BuiltInRegistries.TEMPLATE_ARGUMENT_TYPE) + .register(ResourceKey.create(Registries.TEMPLATE_ARGUMENT_TYPE.location(), key), type); + return type; } @SuppressWarnings("unchecked") public static TemplateArgument fromObject(Object object) { return switch (object) { case null -> NullTemplateArgument.INSTANCE; - case List list -> new ListTemplateArgument((List) list); + case List list -> ListTemplateArgument.list((List) list); case Map map -> fromMap((Map) map); - default -> new ObjectTemplateArgument(object); + default -> ObjectTemplateArgument.object(object); }; } public static TemplateArgument fromMap(Map map) { Object type = map.get("type"); if (!(type instanceof String type0) || map.containsKey("__skip_template_argument__")) { - return new MapTemplateArgument(map); + return MapTemplateArgument.map(map); } else { Key key = Key.withDefaultNamespace(type0, Key.DEFAULT_NAMESPACE); - TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key); - if (factory == null) { + TemplateArgumentType argumentType = BuiltInRegistries.TEMPLATE_ARGUMENT_TYPE.getValue(key); + if (argumentType == null) { throw new IllegalArgumentException("Unknown argument type: " + type); } - return factory.create(map); + return argumentType.factory().create(map); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToLowerCaseTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToLowerCaseTemplateArgument.java index 83e2c8dae..60c99d430 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToLowerCaseTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToLowerCaseTemplateArgument.java @@ -8,17 +8,21 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Locale; import java.util.Map; -public class ToLowerCaseTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class ToLowerCaseTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:to_lower_case"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final String result; private ToLowerCaseTemplateArgument(String result) { this.result = result; } - @Override - public Key type() { - return TemplateArguments.TO_LOWER_CASE; + public static ToLowerCaseTemplateArgument toLowerCase(String result) { + return new ToLowerCaseTemplateArgument(result.toLowerCase(Locale.ROOT)); + } + + public String result() { + return this.result; } @Override @@ -26,7 +30,7 @@ public class ToLowerCaseTemplateArgument implements TemplateArgument { return this.result; } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToUpperCaseTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToUpperCaseTemplateArgument.java index d3600a5eb..0f4f8dd91 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToUpperCaseTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/ToUpperCaseTemplateArgument.java @@ -8,17 +8,21 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Locale; import java.util.Map; -public class ToUpperCaseTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class ToUpperCaseTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:to_upper_case"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final String result; private ToUpperCaseTemplateArgument(String result) { this.result = result; } - @Override - public Key type() { - return TemplateArguments.TO_UPPER_CASE; + public static ToUpperCaseTemplateArgument toUpperCase(String result) { + return new ToUpperCaseTemplateArgument(result.toUpperCase(Locale.ROOT)); + } + + public String result() { + return this.result; } @Override @@ -26,7 +30,7 @@ public class ToUpperCaseTemplateArgument implements TemplateArgument { return this.result; } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/WhenTemplateArgument.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/WhenTemplateArgument.java index 98dfcb7a0..22af726ea 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/WhenTemplateArgument.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/argument/WhenTemplateArgument.java @@ -5,17 +5,21 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class WhenTemplateArgument implements TemplateArgument { - public static final Factory FACTORY = new Factory(); +public final class WhenTemplateArgument implements TemplateArgument { + public static final Key ID = Key.of("craftengine:when"); + public static final TemplateArgumentFactory FACTORY = new Factory(); private final TemplateArgument result; private WhenTemplateArgument(TemplateArgument result) { this.result = result; } - @Override - public Key type() { - return TemplateArguments.WHEN; + public static WhenTemplateArgument when(TemplateArgument result) { + return new WhenTemplateArgument(result); + } + + public TemplateArgument result() { + return this.result; } @Override @@ -23,7 +27,7 @@ public class WhenTemplateArgument implements TemplateArgument { return this.result.get(arguments); } - public static class Factory implements TemplateArgumentFactory { + private static class Factory implements TemplateArgumentFactory { @Override public TemplateArgument create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java index e5a533f8b..3cb656687 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java @@ -32,11 +32,10 @@ import net.momirealms.craftengine.core.pack.model.definition.rangedisptach.Range import net.momirealms.craftengine.core.pack.model.definition.select.SelectPropertyType; import net.momirealms.craftengine.core.pack.model.definition.special.SpecialModelType; import net.momirealms.craftengine.core.pack.model.definition.tint.TintType; -import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentFactory; +import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType; import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory; import net.momirealms.craftengine.core.plugin.context.function.FunctionFactory; -import net.momirealms.craftengine.core.plugin.context.number.NumberProviderFactory; import net.momirealms.craftengine.core.plugin.context.number.NumberProviderType; import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectorFactory; import net.momirealms.craftengine.core.plugin.network.ModPacket; @@ -53,7 +52,7 @@ public final class BuiltInRegistries { public static final Registry> LOOT_FUNCTION_TYPE = createConstantBoundRegistry(Registries.LOOT_FUNCTION_TYPE, 32); public static final Registry> LOOT_ENTRY_CONTAINER_TYPE = createConstantBoundRegistry(Registries.LOOT_ENTRY_CONTAINER_TYPE, 16); public static final Registry NUMBER_PROVIDER_TYPE = createConstantBoundRegistry(Registries.NUMBER_PROVIDER_TYPE, 16); - public static final Registry TEMPLATE_ARGUMENT_FACTORY = createConstantBoundRegistry(Registries.TEMPLATE_ARGUMENT_FACTORY, 16); + public static final Registry TEMPLATE_ARGUMENT_TYPE = createConstantBoundRegistry(Registries.TEMPLATE_ARGUMENT_TYPE, 16); public static final Registry ITEM_MODEL_TYPE = createConstantBoundRegistry(Registries.ITEM_MODEL_TYPE, 16); public static final Registry TINT_TYPE = createConstantBoundRegistry(Registries.TINT_TYPE, 16); public static final Registry SPECIAL_MODEL_TYPE = createConstantBoundRegistry(Registries.SPECIAL_MODEL_TYPE, 16); diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java index 3b19136cd..100f732b4 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java @@ -32,11 +32,10 @@ import net.momirealms.craftengine.core.pack.model.definition.rangedisptach.Range import net.momirealms.craftengine.core.pack.model.definition.select.SelectPropertyType; import net.momirealms.craftengine.core.pack.model.definition.special.SpecialModelType; import net.momirealms.craftengine.core.pack.model.definition.tint.TintType; -import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentFactory; +import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType; import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory; import net.momirealms.craftengine.core.plugin.context.function.FunctionFactory; -import net.momirealms.craftengine.core.plugin.context.number.NumberProviderFactory; import net.momirealms.craftengine.core.plugin.context.number.NumberProviderType; import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectorFactory; import net.momirealms.craftengine.core.plugin.network.ModPacket; @@ -57,7 +56,7 @@ public final class Registries { public static final ResourceKey>> LOOT_FUNCTION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("loot_function_type")); public static final ResourceKey>> LOOT_ENTRY_CONTAINER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("loot_entry_container_type")); public static final ResourceKey> NUMBER_PROVIDER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_type")); - public static final ResourceKey> TEMPLATE_ARGUMENT_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_factory")); + public static final ResourceKey> TEMPLATE_ARGUMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_type")); public static final ResourceKey> ITEM_MODEL_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_type")); public static final ResourceKey> TINT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("tint_type")); public static final ResourceKey> SPECIAL_MODEL_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("special_model_type"));