Skip to content

Instantly share code, notes, and snippets.

@gollilla
Last active March 5, 2018 17:22
Show Gist options
  • Save gollilla/1970988f2fe2e460c5a1c2ccd24d86fc to your computer and use it in GitHub Desktop.
Save gollilla/1970988f2fe2e460c5a1c2ccd24d86fc to your computer and use it in GitHub Desktop.
<?php
use pocketmine\scheduler\Task;
class Main extends PluginBase implements Listener{
public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
public function onJoin(PlayerJoinEvent $ev){
$player = $ev->getPlayer();
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "test"], [$player]), 1);
}
public function test($player){
$player->sendMessage("ようこそ");
}
}
class CallbackTask extends Task {
protected $callable, $args;
/**
* @param callable $callable
* @param array $args
*/
public function __construct(callable $callable, array $args = [])
{
$this->callable = $callable;
$this->args = $args;
$this->args[] = $this;
}
/**
* @return callable
*/
public function getCallable() : callable
{
return $this->callable;
}
/**
* @param $currentTick
*/
public function onRun(int $currentTick)
{
call_user_func_array($this->callable, $this->args);//関数呼び出し
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment