implemented custom check function
This commit is contained in:
parent
8e90d957f7
commit
bfa145b862
@ -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,11 +30,19 @@ 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){
|
||||
if(this.mode == BlockComponentMode.CUSTOM){
|
||||
return this.customCheckFunction.apply(location);
|
||||
}else{
|
||||
return isValidType(location.getBlock().getType());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidType(Material type){
|
||||
switch (this.mode){
|
||||
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user