implemented custom check function

This commit is contained in:
Niklas 2020-06-27 17:14:22 +02:00
parent 8e90d957f7
commit bfa145b862

View File

@ -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<Material> 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;