Skip to content

Commit 7281fa3

Browse files
authored
Make property changes more robust (#2962)
1 parent bd94632 commit 7281fa3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKey.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ public int compareTo(@Nonnull PropertyKey o) {
137137
return Integer.compare(this.id, o.id);
138138
}
139139

140+
@Override
141+
public String toString() {
142+
return "PropertyKey[" + getName() + "]";
143+
}
144+
140145
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public <V> BlockState withProperties(final BlockState other) {
351351
BlockState newState = this;
352352
for (Property<?> prop : ot.getProperties()) {
353353
PropertyKey key = prop.getKey();
354-
if (blockType.hasProperty(key)) {
354+
if (blockType.hasPropertyOfType(key, prop.getClass())) {
355355
newState = newState.with(key, other.getState(key));
356356
}
357357
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ public boolean hasProperty(PropertyKey key) {
247247
return this.settings.propertiesMapArr.length > ordinal && this.settings.propertiesMapArr[ordinal] != null;
248248
}
249249

250+
/**
251+
* {@return whether this block type has a property with given key of the given type}
252+
*
253+
* @param key the key identifying the property
254+
* @param propertyType the expected type of the property
255+
* @since TODO
256+
*/
257+
public boolean hasPropertyOfType(PropertyKey key, Class<?> propertyType) {
258+
int ordinal = key.getId();
259+
Property<?> property;
260+
return this.settings.propertiesMapArr.length > ordinal
261+
&& (property = this.settings.propertiesMapArr[ordinal]) != null
262+
&& property.getClass() == propertyType;
263+
}
264+
250265
public <V> Property<V> getProperty(PropertyKey key) {
251266
try {
252267
return (Property<V>) this.settings.propertiesMapArr[key.getId()];

0 commit comments

Comments
 (0)