From 6bdd3dccde24ee85547824a0843c90647e3a134d Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Fri, 2 May 2025 18:24:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=B1=E8=BF=99=E6=A0=B7=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/behavior/CropBlockBehavior.java | 4 ++-- .../craftengine/core/loot/LootContext.java | 24 +++++-------------- .../craftengine/core/loot/LootTable.java | 2 +- .../core/loot/condition/AllOfCondition.java | 1 + .../core/pack/AbstractPackManager.java | 4 ++-- ...PathMatcher.java => PathMatcherAllOf.java} | 13 ++++------ ...PathMatcher.java => PathMatcherAnyOf.java} | 14 ++++------- ...sMatcher.java => PathMatcherContains.java} | 6 ++--- ...PathMatcher.java => PathMatcherExact.java} | 6 ++--- ...eMatcher.java => PathMatcherFilename.java} | 6 ++--- ...hMatcher.java => PathMatcherInverted.java} | 11 +++------ ...cher.java => PathMatcherParentPrefix.java} | 6 ++--- ...cher.java => PathMatcherParentSuffix.java} | 6 ++--- .../pack/conflict/matcher/PathMatchers.java | 17 ++++++------- ...lution.java => ResolutionConditional.java} | 6 ++--- ...olution.java => ResolutionMergeAltas.java} | 4 ++-- ...solution.java => ResolutionMergeJson.java} | 6 ++--- ...on.java => ResolutionMergePackMcMeta.java} | 6 ++--- .../pack/conflict/resolution/Resolutions.java | 8 +++---- .../core/plugin/config/Config.java | 8 +++---- .../minimessage/MiniMessageTextContext.java | 1 - .../core/util/condition/AllOfCondition.java | 6 +++++ .../core/util/condition/AnyOfCondition.java | 6 +++++ .../core/util/condition/CommonConditions.java | 11 +++++++++ .../util/condition/InvertedCondition.java | 6 +++++ .../core/util/context/CommonContext.java | 8 +++---- .../core/util/context/CommonParameters.java | 7 +++++- 27 files changed, 105 insertions(+), 98 deletions(-) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{AllOfPathMatcher.java => PathMatcherAllOf.java} (79%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{AnyOfPathMatcher.java => PathMatcherAnyOf.java} (76%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{PathContainsMatcher.java => PathMatcherContains.java} (87%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{ExactPathMatcher.java => PathMatcherExact.java} (88%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{FilenameMatcher.java => PathMatcherFilename.java} (87%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{InvertedPathMatcher.java => PathMatcherInverted.java} (79%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{ParentPathPrefixMatcher.java => PathMatcherParentPrefix.java} (87%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/{ParentPathSuffixMatcher.java => PathMatcherParentSuffix.java} (87%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/{ConditionalResolution.java => ResolutionConditional.java} (85%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/{MergeAltasResolution.java => ResolutionMergeAltas.java} (93%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/{MergeJsonResolution.java => ResolutionMergeJson.java} (90%) rename core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/{MergePackMcMetaResolution.java => ResolutionMergePackMcMeta.java} (97%) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java index 6e18976af..9228904eb 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java @@ -148,10 +148,10 @@ public class CropBlockBehavior extends BushBlockBehavior { int z = FastNMS.INSTANCE.field$Vec3i$z(pos); net.momirealms.craftengine.core.world.World wrappedWorld = new BukkitWorld(world); - int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, ContextHolder.builder() + int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, 1, ThreadLocalRandom.current(), ContextHolder.builder() .withParameter(LootParameters.WORLD, wrappedWorld) .withParameter(LootParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z))) - .build(), ThreadLocalRandom.current(), 1)); + .build())); int maxAge = this.ageProperty.max; if (i > maxAge) { i = maxAge; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java index 2ad3dc4f4..ae73df88a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.loot; +import net.momirealms.craftengine.core.util.context.CommonContext; import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.util.context.ContextKey; import net.momirealms.craftengine.core.world.World; @@ -7,43 +8,30 @@ import net.momirealms.craftengine.core.world.World; import java.util.Optional; import java.util.Random; -public class LootContext { +public class LootContext extends CommonContext { private final World world; - private final ContextHolder contexts; private final Random randomSource; private final float luck; - public LootContext(World world, ContextHolder contexts, Random randomSource, float luck) { + public LootContext(World world, float luck, Random randomSource, ContextHolder contexts) { + super(contexts); this.randomSource = randomSource; - this.contexts = contexts; this.world = world; this.luck = luck; } public Random randomSource() { - return randomSource; + return this.randomSource; } public Optional getOptionalParameter(ContextKey parameter) { - return this.contexts.getOptional(parameter); - } - - public boolean hasParameter(ContextKey parameter) { - return this.contexts.has(parameter); - } - - public T getParameterOrThrow(ContextKey parameter) { - return this.contexts.getOrThrow(parameter); + return super.contexts.getOptional(parameter); } public float luck() { return luck; } - public ContextHolder contexts() { - return contexts; - } - public World world() { return world; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java index e8b2176ff..152eec336 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java @@ -80,7 +80,7 @@ public class LootTable { } public ArrayList> getRandomItems(ContextHolder parameters, World world) { - return this.getRandomItems(new LootContext(world, parameters, ThreadLocalRandom.current(), 1)); + return this.getRandomItems(new LootContext(world, 1, ThreadLocalRandom.current(), parameters)); } private ArrayList> getRandomItems(LootContext context) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/AllOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/AllOfCondition.java index 6c1e9eaa1..7a693dde4 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/AllOfCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/AllOfCondition.java @@ -30,6 +30,7 @@ public class AllOfCondition implements LootCondition { } public static class Factory implements LootConditionFactory { + @SuppressWarnings("unchecked") @Override public LootCondition create(Map arguments) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java index bc4831cec..ff722cd59 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java @@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.font.BitmapImage; import net.momirealms.craftengine.core.font.Font; import net.momirealms.craftengine.core.item.EquipmentData; import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution; +import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional; 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; @@ -1159,7 +1159,7 @@ public abstract class AbstractPackManager implements PackManager { PathContext relativeCTX = PathContext.of(relative); PathContext targetCTX = PathContext.of(targetPath); PathContext fileCTX = PathContext.of(file); - for (ConditionalResolution resolution : Config.resolutions()) { + for (ResolutionConditional resolution : Config.resolutions()) { if (resolution.matcher().test(relativeCTX)) { resolution.resolution().run(targetCTX, fileCTX); return FileVisitResult.CONTINUE; diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AllOfPathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java similarity index 79% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AllOfPathMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java index 325f7632b..70daf8447 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AllOfPathMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java @@ -10,18 +10,13 @@ import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; import java.util.Map; -public class AllOfPathMatcher extends AllOfCondition implements PathMatcher { +public class PathMatcherAllOf extends AllOfCondition implements PathMatcher { public static final Factory FACTORY = new Factory(); - public AllOfPathMatcher(List> conditions) { + public PathMatcherAllOf(List> conditions) { super(conditions); } - @Override - public Key type() { - return PathMatchers.ALL_OF; - } - public static class Factory implements PathMatcherFactory { @SuppressWarnings("unchecked") @@ -30,10 +25,10 @@ public class AllOfPathMatcher extends AllOfCondition implements Pat Object termsObj = arguments.get("terms"); if (termsObj instanceof List list) { List> terms = (List>) list; - return new AllOfPathMatcher(PathMatchers.fromMapList(terms)); + return new PathMatcherAllOf(PathMatchers.fromMapList(terms)); } else if (termsObj instanceof Map) { Map terms = MiscUtils.castToMap(termsObj, false); - return new AllOfPathMatcher(PathMatchers.fromMapList(List.of(terms))); + return new PathMatcherAllOf(PathMatchers.fromMapList(List.of(terms))); } else { throw new LocalizedException("warning.config.conflict_matcher.all_of.missing_terms"); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AnyOfPathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java similarity index 76% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AnyOfPathMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java index 4138629e2..efb1d584c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/AnyOfPathMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java @@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.condition.AnyOfCondition; import net.momirealms.craftengine.core.util.context.Condition; @@ -10,18 +9,13 @@ import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; import java.util.Map; -public class AnyOfPathMatcher extends AnyOfCondition implements PathMatcher { +public class PathMatcherAnyOf extends AnyOfCondition implements PathMatcher { public static final Factory FACTORY = new Factory(); - public AnyOfPathMatcher(List> conditions) { + public PathMatcherAnyOf(List> conditions) { super(conditions); } - @Override - public Key type() { - return PathMatchers.ANY_OF; - } - public static class Factory implements PathMatcherFactory { @SuppressWarnings("unchecked") @@ -30,10 +24,10 @@ public class AnyOfPathMatcher extends AnyOfCondition implements Pat Object termsObj = arguments.get("terms"); if (termsObj instanceof List list) { List> terms = (List>) list; - return new AnyOfPathMatcher(PathMatchers.fromMapList(terms)); + return new PathMatcherAnyOf(PathMatchers.fromMapList(terms)); } else if (termsObj instanceof Map) { Map terms = MiscUtils.castToMap(termsObj, false); - return new AnyOfPathMatcher(PathMatchers.fromMapList(List.of(terms))); + return new PathMatcherAnyOf(PathMatchers.fromMapList(List.of(terms))); } else { throw new LocalizedException("warning.config.conflict_matcher.any_of.missing_terms"); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathContainsMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathContainsMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java index b11b30f2a..77ee9f683 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathContainsMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java @@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class PathContainsMatcher implements PathMatcher { +public class PathMatcherContains implements PathMatcher { public static final Factory FACTORY = new Factory(); private final String path; - public PathContainsMatcher(String path) { + public PathMatcherContains(String path) { this.path = path; } @@ -31,7 +31,7 @@ public class PathContainsMatcher implements PathMatcher { @Override public PathMatcher create(Map arguments) { String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path")); - return new PathContainsMatcher(path); + return new PathMatcherContains(path); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ExactPathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java similarity index 88% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ExactPathMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java index 34b55bb4d..7864822fa 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ExactPathMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java @@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class ExactPathMatcher implements PathMatcher { +public class PathMatcherExact implements PathMatcher { public static final Factory FACTORY = new Factory(); private final String path; - public ExactPathMatcher(String path) { + public PathMatcherExact(String path) { this.path = path; } @@ -31,7 +31,7 @@ public class ExactPathMatcher implements PathMatcher { @Override public PathMatcher create(Map arguments) { String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path")); - return new ExactPathMatcher(path); + return new PathMatcherExact(path); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/FilenameMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/FilenameMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java index e221ebfd2..3a33b6442 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/FilenameMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java @@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class FilenameMatcher implements PathMatcher { +public class PathMatcherFilename implements PathMatcher { public static final Factory FACTORY = new Factory(); private final String name; - public FilenameMatcher(String name) { + public PathMatcherFilename(String name) { this.name = name; } @@ -31,7 +31,7 @@ public class FilenameMatcher implements PathMatcher { @Override public PathMatcher create(Map arguments) { String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name")); - return new FilenameMatcher(name); + return new PathMatcherFilename(name); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/InvertedPathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java similarity index 79% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/InvertedPathMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java index d200f979e..c1d6060fb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/InvertedPathMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java @@ -9,25 +9,20 @@ import net.momirealms.craftengine.core.util.condition.InvertedCondition; import java.util.Map; -public class InvertedPathMatcher extends InvertedCondition implements PathMatcher { +public class PathMatcherInverted extends InvertedCondition implements PathMatcher { public static final Factory FACTORY = new Factory(); - public InvertedPathMatcher(PathMatcher condition) { + public PathMatcherInverted(PathMatcher condition) { super(condition); } - @Override - public Key type() { - return PathMatchers.INVERTED; - } - public static class Factory implements PathMatcherFactory { @Override public PathMatcher create(Map arguments) { Object inverted = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("term"), () -> new LocalizedException("warning.config.conflict_matcher.inverted.missing_term")); Map term = MiscUtils.castToMap(inverted, false); - return new InvertedPathMatcher(PathMatchers.fromMap(term)); + return new PathMatcherInverted(PathMatchers.fromMap(term)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathPrefixMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathPrefixMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java index 9b753bebd..fb3bbafa7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathPrefixMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java @@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.nio.file.Path; import java.util.Map; -public class ParentPathPrefixMatcher implements PathMatcher { +public class PathMatcherParentPrefix implements PathMatcher { public static final Factory FACTORY = new Factory(); private final String prefix; - public ParentPathPrefixMatcher(String prefix) { + public PathMatcherParentPrefix(String prefix) { this.prefix = prefix; } @@ -34,7 +34,7 @@ public class ParentPathPrefixMatcher implements PathMatcher { @Override public PathMatcher create(Map arguments) { String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix")); - return new ParentPathPrefixMatcher(prefix); + return new PathMatcherParentPrefix(prefix); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathSuffixMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathSuffixMatcher.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java index e91fc8e1a..971cdd82b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/ParentPathSuffixMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java @@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.nio.file.Path; import java.util.Map; -public class ParentPathSuffixMatcher implements PathMatcher { +public class PathMatcherParentSuffix implements PathMatcher { public static final Factory FACTORY = new Factory(); private final String suffix; - public ParentPathSuffixMatcher(String suffix) { + public PathMatcherParentSuffix(String suffix) { this.suffix = suffix; } @@ -34,7 +34,7 @@ public class ParentPathSuffixMatcher implements PathMatcher { @Override public PathMatcher create(Map arguments) { String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix")); - return new ParentPathSuffixMatcher(suffix); + return new PathMatcherParentSuffix(suffix); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java index a9de55bfd..7316e0d58 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java @@ -8,6 +8,7 @@ import net.momirealms.craftengine.core.registry.WritableRegistry; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import net.momirealms.craftengine.core.util.ResourceKey; +import net.momirealms.craftengine.core.util.condition.AllOfCondition; import java.util.ArrayList; import java.util.List; @@ -25,15 +26,15 @@ public class PathMatchers { public static final Key INVERTED = Key.of("craftengine:inverted"); static { - register(PARENT_PATH_SUFFIX, ParentPathSuffixMatcher.FACTORY); - register(PARENT_PATH_PREFIX, ParentPathPrefixMatcher.FACTORY); + register(PARENT_PATH_SUFFIX, PathMatcherParentSuffix.FACTORY); + register(PARENT_PATH_PREFIX, PathMatcherParentPrefix.FACTORY); register(PATTERN, PathPatternMatcher.FACTORY); - register(EXACT, ExactPathMatcher.FACTORY); - register(FILENAME, FilenameMatcher.FACTORY); - register(ANY_OF, AnyOfPathMatcher.FACTORY); - register(ALL_OF, AllOfPathMatcher.FACTORY); - register(INVERTED, InvertedPathMatcher.FACTORY); - register(CONTAINS, PathContainsMatcher.FACTORY); + register(EXACT, PathMatcherExact.FACTORY); + register(FILENAME, PathMatcherFilename.FACTORY); + register(ANY_OF, PathMatcherAnyOf.FACTORY); + register(ALL_OF, PathMatcherAllOf.FACTORY); + register(INVERTED, PathMatcherInverted.FACTORY); + register(CONTAINS, PathMatcherContains.FACTORY); } public static void register(Key key, PathMatcherFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ConditionalResolution.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java similarity index 85% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ConditionalResolution.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java index f54c04c39..0c79d0c23 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ConditionalResolution.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java @@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.MiscUtils; import java.util.Map; -public record ConditionalResolution(PathMatcher matcher, Resolution resolution) implements Resolution { +public record ResolutionConditional(PathMatcher matcher, Resolution resolution) implements Resolution { public static final Factory FACTORY = new Factory(); @Override @@ -26,10 +26,10 @@ public record ConditionalResolution(PathMatcher matcher, Resolution resolution) public static class Factory implements ResolutionFactory { @Override - public ConditionalResolution create(Map arguments) { + public ResolutionConditional create(Map arguments) { Map term = MiscUtils.castToMap(arguments.get("term"), false); Map resolution = MiscUtils.castToMap(arguments.get("resolution"), false); - return new ConditionalResolution(PathMatchers.fromMap(term), Resolutions.fromMap(resolution)); + return new ResolutionConditional(PathMatchers.fromMap(term), Resolutions.fromMap(resolution)); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeAltasResolution.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeAltas.java similarity index 93% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeAltasResolution.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeAltas.java index 6cced38f0..6f75bbb4d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeAltasResolution.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeAltas.java @@ -12,9 +12,9 @@ import java.io.IOException; import java.util.HashSet; import java.util.Map; -public class MergeAltasResolution implements Resolution { +public class ResolutionMergeAltas implements Resolution { public static final Factory FACTORY = new Factory(); - public static final MergeAltasResolution INSTANCE = new MergeAltasResolution(); + public static final ResolutionMergeAltas INSTANCE = new ResolutionMergeAltas(); @Override public void run(PathContext existing, PathContext conflict) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeJsonResolution.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeJson.java similarity index 90% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeJsonResolution.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeJson.java index aca0b9425..88679856d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergeJsonResolution.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergeJson.java @@ -9,11 +9,11 @@ import net.momirealms.craftengine.core.util.Key; import java.io.IOException; import java.util.Map; -public class MergeJsonResolution implements Resolution { +public class ResolutionMergeJson implements Resolution { public static final Factory FACTORY = new Factory(); private final boolean deeply; - public MergeJsonResolution(boolean deeply) { + public ResolutionMergeJson(boolean deeply) { this.deeply = deeply; } @@ -44,7 +44,7 @@ public class MergeJsonResolution implements Resolution { @Override public Resolution create(Map arguments) { boolean deeply = (boolean) arguments.getOrDefault("deeply", false); - return new MergeJsonResolution(deeply); + return new ResolutionMergeJson(deeply); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergePackMcMetaResolution.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java similarity index 97% rename from core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergePackMcMetaResolution.java rename to core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java index 1ebeadd67..186a1c3eb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/MergePackMcMetaResolution.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionMergePackMcMeta.java @@ -11,11 +11,11 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Map; -public class MergePackMcMetaResolution implements Resolution { +public class ResolutionMergePackMcMeta implements Resolution { public static final Factory FACTORY = new Factory(); private final String description; - public MergePackMcMetaResolution(String description) { + public ResolutionMergePackMcMeta(String description) { this.description = description; } @@ -209,7 +209,7 @@ public class MergePackMcMetaResolution implements Resolution { @Override public Resolution create(Map arguments) { String description = arguments.getOrDefault("description", "CraftEngine ResourcePack").toString(); - return new MergePackMcMetaResolution(description); + return new ResolutionMergePackMcMeta(description); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java index 38f7754ca..86a3ae54d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java @@ -20,10 +20,10 @@ public class Resolutions { static { register(RETAIN_MATCHING, RetainMatchingResolution.FACTORY); - register(MERGE_JSON, MergeJsonResolution.FACTORY); - register(CONDITIONAL, ConditionalResolution.FACTORY); - register(MERGE_PACK_MCMETA, MergePackMcMetaResolution.FACTORY); - register(MERGE_ATLAS, MergeAltasResolution.FACTORY); + register(MERGE_JSON, ResolutionMergeJson.FACTORY); + register(CONDITIONAL, ResolutionConditional.FACTORY); + register(MERGE_PACK_MCMETA, ResolutionMergePackMcMeta.FACTORY); + register(MERGE_ATLAS, ResolutionMergeAltas.FACTORY); } public static void register(Key key, ResolutionFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java index e823d35e4..be4757d67 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/Config.java @@ -13,7 +13,7 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; 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.conflict.resolution.ConditionalResolution; +import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.PluginProperties; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; @@ -54,7 +54,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 resource_pack$duplicated_files_handler; + protected List resource_pack$duplicated_files_handler; protected List resource_pack$merge_external_folders; protected boolean resource_pack$protection$crash_tools$method_1; @@ -245,7 +245,7 @@ public class Config { try { resource_pack$duplicated_files_handler = config.getMapList("resource-pack.duplicated-files-handler").stream().map(it -> { Map args = MiscUtils.castToMap(it, false); - return ConditionalResolution.FACTORY.create(args); + return ResolutionConditional.FACTORY.create(args); }).toList(); } catch (LocalizedResourceConfigException e) { TranslationManager.instance().log(e.node(), e.arguments()); @@ -479,7 +479,7 @@ public class Config { return instance.resource_pack$delivery$file_to_upload; } - public static List resolutions() { + public static List resolutions() { return instance.resource_pack$duplicated_files_handler; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTextContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTextContext.java index 5fe4279ec..fea64a87b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTextContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTextContext.java @@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.text.minimessage; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.momirealms.craftengine.core.util.context.Context; -import net.momirealms.craftengine.core.util.context.ContextHolder; public interface MiniMessageTextContext extends Context { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java index c50420e13..3abcf3ef1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.util.condition; +import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; @@ -20,4 +21,9 @@ public abstract class AllOfCondition implements Condition { } return true; } + + @Override + public Key type() { + return CommonConditions.ALL_OF; + } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java index bb2e08e4a..b9803a62b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.util.condition; +import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; @@ -20,4 +21,9 @@ public abstract class AnyOfCondition implements Condition { } return false; } + + @Override + public Key type() { + return CommonConditions.ANY_OF; + } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java new file mode 100644 index 000000000..017c51d11 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java @@ -0,0 +1,11 @@ +package net.momirealms.craftengine.core.util.condition; + +import net.momirealms.craftengine.core.util.Key; + +public final class CommonConditions { + private CommonConditions() {} + + public static final Key ALL_OF = Key.of("craftengine:all_of"); + public static final Key ANY_OF = Key.of("craftengine:any_of"); + public static final Key INVERTED = Key.of("craftengine:inverted"); +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java index 6fa42c944..7c2304344 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.util.condition; +import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.context.Condition; public abstract class InvertedCondition implements Condition { @@ -13,4 +14,9 @@ public abstract class InvertedCondition implements Condition { public boolean test(CTX ctx) { return !this.condition.test(ctx); } + + @Override + public Key type() { + return CommonConditions.INVERTED; + } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonContext.java b/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonContext.java index 7941d363a..be8a598f7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonContext.java @@ -1,14 +1,14 @@ package net.momirealms.craftengine.core.util.context; public abstract class CommonContext implements Context { - protected final ContextHolder holder; + protected final ContextHolder contexts; - public CommonContext(ContextHolder holder) { - this.holder = holder; + public CommonContext(ContextHolder contexts) { + this.contexts = contexts; } @Override public ContextHolder contexts() { - return holder; + return contexts; } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonParameters.java b/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonParameters.java index 5544449b7..339e41e93 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/context/CommonParameters.java @@ -1,4 +1,9 @@ package net.momirealms.craftengine.core.util.context; -public class CommonParameters { +public final class CommonParameters { + + private CommonParameters() {} + + public static ContextKey RANDOM = ContextKey.of("random"); + public static ContextKey LAST_RANDOM = ContextKey.of("last_random"); }