Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.langricr.mcconstruct.samples;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.langricr.mcconstruct.McConstruct;
- import org.langricr.mcconstruct.Utils;
- import org.langricr.mcconstruct.construct.Construct;
- import org.langricr.mcconstruct.construct.blueprint.BlueprintManager;
- import org.langricr.mcconstruct.construct.blueprint.BlueprintPoint;
- import org.langricr.mcconstruct.event.Event.Type;
- import org.langricr.mcconstruct.event.EventListener;
- import org.langricr.mcconstruct.event.block.CBlockDamageEvent;
- import org.langricr.mcconstruct.event.block.CBlockRightClickEvent;
- import org.langricr.mcconstruct.event.construct.ConstructDeleteEvent;
- import org.langricr.util.PolarCoordinate;
- import org.langricr.util.PolarCoordinate.Rotation;
- import org.langricr.util.WorldCoordinate;
- public class ButtonBreaker extends Construct {
- public ButtonBreaker(WorldCoordinate core, Rotation rotation) {
- super(core, rotation);
- EventListener.getInstance().registerConstructEvent( this, Type.CONSTRUCT_DELETE );
- EventListener.getInstance().registerConstructEvent( this, Type.BLOCK_DAMAGED );
- EventListener.getInstance().registerConstructEvent( this, Type.BLOCK_RIGHTCLICKED );
- }
- public void onConstructDeleted( ConstructDeleteEvent cde ) {
- if ( cde.getConstruct() != this ) return;
- for ( BlueprintPoint bp : BlueprintManager.getInstance().getBlueprint( this.getClass().getName() ).getPoints() ) {
- Block block = Utils.getBlockAt( getCore().offset( new PolarCoordinate( bp ).rotate( getRotation() ) ) );
- block.setType( Material.AIR );
- }
- }
- public void onBlockDamaged( CBlockDamageEvent bde ) {
- if ( bde.getBlock().getType() == Material.STONE_BUTTON && getCore().distanceTo( new WorldCoordinate( bde.getBlock() ) ) <= 16.0D ) {
- queueButton( bde.getBlock() );
- }
- }
- public void onBlockRightClicked( CBlockRightClickEvent cbrce ) {
- if ( cbrce.getBlock().getType() == Material.STONE_BUTTON && getCore().distanceTo( new WorldCoordinate( cbrce.getBlock() ) ) <= 16.0D ) {
- queueButton( cbrce.getBlock() );
- }
- }
- public void queueButton( final Block block ) {
- Runnable r = new Runnable() {
- @Override
- public void run() {
- block.setType( Material.AIR );
- }
- };
- McConstruct.getInstance().getServer().getScheduler().scheduleSyncDelayedTask( McConstruct.getInstance(), r, 40 );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement