Solved how to cancel explosion in item frames and cancel item drop?

Discussion in 'Spigot Plugin Development' started by Lukinhasl157, Feb 4, 2020.

  1. I created a skills plugin, one of these skills shoots wither heads and if you catch a player he creates an extra explosion, but if someone shoots an item frame it explodes and the item falls, how can I cancel it?
     
  2. HangingBreakByEntityEvent
     
  3. I tried it, but is not work
     
  4. I got it, it doesn't break the frame item, but the item in the frame item it disappears


    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.hanging.HangingBreakByEntityEvent;
    import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
    public class HangingBreakByEntity implements Listener {
    @EventHandler
    public void hangingBreak(HangingBreakByEntityEvent e) {
    if (e.getRemover() instanceof Player && e.getCause().equals(RemoveCause.ENTITY)) {
    e.setCancelled(true);
    }
    }
    }
     
  5. its worked for me, if anyone needs


    this event cancel drops items in itemframe by wither head

    @EventHandler
    public void entityDamageByEntity(EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof ItemFrame && e.getDamager() instanceof WitherSkull) {
    e.setCancelled(true);
    }
    }

    this event cancels the itemframe and painting break by player

    @EventHandler
    public void hangingBreak(HangingBreakByEntityEvent e) {
    if (e.getRemover() instanceof Player && e.getCause().equals(RemoveCause.ENTITY)) {
    e.setCancelled(true);
    }
    }
     
    • Useful Useful x 1