Search in sources :

Example 11 with Player

use of org.spongepowered.api.entity.player.Player in project modules-extra by CubeEngine.

the class ListenerBlockIgnite method onIgnite.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIgnite(BlockIgniteEvent event) {
    BlockState oldState = event.getBlock().getState();
    ActionBlock action;
    switch(event.getCause()) {
        case FIREBALL:
            action = this.newAction(IgniteFireball.class, oldState.getWorld());
            if (action != null) {
                ProjectileSource shooter = ((Fireball) event.getIgnitingEntity()).getShooter();
                if (shooter instanceof Entity) {
                    ((IgniteFireball) action).setShooter((Entity) shooter);
                    if (shooter instanceof Ghast) {
                        LivingEntity target = BukkitUtils.getTarget((Ghast) shooter);
                        if (target instanceof Player) {
                            ((IgniteFireball) action).setPlayer((Player) target);
                        }
                    } else if (shooter instanceof Player) {
                        ((IgniteFireball) action).setPlayer((Player) shooter);
                    }
                }
            }
            break;
        case LAVA:
            action = this.newAction(IgniteLava.class, oldState.getWorld());
            if (action != null) {
                ((IgniteLava) action).setSource(event.getIgnitingBlock().getLocation());
            }
            break;
        case LIGHTNING:
            action = this.newAction(IgniteLightning.class, oldState.getWorld());
            break;
        case FLINT_AND_STEEL:
            action = this.newAction(IgniteLighter.class, oldState.getWorld());
            if (action != null && event.getPlayer() != null) {
                ((IgniteLighter) action).setPlayer(event.getPlayer());
            }
            break;
        case ENDER_CRYSTAL:
        case EXPLOSION:
            action = this.newAction(IgniteOther.class, oldState.getWorld());
            break;
        case SPREAD:
            return;
        default:
            this.module.getLog().warn("Unknown IgniteCause! {}", event.getCause().name());
            return;
    }
    if (action != null) {
        action.setOldBlock(oldState);
        action.setNewBlock(FIRE);
        action.setLocation(oldState.getLocation());
        this.logAction(action);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) ActionBlock(org.cubeengine.module.log.action.block.ActionBlock) LivingEntity(org.bukkit.entity.LivingEntity) BlockState(org.bukkit.block.BlockState) Fireball(org.bukkit.entity.Fireball) Ghast(org.bukkit.entity.Ghast) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Player (org.spongepowered.api.entity.player.Player)11 EventHandler (org.bukkit.event.EventHandler)10 Entity (org.spongepowered.api.entity.Entity)7 Projectile (org.bukkit.entity.Projectile)4 ProjectileSource (org.bukkit.projectiles.ProjectileSource)4 LivingEntity (org.bukkit.entity.LivingEntity)3 Location (org.spongepowered.api.world.Location)3 ItemFrame (org.bukkit.entity.ItemFrame)2 Tameable (org.bukkit.entity.Tameable)2 BrewerInventory (org.bukkit.inventory.BrewerInventory)2 FurnaceInventory (org.bukkit.inventory.FurnaceInventory)2 Inventory (org.bukkit.inventory.Inventory)2 PlayerSection (org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 BasicDBObject (com.mongodb.BasicDBObject)1 BlockState (org.bukkit.block.BlockState)1 BrewingStand (org.bukkit.block.BrewingStand)1 Furnace (org.bukkit.block.Furnace)1 AnimalTamer (org.bukkit.entity.AnimalTamer)1 Animals (org.bukkit.entity.Animals)1