have a error on getHealth();

Discussion in 'Spigot Plugin Development' started by Angeles, May 27, 2016.

  1. public static void setLastHealth(Player player) {
    lastHealth.put(player.getUniqueId(), Double.valueOf(player.getHealth()));
    }

    Someone help me fix player.getHealth it errors with an anbiouse methord or something
     
  2. Why are you convering it to a double?
     
    • Agree Agree x 1
  3. o_O
    Tell us what it actually does.

    Also #getHealth() is a double already.
     
  4. Code (Text):
    public class Util {

        public static HashMap<UUID, Long> lastLanding = new HashMap<UUID, Long>();
        static HashMap<UUID, Long> lastRegen = new HashMap<UUID, Long>();
        static HashMap<UUID, Double> lastHealth = new HashMap<UUID, Double>();
        static HashMap<UUID, Long> lastForcefield = new HashMap<UUID, Long>();
        public static HashMap<UUID, Integer> clicksPerSecond = new HashMap<UUID, Integer>();

        public static long getLastLanding(Player player) {
            if (lastLanding.containsKey(player.getUniqueId())) {
                return lastLanding.get(player.getUniqueId()).longValue();
            }
            return 0;
        }
       
        public static void updateLastLanding(Player player) {
            lastLanding.put(player.getUniqueId(), System.currentTimeMillis());
        }
       
        public static long getLastRegen(Player player) {
            if (lastRegen.containsKey(player.getUniqueId())) {
                return lastRegen.get(player.getUniqueId()).longValue();
            }
            return 0;
        }

        public static void setLastRegen(Player player, long time) {
            lastRegen.put(player.getUniqueId(), Long.valueOf(time));
        }

        public static Integer getLastCPS(Player player) {
            if (clicksPerSecond.containsKey(player.getUniqueId())) {
                return clicksPerSecond.get(player.getUniqueId()).intValue();
            }
            return 0;
        }
       
        public static void setLastCPS(Player player, Integer cps) {
            clicksPerSecond.put(player.getUniqueId(), cps);
        }
       
        public static Double getLastHealth(Player player) {
            if (lastHealth.containsKey(player.getUniqueId())) {
                return lastHealth.get(player.getUniqueId());
            }
            return 0.0;
        }

        public static void setLastHealth(Player player) {
            lastHealth.put(player.getUniqueId(), Double.valueOf(player.getHealth()));
        }

        public static long lastForcefield(Player player) {
            if (lastForcefield.containsKey(player.getUniqueId())) {
                return lastForcefield.get(player.getUniqueId()).longValue();
            }
            return 0;
        }

        public static void updateForcefield(Player player) {
            lastForcefield.put(player.getUniqueId(), Long.valueOf(System.nanoTime()));
        }
    }
     
  5. You can remove the #longValue() from this "return lastLanding.get(player.getUniqueId()).longValue();"
    Can you show us the stack trace?
     
  6. No i just need help fixing getHealth();
     
  7. Exactly what I am trying to do. You said "Someone help me fix player.getHealth it errors with an anbiouse methord or something" This makes no sense at all. Can you show the actually error.
     
  8. Cast your player to Damageable and then use getHealth.

    Next time use Google for these types of easy questions instead of wasting our time. This question has been asked and solved a billion times.

    EDIT: What's up with all the other shitty answers? If you don't know the solution, just don't answer.
     
    #8 RobiRami, May 27, 2016
    Last edited: May 27, 2016
  9. You watse my time that didnt even work
     
    • Optimistic Optimistic x 2
    • Funny Funny x 1
  10. Your comment and the fact that I even tried to help you is a waste of my time, idiot.
     
    • Agree Agree x 2
    • Like Like x 1
    • Funny Funny x 1
  11. In which version are you doing this? If I go to my ide and I cast the player.getHealth() to long without any problems.

    There are already other users that had this problem, check out this
    This is basicly @RobiRami answer but you can do one of this things
    1.
    Try to do this:
    Code (Text):
    Damagable dam = (Damagable) player;
    dam.getHealth();
    2. Add the Spigot API jar to the buildpath and make it higher in the hierarchy order
     
  12. He probably didn't cast it correctly. They just want spoonfed code.
     
    • Agree Agree x 2