Exemplo n.º 1
0
 public static double getMaxHealth(Damageable d) {
   Validate.notNull(d, "Damageable cannot be null");
   try {
     return d.getMaxHealth();
   } catch (NoSuchMethodError ignored) {
     Class<? extends Damageable> dClass = d.getClass();
     try {
       Method healthMethod = dClass.getMethod("getMaxHealth");
       Object obj = healthMethod.invoke(d);
       if (obj instanceof Number) {
         return ((Number) obj).doubleValue();
       } else {
         SkyStatic.getLogger()
             .log(
                 Level.WARNING,
                 "LivingEntity.getHealth returned {0}, which is not a Number!",
                 obj);
       }
     } catch (NoSuchMethodException
         | SecurityException
         | IllegalAccessException
         | IllegalArgumentException
         | InvocationTargetException ex) {
       SkyStatic.getLogger()
           .log(Level.WARNING, "Couldn't find / use .getMaxHealth method of LivingEntity!", ex);
     }
     return 10;
   }
 }
Exemplo n.º 2
0
 public static void setHealth(Damageable d, double health) {
   Validate.notNull(d, "Damageable cannot be null");
   try {
     d.setHealth(health);
   } catch (NoSuchMethodError ignored) {
     Class<? extends Damageable> dClass = d.getClass();
     try {
       Method healthMethod = dClass.getMethod("setHealth", Integer.TYPE);
       healthMethod.invoke(d, (int) health);
     } catch (NoSuchMethodException
         | SecurityException
         | IllegalAccessException
         | IllegalArgumentException
         | InvocationTargetException ex) {
       SkyStatic.getLogger()
           .log(Level.WARNING, "Couldn't find / use .setHealth method of LivingEntity!", ex);
     }
   }
 }