Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace serverdeathrestarter;
- use pocketmine\Thread;
- class CheckerThread extends Thread{
- public $lastAlive;
- /** @var number */
- private $timeout;
- public function __construct($timeout){
- $this->timeout = $timeout;
- }
- public function run(){
- $this->lastAlive = microtime(true);
- while(true){
- $time = microtime(true);
- if($time - $this->lastAlive > $this->timeout){
- die("Main thread timeout ($this->timeout second(s))");
- }
- sleep(1);
- }
- }
- }
- =====================================================
- <?php
- namespace serverdeathrestarter;
- use pocketmine\command\Command;
- use pocketmine\command\CommandSender;
- use pocketmine\plugin\PluginBase;
- class SDRPlugin extends PluginBase{
- public function onEnable(){
- $this->saveDefaultConfig();
- $thread = new CheckerThread($this->getConfig()->get("timeout"));
- $thread->start();
- }
- public function onCommand(CommandSender $sender, Command $cmd, $alias, array $args){
- if($cmd->getName() === "serverdie"){
- die;
- }
- if($cmd->getName() === "suspend"){
- $this->suspendThread();
- }
- }
- /**
- * Function for testing
- */
- public static function suspendThread(){
- while(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement