Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. declare(strict_types = 1);
  3.  
  4. namespace Kirill_Poroh;
  5.  
  6.  
  7. use pocketmine\Player;
  8. use Kirill_Poroh\CallbackTask;
  9.  
  10.  
  11. class Marquee
  12. {  
  13.     private $plugin;
  14.    
  15.     public $marquee_text;
  16.     public $marquee_number;
  17.     public $marquee_offset;
  18.    
  19.     public function __construct($plugin)
  20.     {
  21.         $this->plugin = $plugin;
  22.        
  23.         $this->marquee_number = 0;
  24.        
  25.         $plugin->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "sendMarquee"]), 20);
  26.         $plugin->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "updateMarquee"]), 20 * 60);
  27.     }
  28.  
  29.     public function sendMarquee()
  30.     {
  31.         if($this->marquee_offset < 1) return;
  32.        
  33.         $output = $this->marquee_text;
  34.        
  35.         $output = substr($output, 0, $this->marquee_offset);
  36.         $output = ( str_repeat(" ", 50 - mb_strlen($output)) . $output );
  37.        
  38.         foreach($this->plugin->getServer()->getOnlinePlayers() as $p)
  39.         {
  40.             $p->sendTip($output);
  41.         }
  42.        
  43.         $this->marquee_offset--;
  44.     }
  45.    
  46.     public function updateMarquee()
  47.     {
  48.         if(!file_exists($this->plugin->getDirectory() . "marquee.txt"))
  49.             $this->marquee_text = "Файл текстов marquee.txt не настроен!";
  50.         else
  51.         {
  52.             $texts = explode("\r\n", file_get_contents($this->plugin->getDirectory() . "marquee.txt"));
  53.            
  54.             if($this->marquee_number >= count($texts)) $this->marquee_number = 0;
  55.            
  56.             $this->marquee_text = "§0" . $texts[$this->marquee_number];
  57.         }
  58.        
  59.         $this->marquee_offset = 50;
  60.         $this->marquee_number++;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement