From bfa145b862b891e40b2ce2f920ab1477f4a91f41 Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 27 Jun 2020 17:14:22 +0200 Subject: [PATCH] implemented custom check function --- .../kapelle/multiblock/BlockComponent.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/kapelle/multiblock/BlockComponent.java b/src/main/java/org/kapelle/multiblock/BlockComponent.java index 136a2b0..8882131 100644 --- a/src/main/java/org/kapelle/multiblock/BlockComponent.java +++ b/src/main/java/org/kapelle/multiblock/BlockComponent.java @@ -7,14 +7,14 @@ import org.bukkit.block.Block; import java.util.Collections; import java.util.Set; +interface CheckFunction { + boolean apply(Location location); +} + public class BlockComponent { private final BlockComponentMode mode; private final Set blocks; - - public BlockComponent(){ - this.mode = BlockComponentMode.ANY; - this.blocks = Collections.emptySet(); - } + private CheckFunction customCheckFunction; public BlockComponent(BlockComponentMode mode){ if(mode == BlockComponentMode.SET){ @@ -30,10 +30,18 @@ public class BlockComponent { this.blocks = validBlocks; } - // TODO: custom check function constructor + public BlockComponent(CheckFunction customCheckFunction){ + this.mode = BlockComponentMode.CUSTOM; + this.blocks = Collections.emptySet(); + this.customCheckFunction = customCheckFunction; + } public boolean isValidBlock(Location location){ - return isValidType(location.getBlock().getType()); + if(this.mode == BlockComponentMode.CUSTOM){ + return this.customCheckFunction.apply(location); + }else{ + return isValidType(location.getBlock().getType()); + } } private boolean isValidType(Material type){ @@ -44,8 +52,6 @@ public class BlockComponent { return true; case SET: return blocks.contains(type); - case CUSTOM: - return false; // TODO custom function default: return false;