mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 15:08:35 +00:00
Selective upstream merge
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user