How do i cancel task from outside task file

Discussion in 'Development' started by Besher, Apr 11, 2022.

  1. Besher

    Besher Witch

    Messages:
    51
    I am making a plugin where when someone moves in the duration of the 10 seconds the teleportation cancels I'm trying to cancel the task on PlayerMoveEvent. I figured out how to check when a player has moved but need help with cancelling the task.
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    735
    Move event is also fired when the player moves the camera. It would also be a massive overhead as you would need to run checks on each player per each movement.

    Instead, you can run the task in second intervals and check on each run if the player's distance from the origin position has met the threshold for the teleportation to be canceled.
     
  3. Besher

    Besher Witch

    Messages:
    51
    I know that I just need help with the cancelling part
     
  4. GamingFR91

    GamingFR91 Spider Jockey

    Messages:
    27
    GitHub:
    kanekilechomeur
    You can try to create a function in your task to stop it
    like:

    public function stop(): void{
    \\stop the task here
    }

    and in your Main you could do:

    $mytask = new MyTaskName();
    $mytask->stop();
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    735
    The comment line in your code is exactly what he is trying to do. He wants exactly that part of the code.
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    735
    $task->getHandler()->cancel();
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.