Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do I cancel an event with a Task?

Comments in 'Plugin Development' started by Hotshot_9930, Aug 4, 2015.

  1. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    For example, let's say I created a Task and i want to use that task to cancel and event like PlayerChatEvent for example. How would i do that?
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    what event runs only once
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Task is something that runs after a defined number of ticks.
    Event is something that PocketMine (or some plugins) calls when something happens. Technically the two have no direct relationship. Event can be inside a task, and task can be inside an event.
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I already know this. My question is, how do I cancel an event from within a task? For example, a spam filter. The PlayerChatEvent gets cancelled if the player talks, let's say about 1 - 40 ticks after the last time they talked using a delayedtask maybe?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You are not cancelling an event through a task. They are separate things. Task is one individual line and event is another individual line.

    I would say, you shouldn't use tasks at all. Instead, save the microtime(true) when the player talks, in a class property. The next time he talks, check if microtime(true) is less than 2, and if yes, cancel the event.
    Hotshot_9930 likes this.
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Thank you so much :D it's working great now.
    PEMapModder likes this.
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I dont use the method mentioned in this thread anymore.

Share This Page

Advertisement