Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. package org.langricr.mcconstruct.samples;
  2.  
  3. import org.bukkit.Material;
  4. import org.bukkit.block.Block;
  5. import org.langricr.mcconstruct.McConstruct;
  6. import org.langricr.mcconstruct.Utils;
  7. import org.langricr.mcconstruct.construct.Construct;
  8. import org.langricr.mcconstruct.construct.blueprint.BlueprintManager;
  9. import org.langricr.mcconstruct.construct.blueprint.BlueprintPoint;
  10. import org.langricr.mcconstruct.event.Event.Type;
  11. import org.langricr.mcconstruct.event.EventListener;
  12. import org.langricr.mcconstruct.event.block.CBlockDamageEvent;
  13. import org.langricr.mcconstruct.event.block.CBlockRightClickEvent;
  14. import org.langricr.mcconstruct.event.construct.ConstructDeleteEvent;
  15. import org.langricr.util.PolarCoordinate;
  16. import org.langricr.util.PolarCoordinate.Rotation;
  17. import org.langricr.util.WorldCoordinate;
  18.  
  19. public class ButtonBreaker extends Construct {
  20.  
  21. public ButtonBreaker(WorldCoordinate core, Rotation rotation) {
  22. super(core, rotation);
  23.  
  24. EventListener.getInstance().registerConstructEvent( this, Type.CONSTRUCT_DELETE );
  25. EventListener.getInstance().registerConstructEvent( this, Type.BLOCK_DAMAGED );
  26. EventListener.getInstance().registerConstructEvent( this, Type.BLOCK_RIGHTCLICKED );
  27. }
  28.  
  29. public void onConstructDeleted( ConstructDeleteEvent cde ) {
  30. if ( cde.getConstruct() != this ) return;
  31.  
  32. for ( BlueprintPoint bp : BlueprintManager.getInstance().getBlueprint( this.getClass().getName() ).getPoints() ) {
  33. Block block = Utils.getBlockAt( getCore().offset( new PolarCoordinate( bp ).rotate( getRotation() ) ) );
  34.  
  35. block.setType( Material.AIR );
  36. }
  37. }
  38.  
  39. public void onBlockDamaged( CBlockDamageEvent bde ) {
  40. if ( bde.getBlock().getType() == Material.STONE_BUTTON && getCore().distanceTo( new WorldCoordinate( bde.getBlock() ) ) <= 16.0D ) {
  41. queueButton( bde.getBlock() );
  42. }
  43. }
  44.  
  45. public void onBlockRightClicked( CBlockRightClickEvent cbrce ) {
  46. if ( cbrce.getBlock().getType() == Material.STONE_BUTTON && getCore().distanceTo( new WorldCoordinate( cbrce.getBlock() ) ) <= 16.0D ) {
  47. queueButton( cbrce.getBlock() );
  48. }
  49. }
  50.  
  51. public void queueButton( final Block block ) {
  52. Runnable r = new Runnable() {
  53. @Override
  54. public void run() {
  55. block.setType( Material.AIR );
  56. }
  57. };
  58.  
  59. McConstruct.getInstance().getServer().getScheduler().scheduleSyncDelayedTask( McConstruct.getInstance(), r, 40 );
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement