diff --git a/src/main/java/org/kapelle/multiblock/MultiblockListener.java b/src/main/java/org/kapelle/multiblock/MultiblockListener.java new file mode 100644 index 0000000..7dc5390 --- /dev/null +++ b/src/main/java/org/kapelle/multiblock/MultiblockListener.java @@ -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); + +}