1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Use scheduler in Player class

Discussion in 'Plugin Help' started by PJZ9n, Jun 12, 2020.

  1. PJZ9n

    PJZ9n Silverfish

    Messages:
    17
    GitHub:
    pjz9n
    Hello.
    I want to modify the Player class. How can I use something like TaskScheduler without depending on Plugin? Specifically, after handleLoginPacket, send the message with 20tick delay.
    This may seem nonsensical, but it is an example.
    Regards.
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You don't need to modify the Player class for that, you just need to listen for DataPacketReceiveEvent and schedule a delayed task, though the better way will be to listen for PlayerJoinEvent for that matter
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    Server::getInstance()->getScheduler()->scheduleDelayedTask(new class extends Task {
       
    /** @var Player */
       
    protected $player;
      
       public function 
    __construct(Player $player) {
          
    $this->player $player;
       } 
      
       public function 
    onRun(int $currentTick) {
          
    $this->player->sendMessage("Hello World!");
       }
    }(
    $this), 20);
     
  4. PJZ9n

    PJZ9n Silverfish

    Messages:
    17
    GitHub:
    pjz9n
    I hope to do it by rewriting the PM core. Due to various reasons, plugins cannot be used.
     
  5. PJZ9n

    PJZ9n Silverfish

    Messages:
    17
    GitHub:
    pjz9n
    Does the current PM have TaskScheduler in Server instance?
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Nope it doesn't
    If you really have to modify the Player class, add a class property, set the value when you get the packet, decrement the value in entityBaseTick and send the message if it reaches 0
     
    Primus likes this.
  7. PJZ9n

    PJZ9n Silverfish

    Messages:
    17
    GitHub:
    pjz9n
    However, EntityBaseTick works only after the entity has spawned, and does it work at the LoginPacket(Player::handleLogin()) stage?
     
  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.