Solved FoodLevel Help

Discussion in 'Plugin Development' started by MunchMallow, Dec 8, 2013.

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

    MunchMallow

    Hello everybody for the third time!
    And you know what they say about 3, it's of course the lucky number!​
    Anyway, I have been working progressive on my plugin, which is absolutely really nice.​
    ---------------
    But i encountered a strange problem, which is terrible.​
    What I want the coding to do, is to run a repeated task, IF​
    the HungerLevel is under 20. But it keeps running, even if it's over​
    20.​
    ---------------
    I appreciate any quick responses, I am not the most patient guy ever. xD​
    So here is the coding.​
    ---------------
    By the way, I feel very embarrassed posting here,​
    since I don't do it very often. xD​
    But you learn from your mistakes, right?​
    ---------------
    Oh yeah, I forgot to tell, I won't post the whole code, so copy cats can't​
    steal my whole code. Unless you tell me to upload the​
    whole code.​
    ---------------
    The beautiful code:​
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent e) {
    3. final Player p = e.getPlayer();
    4. if(p.getFoodLevel() < 20) {
    5.  
    6. Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    7. public void run() {
    8. p.sendMessage("Test");
    9. p.setFoodLevel(p.getFoodLevel() + 2);
    10. }
    11. }, 0, 20);
    12. }
    13. }

     
  2. Offline

    Chlorek

    You check if food level is under 20 then you start a new task. It means that it won't stop. You must terminate this task if foodlevel >= 20.
     
  3. Offline

    MunchMallow

    Hmmm, let me see if I can fix it :) I feel very stupid now xD

    Lol, thank you! :)
    Didn't even see it.
    I feel so stupid now! xD

    SOLVED!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page