Solved Disable Item Frame from Breaking?

Discussion in 'Plugin Development' started by SlimeZAP, Jan 3, 2013.

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

    SlimeZAP

    How would I disable players from breaking item frames? I've tried blockBreakEvent but haven't had any luck. What would the code look like?

    Thanks - Zach
     
  2. Offline

    ImDeJay

    i think an item frame is considered an entity.

    so look at entitydamagebyentity?

    Code:
    @EventHandler
    public void blockBreak(BlockBreakEvent event){
    Block block = event.getBlock();
     
    if(block instanceof ItemFrame){
    //do something here
     
    }
     
    }
     
  3. Offline

    SlimeZAP

    No, that didn't work. Anything else I can try?
     
  4. Offline

    Sparta

    How about this:

    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
    Block b = event.getBlock();
    if(event.getBlock().getType().equals(Material.ITEM_FRAME)) {
    event.setCancelled(true);
    //Do other things here if necessary.
    }
    }

    I did this off of my head, so do something SIMILAR to that.
     
  5. Offline

    DarkBladee12

    SlimeZAP try the HangingBreakByEntityEvent and check "if(event.getEntity() instanceof ItemFrame)". BlockBreakEvent will not work, because the ItemFrame is an entity ;)
     
    SlimeZAP likes this.
  6. Offline

    SlimeZAP

    Thanks DarkBladee12, I never knew that existed. Got it to work :)
     
Thread Status:
Not open for further replies.

Share This Page