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

冲突管理器重构

This commit is contained in:
XiaoMoMi
2025-12-27 05:07:14 +08:00
parent 1f8f23f1d3
commit b4988d2540
123 changed files with 551 additions and 958 deletions

View File

@@ -33,7 +33,6 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.core.block.BlockManager;
import net.momirealms.craftengine.core.entity.furniture.ExternalModel;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.loot.LootConditions;
import net.momirealms.craftengine.core.plugin.compatibility.*;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.context.CommonConditions;
@@ -125,12 +124,10 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
Key worldGuardRegion = Key.of("worldguard:region");
if (this.hasPlugin("WorldGuard")) {
runCatchingHook(() -> {
CommonConditions.register(worldGuardRegion, new WorldGuardRegionCondition.FactoryImpl<>());
LootConditions.register(worldGuardRegion, new WorldGuardRegionCondition.FactoryImpl<>());
CommonConditions.register(worldGuardRegion, WorldGuardRegionCondition.factory());
}, "WorldGuard");
} else {
CommonConditions.register(worldGuardRegion, new AlwaysFalseCondition.FactoryImpl<>());
LootConditions.register(worldGuardRegion, new AlwaysFalseCondition.FactoryImpl<>());
CommonConditions.register(worldGuardRegion, AlwaysFalseCondition.factory());
}
if (this.hasPlugin("Geyser-Spigot")) {
this.hasGeyser = true;

View File

@@ -8,6 +8,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.condition.AlwaysTrueCondition;
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
@@ -33,6 +34,10 @@ public class WorldGuardRegionCondition<CTX extends Context> implements Condition
this.regions = regions;
}
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
@Override
public boolean test(CTX ctx) {
if (this.regions.isEmpty()) return false;
@@ -55,11 +60,6 @@ public class WorldGuardRegionCondition<CTX extends Context> implements Condition
return false;
}
@Override
public Key type() {
return TYPE;
}
public enum MatchMode {
ANY((p, regions) -> {
for (String region : regions) {
@@ -85,7 +85,7 @@ public class WorldGuardRegionCondition<CTX extends Context> implements Condition
}
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -18,30 +18,30 @@ import java.util.function.Predicate;
public class LootConditions {
static {
register(CommonConditions.MATCH_ITEM, new MatchItemCondition.FactoryImpl<>());
register(CommonConditions.MATCH_BLOCK_PROPERTY, new MatchBlockPropertyCondition.FactoryImpl<>());
register(CommonConditions.TABLE_BONUS, new TableBonusCondition.FactoryImpl<>());
register(CommonConditions.SURVIVES_EXPLOSION, new SurvivesExplosionCondition.FactoryImpl<>());
register(CommonConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(LootConditions::fromMap));
register(CommonConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(LootConditions::fromMap));
register(CommonConditions.HAS_PLAYER, new HasPlayerCondition.FactoryImpl<>());
register(CommonConditions.HAS_ITEM, new HasItemCondition.FactoryImpl<>());
register(CommonConditions.ENCHANTMENT, new EnchantmentCondition.Factory<>());
register(CommonConditions.INVERTED, new InvertedCondition.FactoryImpl<>(LootConditions::fromMap));
register(CommonConditions.FALLING_BLOCK, new FallingBlockCondition.FactoryImpl<>());
register(CommonConditions.RANDOM, new RandomCondition.FactoryImpl<>());
register(CommonConditions.DISTANCE, new DistanceCondition.FactoryImpl<>());
register(CommonConditions.PERMISSION, new PermissionCondition.FactoryImpl<>());
register(CommonConditions.EQUALS, new StringEqualsCondition.FactoryImpl<>());
register(CommonConditions.STRING_REGEX, new StringRegexCondition.FactoryImpl<>());
register(CommonConditions.STRING_EQUALS, new StringEqualsCondition.FactoryImpl<>());
register(CommonConditions.STRING_CONTAINS, new StringContainsCondition.FactoryImpl<>());
register(CommonConditions.EXPRESSION, new ExpressionCondition.FactoryImpl<>());
register(CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>());
register(CommonConditions.HAND, new HandCondition.FactoryImpl<>());
register(CommonConditions.ON_COOLDOWN, new OnCooldownCondition.FactoryImpl<>());
register(CommonConditions.INVENTORY_HAS_ITEM, new InventoryHasItemCondition.FactoryImpl<>());
register(CommonConditions.MATCH_FURNITURE_VARIANT, new MatchFurnitureVariantCondition.FactoryImpl<>());
register(CommonConditions.MATCH_ITEM, MatchItemCondition.factory());
register(CommonConditions.MATCH_BLOCK_PROPERTY, MatchBlockPropertyCondition.factory());
register(CommonConditions.TABLE_BONUS, TableBonusCondition.factory());
register(CommonConditions.SURVIVES_EXPLOSION, SurvivesExplosionCondition.factory());
register(CommonConditions.ANY_OF, AnyOfCondition.factory(LootConditions::fromMap));
register(CommonConditions.ALL_OF, AllOfCondition.factory(LootConditions::fromMap));
register(CommonConditions.HAS_PLAYER, HasPlayerCondition.factory());
register(CommonConditions.HAS_ITEM, HasItemCondition.factory());
register(CommonConditions.ENCHANTMENT, EnchantmentCondition.factory());
register(CommonConditions.INVERTED, InvertedCondition.factory(LootConditions::fromMap));
register(CommonConditions.FALLING_BLOCK, FallingBlockCondition.factory());
register(CommonConditions.RANDOM, RandomCondition.factory());
register(CommonConditions.DISTANCE, DistanceCondition.factory());
register(CommonConditions.PERMISSION, PermissionCondition.factory());
register(CommonConditions.EQUALS, StringEqualsCondition.factory());
register(CommonConditions.STRING_REGEX, StringRegexCondition.factory());
register(CommonConditions.STRING_EQUALS, StringEqualsCondition.factory());
register(CommonConditions.STRING_CONTAINS, StringContainsCondition.factory());
register(CommonConditions.EXPRESSION, ExpressionCondition.factory());
register(CommonConditions.IS_NULL, IsNullCondition.factory());
register(CommonConditions.HAND, HandCondition.factory());
register(CommonConditions.ON_COOLDOWN, OnCooldownCondition.factory());
register(CommonConditions.INVENTORY_HAS_ITEM, InventoryHasItemCondition.factory());
register(CommonConditions.MATCH_FURNITURE_VARIANT, MatchFurnitureVariantCondition.factory());
}
public static void register(Key key, ConditionFactory<LootContext> factory) {

View File

@@ -14,7 +14,7 @@ import net.momirealms.craftengine.core.item.equipment.TrimBasedEquipment;
import net.momirealms.craftengine.core.pack.atlas.Atlas;
import net.momirealms.craftengine.core.pack.atlas.TexturedModel;
import net.momirealms.craftengine.core.pack.conflict.PathContext;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
import net.momirealms.craftengine.core.pack.host.ResourcePackHosts;
import net.momirealms.craftengine.core.pack.host.impl.NoneHost;
@@ -3296,7 +3296,7 @@ public abstract class AbstractPackManager implements PackManager {
PathContext relativeCTX = PathContext.of(relative);
PathContext targetCTX = PathContext.of(targetPath);
PathContext sourceCTX = PathContext.of(sourcePath);
for (ResolutionConditional resolution : Config.resolutions()) {
for (ConditionalResolution resolution : Config.resolutions()) {
if (resolution.matcher().test(relativeCTX)) {
resolution.resolution().run(targetCTX, sourceCTX);
return;

View File

@@ -5,19 +5,19 @@ import net.momirealms.craftengine.core.plugin.context.ContextHolder;
import java.nio.file.Path;
public class PathContext extends AbstractCommonContext {
public final class PathContext extends AbstractCommonContext {
private final Path path;
public PathContext(ContextHolder holder, Path path) {
public PathContext(Path path, ContextHolder holder) {
super(holder);
this.path = path;
}
public Path path() {
return path;
return this.path;
}
public static PathContext of(Path path) {
return new PathContext(ContextHolder.empty(), path);
return new PathContext(path, ContextHolder.empty());
}
}

View File

@@ -10,12 +10,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class PathMatcherContains implements Condition<PathContext> {
private final String path;
public PathMatcherContains(String path) {
this.path = path;
}
public record ContainsPathMatcher(String path) implements Condition<PathContext> {
public static final Key ID = Key.of("craftengine:contains");
public static final ConditionFactory<PathContext> FACTORY = new Factory();
@Override
public boolean test(PathContext path) {
@@ -23,17 +20,11 @@ public class PathMatcherContains implements Condition<PathContext> {
return pathStr.contains(this.path);
}
@Override
public Key type() {
return PathMatchers.CONTAINS;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
return new PathMatcherContains(path);
return new ContainsPathMatcher(path);
}
}
}

View File

@@ -10,12 +10,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class PathMatcherExact implements Condition<PathContext> {
private final String path;
public PathMatcherExact(String path) {
this.path = path;
}
public record ExactPathMatcher(String path) implements Condition<PathContext> {
public static final ConditionFactory<PathContext> FACTORY = new Factory();
public static final Key ID = Key.of("craftengine:exact");
@Override
public boolean test(PathContext path) {
@@ -23,17 +20,11 @@ public class PathMatcherExact implements Condition<PathContext> {
return pathStr.equals(this.path);
}
@Override
public Key type() {
return PathMatchers.EXACT;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
return new PathMatcherExact(path);
return new ExactPathMatcher(path);
}
}
}

View File

@@ -9,12 +9,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class PathMatcherFilename implements Condition<PathContext> {
private final String name;
public PathMatcherFilename(String name) {
this.name = name;
}
public record FilenamePathMatcher(String name) implements Condition<PathContext> {
public static final ConditionFactory<PathContext> FACTORY = new Factory();
public static final Key ID = Key.of("craftengine:filename");
@Override
public boolean test(PathContext path) {
@@ -22,17 +19,11 @@ public class PathMatcherFilename implements Condition<PathContext> {
return fileName.equals(name);
}
@Override
public Key type() {
return PathMatchers.FILENAME;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
return new PathMatcherFilename(name);
return new FilenamePathMatcher(name);
}
}
}

View File

@@ -11,12 +11,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class PathMatcherParentPrefix implements Condition<PathContext> {
private final String prefix;
public PathMatcherParentPrefix(String prefix) {
this.prefix = prefix;
}
public record ParentPrefixPathMatcher(String prefix) implements Condition<PathContext> {
public static final ConditionFactory<PathContext> FACTORY = new Factory();
public static final Key ID = Key.of("craftengine:parent_path_prefix");
@Override
public boolean test(PathContext path) {
@@ -26,17 +23,11 @@ public class PathMatcherParentPrefix implements Condition<PathContext> {
return pathStr.startsWith(this.prefix);
}
@Override
public Key type() {
return PathMatchers.PARENT_PATH_PREFIX;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
return new PathMatcherParentPrefix(prefix);
return new ParentPrefixPathMatcher(prefix);
}
}
}

View File

@@ -11,12 +11,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class PathMatcherParentSuffix implements Condition<PathContext> {
private final String suffix;
public PathMatcherParentSuffix(String suffix) {
this.suffix = suffix;
}
public record ParentSuffixPathMatcher(String suffix) implements Condition<PathContext> {
public static final ConditionFactory<PathContext> FACTORY = new Factory();
public static final Key ID = Key.of("craftengine:parent_path_suffix");
@Override
public boolean test(PathContext path) {
@@ -26,17 +23,11 @@ public class PathMatcherParentSuffix implements Condition<PathContext> {
return pathStr.endsWith(suffix);
}
@Override
public Key type() {
return PathMatchers.PARENT_PATH_SUFFIX;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
return new PathMatcherParentSuffix(suffix);
return new ParentSuffixPathMatcher(suffix);
}
}
}

View File

@@ -0,0 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.pack.conflict.PathContext;
import net.momirealms.craftengine.core.plugin.context.condition.ConditionFactory;
import net.momirealms.craftengine.core.util.Key;
public record PathMatcherType(Key id, ConditionFactory<PathContext> factory) {
}

View File

@@ -15,29 +15,24 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PathMatchers {
public static final Key EXACT = Key.of("craftengine:exact");
public static final Key CONTAINS = Key.of("craftengine:contains");
public static final Key FILENAME = Key.of("craftengine:filename");
public static final Key PARENT_PATH_SUFFIX = Key.of("craftengine:parent_path_suffix");
public static final Key PARENT_PATH_PREFIX = Key.of("craftengine:parent_path_prefix");
public static final Key PATTERN = Key.of("craftengine:pattern");
public final class PathMatchers {
public static final PathMatcherType ANY_OF = register(Key.of("craftengine:any_of"), AnyOfCondition.factory(PathMatchers::fromMap));
public static final PathMatcherType ALL_OF = register(Key.of("craftengine:all_of"), AllOfCondition.factory(PathMatchers::fromMap));
public static final PathMatcherType INVERTED = register(Key.of("craftengine:inverted"), InvertedCondition.factory(PathMatchers::fromMap));
public static final PathMatcherType CONTAINS = register(ContainsPathMatcher.ID, ContainsPathMatcher.FACTORY);
public static final PathMatcherType EXACT = register(ExactPathMatcher.ID, ExactPathMatcher.FACTORY);
public static final PathMatcherType FILENAME = register(FilenamePathMatcher.ID, FilenamePathMatcher.FACTORY);
public static final PathMatcherType PATTERN = register(PatternPathMatcher.ID, PatternPathMatcher.FACTORY);
public static final PathMatcherType PARENT_PATH_SUFFIX = register(ParentSuffixPathMatcher.ID, ParentSuffixPathMatcher.FACTORY);
public static final PathMatcherType PARENT_PATH_PREFIX = register(ParentPrefixPathMatcher.ID, ParentPrefixPathMatcher.FACTORY);
static {
register(CommonConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(PathMatchers::fromMap));
register(CommonConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(PathMatchers::fromMap));
register(CommonConditions.INVERTED, new InvertedCondition.FactoryImpl<>(PathMatchers::fromMap));
register(PARENT_PATH_SUFFIX, new PathMatcherParentSuffix.FactoryImpl());
register(PARENT_PATH_PREFIX, new PathMatcherParentPrefix.FactoryImpl());
register(PATTERN, new PathPatternMatcher.FactoryImpl());
register(EXACT, new PathMatcherExact.FactoryImpl());
register(FILENAME, new PathMatcherFilename.FactoryImpl());
register(CONTAINS, new PathMatcherContains.FactoryImpl());
}
private PathMatchers() {}
public static void register(Key key, ConditionFactory<PathContext> factory) {
((WritableRegistry<ConditionFactory<PathContext>>) BuiltInRegistries.PATH_MATCHER_FACTORY)
.register(ResourceKey.create(Registries.PATH_MATCHER_FACTORY.location(), key), factory);
public static PathMatcherType register(Key key, ConditionFactory<PathContext> factory) {
PathMatcherType type = new PathMatcherType(key, factory);
((WritableRegistry<PathMatcherType>) BuiltInRegistries.PATH_MATCHER_TYPE)
.register(ResourceKey.create(Registries.PATH_MATCHER_TYPE.location(), key), type);
return type;
}
public static List<Condition<PathContext>> fromMapList(List<Map<String, Object>> arguments) {
@@ -50,19 +45,15 @@ public class PathMatchers {
public static Condition<PathContext> fromMap(Map<String, Object> map) {
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type"));
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
if (key.value().charAt(0) == '!') {
ConditionFactory<PathContext> factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(new Key(key.namespace(), key.value().substring(1)));
if (factory == null) {
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
}
return new InvertedCondition<>(factory.create(map));
} else {
ConditionFactory<PathContext> factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
}
return factory.create(map);
boolean reverted = type.charAt(0) == '!';
if (reverted) {
type = type.substring(1);
}
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
PathMatcherType matcherType = BuiltInRegistries.PATH_MATCHER_TYPE.getValue(key);
if (matcherType == null) {
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
}
return reverted ? new InvertedCondition<>(matcherType.factory().create(map)) : matcherType.factory().create(map);
}
}

View File

@@ -11,38 +11,34 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.regex.Pattern;
public class PathPatternMatcher implements Condition<PathContext> {
public final class PatternPathMatcher implements Condition<PathContext> {
public static final ConditionFactory<PathContext> FACTORY = new Factory();
public static final Key ID = Key.of("craftengine:pattern");
private final Pattern pattern;
public PathPatternMatcher(String pattern) {
public PatternPathMatcher(String pattern) {
this.pattern = Pattern.compile(pattern);
}
public PathPatternMatcher(Pattern pattern) {
public PatternPathMatcher(Pattern pattern) {
this.pattern = pattern;
}
public Pattern pattern() {
return pattern;
}
@Override
public boolean test(PathContext path) {
String pathStr = CharacterUtils.replaceBackslashWithSlash(path.path().toString());
return this.pattern.matcher(pathStr).matches();
}
@Override
public Key type() {
return PathMatchers.PATTERN;
}
public Pattern pattern() {
return pattern;
}
public static class FactoryImpl implements ConditionFactory<PathContext> {
private static class Factory implements ConditionFactory<PathContext> {
@Override
public Condition<PathContext> create(Map<String, Object> arguments) {
String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), () -> new LocalizedException("warning.config.conflict_matcher.pattern.missing_pattern"));
return new PathPatternMatcher(pattern);
return new PatternPathMatcher(pattern);
}
}
}

View File

@@ -8,8 +8,9 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.Map;
public record ResolutionConditional(Condition<PathContext> matcher, Resolution resolution) implements Resolution {
public static final Factory FACTORY = new Factory();
public record ConditionalResolution(Condition<PathContext> matcher, Resolution resolution) implements Resolution {
public static final Key ID = Key.of("craftengine:conditional");
public static final ResolutionFactory FACTORY = new Factory();
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -18,18 +19,13 @@ public record ResolutionConditional(Condition<PathContext> matcher, Resolution r
}
}
@Override
public Key type() {
return Resolutions.CONDITIONAL;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public ResolutionConditional create(Map<String, Object> arguments) {
public ConditionalResolution create(Map<String, Object> arguments) {
Map<String, Object> term = MiscUtils.castToMap(arguments.get("term"), false);
Map<String, Object> resolution = MiscUtils.castToMap(arguments.get("resolution"), false);
return new ResolutionConditional(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
return new ConditionalResolution(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
}
}
}

View File

@@ -11,9 +11,12 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.HashSet;
import java.util.Map;
public class ResolutionMergeAltas implements Resolution {
public static final Factory FACTORY = new Factory();
public static final ResolutionMergeAltas INSTANCE = new ResolutionMergeAltas();
public final class MergeAltasResolution implements Resolution {
public static final Key ID = Key.of("craftengine:merge_atlas");
public static final ResolutionFactory FACTORY = new Factory();
public static final MergeAltasResolution INSTANCE = new MergeAltasResolution();
private MergeAltasResolution() {}
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -42,12 +45,7 @@ public class ResolutionMergeAltas implements Resolution {
}
}
@Override
public Key type() {
return Resolutions.MERGE_ATLAS;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {

View File

@@ -11,9 +11,12 @@ import net.momirealms.craftengine.core.util.Key;
import java.util.HashSet;
import java.util.Map;
public class ResolutionMergeFont implements Resolution {
public static final Factory FACTORY = new Factory();
public static final ResolutionMergeFont INSTANCE = new ResolutionMergeFont();
public final class MergeFontResolution implements Resolution {
public static final Key ID = Key.of("craftengine:merge_font");
public static final ResolutionFactory FACTORY = new Factory();
public static final MergeFontResolution INSTANCE = new MergeFontResolution();
private MergeFontResolution() {}
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -42,12 +45,7 @@ public class ResolutionMergeFont implements Resolution {
}
}
@Override
public Key type() {
return Resolutions.MERGE_FONT;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {

View File

@@ -10,13 +10,9 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.io.IOException;
import java.util.Map;
public class ResolutionMergeJson implements Resolution {
public static final Factory FACTORY = new Factory();
private final boolean deeply;
public ResolutionMergeJson(boolean deeply) {
this.deeply = deeply;
}
public record MergeJsonResolution(boolean deeply) implements Resolution {
public static final Key ID = Key.of("craftengine:merge_json");
public static final ResolutionFactory FACTORY = new Factory();
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -35,17 +31,12 @@ public class ResolutionMergeJson implements Resolution {
}
}
@Override
public Key type() {
return Resolutions.MERGE_JSON;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {
boolean deeply = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("deeply", false), "deeply");
return new ResolutionMergeJson(deeply);
return new MergeJsonResolution(deeply);
}
}
}

View File

@@ -13,8 +13,12 @@ import java.io.IOException;
import java.util.Map;
import java.util.TreeSet;
public class ResolutionMergeLegacyModel implements Resolution {
public static final Factory FACTORY = new Factory();
public final class MergeLegacyModelResolution implements Resolution {
public static final Key ID = Key.of("craftengine:merge_legacy_model");
public static final ResolutionFactory FACTORY = new Factory();
public static final MergeLegacyModelResolution INSTANCE = new MergeLegacyModelResolution();
private MergeLegacyModelResolution() {}
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -61,16 +65,11 @@ public class ResolutionMergeLegacyModel implements Resolution {
return element != null && element.isJsonArray();
}
@Override
public Key type() {
return Resolutions.MERGE_LEGACY_MODEL;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {
return new ResolutionMergeLegacyModel();
return INSTANCE;
}
}
}

View File

@@ -17,9 +17,13 @@ import java.nio.file.Path;
import java.util.*;
import java.util.function.Consumer;
public class ResolutionMergePackMcMeta implements Resolution {
public static final Factory FACTORY = new Factory();
public final class MergePackMcMetaResolution implements Resolution {
public static final Key ID = Key.of("craftengine:merge_pack_mcmeta");
public static final ResolutionFactory FACTORY = new Factory();
public static final Set<String> STANDARD_PACK_KEYS = ImmutableSet.of("pack", "features", "filter", "overlays", "language");
public static final MergePackMcMetaResolution INSTANCE = new MergePackMcMetaResolution();
private MergePackMcMetaResolution() {}
public static void merge(Path file1, Path file2) throws IOException {
// 第一步解析全部的mcmeta文件为json对象
@@ -255,15 +259,10 @@ public class ResolutionMergePackMcMeta implements Resolution {
}
}
@Override
public Key type() {
return Resolutions.MERGE_PACK_MCMETA;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {
return new ResolutionMergePackMcMeta();
return INSTANCE;
}
}
}

View File

@@ -6,6 +6,4 @@ import net.momirealms.craftengine.core.util.Key;
public interface Resolution {
void run(PathContext existing, PathContext conflict);
Key type();
}

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.resolution;
import java.util.Map;
@FunctionalInterface
public interface ResolutionFactory {
Resolution create(Map<String, Object> arguments);

View File

@@ -0,0 +1,6 @@
package net.momirealms.craftengine.core.pack.conflict.resolution;
import net.momirealms.craftengine.core.util.Key;
public record ResolutionType(Key id, ResolutionFactory factory) {
}

View File

@@ -10,36 +10,31 @@ import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
public class Resolutions {
public static final Key RETAIN_MATCHING = Key.of("craftengine:retain_matching");
public static final Key MERGE_JSON = Key.of("craftengine:merge_json");
public static final Key MERGE_ATLAS = Key.of("craftengine:merge_atlas");
public static final Key MERGE_FONT = Key.of("craftengine:merge_font");
public static final Key CONDITIONAL = Key.of("craftengine:conditional");
public static final Key MERGE_PACK_MCMETA = Key.of("craftengine:merge_pack_mcmeta");
public static final Key MERGE_LEGACY_MODEL = Key.of("craftengine:merge_legacy_model");
public final class Resolutions {
public static final ResolutionType RETAIN_MATCHING = register(RetainMatchingResolution.ID, RetainMatchingResolution.FACTORY);
public static final ResolutionType MERGE_JSON = register(MergeJsonResolution.ID, MergeJsonResolution.FACTORY);
public static final ResolutionType MERGE_ATLAS = register(MergeAltasResolution.ID, MergeAltasResolution.FACTORY);
public static final ResolutionType MERGE_FONT = register(MergeFontResolution.ID, MergeFontResolution.FACTORY);
public static final ResolutionType CONDITIONAL = register(ConditionalResolution.ID, ConditionalResolution.FACTORY);
public static final ResolutionType MERGE_PACK_MCMETA = register(MergePackMcMetaResolution.ID, MergePackMcMetaResolution.FACTORY);
public static final ResolutionType MERGE_LEGACY_MODEL = register(MergeLegacyModelResolution.ID, MergeLegacyModelResolution.FACTORY);
static {
register(RETAIN_MATCHING, RetainMatchingResolution.FACTORY);
register(MERGE_JSON, ResolutionMergeJson.FACTORY);
register(CONDITIONAL, ResolutionConditional.FACTORY);
register(MERGE_PACK_MCMETA, ResolutionMergePackMcMeta.FACTORY);
register(MERGE_ATLAS, ResolutionMergeAltas.FACTORY);
register(MERGE_LEGACY_MODEL, ResolutionMergeLegacyModel.FACTORY);
register(MERGE_FONT, ResolutionMergeFont.FACTORY);
}
private Resolutions() {}
public static void register(Key key, ResolutionFactory factory) {
((WritableRegistry<ResolutionFactory>) BuiltInRegistries.RESOLUTION_FACTORY).register(ResourceKey.create(Registries.RESOLUTION_FACTORY.location(), key), factory);
public static ResolutionType register(Key key, ResolutionFactory factory) {
ResolutionType type = new ResolutionType(key, factory);
((WritableRegistry<ResolutionType>) BuiltInRegistries.RESOLUTION_TYPE)
.register(ResourceKey.create(Registries.RESOLUTION_TYPE.location(), key), type);
return type;
}
public static Resolution fromMap(Map<String, Object> map) {
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_resolution.missing_type"));
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
ResolutionFactory factory = BuiltInRegistries.RESOLUTION_FACTORY.getValue(key);
if (factory == null) {
ResolutionType resolutionType = BuiltInRegistries.RESOLUTION_TYPE.getValue(key);
if (resolutionType == null) {
throw new LocalizedException("warning.config.conflict_resolution.invalid_type", type);
}
return factory.create(map);
return resolutionType.factory().create(map);
}
}

View File

@@ -12,13 +12,9 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;
public class RetainMatchingResolution implements Resolution {
public static final Factory FACTORY = new Factory();
private final Condition<PathContext> matcher;
public RetainMatchingResolution(Condition<PathContext> matcher) {
this.matcher = matcher;
}
public record RetainMatchingResolution(Condition<PathContext> matcher) implements Resolution {
public static final Key ID = Key.of("craftengine:retain_matching");
public static final ResolutionFactory FACTORY = new Factory();
@Override
public void run(PathContext existing, PathContext conflict) {
@@ -31,12 +27,7 @@ public class RetainMatchingResolution implements Resolution {
}
}
@Override
public Key type() {
return Resolutions.RETAIN_MATCHING;
}
public static class Factory implements ResolutionFactory {
private static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {

View File

@@ -32,7 +32,7 @@ import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class AlistHost implements ResourcePackHost {
public final class AlistHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final String apiUrl;
private final String userName;

View File

@@ -26,7 +26,7 @@ import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.ReentrantLock;
public class DropboxHost implements ResourcePackHost {
public final class DropboxHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final String appKey;
private final String appSecret;

View File

@@ -15,7 +15,7 @@ import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class ExternalHost implements ResourcePackHost {
public final class ExternalHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final ResourcePackDownloadData downloadData;

View File

@@ -26,7 +26,7 @@ import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class GitLabHost implements ResourcePackHost {
public final class GitLabHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final String gitlabUrl;
private final String accessToken;

View File

@@ -32,7 +32,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class LobFileHost implements ResourcePackHost {
public final class LobFileHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final String apiKey;
private final ProxySelector proxy;

View File

@@ -12,10 +12,12 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class NoneHost implements ResourcePackHost {
public final class NoneHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
public static final NoneHost INSTANCE = new NoneHost();
private NoneHost() {}
@Override
public CompletableFuture<List<ResourcePackDownloadData>> requestResourcePackDownloadLink(UUID player) {
return CompletableFuture.completedFuture(List.of());

View File

@@ -29,7 +29,7 @@ import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class OneDriveHost implements ResourcePackHost {
public final class OneDriveHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private final String clientId;
private final String clientSecret;

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.plugin.dependency.Dependencies;
import java.util.List;
import java.util.Map;
public class S3HostFactory implements ResourcePackHostFactory {
public final class S3HostFactory implements ResourcePackHostFactory {
public static final ResourcePackHostFactory INSTANCE = new S3HostFactory();
@Override

View File

@@ -18,7 +18,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class SelfHost implements ResourcePackHost {
public final class SelfHost implements ResourcePackHost {
public static final ResourcePackHostFactory FACTORY = new Factory();
private static final SelfHost INSTANCE = new SelfHost();

View File

@@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.util.Pair;
import java.util.ArrayList;
import java.util.List;
public class Overlay {
public final class Overlay {
private final PackVersion minVersion;
private final PackVersion maxVersion;
private final String directory;

View File

@@ -7,7 +7,7 @@ import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.List;
public class PackMcMeta {
public final class PackMcMeta {
private final List<Overlay> overlays;
public PackMcMeta(JsonObject mcmeta) {

View File

@@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
public class OverlayCombination {
public final class OverlayCombination {
private final List<VersionBasedEvent> versionBasedEvents;
private final List<Overlay> currentOverlays;
private int cursor;

View File

@@ -17,7 +17,7 @@ import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
public class ModelGeneration implements Supplier<JsonObject> {
public final class ModelGeneration implements Supplier<JsonObject> {
private static final Map<String, BiConsumer<Builder, Object>> BUILDER_FUNCTIONS = new HashMap<>();
static {
BUILDER_FUNCTIONS.put("textures", (b, data) -> {

View File

@@ -11,7 +11,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LegacyItemModel {
public final class LegacyItemModel {
private final List<ModelGeneration> modelsToGenerate;
private final String path;
private final List<LegacyOverridesModel> overrides;

View File

@@ -11,7 +11,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class LegacyOverridesModel implements Comparable<LegacyOverridesModel> {
public final class LegacyOverridesModel implements Comparable<LegacyOverridesModel> {
private final Map<String, Object> predicate;
private final String model;
private final int customModelData;

View File

@@ -2,16 +2,17 @@ package net.momirealms.craftengine.core.pack.model.simplified;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public class BowModelReader implements SimplifiedModelReader {
public final class BowModelReader implements SimplifiedModelReader {
public static final BowModelReader INSTANCE = new BowModelReader();
@Override
public @Nullable Map<String, Object> convert(List<String> textures, List<String> optionalModelPaths, Key id) {
public @NotNull Map<String, Object> convert(List<String> textures, List<String> optionalModelPaths, Key id) {
if (textures.size() != 4) {
throw new LocalizedResourceConfigException("warning.config.item.simplified_model.invalid_texture", "4", String.valueOf(textures.size()));
}
@@ -75,7 +76,7 @@ public class BowModelReader implements SimplifiedModelReader {
}
@Override
public @Nullable Map<String, Object> convert(List<String> models) {
public @NotNull Map<String, Object> convert(List<String> models) {
if (models.size() != 4) {
throw new LocalizedResourceConfigException("warning.config.item.simplified_model.invalid_model", "4", String.valueOf(models.size()));
}

View File

@@ -2,12 +2,13 @@ package net.momirealms.craftengine.core.pack.model.simplified;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public class ConditionModelReader implements SimplifiedModelReader {
public final class ConditionModelReader implements SimplifiedModelReader {
public static final ConditionModelReader FISHING_ROD = new ConditionModelReader("fishing_rod", "fishing_rod/cast", "_cast");
public static final ConditionModelReader ELYTRA = new ConditionModelReader("generated", "broken", "_broken");
public static final ConditionModelReader SHIELD = new ConditionModelReader("", "using_item", "_blocking");
@@ -58,7 +59,7 @@ public class ConditionModelReader implements SimplifiedModelReader {
}
@Override
public @Nullable Map<String, Object> convert(List<String> models) {
public @NotNull Map<String, Object> convert(List<String> models) {
if (models.size() != 2) {
throw new LocalizedResourceConfigException("warning.config.item.simplified_model.invalid_model", "2", String.valueOf(models.size()));
}

View File

@@ -2,16 +2,17 @@ package net.momirealms.craftengine.core.pack.model.simplified;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public class CrossbowModelReader implements SimplifiedModelReader {
public final class CrossbowModelReader implements SimplifiedModelReader {
public static final CrossbowModelReader INSTANCE = new CrossbowModelReader();
@Override
public @Nullable Map<String, Object> convert(List<String> textures, List<String> optionalModelPaths, Key id) {
public @NotNull Map<String, Object> convert(List<String> textures, List<String> optionalModelPaths, Key id) {
if (textures.size() != 6) {
throw new LocalizedResourceConfigException("warning.config.item.simplified_model.invalid_texture", "6", String.valueOf(textures.size()));
}
@@ -110,7 +111,7 @@ public class CrossbowModelReader implements SimplifiedModelReader {
}
@Override
public @Nullable Map<String, Object> convert(List<String> models) {
public @NotNull Map<String, Object> convert(List<String> models) {
if (models.size() != 6) {
throw new LocalizedResourceConfigException("warning.config.item.simplified_model.invalid_model", "6", String.valueOf(models.size()));
}

View File

@@ -2,13 +2,14 @@ package net.momirealms.craftengine.core.pack.model.simplified;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GeneratedModelReader implements SimplifiedModelReader {
public final class GeneratedModelReader implements SimplifiedModelReader {
public static final GeneratedModelReader GENERATED = new GeneratedModelReader("generated");
public static final GeneratedModelReader HANDHELD = new GeneratedModelReader("handheld");
@@ -49,7 +50,7 @@ public class GeneratedModelReader implements SimplifiedModelReader {
}
@Override
public @Nullable Map<String, Object> convert(List<String> optionalModelPaths) {
public @NotNull Map<String, Object> convert(List<String> optionalModelPaths) {
if (optionalModelPaths.size() >= 2) {
return Map.of(
"type", "composite",

View File

@@ -14,7 +14,7 @@ import dev.dejvokep.boostedyaml.utils.format.NodeRole;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.core.entity.furniture.ColliderType;
import net.momirealms.craftengine.core.pack.AbstractPackManager;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.PluginProperties;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
@@ -63,7 +63,7 @@ public class Config {
protected boolean resource_pack$remove_tinted_leaves_particle;
protected boolean resource_pack$generate_mod_assets;
protected boolean resource_pack$override_uniform_font;
protected List<ResolutionConditional> resource_pack$duplicated_files_handler;
protected List<ConditionalResolution> resource_pack$duplicated_files_handler;
protected List<String> resource_pack$merge_external_folders;
protected List<String> resource_pack$merge_external_zips;
protected Set<String> resource_pack$exclude_file_extensions;
@@ -417,7 +417,7 @@ public class Config {
try {
resource_pack$duplicated_files_handler = config.getMapList("resource-pack.duplicated-files-handler").stream().map(it -> {
Map<String, Object> args = MiscUtils.castToMap(it, false);
return ResolutionConditional.FACTORY.create(args);
return (ConditionalResolution) ConditionalResolution.FACTORY.create(args);
}).toList();
} catch (LocalizedResourceConfigException e) {
TranslationManager.instance().log(e.node(), e.arguments());
@@ -825,7 +825,7 @@ public class Config {
return instance.resource_pack$delivery$file_to_upload;
}
public static List<ResolutionConditional> resolutions() {
public static List<ConditionalResolution> resolutions() {
return instance.resource_pack$duplicated_files_handler;
}

View File

@@ -14,32 +14,32 @@ import java.util.Map;
public class CommonConditions {
static {
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAS_PLAYER, new HasPlayerCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAS_ITEM, new HasItemCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_ITEM, new MatchItemCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_ENTITY, new MatchEntityCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_BLOCK, new MatchBlockCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_BLOCK_PROPERTY, new MatchBlockPropertyCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.TABLE_BONUS, new TableBonusCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.SURVIVES_EXPLOSION, new SurvivesExplosionCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ENCHANTMENT, new EnchantmentCondition.Factory<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.INVERTED, new InvertedCondition.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.FALLING_BLOCK, new FallingBlockCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.RANDOM, new RandomCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.DISTANCE, new DistanceCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.PERMISSION, new PermissionCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.EQUALS, new StringEqualsCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_REGEX, new StringRegexCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_EQUALS, new StringEqualsCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_CONTAINS, new StringContainsCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.EXPRESSION, new ExpressionCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAND, new HandCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ON_COOLDOWN, new OnCooldownCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.INVENTORY_HAS_ITEM, new InventoryHasItemCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_FURNITURE_VARIANT, new MatchFurnitureVariantCondition.FactoryImpl<>());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAS_PLAYER, HasPlayerCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAS_ITEM, HasItemCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_ITEM, MatchItemCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_ENTITY, MatchEntityCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_BLOCK, MatchBlockCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_BLOCK_PROPERTY, MatchBlockPropertyCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.TABLE_BONUS, TableBonusCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.SURVIVES_EXPLOSION, SurvivesExplosionCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ANY_OF, AnyOfCondition.factory(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ALL_OF, AllOfCondition.factory(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ENCHANTMENT, EnchantmentCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.INVERTED, InvertedCondition.factory(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.FALLING_BLOCK, FallingBlockCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.RANDOM, RandomCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.DISTANCE, DistanceCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.PERMISSION, PermissionCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.EQUALS, StringEqualsCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_REGEX, StringRegexCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_EQUALS, StringEqualsCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.STRING_CONTAINS, StringContainsCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.EXPRESSION, ExpressionCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.IS_NULL, IsNullCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.HAND, HandCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.ON_COOLDOWN, OnCooldownCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.INVENTORY_HAS_ITEM, InventoryHasItemCondition.factory());
register(net.momirealms.craftengine.core.plugin.context.condition.CommonConditions.MATCH_FURNITURE_VARIANT, MatchFurnitureVariantCondition.factory());
}
public static void register(Key key, ConditionFactory<Context> factory) {
@@ -50,19 +50,15 @@ public class CommonConditions {
@SuppressWarnings("unchecked")
public static <CTX extends Context> Condition<CTX> fromMap(Map<String, Object> map) {
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.event.condition.missing_type");
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
if (type.charAt(0) == '!') {
ConditionFactory<Context> factory = BuiltInRegistries.EVENT_CONDITION_FACTORY.getValue(new Key(key.namespace(), key.value().substring(1)));
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
}
return new InvertedCondition<>((Condition<CTX>) factory.create(map));
} else {
ConditionFactory<Context> factory = BuiltInRegistries.EVENT_CONDITION_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
}
return (Condition<CTX>) factory.create(map);
boolean inverted = type.charAt(0) == '!';
if (inverted) {
type = type.substring(1);
}
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
ConditionFactory<Context> factory = BuiltInRegistries.EVENT_CONDITION_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
}
return inverted ? new InvertedCondition<>((Condition<CTX>) factory.create(map)) : (Condition<CTX>) factory.create(map);
}
}

View File

@@ -15,51 +15,51 @@ import java.util.*;
public class CommonFunctions {
static {
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.COMMAND, new CommandFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MESSAGE, new MessageFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ACTIONBAR, new ActionBarFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TITLE, new TitleFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.OPEN_WINDOW, new OpenWindowFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CANCEL_EVENT, new CancelEventFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.RUN, new RunFunction.FactoryImpl<>(CommonFunctions::fromMap, CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLACE_BLOCK, new PlaceBlockFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.UPDATE_BLOCK_PROPERTY, new UpdateBlockPropertyFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TRANSFORM_BLOCK, new TransformBlockFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.BREAK_BLOCK, new BreakBlockFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.UPDATE_INTERACTION_TICK, new UpdateInteractionFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_COUNT, new SetCountFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DROP_LOOT, new DropLootFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SWING_HAND, new SwingHandFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_FOOD, new SetFoodFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_SATURATION, new SetSaturationFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLAY_SOUND, new PlaySoundFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PARTICLE, new ParticleFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.POTION_EFFECT, new PotionEffectFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_POTION_EFFECT, new RemovePotionEffectFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.LEVELER_EXP, new LevelerExpFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_COOLDOWN, new SetCooldownFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_COOLDOWN, new RemoveCooldownFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SPAWN_FURNITURE, new SpawnFurnitureFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_FURNITURE, new RemoveFurnitureFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REPLACE_FURNITURE, new ReplaceFurnitureFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ROTATE_FURNITURE, new RotateFurnitureFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MYTHIC_MOBS_SKILL, new MythicMobsSkillFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TELEPORT, new TeleportFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_VARIABLE, new SetVariableFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TOAST, new ToastFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DAMAGE, new DamageFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MERCHANT_TRADE, new MerchantTradeFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_ENTITY, new RemoveEntityFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.IF_ELSE, new IfElseFunction.FactoryImpl<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ALTERNATIVES, new IfElseFunction.FactoryImpl<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.WHEN, new WhenFunction.FactoryImpl<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DAMAGE_ITEM, new DamageItemFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CYCLE_BLOCK_PROPERTY, new CycleBlockPropertyFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_EXP, new SetExpFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_LEVEL, new SetLevelFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLAY_TOTEM_ANIMATION, new PlayTotemAnimationFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CLOSE_INVENTORY, new CloseInventoryFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CLEAR_ITEM, new ClearItemFunction.FactoryImpl<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.COMMAND, new CommandFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MESSAGE, new MessageFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ACTIONBAR, new ActionBarFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TITLE, new TitleFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.OPEN_WINDOW, new OpenWindowFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CANCEL_EVENT, new CancelEventFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.RUN, new RunFunction.Factory<>(CommonFunctions::fromMap, CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLACE_BLOCK, new PlaceBlockFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.UPDATE_BLOCK_PROPERTY, new UpdateBlockPropertyFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TRANSFORM_BLOCK, new TransformBlockFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.BREAK_BLOCK, new BreakBlockFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.UPDATE_INTERACTION_TICK, new UpdateInteractionFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_COUNT, new SetCountFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DROP_LOOT, new DropLootFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SWING_HAND, new SwingHandFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_FOOD, new SetFoodFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_SATURATION, new SetSaturationFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLAY_SOUND, new PlaySoundFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PARTICLE, new ParticleFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.POTION_EFFECT, new PotionEffectFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_POTION_EFFECT, new RemovePotionEffectFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.LEVELER_EXP, new LevelerExpFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_COOLDOWN, new SetCooldownFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_COOLDOWN, new RemoveCooldownFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SPAWN_FURNITURE, new SpawnFurnitureFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_FURNITURE, new RemoveFurnitureFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REPLACE_FURNITURE, new ReplaceFurnitureFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ROTATE_FURNITURE, new RotateFurnitureFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MYTHIC_MOBS_SKILL, new MythicMobsSkillFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TELEPORT, new TeleportFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_VARIABLE, new SetVariableFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.TOAST, new ToastFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DAMAGE, new DamageFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.MERCHANT_TRADE, new MerchantTradeFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.REMOVE_ENTITY, new RemoveEntityFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.IF_ELSE, new IfElseFunction.Factory<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.ALTERNATIVES, new IfElseFunction.Factory<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.WHEN, new WhenFunction.Factory<>(CommonConditions::fromMap, CommonFunctions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.DAMAGE_ITEM, new DamageItemFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CYCLE_BLOCK_PROPERTY, new CycleBlockPropertyFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_EXP, new SetExpFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.SET_LEVEL, new SetLevelFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.PLAY_TOTEM_ANIMATION, new PlayTotemAnimationFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CLOSE_INVENTORY, new CloseInventoryFunction.Factory<>(CommonConditions::fromMap));
register(net.momirealms.craftengine.core.plugin.context.function.CommonFunctions.CLEAR_ITEM, new ClearItemFunction.Factory<>(CommonConditions::fromMap));
}
public static void register(Key key, FunctionFactory<Context> factory) {

View File

@@ -1,7 +1,5 @@
package net.momirealms.craftengine.core.plugin.context;
import net.momirealms.craftengine.core.util.Key;
import java.util.function.Predicate;
public interface Condition<CTX extends Context> extends Predicate<CTX> {
@@ -10,6 +8,4 @@ public interface Condition<CTX extends Context> extends Predicate<CTX> {
default boolean test(CTX ctx) {
return false;
}
Key type();
}

View File

@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -13,8 +12,8 @@ import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
public class AllOfCondition<CTX extends Context> implements Condition<CTX> {
protected final Predicate<CTX> condition;
public final class AllOfCondition<CTX extends Context> implements Condition<CTX> {
private final Predicate<CTX> condition;
public AllOfCondition(List<? extends Condition<CTX>> conditions) {
this.condition = MiscUtils.allOf(conditions);
@@ -25,17 +24,11 @@ public class AllOfCondition<CTX extends Context> implements Condition<CTX> {
return this.condition.test(ctx);
}
@Override
public Key type() {
return CommonConditions.ALL_OF;
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
return new Factory<>(factory);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
private final Function<Map<String, Object>, Condition<CTX>> factory;
public FactoryImpl(Function<Map<String, Object>, Condition<CTX>> factory) {
this.factory = factory;
}
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
@SuppressWarnings("unchecked")
@Override

View File

@@ -5,19 +5,21 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
import java.util.function.Function;
public 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<>();
@Override
public Key type() {
return CommonConditions.ALWAYS_FALSE;
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new FactoryImpl<>();
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
private static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
@SuppressWarnings("unchecked")
@Override
public Condition<CTX> create(Map<String, Object> arguments) {
return new AlwaysFalseCondition<>();
return (Condition<CTX>) INSTANCE;
}
}
}

View File

@@ -2,27 +2,27 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
public class AlwaysTrueCondition<CTX extends Context> implements Condition<CTX> {
@Override
public Key type() {
return CommonConditions.ALWAYS_TRUE;
}
public final class AlwaysTrueCondition<CTX extends Context> implements Condition<CTX> {
public static final AlwaysTrueCondition<Context> INSTANCE = new AlwaysTrueCondition<Context>();
@Override
public boolean test(CTX ctx) {
return true;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@SuppressWarnings("unchecked")
@Override
public Condition<CTX> create(Map<String, Object> arguments) {
return new AlwaysTrueCondition<>();
return (Condition<CTX>) INSTANCE;
}
}
}

View File

@@ -13,8 +13,8 @@ import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
public class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
protected final Predicate<CTX> condition;
public final class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
private final Predicate<CTX> condition;
public AnyOfCondition(List<? extends Condition<CTX>> conditions) {
this.condition = MiscUtils.anyOf(conditions);
@@ -25,17 +25,11 @@ public class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
return this.condition.test(ctx);
}
@Override
public Key type() {
return CommonConditions.ANY_OF;
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
return new Factory<>(factory);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
private final Function<Map<String, Object>, Condition<CTX>> factory;
public FactoryImpl(Function<Map<String, Object>, Condition<CTX>> factory) {
this.factory = factory;
}
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
@SuppressWarnings("unchecked")
@Override

View File

@@ -6,14 +6,13 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.world.WorldPosition;
import java.util.Map;
import java.util.Optional;
// TODO It's designed for players for the moment, better using entities
public class DistanceCondition<CTX extends Context> implements Condition<CTX> {
public final class DistanceCondition<CTX extends Context> implements Condition<CTX> {
private final NumberProvider min;
private final NumberProvider max;
@@ -22,11 +21,6 @@ public class DistanceCondition<CTX extends Context> implements Condition<CTX> {
this.min = min;
}
@Override
public Key type() {
return CommonConditions.DISTANCE;
}
@Override
public boolean test(CTX ctx) {
float min = this.min.getFloat(ctx);
@@ -56,7 +50,11 @@ public class DistanceCondition<CTX extends Context> implements Condition<CTX> {
return distanceSquared >= minSquared && distanceSquared <= maxSquared;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -13,7 +13,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public class EnchantmentCondition<CTX extends Context> implements Condition<CTX> {
public final class EnchantmentCondition<CTX extends Context> implements Condition<CTX> {
private final Key id;
private final Function<Integer, Boolean> expression;
@@ -22,11 +22,6 @@ public class EnchantmentCondition<CTX extends Context> implements Condition<CTX>
this.id = id;
}
@Override
public Key type() {
return CommonConditions.ENCHANTMENT;
}
@Override
public boolean test(CTX ctx) {
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
@@ -36,7 +31,11 @@ public class EnchantmentCondition<CTX extends Context> implements Condition<CTX>
return this.expression.apply(level);
}
public static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -8,23 +8,17 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class ExpressionCondition<CTX extends Context> implements Condition<CTX> {
public final class ExpressionCondition<CTX extends Context> implements Condition<CTX> {
private final TextProvider expression;
public ExpressionCondition(TextProvider expression) {
this.expression = expression;
}
@Override
public Key type() {
return CommonConditions.EXPRESSION;
}
@Override
public boolean test(CTX ctx) {
String exp = this.expression.get(ctx).replace("\\<", "<"); // fixme minimessage added a \ before <
@@ -37,7 +31,11 @@ public class ExpressionCondition<CTX extends Context> implements Condition<CTX>
}
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -3,23 +3,21 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
public class FallingBlockCondition<CTX extends Context> implements Condition<CTX> {
@Override
public Key type() {
return CommonConditions.FALLING_BLOCK;
}
public final class FallingBlockCondition<CTX extends Context> implements Condition<CTX> {
@Override
public boolean test(CTX ctx) {
return ctx.getOptionalParameter(DirectContextParameters.FALLING_BLOCK).orElse(false);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -6,25 +6,19 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.EnumUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
public class HandCondition<CTX extends Context> implements Condition<CTX> {
public final class HandCondition<CTX extends Context> implements Condition<CTX> {
private final InteractionHand hand;
public HandCondition(InteractionHand hand) {
this.hand = hand;
}
@Override
public Key type() {
return CommonConditions.HAND;
}
@Override
public boolean test(CTX ctx) {
Optional<InteractionHand> optional = ctx.getOptionalParameter(DirectContextParameters.HAND);
@@ -35,7 +29,11 @@ public class HandCondition<CTX extends Context> implements Condition<CTX> {
return false;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -5,21 +5,15 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.ItemUtils;
import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
import java.util.Optional;
public class HasItemCondition<CTX extends Context> implements Condition<CTX> {
public final class HasItemCondition<CTX extends Context> implements Condition<CTX> {
public HasItemCondition() {
}
@Override
public Key type() {
return CommonConditions.HAS_ITEM;
}
@Override
public boolean test(CTX ctx) {
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
@@ -28,7 +22,11 @@ public class HasItemCondition<CTX extends Context> implements Condition<CTX> {
return !ItemUtils.isEmpty(itemInHand);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -3,20 +3,14 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
import net.momirealms.craftengine.core.util.Key;
import java.util.Map;
public class HasPlayerCondition<CTX extends Context> implements Condition<CTX> {
public final class HasPlayerCondition<CTX extends Context> implements Condition<CTX> {
public HasPlayerCondition() {
}
@Override
public Key type() {
return CommonConditions.HAS_PLAYER;
}
@Override
public boolean test(CTX ctx) {
if (ctx instanceof PlayerOptionalContext context) {
@@ -25,7 +19,11 @@ public class HasPlayerCondition<CTX extends Context> implements Condition<CTX> {
return false;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -12,7 +12,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Optional;
public class InventoryHasItemCondition<CTX extends Context> implements Condition<CTX> {
public final class InventoryHasItemCondition<CTX extends Context> implements Condition<CTX> {
private final Key itemId;
private final NumberProvider count;
@@ -21,11 +21,6 @@ public class InventoryHasItemCondition<CTX extends Context> implements Condition
this.count = count;
}
@Override
public Key type() {
return CommonConditions.INVENTORY_HAS_ITEM;
}
@Override
public boolean test(CTX ctx) {
Optional<Player> optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
@@ -36,7 +31,11 @@ public class InventoryHasItemCondition<CTX extends Context> implements Condition
return player.clearOrCountMatchingInventoryItems(this.itemId, 0) >= this.count.getInt(ctx);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -12,7 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class InvertedCondition<CTX extends Context> implements Condition<CTX> {
public final class InvertedCondition<CTX extends Context> implements Condition<CTX> {
protected final Condition<CTX> condition;
public InvertedCondition(Condition<CTX> condition) {
@@ -24,17 +23,11 @@ public class InvertedCondition<CTX extends Context> implements Condition<CTX> {
return !this.condition.test(ctx);
}
@Override
public Key type() {
return CommonConditions.INVERTED;
public static <CTX extends Context> ConditionFactory<CTX> factory(Function<Map<String, Object>, Condition<CTX>> factory) {
return new Factory<>(factory);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
private final Function<Map<String, Object>, Condition<CTX>> factory;
public FactoryImpl(Function<Map<String, Object>, Condition<CTX>> factory) {
this.factory = factory;
}
private record Factory<CTX extends Context>(Function<Map<String, Object>, Condition<CTX>> factory) implements ConditionFactory<CTX> {
@SuppressWarnings("unchecked")
@Override
@@ -43,7 +36,7 @@ public class InvertedCondition<CTX extends Context> implements Condition<CTX> {
ResourceConfigUtils.get(arguments, "term", "terms"),
"warning.config.condition.inverted.missing_term"
);
if (termObj instanceof Map<?,?> map) {
if (termObj instanceof Map<?, ?> map) {
return new InvertedCondition<>(this.factory.apply(MiscUtils.castToMap(map, false)));
} else if (termObj instanceof List<?> list) {
List<Condition<CTX>> conditions = new ArrayList<>();

View File

@@ -3,31 +3,29 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.ContextKey;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Optional;
public class IsNullCondition<CTX extends Context> implements Condition<CTX> {
public final class IsNullCondition<CTX extends Context> implements Condition<CTX> {
private final ContextKey<?> key;
public IsNullCondition(ContextKey<?> key) {
this.key = key;
}
@Override
public Key type() {
return CommonConditions.IS_NULL;
}
@Override
public boolean test(CTX ctx) {
Optional<?> optional = ctx.getOptionalParameter(this.key);
return optional.isEmpty();
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -6,7 +6,6 @@ import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.ExistingBlock;
@@ -15,7 +14,7 @@ import net.momirealms.craftengine.core.world.WorldPosition;
import java.util.*;
public class MatchBlockCondition<CTX extends Context> implements Condition<CTX> {
public final class MatchBlockCondition<CTX extends Context> implements Condition<CTX> {
private final Set<String> ids;
private final boolean regexMatch;
private final NumberProvider x;
@@ -30,11 +29,6 @@ public class MatchBlockCondition<CTX extends Context> implements Condition<CTX>
this.z = z;
}
@Override
public Key type() {
return CommonConditions.MATCH_BLOCK;
}
@Override
public boolean test(CTX ctx) {
Optional<WorldPosition> optionalWorldPosition = ctx.getOptionalParameter(DirectContextParameters.POSITION);
@@ -46,7 +40,11 @@ public class MatchBlockCondition<CTX extends Context> implements Condition<CTX>
return false;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -7,7 +7,6 @@ import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.Pair;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -15,18 +14,13 @@ import net.momirealms.craftengine.core.world.ExistingBlock;
import java.util.*;
public class MatchBlockPropertyCondition<CTX extends Context> implements Condition<CTX> {
public final class MatchBlockPropertyCondition<CTX extends Context> implements Condition<CTX> {
private final List<Pair<String, String>> properties;
public MatchBlockPropertyCondition(List<Pair<String, String>> properties) {
this.properties = properties;
}
@Override
public Key type() {
return CommonConditions.MATCH_BLOCK_PROPERTY;
}
@Override
public boolean test(CTX ctx) {
ImmutableBlockState customBlockState = null;
@@ -74,7 +68,11 @@ public class MatchBlockPropertyCondition<CTX extends Context> implements Conditi
return true;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -5,13 +5,12 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.*;
public class MatchEntityCondition<CTX extends Context> implements Condition<CTX> {
public final class MatchEntityCondition<CTX extends Context> implements Condition<CTX> {
private final Set<String> ids;
private final boolean regexMatch;
@@ -20,18 +19,17 @@ public class MatchEntityCondition<CTX extends Context> implements Condition<CTX>
this.regexMatch = regexMatch;
}
@Override
public Key type() {
return CommonConditions.MATCH_ENTITY;
}
@Override
public boolean test(CTX ctx) {
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent();
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,31 +4,29 @@ import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.*;
public class MatchFurnitureVariantCondition<CTX extends Context> implements Condition<CTX> {
public final class MatchFurnitureVariantCondition<CTX extends Context> implements Condition<CTX> {
private final Set<String> variants;
public MatchFurnitureVariantCondition(Collection<String> variants) {
this.variants = new HashSet<>(variants);
}
@Override
public Key type() {
return CommonConditions.MATCH_FURNITURE_VARIANT;
}
@Override
public boolean test(CTX ctx) {
Optional<Furniture> furniture = ctx.getOptionalParameter(DirectContextParameters.FURNITURE);
return furniture.filter(value -> this.variants.contains(value.getCurrentVariant().name())).isPresent();
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -5,13 +5,12 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.*;
public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
public final class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
private final Set<String> ids;
private final boolean regexMatch;
@@ -20,18 +19,17 @@ public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
this.regexMatch = regexMatch;
}
@Override
public Key type() {
return CommonConditions.MATCH_ITEM;
}
@Override
public boolean test(CTX ctx) {
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
return item.filter(value -> MiscUtils.matchRegex(value.id().asString(), this.ids, this.regexMatch)).isPresent();
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,24 +4,18 @@ import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Optional;
public class OnCooldownCondition<CTX extends Context> implements Condition<CTX> {
public final class OnCooldownCondition<CTX extends Context> implements Condition<CTX> {
private final String key;
public OnCooldownCondition(String key) {
this.key = key;
}
@Override
public Key type() {
return CommonConditions.ON_COOLDOWN;
}
@Override
public boolean test(CTX ctx) {
Optional<Player> player = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
@@ -32,7 +26,11 @@ public class OnCooldownCondition<CTX extends Context> implements Condition<CTX>
return false;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,31 +4,29 @@ import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Optional;
public class PermissionCondition<CTX extends Context> implements Condition<CTX> {
public final class PermissionCondition<CTX extends Context> implements Condition<CTX> {
private final String permission;
public PermissionCondition(String permission) {
this.permission = permission;
}
@Override
public Key type() {
return CommonConditions.PERMISSION;
}
@Override
public boolean test(CTX ctx) {
Optional<Player> player = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
return player.map(value -> value.hasPermission(this.permission)).orElse(false);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -5,13 +5,12 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.RandomUtils;
import java.util.Map;
import java.util.Optional;
public class RandomCondition<CTX extends Context> implements Condition<CTX> {
public final class RandomCondition<CTX extends Context> implements Condition<CTX> {
private final NumberProvider chance;
private final boolean previous;
@@ -20,11 +19,6 @@ public class RandomCondition<CTX extends Context> implements Condition<CTX> {
this.previous = previous;
}
@Override
public Key type() {
return CommonConditions.RANDOM;
}
@Override
public boolean test(CTX ctx) {
if (this.previous) {
@@ -38,7 +32,11 @@ public class RandomCondition<CTX extends Context> implements Condition<CTX> {
}
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,12 +4,11 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class StringContainsCondition<CTX extends Context> implements Condition<CTX> {
public final class StringContainsCondition<CTX extends Context> implements Condition<CTX> {
private final TextProvider value1;
private final TextProvider value2;
@@ -18,17 +17,16 @@ public class StringContainsCondition<CTX extends Context> implements Condition<C
this.value2 = value2;
}
@Override
public Key type() {
return CommonConditions.STRING_CONTAINS;
}
@Override
public boolean test(CTX ctx) {
return this.value1.get(ctx).contains(this.value2.get(ctx));
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,12 +4,11 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class StringEqualsCondition<CTX extends Context> implements Condition<CTX> {
public final class StringEqualsCondition<CTX extends Context> implements Condition<CTX> {
private final TextProvider value1;
private final TextProvider value2;
@@ -18,17 +17,16 @@ public class StringEqualsCondition<CTX extends Context> implements Condition<CTX
this.value2 = value2;
}
@Override
public Key type() {
return CommonConditions.EQUALS;
}
@Override
public boolean test(CTX ctx) {
return this.value1.get(ctx).equals(this.value2.get(ctx));
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -4,12 +4,11 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class StringRegexCondition<CTX extends Context> implements Condition<CTX> {
public final class StringRegexCondition<CTX extends Context> implements Condition<CTX> {
private final TextProvider value;
private final TextProvider regex;
@@ -18,17 +17,16 @@ public class StringRegexCondition<CTX extends Context> implements Condition<CTX>
this.regex = regex;
}
@Override
public Key type() {
return CommonConditions.STRING_REGEX;
}
@Override
public boolean test(CTX ctx) {
return this.value.get(ctx).matches(this.regex.get(ctx));
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -3,18 +3,12 @@ package net.momirealms.craftengine.core.plugin.context.condition;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.RandomUtils;
import java.util.Map;
import java.util.Optional;
public class SurvivesExplosionCondition<CTX extends Context> implements Condition<CTX> {
@Override
public Key type() {
return CommonConditions.SURVIVES_EXPLOSION;
}
public final class SurvivesExplosionCondition<CTX extends Context> implements Condition<CTX> {
@Override
public boolean test(CTX ctx) {
@@ -26,7 +20,11 @@ public class SurvivesExplosionCondition<CTX extends Context> implements Conditio
return true;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -15,7 +15,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class TableBonusCondition<CTX extends Context> implements Condition<CTX> {
public final class TableBonusCondition<CTX extends Context> implements Condition<CTX> {
private final Key enchantmentType;
private final List<Float> values;
@@ -24,11 +24,6 @@ public class TableBonusCondition<CTX extends Context> implements Condition<CTX>
this.values = values;
}
@Override
public Key type() {
return CommonConditions.TABLE_BONUS;
}
@Override
public boolean test(CTX ctx) {
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
@@ -37,7 +32,11 @@ public class TableBonusCondition<CTX extends Context> implements Condition<CTX>
return RandomUtils.generateRandomFloat(0, 1) < f;
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
public static <CTX extends Context> ConditionFactory<CTX> factory() {
return new Factory<>();
}
private static class Factory<CTX extends Context> implements ConditionFactory<CTX> {
@Override
public Condition<CTX> create(Map<String, Object> arguments) {

View File

@@ -6,7 +6,6 @@ import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextPar
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.AdventureHelper;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
@@ -37,14 +36,9 @@ public class ActionBarFunction<CTX extends Context> extends AbstractConditionalF
}
}
@Override
public Key type() {
return CommonFunctions.ACTIONBAR;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -23,9 +23,4 @@ public class AllOfFunction<CTX extends Context> implements Function<CTX> {
function.run(ctx);
}
}
@Override
public Key type() {
return CommonFunctions.ALL_OF;
}
}

View File

@@ -6,7 +6,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.List;
@@ -31,14 +30,9 @@ public class BreakBlockFunction<CTX extends Context> extends AbstractConditional
optionalPlayer.ifPresent(player -> player.breakBlock(MiscUtils.floor(x.getDouble(ctx)), MiscUtils.floor(y.getDouble(ctx)), MiscUtils.floor(z.getDouble(ctx))));
}
@Override
public Key type() {
return CommonFunctions.BREAK_BLOCK;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Cancellable;
import net.momirealms.craftengine.core.util.Key;
import java.util.List;
import java.util.Map;
@@ -22,14 +21,9 @@ public class CancelEventFunction<CTX extends Context> extends AbstractConditiona
cancellable.ifPresent(value -> value.setCancelled(true));
}
@Override
public Key type() {
return CommonFunctions.CANCEL_EVENT;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -33,14 +33,9 @@ public class ClearItemFunction<CTX extends Context> extends AbstractConditionalF
player.clearOrCountMatchingInventoryItems(itemId, count.getInt(ctx));
}
@Override
public Key type() {
return CommonFunctions.CLEAR_ITEM;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -6,7 +6,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -31,14 +30,9 @@ public class CloseInventoryFunction<CTX extends Context> extends AbstractConditi
}
}
@Override
public Key type() {
return CommonFunctions.CLOSE_INVENTORY;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -9,7 +9,6 @@ import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
@@ -63,14 +62,9 @@ public class CommandFunction<CTX extends Context> extends AbstractConditionalFun
}
}
@Override
public Key type() {
return CommonFunctions.COMMAND;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.World;
@@ -79,14 +78,9 @@ public class CycleBlockPropertyFunction<CTX extends Context> extends AbstractCon
return wrapper.withProperty(this.property, mapValue);
}
@Override
public Key type() {
return CommonFunctions.CYCLE_BLOCK_PROPERTY;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -29,14 +29,9 @@ public class DamageFunction<CTX extends Context> extends AbstractConditionalFunc
selector.get(ctx).forEach(p -> p.damage(amount.getDouble(ctx), damageType, null));
}
@Override
public Key type() {
return CommonFunctions.DAMAGE;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -9,7 +9,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import java.util.List;
import java.util.Map;
@@ -37,14 +36,9 @@ public class DamageItemFunction<CTX extends Context> extends AbstractConditional
item.hurtAndBreak(amount.getInt(ctx), player, slot);
}
@Override
public Key type() {
return CommonFunctions.DAMAGE_ITEM;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.world.World;
@@ -54,14 +53,9 @@ public class DropLootFunction<CTX extends Context> extends AbstractConditionalFu
}
}
@Override
public Key type() {
return CommonFunctions.DROP_LOOT;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -8,9 +8,4 @@ public class DummyFunction<CTX extends Context> implements Function<CTX> {
@Override
public void run(CTX ctx) {
}
@Override
public Key type() {
return CommonFunctions.DUMMY;
}
}

View File

@@ -9,8 +9,6 @@ public interface Function<CTX extends Context> {
void run(CTX ctx);
Key type();
static <CTX extends Context> Function<CTX> allOf(List<Function<CTX>> functions) {
if (functions == null || functions.isEmpty()) {
return new DummyFunction<>();

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.Pair;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -29,14 +28,9 @@ public class IfElseFunction<CTX extends Context> extends AbstractConditionalFunc
}
}
@Override
public Key type() {
return CommonFunctions.IF_ELSE;
}
public static class Factory<CTX extends Context> extends AbstractFunctionalFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFunctionalFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> conditionFactory, java.util.function.Function<Map<String, Object>, Function<CTX>> functionFactory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> conditionFactory, java.util.function.Function<Map<String, Object>, Function<CTX>> functionFactory) {
super(conditionFactory, functionFactory);
}

View File

@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
@@ -43,14 +42,9 @@ public class LevelerExpFunction<CTX extends Context> extends AbstractConditional
}
}
@Override
public Key type() {
return CommonFunctions.LEVELER_EXP;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -48,14 +48,9 @@ public class MerchantTradeFunction<CTX extends Context> extends AbstractConditio
}
}
@Override
public Key type() {
return CommonFunctions.MESSAGE;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -6,7 +6,6 @@ import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextPar
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.AdventureHelper;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
@@ -44,14 +43,9 @@ public class MessageFunction<CTX extends Context> extends AbstractConditionalFun
}
}
@Override
public Key type() {
return CommonFunctions.MESSAGE;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
@@ -27,14 +26,9 @@ public class MythicMobsSkillFunction<CTX extends Context> extends AbstractCondit
});
}
@Override
public Key type() {
return CommonFunctions.MYTHIC_MOBS_SKILL;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -10,7 +10,6 @@ import net.momirealms.craftengine.core.plugin.gui.GuiType;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.AdventureHelper;
import net.momirealms.craftengine.core.util.EnumUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
@@ -51,14 +50,9 @@ public class OpenWindowFunction<CTX extends Context> extends AbstractConditional
}
}
@Override
public Key type() {
return CommonFunctions.OPEN_WINDOW;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.world.Position;
import net.momirealms.craftengine.core.world.Vec3d;
import net.momirealms.craftengine.core.world.World;
@@ -32,14 +31,9 @@ public class ParticleFunction<CTX extends Context> extends AbstractConditionalFu
}
}
@Override
public Key type() {
return CommonFunctions.PARTICLE;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -8,7 +8,6 @@ import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.LazyReference;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -44,14 +43,9 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
}
}
@Override
public Key type() {
return CommonFunctions.PLACE_BLOCK;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -60,14 +60,9 @@ public class PlaySoundFunction<CTX extends Context> extends AbstractConditionalF
}
}
@Override
public Key type() {
return CommonFunctions.PLAY_SOUND;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -72,14 +72,9 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
}
}
@Override
public Key type() {
return CommonFunctions.PLAY_TOTEM_ANIMATION;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -45,14 +45,9 @@ public class PotionEffectFunction<CTX extends Context> extends AbstractCondition
}
}
@Override
public Key type() {
return CommonFunctions.POTION_EFFECT;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -7,7 +7,6 @@ import net.momirealms.craftengine.core.plugin.context.CooldownData;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
@@ -44,14 +43,9 @@ public class RemoveCooldownFunction<CTX extends Context> extends AbstractConditi
}
}
@Override
public Key type() {
return CommonFunctions.REMOVE_COOLDOWN;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

View File

@@ -4,7 +4,6 @@ import net.momirealms.craftengine.core.entity.Entity;
import net.momirealms.craftengine.core.plugin.context.Condition;
import net.momirealms.craftengine.core.plugin.context.Context;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.util.Key;
import java.util.List;
import java.util.Map;
@@ -20,14 +19,9 @@ public class RemoveEntityFunction<CTX extends Context> extends AbstractCondition
ctx.getOptionalParameter(DirectContextParameters.ENTITY).ifPresent(Entity::remove);
}
@Override
public Key type() {
return CommonFunctions.REMOVE_ENTITY;
}
public static class Factory<CTX extends Context> extends AbstractFactory<CTX> {
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
public Factory(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}

Some files were not shown because too many files have changed in this diff Show More