mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
parent
3abf964620
commit
0c539b4e84
@ -237,6 +237,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
||||||
String[] blockAndExtraData = input.trim().split("\\|", 2);
|
String[] blockAndExtraData = input.trim().split("\\|", 2);
|
||||||
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
||||||
|
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||||
|
|
||||||
BlockState state = null;
|
BlockState state = null;
|
||||||
|
|
||||||
@ -287,6 +288,10 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
}
|
}
|
||||||
stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1);
|
stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1);
|
||||||
}
|
}
|
||||||
|
String[] stateProperties = EMPTY_STRING_ARRAY;
|
||||||
|
if(stateString != null) {
|
||||||
|
stateProperties = stateString.split(",");
|
||||||
|
}
|
||||||
if (typeString.isEmpty()) {
|
if (typeString.isEmpty()) {
|
||||||
throw new InputParseException("Invalid format");
|
throw new InputParseException("Invalid format");
|
||||||
}
|
}
|
||||||
@ -319,7 +324,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
}
|
}
|
||||||
Player player = (Player) actor;
|
Player player = (Player) actor;
|
||||||
BlockBag bag = player.getInventoryBlockBag();
|
BlockBag bag = player.getInventoryBlockBag();
|
||||||
if (bag == null || !(bag instanceof SlottableBlockBag)) {
|
if (!(bag instanceof SlottableBlockBag)) {
|
||||||
throw new InputParseException("Unsupported!");
|
throw new InputParseException("Unsupported!");
|
||||||
}
|
}
|
||||||
SlottableBlockBag slottable = (SlottableBlockBag) bag;
|
SlottableBlockBag slottable = (SlottableBlockBag) bag;
|
||||||
@ -341,25 +346,21 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
"Does not match a valid block type: '" + input + "'");
|
"Does not match a valid block type: '" + input + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nbt == null) nbt = state.getNbtData();
|
if (nbt == null) {
|
||||||
|
nbt = state.getNbtData();
|
||||||
if (stateString != null) {
|
|
||||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockStates.putAll(parseProperties(state.getBlockType(), stateProperties, context));
|
||||||
if (context.isPreferringWildcard()) {
|
if (context.isPreferringWildcard()) {
|
||||||
if (stateString == null || stateString.isEmpty()) {
|
if (stateString == null || stateString.isEmpty()) {
|
||||||
state = new FuzzyBlockState(state);
|
state = new FuzzyBlockState(state);
|
||||||
} else {
|
} else {
|
||||||
BlockType blockType = state.getBlockType();
|
|
||||||
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
|
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
|
||||||
fuzzyBuilder.type(blockType);
|
fuzzyBuilder.type(state.getBlockType());
|
||||||
String[] entries = stateString.split(",");
|
for (Map.Entry<Property<?>, Object> blockState : blockStates.entrySet()) {
|
||||||
for (String entry : entries) {
|
@SuppressWarnings("unchecked")
|
||||||
String[] split = entry.split("=");
|
Property<Object> objProp = (Property<Object>) blockState.getKey();
|
||||||
String key = split[0];
|
fuzzyBuilder.withProperty(objProp, blockState.getValue());
|
||||||
String val = split[1];
|
|
||||||
Property<Object> prop = blockType.getProperty(key);
|
|
||||||
fuzzyBuilder.withProperty(prop, prop.getValueFor(val));
|
|
||||||
}
|
}
|
||||||
state = fuzzyBuilder.build();
|
state = fuzzyBuilder.build();
|
||||||
}
|
}
|
||||||
@ -390,7 +391,9 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbt != null) return validate(context, state.toBaseBlock(nbt));
|
if (nbt != null) {
|
||||||
|
return validate(context, state.toBaseBlock(nbt));
|
||||||
|
}
|
||||||
|
|
||||||
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN
|
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN
|
||||||
|| BlockCategories.SIGNS.contains(blockType)) {
|
|| BlockCategories.SIGNS.contains(blockType)) {
|
||||||
|
@ -29,6 +29,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
|
import com.sk89q.worldedit.world.block.ImmutableBaseBlock;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -154,9 +155,15 @@ public class BlockMask extends ABlockMask {
|
|||||||
public void add(Collection<BaseBlock> blocks) {
|
public void add(Collection<BaseBlock> blocks) {
|
||||||
checkNotNull(blocks);
|
checkNotNull(blocks);
|
||||||
for (BaseBlock block : blocks) {
|
for (BaseBlock block : blocks) {
|
||||||
|
if (block instanceof ImmutableBaseBlock) {
|
||||||
|
for (BlockState state : block.getBlockType().getAllStates()) {
|
||||||
|
ordinals[state.getOrdinal()] = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
add(block.toBlockState());
|
add(block.toBlockState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given blocks to the list of criteria.
|
* Add the given blocks to the list of criteria.
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.world.block;
|
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.Property;
|
||||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||||
|
|
||||||
@ -29,6 +27,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Fuzzy BlockState. Used for partial matching.
|
* A Fuzzy BlockState. Used for partial matching.
|
||||||
*
|
*
|
||||||
@ -37,6 +37,7 @@ import java.util.Objects;
|
|||||||
public class FuzzyBlockState extends BlockState {
|
public class FuzzyBlockState extends BlockState {
|
||||||
|
|
||||||
private final Map<PropertyKey, Object> props;
|
private final Map<PropertyKey, Object> props;
|
||||||
|
private final Map<Property<?>, Object> values;
|
||||||
|
|
||||||
FuzzyBlockState(BlockType blockType) {
|
FuzzyBlockState(BlockType blockType) {
|
||||||
this(blockType.getDefaultState(), null);
|
this(blockType.getDefaultState(), null);
|
||||||
@ -50,12 +51,15 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
|
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
|
||||||
if (values == null || values.isEmpty()) {
|
if (values == null || values.isEmpty()) {
|
||||||
props = Collections.emptyMap();
|
props = Collections.emptyMap();
|
||||||
|
this.values = Collections.emptyMap();
|
||||||
} else {
|
} else {
|
||||||
props = new HashMap<>(values.size());
|
props = new HashMap<>(values.size());
|
||||||
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
|
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
|
||||||
props.put(entry.getKey().getKey(), entry.getValue());
|
props.put(entry.getKey().getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
this.values = new HashMap<>(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,9 +93,15 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public BaseBlock toBaseBlock() {
|
||||||
public BaseBlock toBaseBlock() {
|
if (props == null || props.isEmpty()) {
|
||||||
return new BaseBlock(this);
|
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
|
@Override
|
||||||
@ -99,6 +109,11 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
return getFullState();
|
return getFullState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Property<?>, Object> getStates() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an instance of a builder.
|
* Gets an instance of a builder.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user