Java 类org.bukkit.event.entity.EntityDamageByBlockEvent 实例源码

项目:Skript    文件:ExprAttackerAlt.java   
private static Object getAttacker(final Event e) {
    if (e instanceof EntityDamageByEntityEvent) {
        if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
            return ((Projectile) ((EntityDamageByEntityEvent) e).getDamager()).getShooter();
        }
        return ((EntityDamageByEntityEvent) e).getDamager();
    } else if (e instanceof EntityDamageByBlockEvent) {
        return ((EntityDamageByBlockEvent) e).getDamager();
    } else if (e instanceof EntityDeathEvent) {
        return getAttacker(((EntityDeathEvent) e).getEntity().getLastDamageCause());
    } else if (e instanceof VehicleDamageEvent) {
        return ((VehicleDamageEvent) e).getAttacker();
    } else if (e instanceof VehicleDestroyEvent) {
        return ((VehicleDestroyEvent) e).getAttacker();
    }
    return null;
}
项目:Almura-Server    文件:BlockCactus.java   
public void a(World world, int i, int j, int k, Entity entity) {
    // CraftBukkit start - EntityDamageByBlock event
    if (entity instanceof EntityLiving) {
        org.bukkit.block.Block damager = world.getWorld().getBlockAt(i, j, k);
        org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();

        EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, org.bukkit.event.entity.EntityDamageEvent.DamageCause.CONTACT, 1D);
        world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            damagee.setLastDamageCause(event);
            entity.damageEntity(DamageSource.CACTUS, (float) event.getDamage());
        }
        return;
    }
    // CraftBukkit end

    entity.damageEntity(DamageSource.CACTUS, 1.0F);
}
项目:BukkitLib    文件:Utilities.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHealthLoss(final EntityDamageEvent event){
    Deque<DamageData> damagers = getDamageInformationDeque(event.getEntity().getUniqueId());

    Object dmgSrc = null;
    if(event instanceof EntityDamageByEntityEvent){
        dmgSrc = ((EntityDamageByEntityEvent)event).getDamager();
    }else if(event instanceof EntityDamageByBlockEvent){
        dmgSrc = ((EntityDamageByBlockEvent)event).getDamager();
    }

    // Similiar objects are not supported here, but are used in the getter methods
    DamageData info = new DamageData();

    info.setCause(event.getCause());
    info.setRawSource(dmgSrc);
    info.setDamageAmount(info.getDamageAmount() + event.getDamage());
    damagers.addFirst(info);
}
项目:simple-survival-games    文件:SSGEntityListener.java   
@EventHandler
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
    Entity e = event.getEntity();
    ArenaManager am = SimpleSurvivalGames.instance.getArenaManager();

    // Is the entity a player
    if(e instanceof Player) {
        Player p = (Player) e;

        // Is the current in any arean
        if(am.isInArena(p)) {
            ArenaPlayer ap = am.getPlayer(p);
            ap.resetLastDamageByPlayer();
        }
    }
}
项目:Craft-city    文件:BlockCactus.java   
public void a(World world, int i, int j, int k, Entity entity) {
    // CraftBukkit start - EntityDamageByBlock event
    if (entity instanceof EntityLiving) {
        org.bukkit.block.Block damager = world.getWorld().getBlockAt(i, j, k);
        org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();

        EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, org.bukkit.event.entity.EntityDamageEvent.DamageCause.CONTACT, 1);
        world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            damagee.setLastDamageCause(event);
            entity.damageEntity(DamageSource.CACTUS, event.getDamage());
        }
        return;
    }
    // CraftBukkit end

    entity.damageEntity(DamageSource.CACTUS, 1);
}
项目:Warzone    文件:BlockDamageResolver.java   
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByBlockEvent && damageEvent.getCause() == DamageCause.CONTACT) {
        EntityDamageByBlockEvent blockEvent = (EntityDamageByBlockEvent) damageEvent;

        return new SimpleBlockDamageInfo(blockEvent.getDamager().getState());
    }

    return null;
}
项目:ProjectAres    文件:EventResolver.java   
default DamageInfo resolveDamage(EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent) {
        return resolveDamage((EntityDamageByEntityEvent) damageEvent);
    } else if(damageEvent instanceof EntityDamageByBlockEvent) {
        return resolveDamage((EntityDamageByBlockEvent) damageEvent);
    } else {
        return resolveDamage(damageEvent.getCause(), damageEvent.getEntity());
    }
}
项目:Pokkit    文件:EntityEvents.java   
@EventHandler(ignoreCancelled = false)
public void onEntityDamage(cn.nukkit.event.entity.EntityDamageEvent event) {
    if (canIgnore(EntityDamageEvent.getHandlerList())) {
        return;
    }

    // EntityDamageEvent and EntityDamageBy*Event share their handler
    // lists. So this method can also be called with the event parameter set
    // to an EntityDamageByEntityEvent or EntityDamageByBlockEvent. In that
    // case, the event translation is a bit more involved.
    if (event instanceof cn.nukkit.event.entity.EntityDamageByEntityEvent) {
        onEntityDamageByEntity((cn.nukkit.event.entity.EntityDamageByEntityEvent) event);
        return;
    }
    if (event instanceof cn.nukkit.event.entity.EntityDamageByBlockEvent) {
        onEntityDamageByBlock((cn.nukkit.event.entity.EntityDamageByBlockEvent) event);
        return;
    }

    // For now, only base damage is taken into account. Potions, armor etc
    // are ignored
    EntityDamageEvent bukkitEvent = new EntityDamageEvent(
            PokkitEntity.toBukkit(event.getEntity()),
            PokkitDamageCause.toBukkit(event.getCause()),
            getDamageMap(event.getDamage()),
            getDamageModifierMap());

    callCancellable(event, bukkitEvent);
    event.setDamage((float) bukkitEvent.getDamage());
}
项目:Pokkit    文件:EntityEvents.java   
private void onEntityDamageByBlock(cn.nukkit.event.entity.EntityDamageByBlockEvent event) {
    // Called by onEntityDamage, so don't use an @EventHandler annotation

    // For now, only base damage is taken into account. Potions, armor etc
    // are ignored
    EntityDamageByBlockEvent bukkitEvent = new EntityDamageByBlockEvent(
            PokkitBlock.toBukkit(event.getDamager()),
            PokkitEntity.toBukkit(event.getEntity()),
            PokkitDamageCause.toBukkit(event.getCause()),
            getDamageMap(event.getDamage()),
            getDamageModifierMap());

    callCancellable(event, bukkitEvent);
    event.setDamage((float) bukkitEvent.getDamage());
}
项目:libelula    文件:EventManager.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageByBlockEvent e) {
    if (e.getEntity() instanceof Player) {
        if (plugin.pm.isSpectator((Player) e.getEntity())) {
            e.setCancelled(true);
        }
    }
}
项目:Almura-Server    文件:Entity.java   
protected void A() {
    if (!this.fireProof) {
        // CraftBukkit start - Fallen in lava TODO: this event spams!
        if (this instanceof EntityLiving) {
            Server server = this.world.getServer();

            // TODO: shouldn't be sending null for the block.
            org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k);
            org.bukkit.entity.Entity damagee = this.getBukkitEntity();

            EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, EntityDamageEvent.DamageCause.LAVA, 4D);
            server.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
                damagee.setLastDamageCause(event);
                this.damageEntity(DamageSource.LAVA, (float) event.getDamage());
            }

            if (this.fireTicks <= 0) {
                // not on fire yet
                EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15);
                server.getPluginManager().callEvent(combustEvent);

                if (!combustEvent.isCancelled()) {
                    this.setOnFire(combustEvent.getDuration());
                }
            } else {
                // This will be called every single tick the entity is in lava, so don't throw an event
                this.setOnFire(15);
            }
            return;
        }
        // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls

        this.damageEntity(DamageSource.LAVA, 4);
        this.setOnFire(15);
    }
}
项目:pexel-platform    文件:EventProcessor.java   
@EventHandler
private void onPlayerDamageByBlock(final EntityDamageByBlockEvent event) {
    if (event.getEntity() instanceof Player)
        if (!this.hasPermission(event.getEntity().getLocation(),
                (Player) event.getEntity(), AreaFlag.PLAYER_GETDAMAGE))
            event.setCancelled(true);
}
项目:PexelCore    文件:EventProcessor.java   
@EventHandler
private void onPlayerDamageByBlock(final EntityDamageByBlockEvent event) {
    if (event.getEntity() instanceof Player)
        if (!this.hasPermission(event.getEntity().getLocation(),
                (Player) event.getEntity(), AreaFlag.PLAYER_GETDAMAGE))
            event.setCancelled(true);
}
项目:Craft-city    文件:Entity.java   
protected void z() {
    if (!this.fireProof) {
        // CraftBukkit start - Fallen in lava TODO: this event spams!
        if (this instanceof EntityLiving) {
            Server server = this.world.getServer();

            // TODO: shouldn't be sending null for the block.
            org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k);
            org.bukkit.entity.Entity damagee = this.getBukkitEntity();

            EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, EntityDamageEvent.DamageCause.LAVA, 4);
            server.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
                damagee.setLastDamageCause(event);
                this.damageEntity(DamageSource.LAVA, event.getDamage());
            }

            if (this.fireTicks <= 0) {
                // not on fire yet
                EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15);
                server.getPluginManager().callEvent(combustEvent);

                if (!combustEvent.isCancelled()) {
                    this.setOnFire(combustEvent.getDuration());
                }
            } else {
                // This will be called every single tick the entity is in lava, so don't throw an event
                this.setOnFire(15);
            }
            return;
        }
        // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls

        this.damageEntity(DamageSource.LAVA, 4);
        this.setOnFire(15);
    }
}
项目:ProjectAres    文件:EventResolver.java   
default DamageInfo resolveDamage(EntityDamageByBlockEvent damageEvent) {
    return resolveDamage(damageEvent.getCause(), damageEvent.getEntity(), damageEvent.getDamager());
}
项目:AgarMC    文件:WorldListener.java   
@EventHandler
public void onEntityDamageByBlock(EntityDamageByBlockEvent e){
    e.setCancelled(true);
}
项目:NucleusFramework    文件:NpcDamageByBlockEvent.java   
/**
 * Get the parent {@link EntityDamageByBlockEvent}.
 */
@Override
public EntityDamageByBlockEvent getParentEvent() {
    return (EntityDamageByBlockEvent)super.getParentEvent();
}
项目:NucleusFramework    文件:NpcDamageByBlockEvent.java   
/**
 * Constructor.
 *
 * @param npc    The NPC the event is for.
 * @param event  The parent {@link EntityDamageByBlockEvent}.
 */
public NpcDamageByBlockEvent(INpc npc, EntityDamageByBlockEvent event) {
    super(npc, event);
}