From 12b3a582b20303f9d81c08bf4423ddae1d4ed4b0 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 12 Apr 2015 23:21:19 +1200 Subject: [PATCH] CustomExplosion: Fixed loop, added max damage --- .../game/core/explosion/CustomExplosion.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/explosion/CustomExplosion.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/explosion/CustomExplosion.java index fb70dbd68..4cdf04c68 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/explosion/CustomExplosion.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/explosion/CustomExplosion.java @@ -52,6 +52,7 @@ public class CustomExplosion extends Explosion private float _damage; private boolean _useCustomDamage; private int _maxFallingBlocks = -1; + private float _maxDamage = 1000; public CustomExplosion(DamageManager manager, mineplex.core.explosion.Explosion explosion, Location loc, float explosionSize, String deathCause) @@ -76,6 +77,13 @@ public class CustomExplosion extends Explosion return this; } + public CustomExplosion setMaxDamage(float maxDamage) + { + _maxDamage = maxDamage; + + return this; + } + public CustomExplosion setBlockExplosionSize(float explosionSize) { _blockExplosionSize = explosionSize; @@ -242,7 +250,7 @@ public class CustomExplosion extends Explosion // Performs a raytrace that determines the percentage of solid blocks between the two double d9 = this._world.a(vec3d, entity.boundingBox); double d10 = (1.0D - d7) * d9; - int damage; + float damage; if (_useCustomDamage) { @@ -251,12 +259,13 @@ public class CustomExplosion extends Explosion else { damage = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * this.size + 1.0D); + damage = Math.min(damage, _maxDamage); } if (entity.getBukkitEntity() instanceof LivingEntity) { _manager.NewDamageEvent((LivingEntity) entity.getBukkitEntity(), _owner, null, - DamageCause.ENTITY_EXPLOSION, damage, true, _ignoreRate, false, _damageReason, null); + DamageCause.ENTITY_EXPLOSION, damage, true, _ignoreRate, false, _damageReason, _damageReason); } else { @@ -331,13 +340,15 @@ public class CustomExplosion extends Explosion { Collection blocks = event.GetBlocks(); - if (_maxFallingBlocks != -1) + if (blocks.size() > _maxFallingBlocks) { blocks = new ArrayList(blocks); Collections.shuffle((ArrayList) blocks); - while (blocks.size() > Math.max(0, _maxFallingBlocks)) + int toRemove = blocks.size() - _maxFallingBlocks; + + for (int i = 0; i < toRemove; i++) { blocks.remove(0); }