mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
重构条件
This commit is contained in:
@@ -33,7 +33,7 @@ public class WorldGuardRegionCondition<CTX extends Context> implements Condition
|
|||||||
this.regions = regions;
|
this.regions = regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, WorldGuardRegionCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +84,10 @@ public class WorldGuardRegionCondition<CTX extends Context> implements Condition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, WorldGuardRegionCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public WorldGuardRegionCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
int mode = ResourceConfigUtils.getAsInt(arguments.getOrDefault("mode", 1), "mode") - 1;
|
int mode = ResourceConfigUtils.getAsInt(arguments.getOrDefault("mode", 1), "mode") - 1;
|
||||||
MatchMode matchMode = MatchMode.values()[mode];
|
MatchMode matchMode = MatchMode.values()[mode];
|
||||||
List<String> regions = MiscUtils.getAsStringList(arguments.get("regions"));
|
List<String> regions = MiscUtils.getAsStringList(arguments.get("regions"));
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ public class BukkitSeatManager implements SeatManager, Listener {
|
|||||||
location.add(0,-0.35,0);
|
location.add(0,-0.35,0);
|
||||||
}
|
}
|
||||||
seat.remove();
|
seat.remove();
|
||||||
|
location.add(0, 0.2, 0); // 防止座椅较低卡进地下
|
||||||
EntityUtils.safeDismount(player, location);
|
EntityUtils.safeDismount(player, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record ContainsPathMatcher(String path) implements Condition<PathContext> {
|
public record ContainsPathMatcher(String path) implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, ContainsPathMatcher> FACTORY = new Factory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(PathContext path) {
|
public boolean test(PathContext path) {
|
||||||
@@ -18,11 +18,11 @@ public record ContainsPathMatcher(String path) implements Condition<PathContext>
|
|||||||
return pathStr.contains(this.path);
|
return pathStr.contains(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, ContainsPathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public ContainsPathMatcher create(Map<String, Object> arguments) {
|
||||||
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
|
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
|
||||||
return new ContainsPathMatcher(path);
|
return new ContainsPathMatcher(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record ExactPathMatcher(String path) implements Condition<PathContext> {
|
public record ExactPathMatcher(String path) implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, ExactPathMatcher> FACTORY = new Factory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(PathContext path) {
|
public boolean test(PathContext path) {
|
||||||
@@ -18,11 +18,11 @@ public record ExactPathMatcher(String path) implements Condition<PathContext> {
|
|||||||
return pathStr.equals(this.path);
|
return pathStr.equals(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, ExactPathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public ExactPathMatcher create(Map<String, Object> arguments) {
|
||||||
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
|
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
|
||||||
return new ExactPathMatcher(path);
|
return new ExactPathMatcher(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record FilenamePathMatcher(String name) implements Condition<PathContext> {
|
public record FilenamePathMatcher(String name) implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, FilenamePathMatcher> FACTORY = new Factory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(PathContext path) {
|
public boolean test(PathContext path) {
|
||||||
@@ -17,11 +17,11 @@ public record FilenamePathMatcher(String name) implements Condition<PathContext>
|
|||||||
return fileName.equals(name);
|
return fileName.equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, FilenamePathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public FilenamePathMatcher create(Map<String, Object> arguments) {
|
||||||
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
|
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
|
||||||
return new FilenamePathMatcher(name);
|
return new FilenamePathMatcher(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record ParentPrefixPathMatcher(String prefix) implements Condition<PathContext> {
|
public record ParentPrefixPathMatcher(String prefix) implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, ParentPrefixPathMatcher> FACTORY = new Factory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(PathContext path) {
|
public boolean test(PathContext path) {
|
||||||
@@ -21,11 +21,11 @@ public record ParentPrefixPathMatcher(String prefix) implements Condition<PathCo
|
|||||||
return pathStr.startsWith(this.prefix);
|
return pathStr.startsWith(this.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, ParentPrefixPathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public ParentPrefixPathMatcher create(Map<String, Object> arguments) {
|
||||||
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
|
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
|
||||||
return new ParentPrefixPathMatcher(prefix);
|
return new ParentPrefixPathMatcher(prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record ParentSuffixPathMatcher(String suffix) implements Condition<PathContext> {
|
public record ParentSuffixPathMatcher(String suffix) implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, ParentSuffixPathMatcher> FACTORY = new Factory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(PathContext path) {
|
public boolean test(PathContext path) {
|
||||||
@@ -21,11 +21,11 @@ public record ParentSuffixPathMatcher(String suffix) implements Condition<PathCo
|
|||||||
return pathStr.endsWith(suffix);
|
return pathStr.endsWith(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, ParentSuffixPathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public ParentSuffixPathMatcher create(Map<String, Object> arguments) {
|
||||||
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
|
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
|
||||||
return new ParentSuffixPathMatcher(suffix);
|
return new ParentSuffixPathMatcher(suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
package net.momirealms.craftengine.core.pack.conflict.matcher;
|
package net.momirealms.craftengine.core.pack.conflict.matcher;
|
||||||
|
|
||||||
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.ConditionType;
|
||||||
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
|
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
|
||||||
import net.momirealms.craftengine.core.util.Key;
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
|
||||||
public record PathMatcherType(Key id, ConditionFactory<PathContext> factory) {
|
public class PathMatcherType<T extends Condition<PathContext>> extends ConditionType<PathContext, T> {
|
||||||
|
|
||||||
|
public PathMatcherType(Key id, ConditionFactory<PathContext, T> factory) {
|
||||||
|
super(id, factory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,38 +14,28 @@ import net.momirealms.craftengine.core.util.Key;
|
|||||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class PathMatchers {
|
public final class PathMatchers {
|
||||||
public static final PathMatcherType ANY_OF = register(Key.ce("any_of"), AnyOfCondition.factory(PathMatchers::fromMap));
|
public static final PathMatcherType<AnyOfCondition<PathContext>> ANY_OF = register(Key.ce("any_of"), AnyOfCondition.factory(PathMatchers::fromMap));
|
||||||
public static final PathMatcherType ALL_OF = register(Key.ce("all_of"), AllOfCondition.factory(PathMatchers::fromMap));
|
public static final PathMatcherType<AllOfCondition<PathContext>> ALL_OF = register(Key.ce("all_of"), AllOfCondition.factory(PathMatchers::fromMap));
|
||||||
public static final PathMatcherType INVERTED = register(Key.ce("inverted"), InvertedCondition.factory(PathMatchers::fromMap));
|
public static final PathMatcherType<InvertedCondition<PathContext>> INVERTED = register(Key.ce("inverted"), InvertedCondition.factory(PathMatchers::fromMap));
|
||||||
public static final PathMatcherType CONTAINS = register(Key.ce("contains"), ContainsPathMatcher.FACTORY);
|
public static final PathMatcherType<ContainsPathMatcher> CONTAINS = register(Key.ce("contains"), ContainsPathMatcher.FACTORY);
|
||||||
public static final PathMatcherType EXACT = register(Key.ce("exact"), ExactPathMatcher.FACTORY);
|
public static final PathMatcherType<ExactPathMatcher> EXACT = register(Key.ce("exact"), ExactPathMatcher.FACTORY);
|
||||||
public static final PathMatcherType FILENAME = register(Key.ce("filename"), FilenamePathMatcher.FACTORY);
|
public static final PathMatcherType<FilenamePathMatcher> FILENAME = register(Key.ce("filename"), FilenamePathMatcher.FACTORY);
|
||||||
public static final PathMatcherType PATTERN = register(Key.ce("pattern"), PatternPathMatcher.FACTORY);
|
public static final PathMatcherType<PatternPathMatcher> PATTERN = register(Key.ce("pattern"), PatternPathMatcher.FACTORY);
|
||||||
public static final PathMatcherType PARENT_PATH_SUFFIX = register(Key.ce("parent_path_suffix"), ParentSuffixPathMatcher.FACTORY);
|
public static final PathMatcherType<ParentSuffixPathMatcher> PARENT_PATH_SUFFIX = register(Key.ce("parent_path_suffix"), ParentSuffixPathMatcher.FACTORY);
|
||||||
public static final PathMatcherType PARENT_PATH_PREFIX = register(Key.ce("parent_path_prefix"), ParentPrefixPathMatcher.FACTORY);
|
public static final PathMatcherType<ParentPrefixPathMatcher> PARENT_PATH_PREFIX = register(Key.ce("parent_path_prefix"), ParentPrefixPathMatcher.FACTORY);
|
||||||
|
|
||||||
private PathMatchers() {}
|
private PathMatchers() {}
|
||||||
|
|
||||||
public static PathMatcherType register(Key key, ConditionFactory<PathContext> factory) {
|
public static <T extends Condition<PathContext>> PathMatcherType<T> register(Key key, ConditionFactory<PathContext, T> factory) {
|
||||||
PathMatcherType type = new PathMatcherType(key, factory);
|
PathMatcherType<T> type = new PathMatcherType<>(key, factory);
|
||||||
((WritableRegistry<PathMatcherType>) BuiltInRegistries.PATH_MATCHER_TYPE)
|
((WritableRegistry<PathMatcherType<?>>) BuiltInRegistries.PATH_MATCHER_TYPE)
|
||||||
.register(ResourceKey.create(Registries.PATH_MATCHER_TYPE.location(), key), type);
|
.register(ResourceKey.create(Registries.PATH_MATCHER_TYPE.location(), key), type);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Condition<PathContext>> fromMapList(List<Map<String, Object>> arguments) {
|
|
||||||
List<Condition<PathContext>> matchers = new ArrayList<>();
|
|
||||||
for (Map<String, Object> term : arguments) {
|
|
||||||
matchers.add(PathMatchers.fromMap(term));
|
|
||||||
}
|
|
||||||
return matchers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Condition<PathContext> fromMap(Map<String, Object> map) {
|
public static Condition<PathContext> fromMap(Map<String, Object> map) {
|
||||||
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type"));
|
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type"));
|
||||||
boolean reverted = type.charAt(0) == '!';
|
boolean reverted = type.charAt(0) == '!';
|
||||||
@@ -53,7 +43,7 @@ public final class PathMatchers {
|
|||||||
type = type.substring(1);
|
type = type.substring(1);
|
||||||
}
|
}
|
||||||
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
||||||
PathMatcherType matcherType = BuiltInRegistries.PATH_MATCHER_TYPE.getValue(key);
|
PathMatcherType<? extends Condition<PathContext>> matcherType = BuiltInRegistries.PATH_MATCHER_TYPE.getValue(key);
|
||||||
if (matcherType == null) {
|
if (matcherType == null) {
|
||||||
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
|
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class PatternPathMatcher implements Condition<PathContext> {
|
public final class PatternPathMatcher implements Condition<PathContext> {
|
||||||
public static final ConditionFactory<PathContext> FACTORY = new Factory();
|
public static final ConditionFactory<PathContext, PatternPathMatcher> FACTORY = new Factory();
|
||||||
private final Pattern pattern;
|
private final Pattern pattern;
|
||||||
|
|
||||||
public PatternPathMatcher(String pattern) {
|
public PatternPathMatcher(String pattern) {
|
||||||
@@ -23,7 +23,7 @@ public final class PatternPathMatcher implements Condition<PathContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Pattern pattern() {
|
public Pattern pattern() {
|
||||||
return pattern;
|
return this.pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,11 +32,11 @@ public final class PatternPathMatcher implements Condition<PathContext> {
|
|||||||
return this.pattern.matcher(pathStr).matches();
|
return this.pattern.matcher(pathStr).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory implements ConditionFactory<PathContext> {
|
private static class Factory implements ConditionFactory<PathContext, PatternPathMatcher> {
|
||||||
@Override
|
@Override
|
||||||
public Condition<PathContext> create(Map<String, Object> arguments) {
|
public PatternPathMatcher create(Map<String, Object> arguments) {
|
||||||
String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), () -> new LocalizedException("warning.config.conflict_matcher.pattern.missing_pattern"));
|
String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), () -> new LocalizedException("warning.config.conflict_matcher.pattern.missing_pattern"));
|
||||||
return new PatternPathMatcher(pattern);
|
return new PatternPathMatcher(pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.momirealms.craftengine.core.plugin.context;
|
||||||
|
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
|
||||||
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
|
||||||
|
public class CommonConditionType<T extends Condition<Context>> extends ConditionType<Context, T> {
|
||||||
|
|
||||||
|
public CommonConditionType(Key id, ConditionFactory<Context, T> factory) {
|
||||||
|
super(id, factory);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,38 +12,38 @@ import net.momirealms.craftengine.core.util.ResourceKey;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class CommonConditions {
|
public final class CommonConditions {
|
||||||
public static final ConditionType<Context> HAS_PLAYER = register(Key.ce("has_player"), HasPlayerCondition.factory());
|
public static final CommonConditionType<HasPlayerCondition<Context>> HAS_PLAYER = register(Key.ce("has_player"), HasPlayerCondition.factory());
|
||||||
public static final ConditionType<Context> HAS_ITEM = register(Key.ce("has_item"), HasItemCondition.factory());
|
public static final CommonConditionType<HasItemCondition<Context>> HAS_ITEM = register(Key.ce("has_item"), HasItemCondition.factory());
|
||||||
public static final ConditionType<Context> MATCH_ITEM = register(Key.ce("match_item"), MatchItemCondition.factory());
|
public static final CommonConditionType<MatchItemCondition<Context>> MATCH_ITEM = register(Key.ce("match_item"), MatchItemCondition.factory());
|
||||||
public static final ConditionType<Context> MATCH_ENTITY = register(Key.ce("match_entity"), MatchEntityCondition.factory());
|
public static final CommonConditionType<MatchEntityCondition<Context>> MATCH_ENTITY = register(Key.ce("match_entity"), MatchEntityCondition.factory());
|
||||||
public static final ConditionType<Context> MATCH_BLOCK = register(Key.ce("match_block"), MatchBlockCondition.factory());
|
public static final CommonConditionType<MatchBlockCondition<Context>> MATCH_BLOCK = register(Key.ce("match_block"), MatchBlockCondition.factory());
|
||||||
public static final ConditionType<Context> MATCH_BLOCK_PROPERTY = register(Key.ce("match_block_property"), MatchBlockPropertyCondition.factory());
|
public static final CommonConditionType<MatchBlockPropertyCondition<Context>> MATCH_BLOCK_PROPERTY = register(Key.ce("match_block_property"), MatchBlockPropertyCondition.factory());
|
||||||
public static final ConditionType<Context> TABLE_BONUS = register(Key.ce("table_bonus"), TableBonusCondition.factory());
|
public static final CommonConditionType<TableBonusCondition<Context>> TABLE_BONUS = register(Key.ce("table_bonus"), TableBonusCondition.factory());
|
||||||
public static final ConditionType<Context> SURVIVES_EXPLOSION = register(Key.ce("survives_explosion"), SurvivesExplosionCondition.factory());
|
public static final CommonConditionType<SurvivesExplosionCondition<Context>> SURVIVES_EXPLOSION = register(Key.ce("survives_explosion"), SurvivesExplosionCondition.factory());
|
||||||
public static final ConditionType<Context> ANY_OF = register(Key.ce("any_of"), AnyOfCondition.factory(CommonConditions::fromMap));
|
public static final CommonConditionType<AnyOfCondition<Context>> ANY_OF = register(Key.ce("any_of"), AnyOfCondition.factory(CommonConditions::fromMap));
|
||||||
public static final ConditionType<Context> ALL_OF = register(Key.ce("all_of"), AllOfCondition.factory(CommonConditions::fromMap));
|
public static final CommonConditionType<AllOfCondition<Context>> ALL_OF = register(Key.ce("all_of"), AllOfCondition.factory(CommonConditions::fromMap));
|
||||||
public static final ConditionType<Context> ENCHANTMENT = register(Key.ce("enchantment"), EnchantmentCondition.factory());
|
public static final CommonConditionType<EnchantmentCondition<Context>> ENCHANTMENT = register(Key.ce("enchantment"), EnchantmentCondition.factory());
|
||||||
public static final ConditionType<Context> INVERTED = register(Key.ce("inverted"), InvertedCondition.factory(CommonConditions::fromMap));
|
public static final CommonConditionType<InvertedCondition<Context>> INVERTED = register(Key.ce("inverted"), InvertedCondition.factory(CommonConditions::fromMap));
|
||||||
public static final ConditionType<Context> FALLING_BLOCK = register(Key.ce("falling_block"), FallingBlockCondition.factory());
|
public static final CommonConditionType<FallingBlockCondition<Context>> FALLING_BLOCK = register(Key.ce("falling_block"), FallingBlockCondition.factory());
|
||||||
public static final ConditionType<Context> RANDOM = register(Key.ce("random"), RandomCondition.factory());
|
public static final CommonConditionType<RandomCondition<Context>> RANDOM = register(Key.ce("random"), RandomCondition.factory());
|
||||||
public static final ConditionType<Context> DISTANCE = register(Key.ce("distance"), DistanceCondition.factory());
|
public static final CommonConditionType<DistanceCondition<Context>> DISTANCE = register(Key.ce("distance"), DistanceCondition.factory());
|
||||||
public static final ConditionType<Context> PERMISSION = register(Key.ce("permission"), PermissionCondition.factory());
|
public static final CommonConditionType<PermissionCondition<Context>> PERMISSION = register(Key.ce("permission"), PermissionCondition.factory());
|
||||||
public static final ConditionType<Context> EQUALS = register(Key.ce("equals"), StringEqualsCondition.factory());
|
public static final CommonConditionType<StringEqualsCondition<Context>> EQUALS = register(Key.ce("equals"), StringEqualsCondition.factory());
|
||||||
public static final ConditionType<Context> REGEX = register(Key.ce("regex"), StringRegexCondition.factory());
|
public static final CommonConditionType<StringRegexCondition<Context>> REGEX = register(Key.ce("regex"), StringRegexCondition.factory());
|
||||||
public static final ConditionType<Context> STRING_EQUALS = register(Key.ce("string_equals"), StringEqualsCondition.factory());
|
public static final CommonConditionType<StringEqualsCondition<Context>> STRING_EQUALS = register(Key.ce("string_equals"), StringEqualsCondition.factory());
|
||||||
public static final ConditionType<Context> STRING_CONTAINS = register(Key.ce("string_contains"), StringContainsCondition.factory());
|
public static final CommonConditionType<StringContainsCondition<Context>> STRING_CONTAINS = register(Key.ce("string_contains"), StringContainsCondition.factory());
|
||||||
public static final ConditionType<Context> EXPRESSION = register(Key.ce("expression"), ExpressionCondition.factory());
|
public static final CommonConditionType<ExpressionCondition<Context>> EXPRESSION = register(Key.ce("expression"), ExpressionCondition.factory());
|
||||||
public static final ConditionType<Context> IS_NULL = register(Key.ce("is_null"), IsNullCondition.factory());
|
public static final CommonConditionType<IsNullCondition<Context>> IS_NULL = register(Key.ce("is_null"), IsNullCondition.factory());
|
||||||
public static final ConditionType<Context> HAND = register(Key.ce("hand"), HandCondition.factory());
|
public static final CommonConditionType<HandCondition<Context>> HAND = register(Key.ce("hand"), HandCondition.factory());
|
||||||
public static final ConditionType<Context> ON_COOLDOWN = register(Key.ce("on_cooldown"), OnCooldownCondition.factory());
|
public static final CommonConditionType<OnCooldownCondition<Context>> ON_COOLDOWN = register(Key.ce("on_cooldown"), OnCooldownCondition.factory());
|
||||||
public static final ConditionType<Context> INVENTORY_HAS_ITEM = register(Key.ce("inventory_has_item"), InventoryHasItemCondition.factory());
|
public static final CommonConditionType<InventoryHasItemCondition<Context>> INVENTORY_HAS_ITEM = register(Key.ce("inventory_has_item"), InventoryHasItemCondition.factory());
|
||||||
public static final ConditionType<Context> MATCH_FURNITURE_VARIANT = register(Key.ce("match_furniture_variant"), MatchFurnitureVariantCondition.factory());
|
public static final CommonConditionType<MatchFurnitureVariantCondition<Context>> MATCH_FURNITURE_VARIANT = register(Key.ce("match_furniture_variant"), MatchFurnitureVariantCondition.factory());
|
||||||
|
|
||||||
private CommonConditions() {}
|
private CommonConditions() {}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionType<CTX> register(Key key, ConditionFactory<CTX> factory) {
|
public static <T extends Condition<Context>> CommonConditionType<T> register(Key key, ConditionFactory<Context, T> factory) {
|
||||||
ConditionType<CTX> type = new ConditionType<>(key, factory);
|
CommonConditionType<T> type = new CommonConditionType<>(key, factory);
|
||||||
((WritableRegistry<ConditionType<?>>) BuiltInRegistries.COMMON_CONDITION_TYPE)
|
((WritableRegistry<CommonConditionType<?>>) BuiltInRegistries.COMMON_CONDITION_TYPE)
|
||||||
.register(ResourceKey.create(Registries.COMMON_CONDITION_TYPE.location(), key), type);
|
.register(ResourceKey.create(Registries.COMMON_CONDITION_TYPE.location(), key), type);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public final class CommonConditions {
|
|||||||
type = type.substring(1);
|
type = type.substring(1);
|
||||||
}
|
}
|
||||||
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
||||||
ConditionType<Context> conditionType = (ConditionType<Context>) BuiltInRegistries.COMMON_CONDITION_TYPE.getValue(key);
|
CommonConditionType<? extends Condition<Context>> conditionType = BuiltInRegistries.COMMON_CONDITION_TYPE.getValue(key);
|
||||||
if (conditionType == null) {
|
if (conditionType == null) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
|
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,20 @@ package net.momirealms.craftengine.core.plugin.context;
|
|||||||
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
|
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
|
||||||
import net.momirealms.craftengine.core.util.Key;
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
|
||||||
public record ConditionType<CTX extends Context>(Key id, ConditionFactory<CTX> factory) {
|
public abstract class ConditionType<CTX extends Context, T extends Condition<CTX>> {
|
||||||
|
protected final Key id;
|
||||||
|
protected final ConditionFactory<CTX, T> factory;
|
||||||
|
|
||||||
|
public ConditionType(Key id, ConditionFactory<CTX, T> factory) {
|
||||||
|
this.id = id;
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Key id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConditionFactory<CTX, T> factory() {
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,15 @@ public final class AllOfCondition<CTX extends Context> implements Condition<CTX>
|
|||||||
return this.condition.test(ctx);
|
return this.condition.test(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
public static <CTX extends Context> ConditionFactory<CTX, AllOfCondition<CTX>> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||||
return new Factory<>(factory);
|
return new Factory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
|
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX, AllOfCondition<CTX>> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public AllOfCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
||||||
ResourceConfigUtils.get(arguments, "terms", "term"),
|
ResourceConfigUtils.get(arguments, "terms", "term"),
|
||||||
"warning.config.condition.all_of.missing_terms"
|
"warning.config.condition.all_of.missing_terms"
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ import java.util.Map;
|
|||||||
public final class AlwaysFalseCondition<CTX extends Context> implements Condition<CTX> {
|
public final class AlwaysFalseCondition<CTX extends Context> implements Condition<CTX> {
|
||||||
public static final AlwaysFalseCondition<Context> INSTANCE = new AlwaysFalseCondition<>();
|
public static final AlwaysFalseCondition<Context> INSTANCE = new AlwaysFalseCondition<>();
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, AlwaysFalseCondition<CTX>> factory() {
|
||||||
return new FactoryImpl<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, AlwaysFalseCondition<CTX>> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public AlwaysFalseCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return (Condition<CTX>) INSTANCE;
|
return (AlwaysFalseCondition<CTX>) INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,16 @@ public final class AlwaysTrueCondition<CTX extends Context> implements Condition
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, AlwaysTrueCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, AlwaysTrueCondition<CTX>> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public AlwaysTrueCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return (Condition<CTX>) INSTANCE;
|
return (AlwaysTrueCondition<CTX>) INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,15 +24,15 @@ public final class AnyOfCondition<CTX extends Context> implements Condition<CTX>
|
|||||||
return this.condition.test(ctx);
|
return this.condition.test(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
public static <CTX extends Context> ConditionFactory<CTX, AnyOfCondition<CTX>> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||||
return new Factory<>(factory);
|
return new Factory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
|
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX, AnyOfCondition<CTX>> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public AnyOfCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
||||||
ResourceConfigUtils.get(arguments, "terms", "term"),
|
ResourceConfigUtils.get(arguments, "terms", "term"),
|
||||||
"warning.config.condition.any_of.missing_terms"
|
"warning.config.condition.any_of.missing_terms"
|
||||||
@@ -50,4 +50,4 @@ public final class AnyOfCondition<CTX extends Context> implements Condition<CTX>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.plugin.context.Context;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ConditionFactory<CTX extends Context> {
|
public interface ConditionFactory<CTX extends Context, T extends Condition<CTX>> {
|
||||||
|
|
||||||
Condition<CTX> create(Map<String, Object> args);
|
T create(Map<String, Object> args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,17 +50,17 @@ public final class DistanceCondition<CTX extends Context> implements Condition<C
|
|||||||
return distanceSquared >= minSquared && distanceSquared <= maxSquared;
|
return distanceSquared >= minSquared && distanceSquared <= maxSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, DistanceCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, DistanceCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public DistanceCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
NumberProvider min = NumberProviders.fromObject(arguments.getOrDefault("min", 0));
|
NumberProvider min = NumberProviders.fromObject(arguments.getOrDefault("min", 0));
|
||||||
NumberProvider max = NumberProviders.fromObject(arguments.getOrDefault("max", 32));
|
NumberProvider max = NumberProviders.fromObject(arguments.getOrDefault("max", 32));
|
||||||
return new DistanceCondition<>(min, max);
|
return new DistanceCondition<>(min, max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,14 +31,14 @@ public final class EnchantmentCondition<CTX extends Context> implements Conditio
|
|||||||
return this.expression.apply(level);
|
return this.expression.apply(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, EnchantmentCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, EnchantmentCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public EnchantmentCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String predicate = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("predicate"), "warning.config.condition.enchantment.missing_predicate");
|
String predicate = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("predicate"), "warning.config.condition.enchantment.missing_predicate");
|
||||||
String[] split = predicate.split("(<=|>=|<|>|==|=)", 2);
|
String[] split = predicate.split("(<=|>=|<|>|==|=)", 2);
|
||||||
int level;
|
int level;
|
||||||
@@ -60,4 +60,4 @@ public final class EnchantmentCondition<CTX extends Context> implements Conditio
|
|||||||
return new EnchantmentCondition<>(Key.of(split[0]), expression);
|
return new EnchantmentCondition<>(Key.of(split[0]), expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,16 +31,16 @@ public final class ExpressionCondition<CTX extends Context> implements Condition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, ExpressionCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, ExpressionCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public ExpressionCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("expression"), "warning.config.condition.expression.missing_expression");
|
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("expression"), "warning.config.condition.expression.missing_expression");
|
||||||
return new ExpressionCondition<>(TextProviders.fromString(value));
|
return new ExpressionCondition<>(TextProviders.fromString(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,15 +13,15 @@ public final class FallingBlockCondition<CTX extends Context> implements Conditi
|
|||||||
return ctx.getOptionalParameter(DirectContextParameters.FALLING_BLOCK).orElse(false);
|
return ctx.getOptionalParameter(DirectContextParameters.FALLING_BLOCK).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, FallingBlockCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, FallingBlockCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public FallingBlockCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return new FallingBlockCondition<>();
|
return new FallingBlockCondition<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,14 +29,14 @@ public final class HandCondition<CTX extends Context> implements Condition<CTX>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, HandCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, HandCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public HandCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String hand = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("hand"), "warning.config.condition.hand.missing_hand");
|
String hand = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("hand"), "warning.config.condition.hand.missing_hand");
|
||||||
try {
|
try {
|
||||||
return new HandCondition<>(InteractionHand.valueOf(hand.toUpperCase(Locale.ENGLISH)));
|
return new HandCondition<>(InteractionHand.valueOf(hand.toUpperCase(Locale.ENGLISH)));
|
||||||
@@ -45,4 +45,4 @@ public final class HandCondition<CTX extends Context> implements Condition<CTX>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,15 @@ public final class HasItemCondition<CTX extends Context> implements Condition<CT
|
|||||||
return !ItemUtils.isEmpty(itemInHand);
|
return !ItemUtils.isEmpty(itemInHand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, HasItemCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, HasItemCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public HasItemCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return new HasItemCondition<>();
|
return new HasItemCondition<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,14 +19,14 @@ public final class HasPlayerCondition<CTX extends Context> implements Condition<
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, HasPlayerCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, HasPlayerCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public HasPlayerCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return new HasPlayerCondition<>();
|
return new HasPlayerCondition<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ public final class InventoryHasItemCondition<CTX extends Context> implements Con
|
|||||||
return player.clearOrCountMatchingInventoryItems(this.itemId, 0) >= this.count.getInt(ctx);
|
return player.clearOrCountMatchingInventoryItems(this.itemId, 0) >= this.count.getInt(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, InventoryHasItemCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, InventoryHasItemCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public InventoryHasItemCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(ResourceConfigUtils.get(arguments, "id", "item"), "warning.config.condition.inventory_has_item.missing_id"));
|
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(ResourceConfigUtils.get(arguments, "id", "item"), "warning.config.condition.inventory_has_item.missing_id"));
|
||||||
NumberProvider count = NumberProviders.fromObject(arguments.getOrDefault("count", 1));
|
NumberProvider count = NumberProviders.fromObject(arguments.getOrDefault("count", 1));
|
||||||
return new InventoryHasItemCondition<>(itemId, count);
|
return new InventoryHasItemCondition<>(itemId, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,15 +23,15 @@ public final class InvertedCondition<CTX extends Context> implements Condition<C
|
|||||||
return !this.condition.test(ctx);
|
return !this.condition.test(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
public static <CTX extends Context> ConditionFactory<CTX, InvertedCondition<CTX>> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||||
return new Factory<>(factory);
|
return new Factory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
|
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX, InvertedCondition<CTX>> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public InvertedCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Object termObj = ResourceConfigUtils.requireNonNullOrThrow(
|
Object termObj = ResourceConfigUtils.requireNonNullOrThrow(
|
||||||
ResourceConfigUtils.get(arguments, "term", "terms"),
|
ResourceConfigUtils.get(arguments, "term", "terms"),
|
||||||
"warning.config.condition.inverted.missing_term"
|
"warning.config.condition.inverted.missing_term"
|
||||||
@@ -49,4 +49,4 @@ public final class InvertedCondition<CTX extends Context> implements Condition<C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,16 +21,16 @@ public final class IsNullCondition<CTX extends Context> implements Condition<CTX
|
|||||||
return optional.isEmpty();
|
return optional.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, IsNullCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, IsNullCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public IsNullCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String argument = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("argument"), "warning.config.condition.is_null.missing_argument");
|
String argument = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("argument"), "warning.config.condition.is_null.missing_argument");
|
||||||
return new IsNullCondition<>(ContextKey.chain(argument));
|
return new IsNullCondition<>(ContextKey.chain(argument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,14 +40,14 @@ public final class MatchBlockCondition<CTX extends Context> implements Condition
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, MatchBlockCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, MatchBlockCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public MatchBlockCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
||||||
if (ids.isEmpty()) {
|
if (ids.isEmpty()) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.condition.match_block.missing_id");
|
throw new LocalizedResourceConfigException("warning.config.condition.match_block.missing_id");
|
||||||
@@ -59,4 +59,4 @@ public final class MatchBlockCondition<CTX extends Context> implements Condition
|
|||||||
NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")));
|
NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,14 +68,14 @@ public final class MatchBlockPropertyCondition<CTX extends Context> implements C
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, MatchBlockPropertyCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, MatchBlockPropertyCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public MatchBlockPropertyCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Object propertyObj = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("properties"), "warning.config.condition.match_block_property.missing_properties");
|
Object propertyObj = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("properties"), "warning.config.condition.match_block_property.missing_properties");
|
||||||
List<Pair<String, String>> propertyList = new ArrayList<>();
|
List<Pair<String, String>> propertyList = new ArrayList<>();
|
||||||
for (Map.Entry<String, Object> entry : MiscUtils.castToMap(propertyObj, false).entrySet()) {
|
for (Map.Entry<String, Object> entry : MiscUtils.castToMap(propertyObj, false).entrySet()) {
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ public final class MatchEntityCondition<CTX extends Context> implements Conditio
|
|||||||
return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent();
|
return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, MatchEntityCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, MatchEntityCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public MatchEntityCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
||||||
if (ids.isEmpty()) {
|
if (ids.isEmpty()) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.condition.match_entity.missing_id");
|
throw new LocalizedResourceConfigException("warning.config.condition.match_entity.missing_id");
|
||||||
@@ -41,4 +41,4 @@ public final class MatchEntityCondition<CTX extends Context> implements Conditio
|
|||||||
return new MatchEntityCondition<>(ids, regex);
|
return new MatchEntityCondition<>(ids, regex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,16 @@ public final class MatchFurnitureVariantCondition<CTX extends Context> implement
|
|||||||
return furniture.filter(value -> this.variants.contains(value.getCurrentVariant().name())).isPresent();
|
return furniture.filter(value -> this.variants.contains(value.getCurrentVariant().name())).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, MatchFurnitureVariantCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, MatchFurnitureVariantCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public MatchFurnitureVariantCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
List<String> variants = MiscUtils.getAsStringList(ResourceConfigUtils.get(arguments, "variant", "variants"));
|
List<String> variants = MiscUtils.getAsStringList(ResourceConfigUtils.get(arguments, "variant", "variants"));
|
||||||
return new MatchFurnitureVariantCondition<>(variants);
|
return new MatchFurnitureVariantCondition<>(variants);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,14 @@ public final class MatchItemCondition<CTX extends Context> implements Condition<
|
|||||||
return item.filter(value -> MiscUtils.matchRegex(value.id().asString(), this.ids, this.regexMatch)).isPresent();
|
return item.filter(value -> MiscUtils.matchRegex(value.id().asString(), this.ids, this.regexMatch)).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, MatchItemCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, MatchItemCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public MatchItemCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
List<String> ids = MiscUtils.getAsStringList(ResourceConfigUtils.get(arguments, "id", "item"));
|
List<String> ids = MiscUtils.getAsStringList(ResourceConfigUtils.get(arguments, "id", "item"));
|
||||||
if (ids.isEmpty()) {
|
if (ids.isEmpty()) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.condition.match_item.missing_id");
|
throw new LocalizedResourceConfigException("warning.config.condition.match_item.missing_id");
|
||||||
@@ -41,4 +41,4 @@ public final class MatchItemCondition<CTX extends Context> implements Condition<
|
|||||||
return new MatchItemCondition<>(ids, regex);
|
return new MatchItemCondition<>(ids, regex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,16 +26,16 @@ public final class OnCooldownCondition<CTX extends Context> implements Condition
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, OnCooldownCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, OnCooldownCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public OnCooldownCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.condition.on_cooldown.missing_id");
|
String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("id"), "warning.config.condition.on_cooldown.missing_id");
|
||||||
return new OnCooldownCondition<>(id);
|
return new OnCooldownCondition<>(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,16 @@ public final class PermissionCondition<CTX extends Context> implements Condition
|
|||||||
return player.map(value -> value.hasPermission(this.permission)).orElse(false);
|
return player.map(value -> value.hasPermission(this.permission)).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, PermissionCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, PermissionCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public PermissionCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String permission = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("permission"), "warning.config.condition.permission.missing_permission");
|
String permission = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("permission"), "warning.config.condition.permission.missing_permission");
|
||||||
return new PermissionCondition<>(permission);
|
return new PermissionCondition<>(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,17 +32,17 @@ public final class RandomCondition<CTX extends Context> implements Condition<CTX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, RandomCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, RandomCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public RandomCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
NumberProvider provider = NumberProviders.fromObject(arguments.getOrDefault("value", 0.5f));
|
NumberProvider provider = NumberProviders.fromObject(arguments.getOrDefault("value", 0.5f));
|
||||||
boolean useLastRandom = Boolean.parseBoolean(arguments.getOrDefault("use-last", "false").toString());
|
boolean useLastRandom = Boolean.parseBoolean(arguments.getOrDefault("use-last", "false").toString());
|
||||||
return new RandomCondition<>(provider, useLastRandom);
|
return new RandomCondition<>(provider, useLastRandom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,17 +22,17 @@ public final class StringContainsCondition<CTX extends Context> implements Condi
|
|||||||
return this.value1.get(ctx).contains(this.value2.get(ctx));
|
return this.value1.get(ctx).contains(this.value2.get(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, StringContainsCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, StringContainsCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public StringContainsCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String value1 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.string_contains.missing_value1");
|
String value1 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.string_contains.missing_value1");
|
||||||
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value2"), "warning.config.condition.string_contains.missing_value2");
|
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value2"), "warning.config.condition.string_contains.missing_value2");
|
||||||
return new StringContainsCondition<>(TextProviders.fromString(value1), TextProviders.fromString(value2));
|
return new StringContainsCondition<>(TextProviders.fromString(value1), TextProviders.fromString(value2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,17 +22,17 @@ public final class StringEqualsCondition<CTX extends Context> implements Conditi
|
|||||||
return this.value1.get(ctx).equals(this.value2.get(ctx));
|
return this.value1.get(ctx).equals(this.value2.get(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, StringEqualsCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, StringEqualsCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public StringEqualsCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String value1 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.string_equals.missing_value1");
|
String value1 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.string_equals.missing_value1");
|
||||||
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value2"), "warning.config.condition.string_equals.missing_value2");
|
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value2"), "warning.config.condition.string_equals.missing_value2");
|
||||||
return new StringEqualsCondition<>(TextProviders.fromString(value1), TextProviders.fromString(value2));
|
return new StringEqualsCondition<>(TextProviders.fromString(value1), TextProviders.fromString(value2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,17 +22,17 @@ public final class StringRegexCondition<CTX extends Context> implements Conditio
|
|||||||
return this.value.get(ctx).matches(this.regex.get(ctx));
|
return this.value.get(ctx).matches(this.regex.get(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, StringRegexCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, StringRegexCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public StringRegexCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value"), "warning.config.condition.string_regex.missing_value");
|
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value"), "warning.config.condition.string_regex.missing_value");
|
||||||
String regex = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("regex"), "warning.config.condition.string_regex.missing_regex");
|
String regex = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("regex"), "warning.config.condition.string_regex.missing_regex");
|
||||||
return new StringRegexCondition<>(TextProviders.fromString(value), TextProviders.fromString(regex));
|
return new StringRegexCondition<>(TextProviders.fromString(value), TextProviders.fromString(regex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,15 +20,15 @@ public final class SurvivesExplosionCondition<CTX extends Context> implements Co
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, SurvivesExplosionCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, SurvivesExplosionCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public SurvivesExplosionCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
return new SurvivesExplosionCondition<>();
|
return new SurvivesExplosionCondition<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,14 +32,14 @@ public final class TableBonusCondition<CTX extends Context> implements Condition
|
|||||||
return RandomUtils.generateRandomFloat(0, 1) < f;
|
return RandomUtils.generateRandomFloat(0, 1) < f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CTX extends Context> ConditionFactory<CTX> factory() {
|
public static <CTX extends Context> ConditionFactory<CTX, TableBonusCondition<CTX>> factory() {
|
||||||
return new Factory<>();
|
return new Factory<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
|
private static class Factory<CTX extends Context> implements ConditionFactory<CTX, TableBonusCondition<CTX>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
public TableBonusCondition<CTX> create(Map<String, Object> arguments) {
|
||||||
Object enchantmentObj = arguments.get("enchantment");
|
Object enchantmentObj = arguments.get("enchantment");
|
||||||
if (enchantmentObj == null) {
|
if (enchantmentObj == null) {
|
||||||
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_enchantment");
|
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_enchantment");
|
||||||
@@ -60,4 +60,4 @@ public final class TableBonusCondition<CTX extends Context> implements Condition
|
|||||||
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_chances");
|
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_chances");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,7 @@ import net.momirealms.craftengine.core.loot.entry.LootEntryContainerType;
|
|||||||
import net.momirealms.craftengine.core.loot.function.LootFunctionType;
|
import net.momirealms.craftengine.core.loot.function.LootFunctionType;
|
||||||
import net.momirealms.craftengine.core.loot.function.formula.Formula;
|
import net.momirealms.craftengine.core.loot.function.formula.Formula;
|
||||||
import net.momirealms.craftengine.core.loot.function.formula.FormulaType;
|
import net.momirealms.craftengine.core.loot.function.formula.FormulaType;
|
||||||
|
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherType;
|
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherType;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.resolution.Resolution;
|
import net.momirealms.craftengine.core.pack.conflict.resolution.Resolution;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionType;
|
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionType;
|
||||||
@@ -55,7 +56,8 @@ import net.momirealms.craftengine.core.pack.model.definition.tint.Tint;
|
|||||||
import net.momirealms.craftengine.core.pack.model.definition.tint.TintType;
|
import net.momirealms.craftengine.core.pack.model.definition.tint.TintType;
|
||||||
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgument;
|
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgument;
|
||||||
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType;
|
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType;
|
||||||
import net.momirealms.craftengine.core.plugin.context.ConditionType;
|
import net.momirealms.craftengine.core.plugin.context.CommonConditionType;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||||
import net.momirealms.craftengine.core.plugin.context.FunctionType;
|
import net.momirealms.craftengine.core.plugin.context.FunctionType;
|
||||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||||
@@ -84,12 +86,12 @@ public final class BuiltInRegistries {
|
|||||||
public static final Registry<SelectPropertyType<? extends SelectProperty>> SELECT_PROPERTY_TYPE = createConstantBoundRegistry(Registries.SELECT_PROPERTY_TYPE, 16);
|
public static final Registry<SelectPropertyType<? extends SelectProperty>> SELECT_PROPERTY_TYPE = createConstantBoundRegistry(Registries.SELECT_PROPERTY_TYPE, 16);
|
||||||
public static final Registry<RecipeSerializer<?, ? extends Recipe<?>>> RECIPE_SERIALIZER = createConstantBoundRegistry(Registries.RECIPE_SERIALIZER, 16);
|
public static final Registry<RecipeSerializer<?, ? extends Recipe<?>>> RECIPE_SERIALIZER = createConstantBoundRegistry(Registries.RECIPE_SERIALIZER, 16);
|
||||||
public static final Registry<FormulaType<? extends Formula>> FORMULA_TYPE = createConstantBoundRegistry(Registries.FORMULA_TYPE, 16);
|
public static final Registry<FormulaType<? extends Formula>> FORMULA_TYPE = createConstantBoundRegistry(Registries.FORMULA_TYPE, 16);
|
||||||
public static final Registry<PathMatcherType> PATH_MATCHER_TYPE = createConstantBoundRegistry(Registries.PATH_MATCHER_TYPE, 16);
|
public static final Registry<PathMatcherType<? extends Condition<PathContext>>> PATH_MATCHER_TYPE = createConstantBoundRegistry(Registries.PATH_MATCHER_TYPE, 16);
|
||||||
public static final Registry<ResolutionType<? extends Resolution>> RESOLUTION_TYPE = createConstantBoundRegistry(Registries.RESOLUTION_TYPE, 16);
|
public static final Registry<ResolutionType<? extends Resolution>> RESOLUTION_TYPE = createConstantBoundRegistry(Registries.RESOLUTION_TYPE, 16);
|
||||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Type<? extends CustomSmithingTransformRecipe.ItemDataProcessor>> SMITHING_RESULT_PROCESSOR_TYPE = createConstantBoundRegistry(Registries.SMITHING_RESULT_PROCESSOR_TYPE, 16);
|
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Type<? extends CustomSmithingTransformRecipe.ItemDataProcessor>> SMITHING_RESULT_PROCESSOR_TYPE = createConstantBoundRegistry(Registries.SMITHING_RESULT_PROCESSOR_TYPE, 16);
|
||||||
public static final Registry<ResourcePackHostType<? extends ResourcePackHost>> RESOURCE_PACK_HOST_TYPE = createConstantBoundRegistry(Registries.RESOURCE_PACK_HOST_TYPE, 16);
|
public static final Registry<ResourcePackHostType<? extends ResourcePackHost>> RESOURCE_PACK_HOST_TYPE = createConstantBoundRegistry(Registries.RESOURCE_PACK_HOST_TYPE, 16);
|
||||||
public static final Registry<FunctionType<? extends Context>> COMMON_FUNCTION_TYPE = createConstantBoundRegistry(Registries.COMMON_FUNCTION_TYPE, 128);
|
public static final Registry<FunctionType<? extends Context>> COMMON_FUNCTION_TYPE = createConstantBoundRegistry(Registries.COMMON_FUNCTION_TYPE, 128);
|
||||||
public static final Registry<ConditionType<? extends Context>> COMMON_CONDITION_TYPE = createConstantBoundRegistry(Registries.COMMON_CONDITION_TYPE, 128);
|
public static final Registry<CommonConditionType<? extends Condition<Context>>> COMMON_CONDITION_TYPE = createConstantBoundRegistry(Registries.COMMON_CONDITION_TYPE, 128);
|
||||||
public static final Registry<PlayerSelectorType<? extends Context>> PLAYER_SELECTOR_TYPE = createConstantBoundRegistry(Registries.PLAYER_SELECTOR_TYPE, 16);
|
public static final Registry<PlayerSelectorType<? extends Context>> PLAYER_SELECTOR_TYPE = createConstantBoundRegistry(Registries.PLAYER_SELECTOR_TYPE, 16);
|
||||||
public static final Registry<EquipmentType<? extends Equipment>> EQUIPMENT_TYPE = createConstantBoundRegistry(Registries.EQUIPMENT_TYPE, 8);
|
public static final Registry<EquipmentType<? extends Equipment>> EQUIPMENT_TYPE = createConstantBoundRegistry(Registries.EQUIPMENT_TYPE, 8);
|
||||||
public static final Registry<SlotDisplay.Type<?>> SLOT_DISPLAY_TYPE = createConstantBoundRegistry(Registries.SLOT_DISPLAY_TYPE, 16);
|
public static final Registry<SlotDisplay.Type<?>> SLOT_DISPLAY_TYPE = createConstantBoundRegistry(Registries.SLOT_DISPLAY_TYPE, 16);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import net.momirealms.craftengine.core.loot.entry.LootEntryContainerType;
|
|||||||
import net.momirealms.craftengine.core.loot.function.LootFunctionType;
|
import net.momirealms.craftengine.core.loot.function.LootFunctionType;
|
||||||
import net.momirealms.craftengine.core.loot.function.formula.Formula;
|
import net.momirealms.craftengine.core.loot.function.formula.Formula;
|
||||||
import net.momirealms.craftengine.core.loot.function.formula.FormulaType;
|
import net.momirealms.craftengine.core.loot.function.formula.FormulaType;
|
||||||
|
import net.momirealms.craftengine.core.pack.conflict.PathContext;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherType;
|
import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherType;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.resolution.Resolution;
|
import net.momirealms.craftengine.core.pack.conflict.resolution.Resolution;
|
||||||
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionType;
|
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionType;
|
||||||
@@ -55,7 +56,8 @@ import net.momirealms.craftengine.core.pack.model.definition.tint.Tint;
|
|||||||
import net.momirealms.craftengine.core.pack.model.definition.tint.TintType;
|
import net.momirealms.craftengine.core.pack.model.definition.tint.TintType;
|
||||||
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgument;
|
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgument;
|
||||||
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType;
|
import net.momirealms.craftengine.core.plugin.config.template.argument.TemplateArgumentType;
|
||||||
import net.momirealms.craftengine.core.plugin.context.ConditionType;
|
import net.momirealms.craftengine.core.plugin.context.CommonConditionType;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||||
import net.momirealms.craftengine.core.plugin.context.FunctionType;
|
import net.momirealms.craftengine.core.plugin.context.FunctionType;
|
||||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||||
@@ -88,12 +90,12 @@ public final class Registries {
|
|||||||
public static final ResourceKey<Registry<SelectPropertyType<? extends SelectProperty>>> SELECT_PROPERTY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_type"));
|
public static final ResourceKey<Registry<SelectPropertyType<? extends SelectProperty>>> SELECT_PROPERTY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_type"));
|
||||||
public static final ResourceKey<Registry<RecipeSerializer<?, ? extends Recipe<?>>>> RECIPE_SERIALIZER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_serializer"));
|
public static final ResourceKey<Registry<RecipeSerializer<?, ? extends Recipe<?>>>> RECIPE_SERIALIZER = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_serializer"));
|
||||||
public static final ResourceKey<Registry<FormulaType<? extends Formula>>> FORMULA_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("formula_type"));
|
public static final ResourceKey<Registry<FormulaType<? extends Formula>>> FORMULA_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("formula_type"));
|
||||||
public static final ResourceKey<Registry<PathMatcherType>> PATH_MATCHER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_type"));
|
public static final ResourceKey<Registry<PathMatcherType<? extends Condition<PathContext>>>> PATH_MATCHER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_type"));
|
||||||
public static final ResourceKey<Registry<ResolutionType<? extends Resolution>>> RESOLUTION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_type"));
|
public static final ResourceKey<Registry<ResolutionType<? extends Resolution>>> RESOLUTION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_type"));
|
||||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Type<? extends CustomSmithingTransformRecipe.ItemDataProcessor>>> SMITHING_RESULT_PROCESSOR_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_type"));
|
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Type<? extends CustomSmithingTransformRecipe.ItemDataProcessor>>> SMITHING_RESULT_PROCESSOR_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_type"));
|
||||||
public static final ResourceKey<Registry<ResourcePackHostType<? extends ResourcePackHost>>> RESOURCE_PACK_HOST_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_type"));
|
public static final ResourceKey<Registry<ResourcePackHostType<? extends ResourcePackHost>>> RESOURCE_PACK_HOST_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_type"));
|
||||||
public static final ResourceKey<Registry<FunctionType<? extends Context>>> COMMON_FUNCTION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("common_function_type"));
|
public static final ResourceKey<Registry<FunctionType<? extends Context>>> COMMON_FUNCTION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("common_function_type"));
|
||||||
public static final ResourceKey<Registry<ConditionType<? extends Context>>> COMMON_CONDITION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("common_condition_type"));
|
public static final ResourceKey<Registry<CommonConditionType<? extends Condition<Context>>>> COMMON_CONDITION_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("common_condition_type"));
|
||||||
public static final ResourceKey<Registry<PlayerSelectorType<? extends Context>>> PLAYER_SELECTOR_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_type"));
|
public static final ResourceKey<Registry<PlayerSelectorType<? extends Context>>> PLAYER_SELECTOR_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_type"));
|
||||||
public static final ResourceKey<Registry<EquipmentType<? extends Equipment>>> EQUIPMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_type"));
|
public static final ResourceKey<Registry<EquipmentType<? extends Equipment>>> EQUIPMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_type"));
|
||||||
public static final ResourceKey<Registry<SlotDisplay.Type<?>>> SLOT_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
public static final ResourceKey<Registry<SlotDisplay.Type<?>>> SLOT_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
||||||
|
|||||||
Reference in New Issue
Block a user