Clearing a value after a certain amount of time

Discussion in 'Plugin Development' started by ohtwo, Mar 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ohtwo

    Hey guys, what would be the most efficient way to clear a value (of type String) after a certain amount of time? This would be a repeating task.
     
  2. Offline

    RingOfStorms

    So like you have string, "bob", and every 3 min you want to set it to "" (empty string)?
     
  3. Offline

    ohtwo

    Yes, exactly. Except the time would be more along the lines of 3-5 seconds for multiple players.
     
  4. Offline

    RingOfStorms

    Hmm so what are you really doing? If you cleared it why would you have to repeat it right away and clear an already cleared string? Just curious :eek:
     
  5. Offline

    Deckerz

    bukkit repeater? it could possibly be very resource intensive on allot of players running it at the same time.
     
  6. Offline

    RingOfStorms

    Ok well for the every x seconds:

    Code:java
    1.  
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), new Runnable() {
    3. public void run () {
    4. //do stuff every 5 sec
    5. }
    6. }, 20L * 5, 20L * 5);
    7.  


    the last two parameters are ... , delay start, repeating interval);

    So that first one says, it will run 5 seconds after you call the schedule, and you can set that to zero if you want it to start right away. Then the second one is saying every 5 seconds it will run again.

    The time is in ticks, 20 ticks = 1 sec

    so 20 * 5 = 5 sec, or you can do 20 * 60 * 5 for 5 minutes, etc.
     
  7. Offline

    ohtwo

    Kinda hard to explain, as it makes more sense in my head haha. But basically I'm keeping track of the last player to damage another player. If during the last five seconds, a player jumps and dies from a jump, and it was within a few seconds of being attacked, the player who attacked the other gets credit. Is there a more efficient way of doing this?
     
  8. Offline

    JazzaG

    You could save a timestamp when the player is injured then just calculate time diff
     
  9. Offline

    ohtwo

    I don't know why I didn't think about that. Good idea, thank you.
     
  10. Offline

    RingOfStorms

    Doesn't minecraft already give them credit for it :?

    If a player hits another player off a cliff then mc already says player x hit player y off.
     
  11. Offline

    ohtwo

    I'm not too sure how to access this feature though.

    EDIT: It's not part of the current API as far as I know.
     
Thread Status:
Not open for further replies.

Share This Page