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

deprecated CallbackTask

Comments in 'Plugin Development' started by mamayadesu, Apr 28, 2015.

  1. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Plugin code
    PHP:
    <?php

    namespace mamayadesu;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\scheduler\CallbackTask;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;

    class 
    message extends PluginBase implements Listener {

    private 
    $cfg;

        public function 
    onEnable() {
            if(! 
    file_exists($this->getDataFolder())) @mkdir($this->getDataFolder());
            
    $this->cfg = new Config($this->getDataFolder()."config.yml"Config::YAML);
            if(empty(
    $this->cfg->get("msg"))) {
                
    $this->cfg->set("msg""Hi, {PLAYER}\nOnline {ONLINECOUNT}/{MAXPLAYERS}");
                
    $this->cfg->save();
            }
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }

        public function 
    messagestart(Player $player) {
            
    $onlineCount 0;
            foreach(
    $this->getServer()->getOnlinePlayers() as $p) {
                if(
    $p->isOnline() && (!($player instanceof Player) or $player->canSee($p))) {
                    ++
    $onlineCount;
                }
            }
            
    $msg str_replace("{PLAYER}"$player->getName(), $this->cfg->get("msg"));
            
    $msg str_replace("{ONLINECOUNT}"$onlineCount$msg);
            
    $msg str_replace("{MAXPLAYERS}"$this->getServer()->getMaxPlayers(), $msg);
            
    $player->sendPopup($msg);
            if(
    $player->isOnline()) $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this,"messagestart" ], [$player]), 10); // 10 ticks = 0.5 seconds
        
    }

        public function 
    onPlayerJoin(PlayerJoinEvent $event) {
            
    $this->messagestart($event->getPlayer());
        }
    }
    Logs:
    Code:
    23:20:55 [WARNING] A plugin attempted to register a deprecated CallbackTask (Callback#mamayadesu\message::messagestart)
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    that means you shouldnt use it anymore. try extending PluginTask.
    PEMapModder likes this.
  3. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Example please.
    RekkuzaRage likes this.
  4. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu

Share This Page

Advertisement