From e4f4324a31261ad5ec765073a4d07ab0cd8d3cce Mon Sep 17 00:00:00 2001 From: halogly Date: Sat, 23 Aug 2025 21:34:28 +0800 Subject: [PATCH 1/4] =?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); } } +} From 6f4cd1e501bb5ed41ad9c799f78ae2c4a2e4890d Mon Sep 17 00:00:00 2001 From: halogly Date: Sat, 23 Aug 2025 23:39:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=81=A2=E5=A4=8DMatchBlockTypeCondition?= =?UTF-8?q?=E8=AF=86=E5=88=ABce=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=B9?= =?UTF-8?q?=E5=9D=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/context/condition/MatchBlockTypeCondition.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 7a08fd238..08d3afe48 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 @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.plugin.context.condition; +import net.momirealms.craftengine.core.block.ImmutableBlockState; 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; @@ -28,7 +29,12 @@ public class MatchBlockTypeCondition implements Condition block = ctx.getOptionalParameter(DirectContextParameters.BLOCK); - return block.filter(blockInWorld -> MiscUtils.matchRegex(blockInWorld.type().asString(), this.ids, this.regexMatch)).isPresent(); + Optional customBlock = ctx.getOptionalParameter(DirectContextParameters.CUSTOM_BLOCK_STATE); + return block.filter(blockInWorld -> { + String key = customBlock.map(immutableBlockState -> + immutableBlockState.owner().value().id().asString()).orElseGet(() -> blockInWorld.type().asString()); + return MiscUtils.matchRegex(key, this.ids, this.regexMatch); + }).isPresent(); } public static class FactoryImpl implements ConditionFactory { From 2697f69730d5c5b28f75a20885e718c12acc6c6e Mon Sep 17 00:00:00 2001 From: halogly Date: Sun, 24 Aug 2025 13:34:16 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=B6=E5=9B=BE?= =?UTF-8?q?=E5=8F=B0=E4=BA=A4=E4=BA=92=E5=88=A4=E6=96=AD=EF=BC=88=E9=81=97?= =?UTF-8?q?=E6=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/momirealms/craftengine/bukkit/util/InteractUtils.java | 1 + .../java/net/momirealms/craftengine/core/block/BlockKeys.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java index d16537def..dee6874b7 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java @@ -169,6 +169,7 @@ public final class InteractUtils { registerInteraction(BlockKeys.DAMAGED_ANVIL, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.FURNACE, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.CRAFTING_TABLE, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.CARTOGRAPHY_TABLE, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.STONECUTTER, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.SMITHING_TABLE, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.LOOM, (player, item, blockState, result) -> true); diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java b/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java index 6f5daecc9..c6b9cd591 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java @@ -8,6 +8,7 @@ public final class BlockKeys { public static final Key NOTE_BLOCK = Key.of("minecraft:note_block"); public static final Key TRIPWIRE = Key.of("minecraft:tripwire"); public static final Key CRAFTING_TABLE = Key.of("minecraft:crafting_table"); + public static final Key CARTOGRAPHY_TABLE = Key.of("minecraft:cartography_table"); public static final Key STONECUTTER = Key.of("minecraft:stonecutter"); public static final Key BELL = Key.of("minecraft:bell"); public static final Key SMITHING_TABLE = Key.of("minecraft:smithing_table"); @@ -176,8 +177,6 @@ public final class BlockKeys { public static final Key WAXED_OXIDIZED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_oxidized_copper_trapdoor"); public static final Key WAXED_WEATHERED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_weathered_copper_trapdoor"); - - public static final Key OAK_FENCE_GATE = Key.of("minecraft:oak_fence_gate"); public static final Key SPRUCE_FENCE_GATE = Key.of("minecraft:spruce_fence_gate"); public static final Key BIRCH_FENCE_GATE = Key.of("minecraft:birch_fence_gate"); From 4d7a7ff4731de9a0e0b77e16b8cd0a38478961ea Mon Sep 17 00:00:00 2001 From: halogly Date: Sun, 24 Aug 2025 17:43:16 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=92=A4=E5=9B=9E=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/context/condition/MatchBlockTypeCondition.java | 8 +------- 1 file changed, 1 insertion(+), 7 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 08d3afe48..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 @@ -1,6 +1,5 @@ package net.momirealms.craftengine.core.plugin.context.condition; -import net.momirealms.craftengine.core.block.ImmutableBlockState; 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; @@ -29,12 +28,7 @@ public class MatchBlockTypeCondition implements Condition block = ctx.getOptionalParameter(DirectContextParameters.BLOCK); - Optional customBlock = ctx.getOptionalParameter(DirectContextParameters.CUSTOM_BLOCK_STATE); - return block.filter(blockInWorld -> { - String key = customBlock.map(immutableBlockState -> - immutableBlockState.owner().value().id().asString()).orElseGet(() -> blockInWorld.type().asString()); - return MiscUtils.matchRegex(key, this.ids, this.regexMatch); - }).isPresent(); + return block.filter(blockInWorld -> MiscUtils.matchRegex(blockInWorld.type().asString(), this.ids, this.regexMatch)).isPresent(); } public static class FactoryImpl implements ConditionFactory {