Skip to content

Commit

Permalink
Added a few utility methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 3, 2018
1 parent 9df4b62 commit 4604502
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -106,6 +107,26 @@ public static World adapt(org.bukkit.World world) {
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.
*
Expand Down
Expand Up @@ -268,7 +268,10 @@ private BlockStateHolder parseLogic(String input, ParserContext context) throws
// 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<Property<?>, Object> blockState : blockStates.entrySet()) {
state = state.with((Property) blockState.getKey(), blockState.getValue());
}
}

state = applyProperties(state, stateProperties);
Expand Down
Expand Up @@ -50,7 +50,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
// Neighbouring state table.
private Table<Property<?>, Object, BlockState> states;

BlockState(BlockType blockType) {
private BlockState(BlockType blockType) {
this.blockType = blockType;
this.values = new LinkedHashMap<>();
this.fuzzy = false;
Expand All @@ -62,13 +62,13 @@ public class BlockState implements BlockStateHolder<BlockState> {
* @param blockType The block type
* @param values The block state values
*/
public BlockState(BlockType blockType, Map<Property<?>, Object> values) {
private BlockState(BlockType blockType, Map<Property<?>, Object> values) {
this.blockType = blockType;
this.values = values;
this.fuzzy = true;
}

public static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
Map<Map<Property<?>, Object>, BlockState> stateMap = new LinkedHashMap<>();
List<? extends Property> properties = blockType.getProperties();

Expand Down Expand Up @@ -105,7 +105,7 @@ public static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockTy
return stateMap;
}

public void populate(Map<Map<Property<?>, Object>, BlockState> stateMap) {
private void populate(Map<Map<Property<?>, Object>, BlockState> stateMap) {
final Table<Property<?>, Object, BlockState> states = HashBasedTable.create();

for(final Map.Entry<Property<?>, Object> entry : this.values.entrySet()) {
Expand Down

0 comments on commit 4604502

Please sign in to comment.