My RepeatingTask... is this safe?

Discussion in 'Plugin Development' started by TerraVale, Jul 11, 2013.

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

    TerraVale

    Hello. I've been working with minecraft's experience system and have actively been making an attempt at changing it into a stamina bar that auto-regenerates every 0.5 seconds. I will have skills deduct experience (in the form of stamina), allowing it to regenerate back to its maximum state afterwards, providing the player does not continue to spam skills disallowing it to regenerate back to its maximum capacity. I've decided the most efficient way of doing this would be to have a single task running (as opposed to a per-player basis).

    http://pastebin.com/daWaYS8T

    I will be disabling all methods of gaining and using experience to have this work as needed. Thus far, it works. However, due to my limited knowledge of scheduled tasks, I am unsure if this is safe. The last thing I want, of course, is a potential memory leak.

    Just as well, if you see anything I should improve, please let me know!

    Thanks.

    EDIT: I should also explain how this works!
    Effectively, it will add 1 experience orb/point every 0.5 seconds providing it meets the conditions presented (i.e. is under level 1 (which would be 0, of course), and does not have maximum experience). Occasionally through the use of skills and subtracting potentially uneven amounts of experience, adding one orb at a time will eventually level up the player. To work around this, every orb it adds it will check to make sure the player is still level 0. If, upon adding an orb, you exceed level zero, it can safely assume you're at maximum experience (or stamina) and it can set it to that amount.
     
  2. What? you called you snipped a javascript, (hoping you know the differences between java and javascript, as there are big differences)

    [ontopic]there shouldn't be anny memory leaks as you aren't creating object that are stored in collections after the task finishes[/ontopic]
     
  3. Offline

    TerraVale


    Sorry, that was a miss-click on my part as for which syntax to use.
     
Thread Status:
Not open for further replies.

Share This Page