Instant break

Discussion in 'Plugin Development' started by Mrskils, May 22, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Mrskils

    how to make it so i can instantbreak blocks now it just breaks them normal not instant
     
  2. You can try using PlayerInteractEvent .
     
  3. Offline

    robertforyou

    Or BlockDamageEvent
     
  4. Offline

    TheDiamond06

    @Mrskils PlayerInteractEvent > Right Click Block With Pickaxe > Break Block
     
  5. Offline

    DuskFireHD

    Just use BlockDamageEvent and then set event.setInstantBreak(true); so simple xD
     
  6. Offline

    Agentleader1

    What others have said is highly true, but I'd recommend to prevent grief that you create another plugin that disables interact and damage block events when the block broken is off limits.

    New(er) code for YOUR plugin:
    Code:
    @EventHandler
    public void onInteract(PlayerInteractEvent pie){
          if(pie.getAction().equals(Action.LEFT_CLICK_BLOCK)){
              if(!(pie.isCancelled())){
                     pie.getClickedBlock().setType(Material.AIR); //or null, I think
              }
          }
    }
    To prevent grief in another plugin:
    Code:
    @EventHandler(priority == EventPriority.HIGHEST)
    public void onInteract(PlayerInteractEvent pie){
          if(pie.getClickedBlock().getState().getLocation() is not in break allowed region){
                pie.setCancelled(true);
          }
    }
    And the reason I use PlayerInteractEvent over BlockDamageEvent is because of Bedrock. If you'd want to instant break Bedrock, use PlayerInteractEvent. If you don't want to break bedrock, use BlockDamageEvent instead.
     
Thread Status:
Not open for further replies.

Share This Page