implemented multiblock block component

This commit is contained in:
Niklas 2020-06-27 16:30:25 +02:00
parent 9438b1b526
commit c5eae6172c
2 changed files with 60 additions and 0 deletions

View File

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

View File

@ -0,0 +1,5 @@
package org.kapelle.multiblock;
public enum BlockComponentMode {
ANY, AIR, SET, CUSTOM
}