public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { Entity defender = event.getEntity(); DamageCause type = event.getCause(); if (defender instanceof Player) { Player player = (Player) defender; GlobalConfiguration cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName()); if (cfg.isInvinciblePlayer(player.getName())) { event.setCancelled(true); return; } if (wcfg.disableLavaDamage && type == DamageCause.LAVA) { event.setCancelled(true); return; } if (wcfg.disableContactDamage && type == DamageCause.CONTACT) { event.setCancelled(true); return; } } }
protected void aa() { if (!this.bD) { // CraftBukkit start - TODO: this event spams! if (this instanceof EntityLiving) { CraftServer server = ((WorldServer) 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(); DamageCause damageType = EntityDamageEvent.DamageCause.LAVA; int damageDone = 4; EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, damageType, damageDone); server.getPluginManager().callEvent(event); if (!event.isCancelled()) { this.damageEntity((Entity) null, event.getDamage()); } if (this.fireTicks <= 0) { // not on fire yet EntityCombustEvent combustEvent = new EntityCombustEvent(damagee); server.getPluginManager().callEvent(combustEvent); if (!combustEvent.isCancelled()) { this.fireTicks = 600; } } else { // reset fire level back to max this.fireTicks = 600; } return; } // CraftBukkit end this.damageEntity((Entity) null, 4); this.fireTicks = 600; } }
public void a() { float f = this.size; byte b0 = 16; int i; int j; int k; double d0; double d1; double d2; for (i = 0; i < b0; ++i) { for (j = 0; j < b0; ++j) { for (k = 0; k < b0; ++k) { if (i == 0 || i == b0 - 1 || j == 0 || j == b0 - 1 || k == 0 || k == b0 - 1) { double d3 = (double) ((float) i / ((float) b0 - 1.0F) * 2.0F - 1.0F); double d4 = (double) ((float) j / ((float) b0 - 1.0F) * 2.0F - 1.0F); double d5 = (double) ((float) k / ((float) b0 - 1.0F) * 2.0F - 1.0F); double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); d3 /= d6; d4 /= d6; d5 /= d6; float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F); d0 = this.posX; d1 = this.posY; d2 = this.posZ; for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) { int l = MathHelper.floor(d0); int i1 = MathHelper.floor(d1); int j1 = MathHelper.floor(d2); int k1 = this.world.getTypeId(l, i1, j1); if (k1 > 0) { f1 -= (Block.byId[k1].a(this.source) + 0.3F) * f2; } if (f1 > 0.0F) { this.g.add(new ChunkPosition(l, i1, j1)); } d0 += d3 * (double) f2; d1 += d4 * (double) f2; d2 += d5 * (double) f2; } } } } } this.size *= 2.0F; i = MathHelper.floor(this.posX - (double) this.size - 1.0D); j = MathHelper.floor(this.posX + (double) this.size + 1.0D); k = MathHelper.floor(this.posY - (double) this.size - 1.0D); int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D); int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D); int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D); List list = this.world.b( this.source, AxisAlignedBB.b( (double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2)); Vec3D vec3d = Vec3D.create(this.posX, this.posY, this.posZ); for (int k2 = 0; k2 < list.size(); ++k2) { Entity entity = (Entity) list.get(k2); double d7 = entity.e(this.posX, this.posY, this.posZ) / (double) this.size; if (d7 <= 1.0D) { d0 = entity.locX - this.posX; d1 = entity.locY - this.posY; d2 = entity.locZ - this.posZ; double d8 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2); d0 /= d8; d1 /= d8; d2 /= d8; double d9 = (double) this.world.a(vec3d, entity.boundingBox); double d10 = (1.0D - d7) * d9; // CraftBukkit start - explosion damage hook CraftServer server = ((WorldServer) this.world).getServer(); org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); DamageCause damageType; int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D); if (damagee == null) { // nothing was hurt } else if (this.source == null) { // Block explosion // TODO: get the x/y/z of the tnt block? // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION; EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone); server.getPluginManager().callEvent(event); if (!event.isCancelled()) { entity.damageEntity(this.source, event.getDamage()); entity.motX += d0 * d10; entity.motY += d1 * d10; entity.motZ += d2 * d10; } } else { org.bukkit.entity.Entity damager = this.source.getBukkitEntity(); damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); server.getPluginManager().callEvent(event); if (!event.isCancelled()) { entity.damageEntity(this.source, event.getDamage()); entity.motX += d0 * d10; entity.motY += d1 * d10; entity.motZ += d2 * d10; } } // CraftBukkit end } } this.size = f; ArrayList arraylist = new ArrayList(); arraylist.addAll(this.g); if (this.a) { for (int l2 = arraylist.size() - 1; l2 >= 0; --l2) { ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2); int i3 = chunkposition.x; int j3 = chunkposition.y; int k3 = chunkposition.z; int l3 = this.world.getTypeId(i3, j3, k3); int i4 = this.world.getTypeId(i3, j3 - 1, k3); if (l3 == 0 && Block.o[i4] && this.h.nextInt(3) == 0) { this.world.setTypeId(i3, j3, k3, Block.FIRE.id); } } } }
public void a() { // CraftBukkit start if (this.size < 0.1F) { return; } // CraftBukkit end float f = this.size; HashSet hashset = new HashSet(); int i; int j; int k; double d0; double d1; double d2; for (i = 0; i < this.i; ++i) { for (j = 0; j < this.i; ++j) { for (k = 0; k < this.i; ++k) { if (i == 0 || i == this.i - 1 || j == 0 || j == this.i - 1 || k == 0 || k == this.i - 1) { double d3 = (double) ((float) i / ((float) this.i - 1.0F) * 2.0F - 1.0F); double d4 = (double) ((float) j / ((float) this.i - 1.0F) * 2.0F - 1.0F); double d5 = (double) ((float) k / ((float) this.i - 1.0F) * 2.0F - 1.0F); double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); d3 /= d6; d4 /= d6; d5 /= d6; float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F); d0 = this.posX; d1 = this.posY; d2 = this.posZ; for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) { int l = MathHelper.floor(d0); int i1 = MathHelper.floor(d1); int j1 = MathHelper.floor(d2); int k1 = this.world.getTypeId(l, i1, j1); if (k1 > 0) { Block block = Block.byId[k1]; float f3 = this.source != null ? this.source.a(this, this.world, l, i1, j1, block) : block.a(this.source); f1 -= (f3 + 0.3F) * f2; } if (f1 > 0.0F && (this.source == null || this.source.a(this, this.world, l, i1, j1, k1, f1)) && i1 < 256 && i1 >= 0) { // CraftBukkit - don't wrap explosions hashset.add(new ChunkPosition(l, i1, j1)); } d0 += d3 * (double) f2; d1 += d4 * (double) f2; d2 += d5 * (double) f2; } } } } } this.blocks.addAll(hashset); this.size *= 2.0F; i = MathHelper.floor(this.posX - (double) this.size - 1.0D); j = MathHelper.floor(this.posX + (double) this.size + 1.0D); k = MathHelper.floor(this.posY - (double) this.size - 1.0D); int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D); int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D); int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D); List list = this.world.getEntities( this.source, AxisAlignedBB.a() .a((double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2)); Vec3D vec3d = this.world.getVec3DPool().create(this.posX, this.posY, this.posZ); for (int k2 = 0; k2 < list.size(); ++k2) { Entity entity = (Entity) list.get(k2); double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) this.size; if (d7 <= 1.0D) { d0 = entity.locX - this.posX; d1 = entity.locY + (double) entity.getHeadHeight() - this.posY; d2 = entity.locZ - this.posZ; double d8 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); if (d8 != 0.0D) { d0 /= d8; d1 /= d8; d2 /= d8; double d9 = (double) this.world.a(vec3d, entity.boundingBox); double d10 = (1.0D - d7) * d9; // CraftBukkit start - Explosion damage hook org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); float damageDone = (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D)); if (damagee == null) { // nothing was hurt } else if (this.source == null) { // Block explosion (without an entity source; bed etc.) EntityDamageByBlockEvent event = new EntityDamageByBlockEvent( null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { damagee.setLastDamageCause(event); entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage()); double d11 = EnchantmentProtection.a(entity, d10); entity.motX += d0 * d11; entity.motY += d1 * d11; entity.motZ += d2 * d11; if (entity instanceof EntityHuman) { this.l.put( (EntityHuman) entity, this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10)); } } } else { final org.bukkit.entity.Entity damager = this.source.getBukkitEntity(); final EntityDamageEvent.DamageCause damageCause; if (damager instanceof org.bukkit.entity.TNTPrimed) { damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION; } else { damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; } EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { entity.getBukkitEntity().setLastDamageCause(event); entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage()); entity.motX += d0 * d10; entity.motY += d1 * d10; entity.motZ += d2 * d10; if (entity instanceof EntityHuman) { this.l.put( (EntityHuman) entity, this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10)); } } } // CraftBukkit end } } } this.size = f; }
public NPCDamageByBlockEvent(final NPC npc, final EntityDamageByBlockEvent event) { super(npc, (EntityDamageEvent) event); this.damager = event.getDamager(); }