Solved Cancel scheduleSyncDelayedTask from another class

Discussion in 'Plugin Development' started by vYN, Apr 17, 2013.

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

    vYN

    Hi. I'm having some issues canceling a "scheduleSyncDelayedTask" from another class...

    Here is my code:
    (I guess you don't need to look inside public void run")
    Code:
    int pName = player.getEntityId();
                        PlayerListener.taskIDs.put(player.getName(), pName);
                        pName = PrivateWarps.pluginST.getServer().getScheduler().scheduleSyncDelayedTask(PrivateWarps.pluginST, new Runnable() {
    My listener class that is gone cancel the task:
    Tried "isCurrentlyRunning" and "isQueued"....
    Code:
    public static HashMap<String, Integer> taskIDs = new HashMap<String, Integer>();
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e){
     
            Player player = e.getPlayer();
     
            BukkitScheduler task = PrivateWarps.pluginST.getServer().getScheduler();
            if(taskIDs.containsKey(player.getName())){
                if(task.isCurrentlyRunning(taskIDs.get(player.getName()))){
                    task.cancelTask(taskIDs.get(player.getName()));
                    player.sendMessage("You moved! Warp canceled!");
                }
            }
        }
    I haven't been using the BukkitSchedular that much... So I'm not sure what to do...
    So please give me some pointers :) Thanks.
     
  2. Offline

    Morthis

    I'm confused what you're trying to do in the first part.

    Is pName supposed to represent the task ID that you store in the hashmap? If so you need to get the task ID first by scheduling it and afterwards put it in the hashmap. The task ID has nothing to do with the player's entity ID.
     
  3. Offline

    vYN

    Morthis
    So how do i get that task ID....?

    SOLVED!!!

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

    ZeusAllMighty11

    I would just do:

    Code:
    public class blah () {
       
        public int ID = 0;
     
    }
    
    [/CODE]
    public class meh(){

    if(Bukkit.getScheduler().isCurrentlyRunning(class.ID)){
    }
    }
    [/CODE]

    simple constructor stuff
     
Thread Status:
Not open for further replies.

Share This Page