From c5eae6172cd57ddb30a668481043d0b692e5ff33 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 27 Jun 2020 16:30:25 +0200 Subject: [PATCH] implemented multiblock block component --- .../kapelle/multiblock/BlockComponent.java | 55 +++++++++++++++++++ .../multiblock/BlockComponentMode.java | 5 ++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/org/kapelle/multiblock/BlockComponent.java create mode 100644 src/main/java/org/kapelle/multiblock/BlockComponentMode.java 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 +}