CustomExplosion: Fixed loop, added max damage

This commit is contained in:
libraryaddict 2015-04-12 23:21:19 +12:00
parent be21968805
commit 12b3a582b2

View File

@ -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<org.bukkit.block.Block> blocks = event.GetBlocks();
if (_maxFallingBlocks != -1)
if (blocks.size() > _maxFallingBlocks)
{
blocks = new ArrayList<org.bukkit.block.Block>(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);
}