Clarify state when asking for caps with no platforms (+ fuzzy system changes)

This commit is contained in:
Kenzie Togami 2018-12-28 22:20:12 -08:00 committed by IronApollo
parent 7d7da78dbc
commit 8f11d0469b
3 changed files with 40 additions and 18 deletions

View File

@ -170,8 +170,13 @@ public class PlatformManager {
if (platform != null) {
return platform;
} else {
if (preferences.isEmpty() && !platforms.isEmpty()) {
return platforms.get(0); // Use the first available if preferences have not been decided yet.
if (preferences.isEmpty()) {
// Use the first available if preferences have not been decided yet.
if (platforms.isEmpty()) {
// No platforms registered, this is being called too early!
throw new NoCapablePlatformException("No platforms have been registered yet! Please wait until WorldEdit is initialized.");
}
return platforms.get(0);
}
throw new NoCapablePlatformException("No platform was found supporting " + capability.name());
}

View File

@ -216,6 +216,10 @@ public class BlockType implements FawePattern {
}
return defaultState;
}
public FuzzyBlockState getFuzzyMatcher() {
return new FuzzyBlockState(this);
}
/**
* Slow

View File

@ -37,12 +37,26 @@ public class FuzzyBlockState extends BlockState {
super(blockType);
}
@SuppressWarnings("unchecked")
@Override
public BlockState toImmutableState() {
private FuzzyBlockState(BlockType blockType, Map<Property<?>, Object> values) {
this(blockType);
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
// setState(entry.getKey(), entry.getValue());
with((Property<Object>)entry.getKey(), entry.getValue());
}
}
/**
* Gets a full BlockState from this fuzzy one, filling in
* properties with default values where necessary.
*
* @return The full BlockState
*/
public BlockState getFullState() {
BlockState state = getBlockType().getDefaultState();
for (Map.Entry<Property<?>, Object> entry : getStates().entrySet()) {
state = state.with((Property<Object>) entry.getKey(), entry.getValue());
@SuppressWarnings("unchecked")
Property<Object> objKey = (Property<Object>) entry.getKey();
state = state.with(objKey, entry.getValue());
}
return getBlockType().getDefaultState();
}
@ -60,7 +74,7 @@ public class FuzzyBlockState extends BlockState {
* Builder for FuzzyBlockState
*/
public static class Builder {
private BlockState internalState;
private BlockType type;
private Map<Property<?>, Object> values = new HashMap<>();
/**
@ -71,7 +85,7 @@ public class FuzzyBlockState extends BlockState {
*/
public Builder type(BlockType type) {
checkNotNull(type);
internalState = type.getDefaultState();
this.type = type;
return this;
}
@ -83,7 +97,7 @@ public class FuzzyBlockState extends BlockState {
*/
public Builder type(BlockState state) {
checkNotNull(state);
internalState = state;
this.type = state.getBlockType();
return this;
}
@ -98,7 +112,8 @@ public class FuzzyBlockState extends BlockState {
public <V> Builder withProperty(Property<V> property, V value) {
checkNotNull(property);
checkNotNull(value);
checkNotNull(internalState, "The type must be set before the properties!");
checkNotNull(type, "The type must be set before the properties!");
type.getProperty(property.getName()); // Verify the property is valid for this type
values.put(property, value);
return this;
}
@ -109,13 +124,11 @@ public class FuzzyBlockState extends BlockState {
* @return The fuzzy BlockState
*/
public FuzzyBlockState build() {
checkNotNull(internalState);
FuzzyBlockState blockState = new FuzzyBlockState(internalState.getBlockType());
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
// blockState.setState(entry.getKey(), entry.getValue());
blockState = (FuzzyBlockState) blockState.with((Property<Object>) entry.getKey(), entry.getValue());
checkNotNull(type);
if (values.isEmpty()) {
return type.getFuzzyMatcher();
}
return blockState;
return new FuzzyBlockState(type, values);
}
/**
@ -124,9 +137,9 @@ public class FuzzyBlockState extends BlockState {
* @return The builder, for chaining
*/
public Builder reset() {
this.internalState = null;
this.type = null;
this.values.clear();
return this;
}
}
}
}