Search in sources :

Example 1 with HangingBreakByEntityEvent

use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Denizen-For-Bukkit by DenizenScript.

the class HangingBreaksScriptEvent method onHangingBreaks.

@EventHandler
public void onHangingBreaks(HangingBreakEvent event) {
    hanging = new dEntity(event.getEntity());
    cause = new Element(event.getCause().name());
    location = new dLocation(hanging.getLocation());
    if (event instanceof HangingBreakByEntityEvent) {
        entity = new dEntity(((HangingBreakByEntityEvent) event).getRemover());
    }
    cuboids = new dList();
    for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
        cuboids.add(cuboid.identifySimple());
    }
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
}
Also used : HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dCuboid(net.aufdemrand.denizen.objects.dCuboid) EventHandler(org.bukkit.event.EventHandler)

Example 2 with HangingBreakByEntityEvent

use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Towny by ElgarL.

the class TownyEntityListener method onHangingBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    TownyWorld townyWorld = null;
    String worldName = null;
    Entity hanging = event.getEntity();
    try {
        worldName = hanging.getWorld().getName();
        townyWorld = TownyUniverse.getDataSource().getWorld(worldName);
        if (!townyWorld.isUsingTowny())
            return;
    } catch (NotRegisteredException e1) {
        // event.setCancelled(true);
        return;
    }
    if (event instanceof HangingBreakByEntityEvent) {
        HangingBreakByEntityEvent evt = (HangingBreakByEntityEvent) event;
        Object remover = evt.getRemover();
        /*
			 * Check if this has a shooter.
			 */
        if (remover instanceof Projectile) {
            remover = ((Projectile) remover).getShooter();
        }
        if (remover instanceof Player) {
            Player player = (Player) remover;
            // Get destroy permissions (updates if none exist)
            boolean bDestroy = PlayerCacheUtil.getCachePermission(player, hanging.getLocation(), 321, (byte) 0, TownyPermission.ActionType.DESTROY);
            // Allow the removal if we are permitted
            if (bDestroy)
                return;
            /*
				 * Fetch the players cache
				 */
            PlayerCache cache = plugin.getCache(player);
            event.setCancelled(true);
            if (cache.hasBlockErrMsg())
                TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
        } else {
            // Explosions are blocked in this plot
            if (!locationCanExplode(townyWorld, hanging.getLocation()))
                event.setCancelled(true);
        }
    } else {
        switch(event.getCause()) {
            case EXPLOSION:
                if (!locationCanExplode(townyWorld, event.getEntity().getLocation()))
                    event.setCancelled(true);
                break;
            default:
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 3 with HangingBreakByEntityEvent

use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Denizen-For-Bukkit by DenizenScript.

the class HangingBreaksScriptEvent method onHangingBreaks.

@EventHandler
public void onHangingBreaks(HangingBreakEvent event) {
    hanging = new EntityTag(event.getEntity());
    cause = new ElementTag(event.getCause().name());
    if (event instanceof HangingBreakByEntityEvent) {
        entity = new EntityTag(((HangingBreakByEntityEvent) event).getRemover());
    } else {
        entity = null;
    }
    this.event = event;
    fire(event);
}
Also used : HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 4 with HangingBreakByEntityEvent

use of org.bukkit.event.hanging.HangingBreakByEntityEvent in project Glowstone by GlowstoneMC.

the class GlowItemFrame method entityInteract.

// //////////////////////////////////////////////////////////////////////////
// Overrides
@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
    if (message.getAction() == Action.INTERACT.ordinal() && message.getHandSlot() == EquipmentSlot.HAND) {
        if (InventoryUtil.isEmpty(getItem())) {
            ItemStack isInHand = player.getItemInHand();
            if (isInHand != null) {
                setItem(isInHand);
                if (player.getGameMode() != GameMode.CREATIVE) {
                    int amount = player.getItemInHand().getAmount();
                    isInHand.setAmount(amount - 1);
                    if (isInHand.getAmount() <= 0) {
                        isInHand = null;
                    }
                    player.setItemInHand(isInHand);
                }
            }
        } else {
            int rot = (getRotation().ordinal() + 1) % 8;
            setRotation(Rotation.values()[rot]);
        }
    }
    if (message.getAction() == Action.ATTACK.ordinal()) {
        if (isEmpty()) {
            if (EventFactory.getInstance().callEvent(new HangingBreakByEntityEvent(this, player)).isCancelled()) {
                return false;
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME));
            }
            remove();
        } else {
            if (EventFactory.getInstance().callEvent(new EntityDamageByEntityEvent(player, this, DamageCause.ENTITY_ATTACK, 0)).isCancelled()) {
                return false;
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                world.dropItemNaturally(location, getItem().clone());
            }
            setItem(InventoryUtil.createEmptyStack());
        }
    }
    return true;
}
Also used : HangingBreakByEntityEvent(org.bukkit.event.hanging.HangingBreakByEntityEvent) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

HangingBreakByEntityEvent (org.bukkit.event.hanging.HangingBreakByEntityEvent)4 EventHandler (org.bukkit.event.EventHandler)3 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)1 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)1 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)1 net.aufdemrand.denizen.objects.dCuboid (net.aufdemrand.denizen.objects.dCuboid)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1