implemented MultiblockListener
This commit is contained in:
parent
eba9493f63
commit
8e90d957f7
36
src/main/java/org/kapelle/multiblock/MultiblockListener.java
Normal file
36
src/main/java/org/kapelle/multiblock/MultiblockListener.java
Normal file
@ -0,0 +1,36 @@
|
||||
package org.kapelle.multiblock;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
public abstract class MultiblockListener implements Listener {
|
||||
private final BlockComponent coreBlock;
|
||||
private final BlockVector coreBlockOffset;
|
||||
private final MultiblockStructure structure;
|
||||
|
||||
public MultiblockListener(JavaPlugin plugin, MultiblockStructure structure, BlockVector coreBlockOffset){
|
||||
this.structure = structure;
|
||||
this.coreBlockOffset = coreBlockOffset;
|
||||
|
||||
this.coreBlock = structure.getComponent(coreBlockOffset);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlaced(BlockPlaceEvent event){
|
||||
Location placedLocation = event.getBlockPlaced().getLocation();
|
||||
if(!event.isCancelled() && this.coreBlock.isValidBlock(placedLocation)){
|
||||
if(this.structure.isValid(placedLocation,this.coreBlockOffset)){
|
||||
callback(placedLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract void callback(Location coreBlockLocation);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user