Search in sources :

Example 1 with DestroyEntityEvent

use of com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent in project WorldGuard by EngineHub.

the class EventAbstractionListener method onHangingBreak.

@EventHandler(ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (event instanceof HangingBreakByEntityEvent) {
        Entity remover = ((HangingBreakByEntityEvent) event).getRemover();
        Events.fireToCancel(event, new DestroyEntityEvent(event, create(remover), event.getEntity()));
        if (event.isCancelled() && remover instanceof Player) {
            playDenyEffect((Player) remover, event.getEntity().getLocation());
        }
    } else if (event.getCause() == HangingBreakEvent.RemoveCause.EXPLOSION) {
        DestroyEntityEvent destroyEntityEvent = new DestroyEntityEvent(event, Cause.unknown(), event.getEntity());
        destroyEntityEvent.getRelevantFlags().add(Flags.OTHER_EXPLOSION);
        if (event.getEntity() instanceof ItemFrame) {
            destroyEntityEvent.getRelevantFlags().add(Flags.ENTITY_ITEM_FRAME_DESTROY);
        } else if (event.getEntity() instanceof Painting) {
            destroyEntityEvent.getRelevantFlags().add(Flags.ENTITY_PAINTING_DESTROY);
        }
        Events.fireToCancel(event, destroyEntityEvent);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) Player(org.bukkit.entity.Player) ItemFrame(org.bukkit.entity.ItemFrame) DestroyEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 2 with DestroyEntityEvent

use of com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent in project WorldGuard by EngineHub.

the class EventAbstractionListener method onPlayerPickupItem.

@EventHandler(ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
    Item item = event.getItem();
    pickupDebounce.debounce(event.getPlayer(), item, event, new DestroyEntityEvent(event, create(event.getPlayer()), event.getItem()));
}
Also used : Item(org.bukkit.entity.Item) DestroyEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

DestroyEntityEvent (com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent)2 EventHandler (org.bukkit.event.EventHandler)2 Entity (org.bukkit.entity.Entity)1 Item (org.bukkit.entity.Item)1 ItemFrame (org.bukkit.entity.ItemFrame)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Painting (org.bukkit.entity.Painting)1 Player (org.bukkit.entity.Player)1 HangingBreakByEntityEvent (org.bukkit.event.hanging.HangingBreakByEntityEvent)1