Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace RestartedRestartedMessage;
- use pocketminecommandConsoleCommandSender;
- use pocketmineschedulerTask;
- class RestartedMessage extends Task{
- public $plugin, $times, $start, $end;
- static $restartSeconds = 0;
- function __construct($plugin, $restartInterval, $messageCount){
- $this->plugin = $plugin;
- $currentTick = $this->start = $this->plugin->getServer()->getTick() - 1;
- $this->end = $end = $currentTick + (($restartInterval * 60) * 20);
- $delay = $end / $messageCount;
- for($i = 1; $i <= $messageCount; $i++){
- $this->times[] = $currentTick + ($delay * $i);
- }
- array_reverse($this->times);
- }
- function onRun(int $currentTick){
- $restartSeconds = $this->end - ($currentTick - 1) / 20;
- var_dump($restartSeconds);
- var_dump($this->end);
- if($restartSeconds <= 10 && !$restartSeconds < 1){
- $this->plugin->getServer()->broadcastMessage($this->plugin->getLangManager()->translateString("restart-countdown-message", $restartSeconds));
- }elseif($restartSeconds < 1){
- foreach($this->plugin->getServer()->getOnlinePlayers() as $player){
- $player->kick($this->plugin->getLangManager()->translateString("restart-kick-message", $player->getName()), false);
- }
- $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), "savestop");
- }else{
- foreach($this->times as $key => $time){
- if(($currentTick - 1) === $time){
- unset($this->times[$key]);
- $countdown = Utils::getCountdown($restartSeconds);
- $lang = $this->plugin->getLangManager();
- $hours = $countdown["hours"];
- $minutes = $countdown["minutes"];
- $seconds = $countdown["seconds"];
- if($hours > 0){
- $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-hours-message", $hours, ($hours > 1 ? "s" : ""), $minutes, ($minutes > 1 ? "s" : "")));
- }elseif($minutes > 0){
- $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-minutes-message", $minutes, ($minutes > 1 ? "s" : "")));
- }elseif($seconds > 0){
- $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-seconds-message", $seconds, ($seconds > 1 ? "s" : "")));
- }
- }
- }
- }
- }
- static function getRestartSeconds(){
- return self::$restartSeconds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement