Fix replace patterns

Fixes #445 #440 #372
This commit is contained in:
dordsor21
2020-05-06 15:50:57 +01:00
parent 3abf964620
commit 0c539b4e84
3 changed files with 46 additions and 21 deletions

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
@ -29,6 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A Fuzzy BlockState. Used for partial matching.
*
@ -37,6 +37,7 @@ import java.util.Objects;
public class FuzzyBlockState extends BlockState {
private final Map<PropertyKey, Object> props;
private final Map<Property<?>, Object> values;
FuzzyBlockState(BlockType blockType) {
this(blockType.getDefaultState(), null);
@ -50,12 +51,15 @@ public class FuzzyBlockState extends BlockState {
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
if (values == null || values.isEmpty()) {
props = Collections.emptyMap();
this.values = Collections.emptyMap();
} else {
props = new HashMap<>(values.size());
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
props.put(entry.getKey().getKey(), entry.getValue());
}
this.values = new HashMap<>(values);
}
}
/**
@ -89,9 +93,15 @@ public class FuzzyBlockState extends BlockState {
return true;
}
@Override
public BaseBlock toBaseBlock() {
return new BaseBlock(this);
@Override public BaseBlock toBaseBlock() {
if (props == null || props.isEmpty()) {
return super.toBaseBlock();
}
BlockState state = this;
for (Map.Entry<PropertyKey, Object> entry : props.entrySet()) {
state = state.with(entry.getKey(), entry.getValue());
}
return new BaseBlock(state);
}
@Override
@ -99,6 +109,11 @@ public class FuzzyBlockState extends BlockState {
return getFullState();
}
@Override
public Map<Property<?>, Object> getStates() {
return values;
}
/**
* Gets an instance of a builder.
*