Created
February 15, 2019 12:24
-
-
Save JackNoordhuis/aede93478c29e2f28d57b0a437dc5b76 to your computer and use it in GitHub Desktop.
Some PocketMine-MP task examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace jacknoordhuis\example; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\scheduler\ClosureTask; | |
class RepeatingTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleRepeatingTask(new class extends \pocketmine\scheduler\Task{ | |
public function onRun(int $currentTick) : void{ | |
//some code here to repeat every 20 ticks (1 second) | |
} | |
}, 20); | |
} | |
} | |
class RepeatingClosureTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleRepeatingTask(new ClosureTask( | |
function(int $currentTick){ | |
//some code here to repeat every 20 ticks (1 second) | |
} | |
), 20); | |
} | |
} | |
class DelayedTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleDelayedTask(new class extends \pocketmine\scheduler\Task{ | |
public function onRun(int $currentTick) : void{ | |
//some code here to run after 20 ticks (1 second) | |
} | |
}, 20); | |
} | |
} | |
class DelayedClosureTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleDelayedTask(new ClosureTask( | |
function(int $currentTick){ | |
//some code here to run after 20 ticks (1 second) | |
} | |
), 20); | |
} | |
} | |
class InstantTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleTask(new class extends \pocketmine\scheduler\Task{ | |
public function onRun(int $currentTick) : void{ | |
//some code here to run on the next scheduler heartbeat (this tick or the next tick) | |
} | |
}); | |
} | |
} | |
class InstantClosureTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleTask(new ClosureTask( | |
function(int $currentTick){ | |
//some code here to run on the next scheduler heartbeat (this tick or the next tick) | |
} | |
)); | |
} | |
} | |
class DelayedRepeatingTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleDelayedRepeatingTask(new class extends \pocketmine\scheduler\Task{ | |
public function onRun(int $currentTick) : void{ | |
//some code here to run after 20 ticks (1 second) have passed, every 20 ticks (1 second) | |
} | |
}, 20,20); | |
} | |
} | |
class DelayedRepeatingClosureTaskExample extends PluginBase{ | |
public function onEnable(){ | |
$this->getScheduler()->scheduleDelayedRepeatingTask(new ClosureTask( | |
function(int $currentTick){ | |
//some code here to run after 20 ticks (1 second) have passed, every 20 ticks (1 second) | |
} | |
), 20, 20); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.