Solved Not ending task

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Jun 10, 2016.

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

    Fhbgsdhkfbl

    It was working a couple hours ago, but it just randomly stopped working

    After it sends the last message and teleports them to the last place, it will end the task, but it's not

    If you could help me out, or steer me the right direction, thanks!

    Code:
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                    int index = 0;
                    public void run() {
                        for(Player p : Bukkit.getOnlinePlayers()) {
                            if(plugin.tutorial.contains(p.getName())) {
                                if(index == locations.length) {
                                    Bukkit.getScheduler().cancelTask(index);
                                    plugin.tutorial.remove(p.getName());
                                    for(int i = 0; i < 200; i++) {
                                        p.sendMessage(" ");
                                    }
                                    p.showPlayer(p);
                                    p.sendMessage("§aYou have completed this tutorial! Please go forward to the rules and read those!");
                                    p.teleport(locations[index]);
                                    for(int i = 0; i < 200; i++) {
                                        p.sendMessage(" ");
                                    }
                                    for(int i = 0; i < messages[index].length;i++) {
                                        p.sendMessage(messages[index][i]);
                                    }
                                    index++;
                                }
                            }
                        }
                    }
                }, 0, 10*20);
            }
        }
    }
     
  2. Offline

    Zombie_Striker

    @Fhbgsdhkfbl
    This is because you are canceling an index value, not the task's ID. What you are doing is canceling all the tasks (including those for plugins that are not yours) until this task is canceled. To fix this, replace the index in "cancelTask(index)" with the taskID . You can get the task's id by using "this.getTaskId()"
     
  3. Offline

    Fhbgsdhkfbl

    I get an error on this.getTaskId(), I've searched all over on why it happens, but I can't find out why.
     
  4. Offline

    timtower Administrator Administrator Moderator

    Change the Runnable into BukkitRunnable
     
Thread Status:
Not open for further replies.

Share This Page