Solved protected itemframes

Discussion in 'Plugin Development' started by BimKurzAfk, Aug 31, 2020.

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

    BimKurzAfk

    Which event do I have to cancel so that the player can no longer knock items out of the ItemFrames?
     
  2. Offline

    Kars

  3. Offline

    BimKurzAfk

  4. Online

    timtower Administrator Administrator Moderator

    With what code?
     
  5. Offline

    BimKurzAfk

    Code:
    @EventHandler
        public void cancleItemFrameDestroy(HangingBreakByEntityEvent event) {
            if(event.getEntity() instanceof ItemFrame) {
                event.setCancelled(true);
            }       
        }
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    BimKurzAfk

    The event gets triggerd when I try to destroy the item frame
     
  8. Offline

    KarimAKL

    @BimKurzAfk I'm not completely sure but, i believe getEntity() might be returning the item inside of the frame, which is probably not another frame. Try checking the kind of entity it is by printing it.
     
    Kars likes this.
  9. Offline

    Kars

    What he said.

    Just cancel the event as a whole and see if you can break the item >.>
     
  10. Offline

    BimKurzAfk

    I tried, not working
     
  11. Offline

    Kars

    @BimKurzAfk you're right.

    It is actually a EntityDamageByEntityEvent where entity is an item frame, and damager is a player.
     
    BimKurzAfk and KarimAKL like this.
  12. Offline

    BimKurzAfk

    It works, thanks a lot!
     
Thread Status:
Not open for further replies.

Share This Page