GithubHelp home page GithubHelp logo

mistefr / autorestarter Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 32 KB

A PocketMine-MP plugin that automatically restart your server once the chosen time is up and who transfers your players to the IP and PORT chosen just before restarting

License: GNU General Public License v3.0

PHP 100.00%
pocketmine-mp-plugin pocketmine-plugin

autorestarter's Introduction

AutoRestarter

A PocketMine-MP plugin that automatically restart your server once the chosen time is up and who transfers your players to the IP and PORT chosen just before restarting !

Config

You can choose in the config the delay between each restart in minutes, the message if you want one to be broadcasted every 10 mins if the time to reboot is > 5 mins and to what IP and PORT are the players transferred just before the restart.

Something that you can do is transfer them to the server that is going to be restarted by leaving "default" to serverIp and serverPort in the config.

Events

This plugin is calling the following events:

  • PreRestartEvent: Called when the time is up and the server is going to restart, you can cancel this event and set a new delay in mins
use miste\autorestarter\event\PreRestartEvent;

/*
  To cancel server reboot and re schedule it 30 mins after
  NB: If you forget to setDelay() the event will be called the next min
*/

public function onPreRestartEvent(PreRestartEvent $ev){
        $ev->setDelay(30);
        $ev->setCancelled(true); 
}
  • MidRestartEvent: Called once all the players have just been transferred and before the plugins are disabled. It can be very useful to deal with configs to save your players data. You can get all the transferred players by doing getTransferredPlayers()
use miste\autorestarter\event\MidRestartEvent;

public function onMidRestartEvent(MidRestartEvent $ev){
        foreach ($ev->getTransferredPlayers() as $playerName){
          //your code here
        }
}

API

If you want to reboot the server at any time you can call the method AutoRestarter::restart(Server $server, ?string $serverIp = "default", ?int $serverPort = 19132);

/*
  This will restart the server and transfer all the players online to play.lbsg.net:19132.
*/
use miste\autorestarter\AutoRestarter;

AutoRestarter::restart($this->getServer(), "play.lbsg.net", 19132);

/*
  This will restart the server and transfer all the players online the IP and port provided in the config.
*/
use miste\autorestarter\AutoRestarter;

AutoRestarter::restart($this->getServer());

NB: You need pcntl extension to be enabled and compiled with PHP (by default on PM Linux binaries but not on Windows one).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.