From b2769befdb1529d62702efb834bdcc9c72b7ce56 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 3 Aug 2018 23:01:56 +1000 Subject: [PATCH] Added a few utility methods. --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 21 +++++++++++++++++++ .../extension/factory/DefaultBlockParser.java | 5 ++++- .../worldedit/world/block/BlockState.java | 8 +++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index 4f41c7e94..f1181cf50 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -41,6 +41,7 @@ import com.sk89q.worldedit.world.item.ItemTypes; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.HashMap; @@ -106,6 +107,26 @@ public class BukkitAdapter { return new BukkitWorld(world); } + /** + * Create a WorldEdit Player from a Bukkit Player. + * + * @param player The Bukkit player + * @return The WorldEdit player + */ + public static BukkitPlayer adapt(Player player) { + return WorldEditPlugin.getInstance().wrapPlayer(player); + } + + /** + * Create a Bukkit Player from a WorldEdit Player. + * + * @param player The WorldEdit player + * @return The Bukkit player + */ + public static Player adapt(com.sk89q.worldedit.entity.Player player) { + return ((BukkitPlayer) player).getPlayer(); + } + /** * Create a Bukkit world from a WorldEdit world. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java index 83959d638..f7bf9770d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java @@ -268,7 +268,10 @@ class DefaultBlockParser extends InputParser { // No wildcards allowed => eliminate them. (Start with default state) state = blockType.getDefaultState(); } else { - state = new BlockState(blockType, blockStates); + state = blockType.getDefaultState().toFuzzy(); + for (Map.Entry, Object> blockState : blockStates.entrySet()) { + state = state.with((Property) blockState.getKey(), blockState.getValue()); + } } state = applyProperties(state, stateProperties); 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 908a2ba67..f32159e55 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 @@ -50,7 +50,7 @@ public class BlockState implements BlockStateHolder { // Neighbouring state table. private Table, Object, BlockState> states; - BlockState(BlockType blockType) { + private BlockState(BlockType blockType) { this.blockType = blockType; this.values = new LinkedHashMap<>(); this.fuzzy = false; @@ -62,13 +62,13 @@ public class BlockState implements BlockStateHolder { * @param blockType The block type * @param values The block state values */ - public BlockState(BlockType blockType, Map, Object> values) { + private BlockState(BlockType blockType, Map, Object> values) { this.blockType = blockType; this.values = values; this.fuzzy = true; } - public static Map, Object>, BlockState> generateStateMap(BlockType blockType) { + static Map, Object>, BlockState> generateStateMap(BlockType blockType) { Map, Object>, BlockState> stateMap = new LinkedHashMap<>(); List properties = blockType.getProperties(); @@ -105,7 +105,7 @@ public class BlockState implements BlockStateHolder { return stateMap; } - public void populate(Map, Object>, BlockState> stateMap) { + private void populate(Map, Object>, BlockState> stateMap) { final Table, Object, BlockState> states = HashBasedTable.create(); for(final Map.Entry, Object> entry : this.values.entrySet()) {