Stop a Repeating Tasks from Scheduler?? :/

Discussion in 'Plugin Development' started by Eistee², Jun 17, 2012.

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

    Eistee²

    Hello , i had a request to make a plugin and i need to check how long the players are online so I thought I can use the Bukkit Scheduler for this currently it looks like that

    Code:
    Boolean PlayerNochOn;
        public void PlayerCheck(final String Playernamen){
           
            this.PlayerNewTrenner();
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    PlayerNochOn = false;
                Player[] PlayerOn = Bukkit.getOnlinePlayers(); //Get all players which are online
                   
                for(int i=0;i < PlayerOn.length ;i++){  //Find the Player when he is offline the boolean PlayerNochOn will be false.
                    System.out.println("Sucht");
                    if(PlayerOn[i].getName().equals(Playernamen)){
                        System.out.println("Gefunden");
                          Bukkit.getPlayer(Playernamen).sendMessage(Playernamen);
                          PlayerNochOn = true;
                          break;
                    }
                }
                if(PlayerNochOn == false){ //When boolean PlayerNochOn is false it will "return;"
                    System.out.println("player raus");
                    return;
                }
                }
     
            }, 60L, 60L);
       
       
    }
    But I really have no idea how to stop it when he goes off :/ the return dosent work can some one help me??? :D would be very nice

    Mfg Eistee²

    Bump :/

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

    FTWin01Gurl

    Terminate it with break;?
     
  3. Offline

    Eistee²

    Ty but dosent work for me or I make somthing worng :(
     
  4. Offline

    FTWin01Gurl

    I don't know what else to help you, because most of your strings are in a different language than I speak.
     
  5. Offline

    Eistee²

    Wait 5 min I will translate it :D XD

    Code:
    Boolean IsPlayerOn;
        public void PlayerCheck(final String Playernamen){
       
            this.PlayerNewTrenner();
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    IsPlayerOn = false;
                Player[] PlayerOn = Bukkit.getOnlinePlayers(); //Get all players which are online
               
                for(int i=0;i < PlayerOn.length ;i++){  //Find the Player when he is offline the boolean IsPlayerOn will be false.
                    System.out.println("Search");
                    if(PlayerOn[i].getName().equals(Playernamen)){
                        System.out.println("Found");
                          IsPlayerOn = true;
                          break;
                    }
                }
                if(IsPlayerhOn == false){ //When boolean PlayerNochOn is false it will "return;"
                    return;
                }
                }
     
            }, 60L, 60L);
     
     
    }
     
  6. Offline

    FTWin01Gurl

    No need.
     
  7. Offline

    Eistee²

    It starts when a player join and stop when the player left :/
     
  8. Offline

    LucasEmanuel

    If you simply want to check the time it takes for the player to be on the server that seems like alot of completely bloated code. All you have to do is log when a player connects and when that player leaves. And just compare the times between those events.

    Pseudo:
    Code:
    PlayerJoinEvent:
        long currenttime = System.currentTimemMillis();
     
        map.put(playername, currenttime); || configfile.put(playername, currenttime);
     
    PlayerLeaveEvent:
        long currenttime = System.currentTimeMillis();
     
        long playedtime = map||config get(playername) - currenttime;
     
        log playedtime;
     
    ferrybig and Eistee² like this.
  9. Offline

    Eistee²

    Danke :)
     
  10. Offline

    blablubbabc

    repeating scheduler task kannst du so beenden: getServer().getScheduler().cancelTask(id)
    die id bekommst du beim starten des schudelerTasks: einfach int id = davor schreiben und das irgendwo speichern

    Gruß bla
     
Thread Status:
Not open for further replies.

Share This Page