Solved Creating Task in another Class

Discussion in 'Development' started by DaRealPandaz, Aug 9, 2019.

  1. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    17
    GitHub:
    mrpandaz
    so im making a coal gen part in my core. I have everything setup and its working, except I want to add a delay on the time it takes to respawn the coal. I have looked everywhere and most people use the main class for their Task. I need it to be in the CoalListener class so i can get the coords of the Coal. Please help me, thank you
     
  2. wolfdale

    wolfdale Zombie

    Messages:
    345
    Its perfectly fine use task anywhere, as long as you can get your plugin main's instance
     
  3. Deniel

    Deniel Spider Jockey

    Messages:
    30
    GitHub:
    DenielWorld
    I believe you resolved this in PMMP discord.
     
  4. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    17
    GitHub:
    mrpandaz
    It is lemme mark this as solved
     
  5. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,650
    GitHub:
    HimbeersaftLP
    In the future it would be cool if you post the answer to the forum, too so that people can reference it easier in case anyone else has the same problem.
     
  6. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    17
    GitHub:
    mrpandaz
    Answer:

    In the Event Listener:

    PHP:

    $this
    ->core->getScheduler()->scheduleDelayedTask(new CoalGenTask($this->core$block), 20);

    In the "CoalGenTask" Class

    PHP:

    private $core;

    private 
    $block;

    public function 
    __construct(core $coreBlock $block)
    {
        
    $this->core $core;
        
    $this->block $block;
    }

    Thank You
     
    HimbeersaftLP likes this.
  7. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,650
    GitHub:
    HimbeersaftLP

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.