mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 03:19:14 +00:00
移动matchObject到MiscUtil类
This commit is contained in:
@@ -30,18 +30,4 @@ public final class CommonConditions {
|
|||||||
public static final Key EXPRESSION = Key.from("craftengine:expression");
|
public static final Key EXPRESSION = Key.from("craftengine:expression");
|
||||||
public static final Key IS_NULL = Key.from("craftengine:is_null");
|
public static final Key IS_NULL = Key.from("craftengine:is_null");
|
||||||
public static final Key HAND = Key.from("craftengine:hand");
|
public static final Key HAND = Key.from("craftengine:hand");
|
||||||
|
|
||||||
public static boolean matchObject(Key key, boolean regexMatch, Set<String> ids) {
|
|
||||||
String id = key.toString();
|
|
||||||
if (regexMatch) {
|
|
||||||
for (String regex : ids) {
|
|
||||||
if (id.matches(regex)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ids.contains(id);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class MatchBlockTypeCondition<CTX extends Context> implements Condition<C
|
|||||||
if (block.isEmpty()) return false;
|
if (block.isEmpty()) return false;
|
||||||
Optional<ImmutableBlockState> customBlock = ctx.getOptionalParameter(DirectContextParameters.CUSTOM_BLOCK_STATE);
|
Optional<ImmutableBlockState> customBlock = ctx.getOptionalParameter(DirectContextParameters.CUSTOM_BLOCK_STATE);
|
||||||
Key key = customBlock.isPresent() ? customBlock.get().owner().value().id() : block.get().type();
|
Key key = customBlock.isPresent() ? customBlock.get().owner().value().id() : block.get().type();
|
||||||
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
|
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
|
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
|
||||||
if (entity.isEmpty()) return false;
|
if (entity.isEmpty()) return false;
|
||||||
Key key = entity.get().type();
|
Key key = entity.get().type();
|
||||||
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
|
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
|
|||||||
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
|
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
|
||||||
if (item.isEmpty()) return false;
|
if (item.isEmpty()) return false;
|
||||||
Key key = item.get().id();
|
Key key = item.get().id();
|
||||||
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
|
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce
|
|||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MiscUtils {
|
public class MiscUtils {
|
||||||
|
|
||||||
@@ -153,4 +150,18 @@ public class MiscUtils {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean matchObject(Key key, boolean regexMatch, Set<String> ids) {
|
||||||
|
String id = key.toString();
|
||||||
|
if (regexMatch) {
|
||||||
|
for (String regex : ids) {
|
||||||
|
if (id.matches(regex)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ids.contains(id);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user