implemented multiblock block component
This commit is contained in:
parent
9438b1b526
commit
c5eae6172c
55
src/main/java/org/kapelle/multiblock/BlockComponent.java
Normal file
55
src/main/java/org/kapelle/multiblock/BlockComponent.java
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.kapelle.multiblock;
|
||||
|
||||
public enum BlockComponentMode {
|
||||
ANY, AIR, SET, CUSTOM
|
||||
}
|
Loading…
Reference in New Issue
Block a user