Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Kill server for inactivity

Comments in 'Plugin Development' started by DC4CODE, Sep 5, 2016.

  1. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    I am starting a FREE MCPE Hosting company but I need servers to kill itself if there is 1 hour of inactivity, e.g. (No Players Joining.. etc) but I have no idea on how I can accomplish this. Can I have some ideas?
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    PHP:
    function onEnable(){
    $this->killServerTask $this->getServer()->getScheduler()->scheduleDelayedTask(new KillServerTask($this), 60*60*20);
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
    function 
    onJoin(PlayerJoinEvent $event){
    $this->killServerTask->cancel();
    }
    function 
    onQuit(PlayerQuitEvent $event){
    if(
    count($this->getServer()->getOnlinePlayers()) === 0$this->killServerTask $this->getServer()->getScheduler()->scheduleDelayedTask(new KillServerTask($this), 60*60*20);
    }

    class 
    KillServerTask extends PluginTask{
    public function 
    __construct($plugin){
         
    parent::__construct($plugin);
    $this->server $plugin->getServer();
      }
    public function 
    onRun($tick){
         
    $this->server->shutdown();
      }
    }
    DC4CODE likes this.
  3. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Thanks!

Share This Page

Advertisement