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.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
interface CheckFunction {
|
||||||
|
boolean apply(Location location);
|
||||||
|
}
|
||||||
|
|
||||||
public class BlockComponent {
|
public class BlockComponent {
|
||||||
private final BlockComponentMode mode;
|
private final BlockComponentMode mode;
|
||||||
private final Set<Material> blocks;
|
private final Set<Material> blocks;
|
||||||
|
private CheckFunction customCheckFunction;
|
||||||
public BlockComponent(){
|
|
||||||
this.mode = BlockComponentMode.ANY;
|
|
||||||
this.blocks = Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockComponent(BlockComponentMode mode){
|
public BlockComponent(BlockComponentMode mode){
|
||||||
if(mode == BlockComponentMode.SET){
|
if(mode == BlockComponentMode.SET){
|
||||||
@ -30,11 +30,19 @@ public class BlockComponent {
|
|||||||
this.blocks = validBlocks;
|
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){
|
public boolean isValidBlock(Location location){
|
||||||
|
if(this.mode == BlockComponentMode.CUSTOM){
|
||||||
|
return this.customCheckFunction.apply(location);
|
||||||
|
}else{
|
||||||
return isValidType(location.getBlock().getType());
|
return isValidType(location.getBlock().getType());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isValidType(Material type){
|
private boolean isValidType(Material type){
|
||||||
switch (this.mode){
|
switch (this.mode){
|
||||||
@ -44,8 +52,6 @@ public class BlockComponent {
|
|||||||
return true;
|
return true;
|
||||||
case SET:
|
case SET:
|
||||||
return blocks.contains(type);
|
return blocks.contains(type);
|
||||||
case CUSTOM:
|
|
||||||
return false; // TODO custom function
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user