Scheduler Issue

Discussion in 'Plugin Development' started by number1_Master, Aug 31, 2012.

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

    number1_Master

    Solved: Just needed to use .isQueued instead of .isCurrentlyRunning when checking the scheduler.

    Show Spoiler
    Well, I have some weird scheduler issue which I do not understand. Anyway, the issue:
    I have two plugins which do something similar to the following: Whenever a player quits, it schedules a task. It puts them into a HashMap too. If the player connects before the task executes, it cancels it and removes them from the HashMap.
    The above is not working. Here is the code:
    PlayerQuitEvent (open)
    Code:java
    1. @EventHandler
    2. public void onPlayerQuit(final PlayerQuitEvent e)
    3. {
    4. Player player = e.getPlayer();
    5. String playerName = player.getName();
    6.  
    7. int task = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    8. {
    9. public void run()
    10. { // CODE }
    11.  
    12. }, 30*20);
    13. clearLag.put(playerName, task);
    14. }

    PlayerJoinEvent (open)
    Code:java
    1. if(clearLag.containsKey(playerName))
    2. {
    3. System.out.println("IS RUNNING!"); // <-- Just some debug
    4. int task = clearLag.get(playerName);
    5. if(Bukkit.getServer().getScheduler().isCurrentlyRunning(task))
    6. {
    7. Bukkit.getServer().getScheduler().cancelTask(task);
    8. }
    9. }

    From a bunch of debugging, I found out that whenever the player joins, it states that the player is not in the HashMap, but under Quit, as another debug message, I made it get the task ID, which returned fine.

    Is this a bukkit bug, or is this something I missed by mistake?
     
  2. Offline

    chaseoes

    clearlag.put should be up one line?
     
  3. Offline

    number1_Master

    Why you say that?

    O.K. I put my plugin onto my main server, and discovered that out of the 50th connection, my code worked.

    I believe this is a bukkit bug.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    chaseoes

    What's it doing where it is?
     
  5. Offline

    number1_Master

    When the player disconnects, it puts them into a hashmap with a scheduler. When the player connects before the scheduler ends, it cancels the scheduler (and removes the player from the hashmap).
     
  6. Offline

    chaseoes

    Still no clue what you want, but I think you want:
    Code:
    int task = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
      public void run() {
        clearLag.put(playerName, task);
      }
    }, 30*20);
     
  7. Offline

    number1_Master

    No! O.K. read carefully! When a player disconnects, it puts they're name and the task into a hashmap. Key = PlayerName, Value = Task.
    If a player connects before the scheduler starts the code (inside run()), I want it to cancel the task!

    It can't get any more simpler then that.
     
  8. Offline

    chaseoes

    All I did was fix the code you provided in the OP..
     
  9. Offline

    Courier

    Then report it so it can get fixed.
     
  10. Offline

    number1_Master

    You didn't fix it because that is not what I'm aiming for.
    I'm not sure if it is an issue. I created a thread because I thought something in my code was wrong. If others are having this issue, then I will report it.
     
  11. Offline

    chaseoes

    Then why did you post it?
     
  12. Offline

    number1_Master

    I think I might of figured out the problem. Instead of using isCurrentlyRunning, I should use isQueued. Ima test it out.

    EDIT: Yup. Works now!

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

Share This Page