From c3d832c3fd838850f92a41f27c24e3c3760501c6 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Wed, 18 Jul 2018 17:39:25 +1000 Subject: [PATCH] State system is done. It works. Finally. Still a few rough edges that need fixing however. --- .../worldedit/bukkit/WorldEditPlugin.java | 4 +- .../bukkit/adapter/impl/Spigot_v1_13_R1.class | Bin 19401 -> 19806 bytes .../extension/factory/DefaultBlockParser.java | 6 ++- .../registry/state/AbstractProperty.java | 3 ++ .../registry/state/DirectionalProperty.java | 2 +- .../worldedit/world/block/BlockState.java | 41 +++++++++++++----- .../world/block/BlockStateHolder.java | 4 +- .../world/registry/BundledBlockData.java | 2 - 8 files changed, 42 insertions(+), 20 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index cbd56f920..057742b92 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -82,6 +82,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { WorldEdit worldEdit = WorldEdit.getInstance(); + loadAdapter(); // Need an adapter to work with special blocks with NBT data + // Setup platform server = new BukkitServerInterface(this, getServer()); worldEdit.getPlatformManager().register(server); @@ -101,8 +103,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { // Forge WorldEdit and there's (probably) not going to be any other // platforms to be worried about... at the current time of writing WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); - - loadAdapter(); // Need an adapter to work with special blocks with NBT data } private void loadConfig() { diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class index f2101f1559f9d3bb1dd4501eda74693cdb116743..8520a5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J-GE+B6;?!yFpgYSlKVg|m& z&0;@xzysJ958}0W2uI^#oP=*P!jG_v$8Z(@^1K?~#WnbW(?Fyaa-j*{k4xG0Na*EU za|ja{*$?7FTot|x&>pI|7>LoD#lV;IZ8g75!)1(eU{7mqVOYUM^H5DIkuS7r!;f$l z { if (propertyKey == null) { throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName()); } - Object value = propertyKey.getValueFor(parts[1]); - if (value == null) { + Object value; + try { + value = propertyKey.getValueFor(parts[1]); + } catch (IllegalArgumentException e) { throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java index 1168db403..905d0466b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java @@ -21,6 +21,9 @@ package com.sk89q.worldedit.registry.state; import static com.google.common.base.Preconditions.checkState; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + import java.util.List; public abstract class AbstractProperty implements Property { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java index ef41a8c0c..32c0e1435 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/DirectionalProperty.java @@ -34,7 +34,7 @@ public class DirectionalProperty extends AbstractProperty { @Nullable @Override public Direction getValueFor(final String string) { - Direction direction = Direction.valueOf(string); + Direction direction = Direction.valueOf(string.toUpperCase()); if (!getValues().contains(direction)) { throw new IllegalArgumentException("Invalid direction value: " + string + ". Must be in " + getValues().toString()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 3430e431e..94159c223 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -24,10 +24,12 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Table; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.registry.state.Property; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -66,19 +68,28 @@ public class BlockState implements BlockStateHolder { } public static Map, Object>, BlockState> generateStateMap(BlockType blockType) { - List properties = blockType.getProperties(); - List> valueLists = Lists.cartesianProduct(properties.stream().map(Property::getValues).collect(Collectors.toList())); Map, Object>, BlockState> stateMap = new LinkedHashMap<>(); - for (int i = 0; i < valueLists.size(); i++) { - List valueList = valueLists.get(i); - Property property = properties.get(i); - LinkedHashMap, Object> valueMap = new LinkedHashMap<>(); - BlockState stateMaker = new BlockState(blockType); - for (Object value : valueList) { - valueMap.put(property, value); - stateMaker.setState(property, value); + List properties = blockType.getProperties(); + + if (!properties.isEmpty()) { + List> separatedValues = Lists.newArrayList(); + for (Property prop : properties) { + List vals = Lists.newArrayList(); + vals.addAll(prop.getValues()); + separatedValues.add(vals); + } + List> valueLists = Lists.cartesianProduct(separatedValues); + for (List valueList : valueLists) { + Map, Object> valueMap = Maps.newTreeMap(Comparator.comparing(Property::getName)); + BlockState stateMaker = new BlockState(blockType); + for (int i = 0; i < valueList.size(); i++) { + Property property = properties.get(i); + Object value = valueList.get(i); + valueMap.put(property, value); + stateMaker.setState(property, value); + } + stateMap.put(valueMap, stateMaker); } - stateMap.put(valueMap, stateMaker); } if (stateMap.isEmpty()) { @@ -101,7 +112,13 @@ public class BlockState implements BlockStateHolder { property.getValues().forEach(value -> { if(value != entry.getValue()) { - states.put(property, value, stateMap.get(this.withValue(property, value))); + BlockState modifiedState = stateMap.get(this.withValue(property, value)); + if (modifiedState != null) { + states.put(property, value, modifiedState); + } else { + System.out.println(stateMap); + WorldEdit.logger.warning("Found a null state at " + this.withValue(property, value)); + } } }); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index b8c2a9bee..b31888ee0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -76,7 +76,9 @@ public interface BlockStateHolder { if (getStates().isEmpty()) { return this.getBlockType().getId(); } else { - String properties = getStates().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining(",")); + String properties = + getStates().entrySet().stream().map(entry -> entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase()).collect(Collectors.joining( + ",")); return this.getBlockType().getId() + "[" + properties + "]"; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index 0ec4ca15f..98987d191 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -133,9 +133,7 @@ public class BundledBlockData { public static class BlockEntry { private String id; - private String unlocalizedName; public String localizedName; - private List aliases; private SimpleBlockMaterial material = new SimpleBlockMaterial(); }