Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php
  2. namespace RestartedRestartedMessage;
  3. use pocketminecommandConsoleCommandSender;
  4. use pocketmineschedulerTask;
  5. class RestartedMessage extends Task{
  6. public $plugin, $times, $start, $end;
  7. static $restartSeconds = 0;
  8. function __construct($plugin, $restartInterval, $messageCount){
  9. $this->plugin = $plugin;
  10. $currentTick = $this->start = $this->plugin->getServer()->getTick() - 1;
  11. $this->end = $end = $currentTick + (($restartInterval * 60) * 20);
  12. $delay = $end / $messageCount;
  13. for($i = 1; $i <= $messageCount; $i++){
  14. $this->times[] = $currentTick + ($delay * $i);
  15. }
  16. array_reverse($this->times);
  17. }
  18.  
  19. function onRun(int $currentTick){
  20. $restartSeconds = $this->end - ($currentTick - 1) / 20;
  21. var_dump($restartSeconds);
  22. var_dump($this->end);
  23. if($restartSeconds <= 10 && !$restartSeconds < 1){
  24. $this->plugin->getServer()->broadcastMessage($this->plugin->getLangManager()->translateString("restart-countdown-message", $restartSeconds));
  25. }elseif($restartSeconds < 1){
  26. foreach($this->plugin->getServer()->getOnlinePlayers() as $player){
  27. $player->kick($this->plugin->getLangManager()->translateString("restart-kick-message", $player->getName()), false);
  28. }
  29. $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), "savestop");
  30. }else{
  31. foreach($this->times as $key => $time){
  32. if(($currentTick - 1) === $time){
  33. unset($this->times[$key]);
  34. $countdown = Utils::getCountdown($restartSeconds);
  35. $lang = $this->plugin->getLangManager();
  36. $hours = $countdown["hours"];
  37. $minutes = $countdown["minutes"];
  38. $seconds = $countdown["seconds"];
  39.  
  40. if($hours > 0){
  41. $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-hours-message", $hours, ($hours > 1 ? "s" : ""), $minutes, ($minutes > 1 ? "s" : "")));
  42. }elseif($minutes > 0){
  43. $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-minutes-message", $minutes, ($minutes > 1 ? "s" : "")));
  44. }elseif($seconds > 0){
  45. $this->plugin->getServer()->broadcastMessage($lang->translateString("restart-seconds-message", $seconds, ($seconds > 1 ? "s" : "")));
  46. }
  47. }
  48. }
  49. }
  50. }
  51.  
  52. static function getRestartSeconds(){
  53. return self::$restartSeconds;
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement