Selective upstream merge

This commit is contained in:
matt
2019-04-02 16:26:51 -04:00
parent 7ad364917f
commit 47e66913e3
7 changed files with 47 additions and 21 deletions

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.blocks;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
@ -26,6 +28,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
@ -190,4 +193,28 @@ public final class Blocks {
return false;
}
/**
* Parses a string->string map to find the matching Property and values for the given BlockType.
*
* @param states the desired states and values
* @param type the block type to get properties and values for
* @return a property->value map
*/
public static Map<Property<Object>, Object> resolveProperties(Map<String, String> states, BlockType type) {
Map<String, ? extends Property<?>> existing = type.getPropertyMap();
Map<Property<Object>, Object> newMap = Maps.newHashMap();
states.forEach((key, value) -> {
@SuppressWarnings("unchecked")
Property<Object> prop = (Property<Object>) existing.get(key);
if (prop == null) return;
Object val = null;
try {
val = prop.getValueFor(value);
} catch (IllegalArgumentException ignored) {
}
if (val == null) return;
newMap.put(prop, val);
});
return newMap;
}
}