Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions LiveSigns/src/aliuly/livesigns/common/PluginCallbackTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace aliuly\livesigns\common;

use pocketmine\scheduler\PluginTask;
use pocketmine\plugin\Plugin;

/**
* Simple plugin callbacks.
*
* Allows the creation of simple callbacks with extra data
* The last parameter in the callback will be the "currentTicks"
*
* Simply put, just do:
*
* new PluginCallbackTask($plugin,[$obj,"method"],[$args])
*
* Pass it to the scheduler and off you go...
*/
class PluginCallbackTask extends PluginTask{

/** @var callable */
protected $callable;

/** @var array */
protected $args;

/**
* @param Plugin $owner
* @param callable $callable
* @param array $args
*/
public function __construct(Plugin $owner, callable $callable, array $args = []){
parent::__construct($owner);
$this->callable = $callable;
$this->args = $args;
$this->args[] = $this;
}
/**
* @return callable
*/
public function getCallable(){
return $this->callable;
}

public function onRun($currentTicks){
$c = $this->callable;
$args = $this->args;
$args[] = $currentTicks;
$c(...$args);
}

}