diff --git a/src/main/java/org/kapelle/multiblock/BlockComponent.java b/src/main/java/org/kapelle/multiblock/BlockComponent.java new file mode 100644 index 0000000..136a2b0 --- /dev/null +++ b/src/main/java/org/kapelle/multiblock/BlockComponent.java @@ -0,0 +1,55 @@ +package org.kapelle.multiblock; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import java.util.Collections; +import java.util.Set; + +public class BlockComponent { + private final BlockComponentMode mode; + private final Set blocks; + + public BlockComponent(){ + this.mode = BlockComponentMode.ANY; + this.blocks = Collections.emptySet(); + } + + public BlockComponent(BlockComponentMode mode){ + if(mode == BlockComponentMode.SET){ + throw new RuntimeException("Component is impossible to satisfy because no valid blocks are given"); + } + + this.mode = mode; + this.blocks = Collections.emptySet(); + } + + public BlockComponent(BlockComponentMode mode, Set validBlocks){ + this.mode = mode; + this.blocks = validBlocks; + } + + // TODO: custom check function constructor + + public boolean isValidBlock(Location location){ + return isValidType(location.getBlock().getType()); + } + + private boolean isValidType(Material type){ + switch (this.mode){ + case AIR: + return type == Material.AIR; + case ANY: + return true; + case SET: + return blocks.contains(type); + case CUSTOM: + return false; // TODO custom function + default: + return false; + + } + } + +} diff --git a/src/main/java/org/kapelle/multiblock/BlockComponentMode.java b/src/main/java/org/kapelle/multiblock/BlockComponentMode.java new file mode 100644 index 0000000..c8c1460 --- /dev/null +++ b/src/main/java/org/kapelle/multiblock/BlockComponentMode.java @@ -0,0 +1,5 @@ +package org.kapelle.multiblock; + +public enum BlockComponentMode { + ANY, AIR, SET, CUSTOM +}