From 7281fa360f52467f4e7cc2d31d1de52e940ef7f2 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 4 Nov 2024 12:22:06 +0100 Subject: [PATCH] Make property changes more robust (#2962) --- .../core/registry/state/PropertyKey.java | 5 +++++ .../sk89q/worldedit/world/block/BlockState.java | 2 +- .../sk89q/worldedit/world/block/BlockType.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKey.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKey.java index baba00a6b..0147d0e91 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKey.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKey.java @@ -137,4 +137,9 @@ public class PropertyKey implements Comparable { return Integer.compare(this.id, o.id); } + @Override + public String toString() { + return "PropertyKey[" + getName() + "]"; + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 824ad2b85..95f2c2585 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -351,7 +351,7 @@ public class BlockState implements BlockStateHolder, Pattern { BlockState newState = this; for (Property prop : ot.getProperties()) { PropertyKey key = prop.getKey(); - if (blockType.hasProperty(key)) { + if (blockType.hasPropertyOfType(key, prop.getClass())) { newState = newState.with(key, other.getState(key)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index d8b0ae046..e72d0b0e3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -247,6 +247,21 @@ public class BlockType implements Keyed, Pattern { return this.settings.propertiesMapArr.length > ordinal && this.settings.propertiesMapArr[ordinal] != null; } + /** + * {@return whether this block type has a property with given key of the given type} + * + * @param key the key identifying the property + * @param propertyType the expected type of the property + * @since TODO + */ + public boolean hasPropertyOfType(PropertyKey key, Class propertyType) { + int ordinal = key.getId(); + Property property; + return this.settings.propertiesMapArr.length > ordinal + && (property = this.settings.propertiesMapArr[ordinal]) != null + && property.getClass() == propertyType; + } + public Property getProperty(PropertyKey key) { try { return (Property) this.settings.propertiesMapArr[key.getId()];