implemented MultiblockListener

This commit is contained in:
Niklas 2020-06-27 16:57:41 +02:00
parent eba9493f63
commit 8e90d957f7

View 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);
}