Search in sources :

Example 1 with SpawnEntityEvent

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

the class EventAbstractionListener method onHangingPlace.

@EventHandler(ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
    Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getEntity()));
    if (event.isCancelled()) {
        Block effectBlock = event.getBlock().getRelative(event.getBlockFace());
        playDenyEffect(event.getPlayer(), effectBlock.getLocation().add(0.5, 0.5, 0.5));
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SpawnEntityEvent

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

the class EventAbstractionListener method handleFallingBlock.

private void handleFallingBlock(EntityChangeBlockEvent event, boolean dropItem) {
    Entity entity = event.getEntity();
    Block block = event.getBlock();
    if (entity instanceof FallingBlock) {
        try {
            if (dropItem) {
                FallingBlock fallingBlock = (FallingBlock) entity;
                if (!fallingBlock.getDropItem())
                    return;
                final Material material = fallingBlock.getBlockData().getMaterial();
                if (!material.isItem())
                    return;
                ItemStack itemStack = new ItemStack(material, 1);
                Item item = block.getWorld().dropItem(fallingBlock.getLocation(), itemStack);
                item.setVelocity(new Vector());
                if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(block, entity), item))) {
                    item.remove();
                }
            }
        } finally {
            Cause.untrackParentCause(entity);
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent)

Example 3 with SpawnEntityEvent

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

the class EventAbstractionListener method onExpBottle.

@EventHandler(ignoreCancelled = true)
public void onExpBottle(ExpBottleEvent event) {
    if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getEntity()), event.getEntity().getLocation(), EntityType.EXPERIENCE_ORB))) {
        event.setExperience(0);
        // Give the player back his or her XP bottle
        ProjectileSource shooter = event.getEntity().getShooter();
        if (shooter instanceof Player) {
            Player player = (Player) shooter;
            if (player.getGameMode() != GameMode.CREATIVE) {
                player.getInventory().addItem(new ItemStack(Material.EXPERIENCE_BOTTLE, 1));
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemStack(org.bukkit.inventory.ItemStack) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Example 4 with SpawnEntityEvent

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

the class EventAbstractionListener method onLingeringSplash.

@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
    AreaEffectCloud aec = event.getAreaEffectCloud();
    ThrownPotion potion = event.getEntity();
    World world = potion.getWorld();
    Cause cause = create(event.getEntity());
    // Fire item interaction event
    Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
    // Fire entity spawn event
    if (!event.isCancelled()) {
        // radius unfortunately doesn't go through with this, so only a single location is tested
        Events.fireToCancel(event, new SpawnEntityEvent(event, cause, aec.getLocation().add(0.5, 0, 0.5), EntityType.AREA_EFFECT_CLOUD));
    }
}
Also used : UseItemEvent(com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent) Cause(com.sk89q.worldguard.bukkit.cause.Cause) ThrownPotion(org.bukkit.entity.ThrownPotion) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) World(org.bukkit.World) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Example 5 with SpawnEntityEvent

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

the class EventAbstractionListener method onEntityChangeBlock.

@EventHandler(ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
    Block block = event.getBlock();
    Entity entity = event.getEntity();
    Material toType = event.getTo();
    Material fromType = block.getType();
    Cause cause = create(entity);
    // Fire two events: one as BREAK and one as PLACE
    if (toType != Material.AIR && fromType != Material.AIR) {
        BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block);
        setDelegateEventMaterialOptions(breakDelagate, fromType, toType);
        boolean denied;
        if (!(denied = Events.fireToCancel(event, breakDelagate))) {
            PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType);
            setDelegateEventMaterialOptions(placeDelegate, fromType, toType);
            denied = Events.fireToCancel(event, placeDelegate);
        }
        if (denied && entity instanceof Player) {
            playDenyEffect((Player) entity, block.getLocation());
        }
        handleFallingBlock(event, denied);
    } else if (toType == Material.AIR) {
        // Track the source so later we can create a proper chain of causes
        if (entity instanceof FallingBlock) {
            Cause.trackParentCause(entity, block);
            // Switch around the event
            Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
        } else {
            entityBreakBlockDebounce.debounce(block, event.getEntity(), event, new BreakBlockEvent(event, cause, block));
        }
    } else {
        // toType != Material.AIR && fromType == Material.AIR
        boolean denied = Events.fireToCancel(event, new PlaceBlockEvent(event, cause, block.getLocation(), toType));
        handleFallingBlock(event, denied);
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Cause(com.sk89q.worldguard.bukkit.cause.Cause) FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) Material(org.bukkit.Material) BreakBlockEvent(com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent) PlaceBlockEvent(com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

SpawnEntityEvent (com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent)6 EventHandler (org.bukkit.event.EventHandler)4 Block (org.bukkit.block.Block)3 FallingBlock (org.bukkit.entity.FallingBlock)3 Cause (com.sk89q.worldguard.bukkit.cause.Cause)2 PlaceBlockEvent (com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent)2 Material (org.bukkit.Material)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 BreakBlockEvent (com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent)1 UseBlockEvent (com.sk89q.worldguard.bukkit.event.block.UseBlockEvent)1 UseItemEvent (com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent)1 World (org.bukkit.World)1 AreaEffectCloud (org.bukkit.entity.AreaEffectCloud)1 EntityType (org.bukkit.entity.EntityType)1 Item (org.bukkit.entity.Item)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1