From e4f4324a31261ad5ec765073a4d07ab0cd8d3cce Mon Sep 17 00:00:00 2001 From: halogly Date: Sat, 23 Aug 2025 21:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3MatchBlockTypeCondition?= =?UTF-8?q?=EF=BC=9B=E6=B8=85=E9=99=A4MatchEntityTypeCondition=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=E7=BC=A9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../condition/MatchBlockTypeCondition.java | 2 +- .../condition/MatchEntityTypeCondition.java | 74 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockTypeCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockTypeCondition.java index 515166d68..7a08fd238 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockTypeCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockTypeCondition.java @@ -22,7 +22,7 @@ public class MatchBlockTypeCondition implements Condition implements Condition { - private final Set ids; - private final boolean regexMatch; +public class MatchEntityTypeCondition implements Condition { + private final Set ids; + private final boolean regexMatch; - public MatchEntityTypeCondition(Collection ids, boolean regexMatch) { - this.ids = new HashSet<>(ids); - this.regexMatch = regexMatch; - } + public MatchEntityTypeCondition(Collection ids, boolean regexMatch) { + this.ids = new HashSet<>(ids); + this.regexMatch = regexMatch; + } + + @Override + public Key type() { + return CommonConditions.MATCH_ENTITY_TYPE; + } + + @Override + public boolean test(CTX ctx) { + Optional entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY); + return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent(); + } + + public static class FactoryImpl implements ConditionFactory { @Override - public Key type() { - return CommonConditions.MATCH_ENTITY_TYPE; - } - - @Override - public boolean test(CTX ctx) { - Optional entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY); - return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent(); - } - - public static class FactoryImpl implements ConditionFactory { - - @Override - public Condition create(Map arguments) { - List ids = MiscUtils.getAsStringList(arguments.get("id")); - if (ids.isEmpty()) { - throw new LocalizedResourceConfigException("warning.config.condition.match_entity_type.missing_id"); - } - boolean regex = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("regex", false), "regex"); - return new MatchEntityTypeCondition<>(ids, regex); + public Condition create(Map arguments) { + List ids = MiscUtils.getAsStringList(arguments.get("id")); + if (ids.isEmpty()) { + throw new LocalizedResourceConfigException("warning.config.condition.match_entity_type.missing_id"); } + boolean regex = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("regex", false), "regex"); + return new MatchEntityTypeCondition<>(ids, regex); } } +}