/** * Increases the blast radius of the explosion. * * @param player Player triggering the explosion * @param event Event whose explosion radius is being changed */ public static void biggerBombs(Player player, ExplosionPrimeEvent event) { final int RANK_1_LEVEL = 250; final int RANK_2_LEVEL = 500; final int RANK_3_LEVEL = 750; final int RANK_4_LEVEL = 1000; int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); float radius = event.getRadius(); if (skillLevel < RANK_1_LEVEL) { return; } if (skillLevel >= RANK_1_LEVEL) { radius++; } if (skillLevel >= RANK_2_LEVEL) { radius++; } if (skillLevel >= RANK_3_LEVEL) { radius++; } if (skillLevel >= RANK_4_LEVEL) { radius++; } event.setRadius(radius); }
@EventHandler(priority = EventPriority.HIGHEST) public void onExplosionPrime(ExplosionPrimeEvent event) { if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { event.setFire(false); } }
public void onExplosionPrime(ExplosionPrimeEvent event) { ArrayList<Integer> ids = iCoLand.landMgr.getLandIds(event.getEntity().getLocation()); for (Integer id : ids) { if (iCoLand.landMgr.getLandById(id).hasAddon("noboom")) { event.setCancelled(true); } } if (ids.size() == 0 && !Config.unclaimedLandCanBoom) { event.setCancelled(true); } }
// blocks projectiles explosions @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onExplosionPrime(ExplosionPrimeEvent event) { final Entity entity = event.getEntity(); if (entity instanceof Projectile) { final Projectile projectile = (Projectile) entity; if (projectile.getShooter() instanceof Player) { if (this.projectileCheck(projectile, projectile.getLocation())) { event.setCancelled(true); event.setRadius(0); } } } }
protected void a(MovingObjectPosition movingobjectposition) { if (!this.world.isStatic) { if (movingobjectposition.entity != null) { if (this.shooter != null) { if (movingobjectposition.entity.damageEntity(DamageSource.mobAttack(this.shooter), 8) && !movingobjectposition.entity.isAlive()) { this.shooter.heal(5, EntityRegainHealthEvent.RegainReason.WITHER); // CraftBukkit } } else { movingobjectposition.entity.damageEntity(DamageSource.MAGIC, 5); } if (movingobjectposition.entity instanceof EntityLiving) { byte b0 = 0; if (this.world.difficulty > 1) { if (this.world.difficulty == 2) { b0 = 10; } else if (this.world.difficulty == 3) { b0 = 40; } } if (b0 > 0) { ((EntityLiving) movingobjectposition.entity) .addEffect(new MobEffect(MobEffectList.WITHER.id, 20 * b0, 1)); } } } // CraftBukkit start ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 1.0F, false); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { this.world.createExplosion( this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire(), this.world.getGameRules().getBoolean("mobGriefing")); } // CraftBukkit end this.die(); } }
/** * Event handler called when an explosive is primed. * * <p>We use it to detect impending creeper explosions. The event is fired immediately before the * explosion. */ @EventHandler(ignoreCancelled = true) public void onCreeperDetonate(ExplosionPrimeEvent event) { if (!CONFIG.isAffectedWorld(event)) { return; } if (event.getEntityType() == EntityType.CREEPER) { event.setRadius((float) CONFIG.BLAST_RADIUS_SCALE * event.getRadius()); Entity creeper = event.getEntity(); launchReinforcements(creeper); Location origin = creeper.getLocation(); World world = origin.getWorld(); Firework firework = (Firework) world.spawnEntity(origin, EntityType.FIREWORK); if (firework != null) { FireworkMeta meta = firework.getFireworkMeta(); meta.setPower(random(0, 1)); meta.addEffect(randomFireworkFffect(true)); firework.setFireworkMeta(meta); } } }
/** * Handle ExplosionPrime events that involve modifying the event. * * @param event The event to modify */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onExplosionPrime(ExplosionPrimeEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) { return; } // We can make this assumption because we (should) be the only ones using this exact metadata Player player = plugin .getServer() .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString()); if (Misc.isNPCEntity(player)) { return; } MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); if (miningManager.canUseBiggerBombs()) { event.setRadius(miningManager.biggerBombs(event.getRadius())); } }
/** * Monitor ExplosionPrime events. * * @param event The event to monitor */ @EventHandler(priority = EventPriority.LOW) public void onExplosionPrime(ExplosionPrimeEvent event) { Entity entity = event.getEntity(); if (entity instanceof TNTPrimed) { int id = entity.getEntityId(); if (plugin.tntTracker.containsKey(id)) { Player player = plugin.tntTracker.get(id); if (mcPermissions.getInstance().biggerBombs(player)) { BlastMining.biggerBombs(player, event); } } } }
@EventHandler(priority = EventPriority.MONITOR) public void onExplosionPrime(ExplosionPrimeEvent event) { if (event.isCancelled() || !(event.getEntity() instanceof TNTPrimed)) { return; } // do stuff CustomExplosion explosion = new CustomExplosion( event.getEntity(), event.getEntity().getLocation(), event.getRadius(), event.getFire()); explosion.doAll(); }
@EventHandler(priority = EventPriority.NORMAL) public void onExplosionPrime(ExplosionPrimeEvent event) { if (event.isCancelled()) return; EntityType entity = event.getEntityType(); FlagPermissions perms = Residence.getPermsByLoc(event.getEntity().getLocation()); if (entity == EntityType.CREEPER) { if (!perms.has("creeper", perms.has("explode", true))) { event.setCancelled(true); event.getEntity().remove(); } } if (entity == EntityType.PRIMED_TNT) { if (!perms.has("tnt", perms.has("explode", true))) { event.setCancelled(true); event.getEntity().remove(); } } if (entity == EntityType.FIREBALL) { if (!perms.has("fireball", perms.has("explode", true))) { event.setCancelled(true); event.getEntity().remove(); } } }
@EventHandler(ignoreCancelled = true) public void onEntityPrime(ExplosionPrimeEvent event) { WorldSettings settings = plugin.getConfigManager().getWorldSettings(event.getEntity().getWorld().getName()); boolean above = event.getEntity().getLocation().getY() >= settings.getWorldSplit(); switch (event.getEntityType()) { case CREEPER: switch (settings.getCreeperType()) { case DISABLE: event.setCancelled(true); break; case MELEE: forMelee((Creeper) event.getEntity()); event.setCancelled(true); break; case ABOVE_MELEE: if (above) { forMelee((Creeper) event.getEntity()); event.setCancelled(true); } break; case ABOVE_DISABLE: event.setCancelled(above); break; } break; case PRIMED_TNT: switch (settings.getTntType()) { case DISABLE: event.setCancelled(true); break; case ABOVE_DISABLE: event.setCancelled(above); break; } } }
protected void bi() { int i; if (this.bU() > 0) { i = this.bU() - 1; if (i <= 0) { // CraftBukkit start ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { this.world.createExplosion( this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, event.getRadius(), event.getFire(), this.world.getGameRules().getBoolean("mobGriefing")); } // CraftBukkit end this.world.createExplosion( this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, 7.0F, false, this.world.getGameRules().getBoolean("mobGriefing")); this.world.d(1013, (int) this.locX, (int) this.locY, (int) this.locZ, 0); } this.p(i); if (this.ticksLived % 10 == 0) { this.heal( 10.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason .WITHER_SPAWN); // CraftBukkit } } else { super.bi(); int j; for (i = 1; i < 3; ++i) { if (this.ticksLived >= this.bt[i - 1]) { this.bt[i - 1] = this.ticksLived + 10 + this.random.nextInt(10); if (this.world.difficulty >= 2) { int i1001 = i - 1; int i1003 = this.bu[i - 1]; this.bu[i1001] = this.bu[i - 1] + 1; if (i1003 > 15) { float f = 10.0F; float f1 = 5.0F; double d0 = MathHelper.a(this.random, this.locX - (double) f, this.locX + (double) f); double d1 = MathHelper.a(this.random, this.locY - (double) f1, this.locY + (double) f1); double d2 = MathHelper.a(this.random, this.locZ - (double) f, this.locZ + (double) f); this.a(i + 1, d0, d1, d2, true); this.bu[i - 1] = 0; } } j = this.q(i); if (j > 0) { Entity entity = this.world.getEntity(j); if (entity != null && entity.isAlive() && this.e(entity) <= 900.0D && this.o(entity)) { this.a(i + 1, (EntityLiving) entity); this.bt[i - 1] = this.ticksLived + 40 + this.random.nextInt(20); this.bu[i - 1] = 0; } else { this.c(i, 0); } } else { List list = this.world.a(EntityLiving.class, this.boundingBox.grow(20.0D, 8.0D, 20.0D), bw); for (int i1 = 0; i1 < 10 && !list.isEmpty(); ++i1) { EntityLiving entityliving = (EntityLiving) list.get(this.random.nextInt(list.size())); if (entityliving != this && entityliving.isAlive() && this.o(entityliving)) { if (entityliving instanceof EntityHuman) { if (!((EntityHuman) entityliving).abilities.isInvulnerable) { this.c(i, entityliving.id); } } else { this.c(i, entityliving.id); } break; } list.remove(entityliving); } } } } if (this.getGoalTarget() != null) { this.c(0, this.getGoalTarget().id); } else { this.c(0, 0); } if (this.bv > 0) { --this.bv; if (this.bv == 0 && this.world.getGameRules().getBoolean("mobGriefing")) { i = MathHelper.floor(this.locY); j = MathHelper.floor(this.locX); int j1 = MathHelper.floor(this.locZ); boolean flag = false; for (int k1 = -1; k1 <= 1; ++k1) { for (int l1 = -1; l1 <= 1; ++l1) { for (int i2 = 0; i2 <= 3; ++i2) { int j2 = j + k1; int k2 = i + i2; int l2 = j1 + l1; int i3 = this.world.getTypeId(j2, k2, l2); if (i3 > 0 && i3 != Block.BEDROCK.id && i3 != Block.ENDER_PORTAL.id && i3 != Block.ENDER_PORTAL_FRAME.id) { // CraftBukkit start if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, 0, 0) .isCancelled()) { continue; } // CraftBukkit end flag = this.world.setAir(j2, k2, l2, true) || flag; } } } } if (flag) { this.world.a( (EntityHuman) null, 1012, (int) this.locX, (int) this.locY, (int) this.locZ, 0); } } } if (this.ticksLived % 20 == 0) { this.heal(1.0F); } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onExplosionPrime(ExplosionPrimeEvent evt) { Location l = evt.getEntity().getLocation(); World w = l.getWorld(); Chunk c = w.getChunkAt(l); if (evt.getEntity() instanceof Creeper) { if (GlobalRegionManager.getGlobalWorldSetting(w) != null) { if (!GlobalRegionManager.getGlobalWorldSetting(w).creeperExplodes) { evt.setCancelled(true); evt.setRadius(0); return; } } } ArrayList<Region> regionSet = new ArrayList<Region>(); for (Region region : GlobalRegionManager.getRegions()) { for (Chunk chunk : region.getChunkGrid().getChunks()) { if (chunk.getWorld() == w) { if (areChunksEqual(chunk, c)) { if (!regionSet.contains(region)) { regionSet.add(region); } } } } } if (regionSet.isEmpty()) { return; } ArrayList<Region> currentRegionSet = new ArrayList<Region>(); for (Region reg : regionSet) { Location rl1 = reg.getL1().toBukkitLocation(), rl2 = reg.getL2().toBukkitLocation(); if (rl1.getX() > rl2.getX()) { rl2.subtract(6, 0, 0); rl1.add(6, 0, 0); } else { rl2.add(6, 0, 0); rl1.subtract(6, 0, 0); } if (rl1.getZ() > rl2.getZ()) { rl2.subtract(0, 0, 6); rl1.add(0, 0, 6); } else { rl2.add(0, 0, 6); rl1.subtract(0, 0, 6); } if (rl1.getY() > rl2.getY()) { rl2.subtract(0, 10, 0); rl1.add(0, 10, 0); } else { rl2.add(0, 10, 0); rl1.subtract(0, 10, 0); } if (extReg.isInsideCuboid(l, rl1, rl2)) { currentRegionSet.add(reg); } } if (currentRegionSet.isEmpty()) { // If player is in chunk range but not // inside region then cancel the // check. return; } else { for (Region r : currentRegionSet) { if (r.is_protection()) { LogRunner.addLogMessage(r, LogRunner.getPrefix(r) + (" Entity explosion was prevented.")); evt.setCancelled(true); evt.setRadius(0); return; } } } }
protected void E() { int i; if (this.cj() > 0) { i = this.cj() - 1; if (i <= 0) { // CraftBukkit start // this.world.createExplosion(this, this.locX, this.locY + (double) this.getHeadHeight(), // this.locZ, 7.0F, false, this.world.getGameRules().getBoolean("mobGriefing")); ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { this.world.createExplosion( this, this.locX, this.locY + (double) this.getHeadHeight(), this.locZ, event.getRadius(), event.getFire(), this.world.getGameRules().getBoolean("mobGriefing")); } // CraftBukkit end // CraftBukkit start - Use relative location for far away sounds // this.world.a(1013, new BlockPosition(this), 0); int viewDistance = ((WorldServer) this.world).getServer().getViewDistance() * 16; for (EntityPlayer player : (List<EntityPlayer>) this.world.players) { double deltaX = this.locX - player.locX; double deltaZ = this.locZ - player.locZ; double distanceSquared = deltaX * deltaX + deltaZ * deltaZ; if (world.spigotConfig.witherSpawnSoundRadius > 0 && distanceSquared > world.spigotConfig.witherSpawnSoundRadius * world.spigotConfig.witherSpawnSoundRadius) continue; // Spigot if (distanceSquared > viewDistance * viewDistance) { double deltaLength = Math.sqrt(distanceSquared); double relativeX = player.locX + (deltaX / deltaLength) * viewDistance; double relativeZ = player.locZ + (deltaZ / deltaLength) * viewDistance; player.playerConnection.sendPacket( new PacketPlayOutWorldEvent( 1013, new BlockPosition((int) relativeX, (int) this.locY, (int) relativeZ), 0, true)); } else { player.playerConnection.sendPacket( new PacketPlayOutWorldEvent( 1013, new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ), 0, true)); } } // CraftBukkit end } this.r(i); if (this.ticksLived % 10 == 0) { this.heal(10.0F, EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); // CraftBukkit } } else { super.E(); int j; for (i = 1; i < 3; ++i) { if (this.ticksLived >= this.bm[i - 1]) { this.bm[i - 1] = this.ticksLived + 10 + this.random.nextInt(10); if (this.world.getDifficulty() == EnumDifficulty.NORMAL || this.world.getDifficulty() == EnumDifficulty.HARD) { int k = i - 1; int l = this.bn[i - 1]; this.bn[k] = this.bn[i - 1] + 1; if (l > 15) { float f = 10.0F; float f1 = 5.0F; double d0 = MathHelper.a(this.random, this.locX - (double) f, this.locX + (double) f); double d1 = MathHelper.a(this.random, this.locY - (double) f1, this.locY + (double) f1); double d2 = MathHelper.a(this.random, this.locZ - (double) f, this.locZ + (double) f); this.a(i + 1, d0, d1, d2, true); this.bn[i - 1] = 0; } } j = this.s(i); if (j > 0) { Entity entity = this.world.a(j); if (entity != null && entity.isAlive() && this.h(entity) <= 900.0D && this.hasLineOfSight(entity)) { this.a(i + 1, (EntityLiving) entity); this.bm[i - 1] = this.ticksLived + 40 + this.random.nextInt(20); this.bn[i - 1] = 0; } else { this.b(i, 0); } } else { List list = this.world.a( EntityLiving.class, this.getBoundingBox().grow(20.0D, 8.0D, 20.0D), Predicates.and(EntityWither.bp, IEntitySelector.d)); for (int i1 = 0; i1 < 10 && !list.isEmpty(); ++i1) { EntityLiving entityliving = (EntityLiving) list.get(this.random.nextInt(list.size())); if (entityliving != this && entityliving.isAlive() && this.hasLineOfSight(entityliving)) { if (entityliving instanceof EntityHuman) { if (!((EntityHuman) entityliving).abilities.isInvulnerable) { this.b(i, entityliving.getId()); } } else { this.b(i, entityliving.getId()); } break; } list.remove(entityliving); } } } } if (this.getGoalTarget() != null) { this.b(0, this.getGoalTarget().getId()); } else { this.b(0, 0); } if (this.bo > 0) { --this.bo; if (this.bo == 0 && this.world.getGameRules().getBoolean("mobGriefing")) { i = MathHelper.floor(this.locY); j = MathHelper.floor(this.locX); int j1 = MathHelper.floor(this.locZ); boolean flag = false; for (int k1 = -1; k1 <= 1; ++k1) { for (int l1 = -1; l1 <= 1; ++l1) { for (int i2 = 0; i2 <= 3; ++i2) { int j2 = j + k1; int k2 = i + i2; int l2 = j1 + l1; Block block = this.world.getType(new BlockPosition(j2, k2, l2)).getBlock(); if (block.getMaterial() != Material.AIR && block != Blocks.BEDROCK && block != Blocks.END_PORTAL && block != Blocks.END_PORTAL_FRAME && block != Blocks.COMMAND_BLOCK && block != Blocks.BARRIER) { // CraftBukkit start if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, Blocks.AIR, 0) .isCancelled()) { continue; } // CraftBukkit end flag = this.world.setAir(new BlockPosition(j2, k2, l2), true) || flag; } } } } if (flag) { this.world.a((EntityHuman) null, 1012, new BlockPosition(this), 0); } } } if (this.ticksLived % 20 == 0) { this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit } } }