Solved Survive time

Discussion in 'Plugin Development' started by rob1998@, Jan 15, 2014.

Thread Status:
Not open for further replies.
  1. Is it possible to retrieve the number of minutes that a player has survived?
    If it is please give an example..
     
  2. Offline

    AmShaegar

    Not via API. You have to calculate it yourself. i'd suggest to save a timestamp in a HashMap when a player joins. When he dies, calculate the difference between the current timestamp and the saved one. That's the survive time. On respawn set the timestamp in the hashmap to the current one.

    Code:java
    1. HashMap<String, Long> reviveTime = new HashMap<String, Long>();
    2.  
    3. // on join
    4.  
    5. reviveTime.put(player.getName(), System.currentTimeMillis());
    6.  
    7. // on death
    8.  
    9. long revive = reviveTim.get(player.getName());
    10.  
    11. long survived = System.currentTimeMillis() - revive;
    12.  
    13. // on respawn
    14.  
    15. reviveTime.put(player.getName(), System.currentTimeMillis());
     
  3. You could use Date for calculating seconds, minutes, hours, days etc...
     
Thread Status:
Not open for further replies.

Share This Page