Java timers?

Discussion in 'Plugin Development' started by contex, Mar 17, 2011.

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

    contex

    I'm currenty trying to add a timer that runs a function x seconds after a player joins. Here's some of my Playelistener:
    Code:
    if(Config.debug_enable)  Utils.Debug("Idle time is: "+seconds);
    
    IdleTimer = new Timer(player.getName());
    
    IdleTimer.schedule(CheckIdle(player), seconds);
    And the function:
    Code:
    public TimerTask CheckIdle(Player  player)
    
    {
    
    if (AuthDB.isAuthorized(player.getEntityId()) == false)
    
    {
    
    Messages.SendMessage("AuthDB_message_idle_kick", player, null);
    
    IdleTimer.cancel();
    
    }
    
    else { IdleTimer.cancel(); }
    
    return null;
    
    }
    What am I doing wrong :)
     
  2. Offline

    Sammy

    You can simplify everything just by using the bukkit schedule
    Code:
    int Schedule = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new CheckIdle(player) , (x* 20L));
    The int Schedule is only used if you want to track your schedule
     
  3. Offline

    contex

    Jesus, been trying to do this for hours now, thanks ALOT!
     
  4. Offline

    Sammy

    No problem, glad I could help =)
     
  5. Offline

    EraDKtor

    Oooh scheduler![​IMG]
    I will need that for my preview functions later.
    Thanks, here have a cake: [​IMG]
     
  6. Offline

    eltorqiro

    Also be aware that since the bukkit api itself isn't thread safe, using any of the bukkit api within one of the Async scheduler methods may not be safe, and certainly isn't safe in your own custom threads.
     
  7. Offline

    Sammy

    That's true, try always using the Sync, like the one on my example =)
     
Thread Status:
Not open for further replies.

Share This Page