Replace Double.isFinite with inhouse method

Double#isFinite is java 1.8 dependant, our inhouse method does exactly the same but isn't.
This commit is contained in:
Benjamin 2015-07-19 12:43:42 +02:00 committed by Olof Larsson
parent 8eec4744dd
commit 2cd6769481

View File

@ -626,13 +626,13 @@ public class MUtil
public static void setDamage(EntityDamageEvent event, double newDamage) public static void setDamage(EntityDamageEvent event, double newDamage)
{ {
// Check New Damage // Check New Damage
if ( ! Double.isFinite(newDamage)) throw new IllegalStateException("not finite newDamage: " + newDamage); if ( ! isFinite(newDamage)) throw new IllegalStateException("not finite newDamage: " + newDamage);
// Get Old Damage // Get Old Damage
final double oldDamage = event.getDamage(DamageModifier.BASE); final double oldDamage = event.getDamage(DamageModifier.BASE);
// Check Old Damage // Check Old Damage
if ( ! Double.isFinite(oldDamage)) throw new IllegalStateException("not finite oldDamage: " + oldDamage); if ( ! isFinite(oldDamage)) throw new IllegalStateException("not finite oldDamage: " + oldDamage);
// No Change? // No Change?
if (newDamage == oldDamage) return; if (newDamage == oldDamage) return;
@ -644,7 +644,7 @@ public class MUtil
final double factor = newDamage / oldDamage; final double factor = newDamage / oldDamage;
// Check Factor // Check Factor
if ( ! Double.isFinite(factor)) throw new IllegalStateException("not finite factor: " + factor + " damage: " + newDamage + " oldDamage: " + oldDamage); if ( ! isFinite(factor)) throw new IllegalStateException("not finite factor: " + factor + " damage: " + newDamage + " oldDamage: " + oldDamage);
// Now scale all damage modifiers! // Now scale all damage modifiers!
for (DamageModifier modifier : DamageModifier.values()) for (DamageModifier modifier : DamageModifier.values())
@ -669,7 +669,7 @@ public class MUtil
public static void scaleDamage(EntityDamageEvent event, double factor) public static void scaleDamage(EntityDamageEvent event, double factor)
{ {
// Clean Input // Clean Input
if ( ! Double.isFinite(factor)) throw new IllegalStateException("not finite factor: " + factor); if ( ! isFinite(factor)) throw new IllegalStateException("not finite factor: " + factor);
// No Change? // No Change?
if (factor == 1) return; if (factor == 1) return;
@ -684,6 +684,12 @@ public class MUtil
} }
} }
// isFinite check recreation to be compatible with java 1.7/1.6
public static boolean isFinite(double d)
{
return Math.abs(d) <= Double.MAX_VALUE;
}
// -------------------------------------------- // // -------------------------------------------- //
// GET IP // GET IP
// -------------------------------------------- // // -------------------------------------------- //