My loop doesn't cancel.

Discussion in 'Plugin Development' started by koochi10, Jul 24, 2013.

?

The loop in both methods counter1 and counter don't stop when I use tell it to can anyone help?

Poll closed Jul 31, 2013.
  1. I dont know what this is

    0 vote(s)
    0.0%
  2. what is a poll choice lol

    0 vote(s)
    0.0%
Multiple votes are allowed.
Thread Status:
Not open for further replies.
  1. Offline

    koochi10

    Code:
    public boolean counter(PlayerJoinEvent ingame){
    getLogger().info("the total is "+total); 
    getLogger().info("Running the game will start");
    final Player p = ingame.getPlayer();
    p.sendMessage(ChatColor.LIGHT_PURPLE+"The game will start in 30 seconds");
    int l = p.getLevel(); 
    taskid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
     public void run() {
     getLogger().info("Test if the loop is working");
     i = i-1;
       p.setLevel(i);
       p.sendMessage("This is a loop");
       if (i < 0){
       Bukkit.getServer().getScheduler().cancelTask(taskid);
       PlayerJoinEvent swag= new PlayerJoinEvent((Player) p, null);
       
       start(swag);
       }
       
     }
    },20L, 20L);
    p.setLevel(l);
    return true;
    }
    public void counter1(PlayerJoinEvent joined){
    final Player p = joined.getPlayer();
    taskid1 = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
     
    @Override
    public void run() {
    if (total == 4){
    Bukkit.getServer().getScheduler().cancelTask(taskid1);
    getLogger().info("There are 4 ppl in the game"); // works
    PlayerJoinEvent nigger = new PlayerJoinEvent((Player) p, null);
    Bukkit.getServer().getScheduler().cancelTask(taskid1);
    counter(swag);
    }
     
    }
    },20L, 20L);
     
    }
    
     
  2. Offline

    Trevor1134

  3. Offline

    Tarestudio

    koochi10
    You are starting scheduler tasks and hoping that the id, returned after the start, can be used in the task at the time of creating it? This will not work this way. >ou have to build an (inner) class extending Runnable, so you can store the id and implement a method to set this id after creating the schedule.
    Here is an example, how that can look like: http://forums.bukkit.org/threads/cooldown.162006/#post-1767527
     
    koochi10 likes this.
  4. Offline

    koochi10

    Thanks really helpful worked now
     
Thread Status:
Not open for further replies.

Share This Page