Guest User

Untitled

a guest
Apr 7th, 2016
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace GamesLoad\SurvivalGames;
  3.  
  4. use pocketmine\plugin\PluginBase;
  5. use pocketmine\scheduler\PluginTask;
  6. use pocketmine\event\Listener;
  7.  
  8. use pocketmine\event\player\PlayerInteractEvent;
  9. use pocketmine\event\player\PlayerLoginEvent;
  10. use pocketmine\command\CommandSender;
  11. use pocketmine\command\Command;
  12. use pocketmine\utils\TextFormat;
  13. use pocketmine\utils\Config;
  14. use pocketmine\math\Vector3;
  15. use pocketmine\level\Position;
  16. use pocketmine\command\ConsoleCommandSender;
  17. use pocketmine\Player;
  18. use pocketmine\block\Block;
  19. use pocketmine\tile\Sign;
  20. use pocketmine\level\Level;
  21. use pocketmine\item\Item;
  22. use pocketmine\event\block\BlockBreakEvent;
  23. use pocketmine\event\block\BlockPlaceEvent;
  24. use pocketmine\event\player\PlayerMoveEvent;
  25. use pocketmine\event\player\PlayerDeathEvent;
  26. use pocketmine\event\entity\EntityDamageEvent;
  27. use pocketmine\event\entity\EntityDamageByEntityEvent;
  28. use pocketmine\entity\Effect;
  29. use pocketmine\tile\Chest;
  30. use pocketmine\inventory\ChestInventory;
  31.  
  32. class Main extends PluginBase implements Listener {
  33.  
  34. public $prefix = TextFormat::YELLOW . "[" . TextFormat::AQUA . TextFormat::BOLD . "SKYWARS" . TextFormat::AQUA . "PE" . TextFormat::RESET . TextFormat::YELLOW . "] ";
  35. public $mode = 0;
  36. public $arenas = array();
  37. public $currentLevel = "";
  38.  
  39. public function onEnable()
  40. {
  41. $this->getLogger()->info(TextFormat::YELLOW . "---------------------------");
  42. $this->getLogger()->info(TextFormat::AQUA ." SKYWARS 1.3");
  43. $this->getLogger()->info(TextFormat::AQUA . " DC4US Rev.2 EDIT");
  44. $this->getLogger()->info(TextFormat::YELLOW . "---------------------------");
  45.  
  46. $this->getServer()->getPluginManager()->registerEvents($this ,$this);
  47. @mkdir($this->getDataFolder());
  48. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  49. if($config->get("arenas")!=null)
  50. {
  51. $this->arenas = $config->get("arenas");
  52. }
  53. foreach($this->arenas as $lev)
  54. {
  55. $this->getServer()->loadLevel($lev);
  56. }
  57. $items = array(array(1,0,36),array(5,0,50),array(261,0,1),array(262,0,38),array(276,0,1),array(278,0,1),array(311,0,1),array(322,0,1),array(308,0,1),array(310,0,1),array(309,0,1));
  58. if($config->get("chestitems")==null)
  59. {
  60. $config->set("chestitems",$items);
  61. }
  62. $config->save();
  63.  
  64. $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML);
  65. $playerlang->save();
  66.  
  67. $lang = new Config($this->getDataFolder() . "/lang.yml", Config::YAML);
  68. if($lang->get("en")==null)
  69. {
  70. $messages = array();
  71. $messages["kill"] = "Killed By";
  72. $messages["cannotjoin"] = "You Can't join this game!";
  73. $messages["seconds"] = " <<DC4.US>> Seconds";
  74. $messages["won"] = "Won the SkyWars game!";
  75. $messages["deathmatchminutes"] = "Minutes until Deathmatch.";
  76. $messages["deathmatchseconds"] = "Seconds until Deathmatch";
  77. $messages["chestrefill"] = "The Chests have been refilled!";
  78. $messages["remainingminutes"] = "Remaining Minutes!";
  79. $messages["remainingseconds"] = "Remaining seconds!";
  80. $messages["nowinner"] = "There are no winners yet!";
  81. $messages["moreplayers"] = "<<DC4.US>> More Players Are Needed!";
  82. $lang->set("en",$messages);
  83. }
  84. $lang->save();
  85.  
  86. $statistic = new Config($this->getDataFolder() . "/statistic.yml", Config::YAML);
  87. $statistic->save();
  88. $this->getServer()->getScheduler()->scheduleRepeatingTask(new GameSender($this), 20);
  89. $this->getServer()->getScheduler()->scheduleRepeatingTask(new RefreshSigns($this), 10);
  90. }
  91.  
  92. public function onDeath(PlayerDeathEvent $event){
  93. $player = $event->getEntity();
  94. $level = $player->getLevel();
  95. $cause = $player->getLastDamageCause();
  96. if(!($cause instanceof EntityDamageByEntityEvent)) return;
  97. $attacker = ($cause->getDamager() instanceof Player ? $cause->getDamager() : false);
  98. if($attacker !== false) {
  99. $event->setDeathMessage("");
  100. foreach($level->getPlayers() as $pl)
  101. {
  102. $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML);
  103. $lang = new Config($this->getDataFolder() . "/lang.yml", Config::YAML);
  104. $toUse = $lang->get($playerlang->get($pl->getName()));
  105. $pl->sendMessage(TextFormat::YELLOW . $player->getName() . TextFormat::YELLOW . " " . $toUse["kill"] . " " . TextFormat::GREEN . $attacker->getName() . TextFormat::YELLOW . ".");
  106. }
  107. $statistic = new Config($this->getDataFolder() . "/statistic.yml", Config::YAML);
  108. $stats = $statistic->get($attacker->getName());
  109. $soFarPlayer = $stats[0];
  110. $soFarPlayer++;
  111. $stats[0] = $soFarPlayer;
  112. $statistic->set($attacker->getName(),$stats);
  113. $statistic->save();
  114. }
  115. }
  116.  
  117. public function onMove(PlayerMoveEvent $event)
  118. {
  119. $player = $event->getPlayer();
  120. $level = $player->getLevel()->getFolderName();
  121. if(in_array($level,$this->arenas))
  122. {
  123. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  124. $sofar = $config->get($level . "StartTime");
  125. if($sofar > 0)
  126. {
  127. $to = clone $event->getFrom();
  128. $to->yaw = $event->getTo()->yaw;
  129. $to->pitch = $event->getTo()->pitch;
  130. $event->setTo($to);
  131. }
  132. }
  133. }
  134.  
  135. public function onLogin(PlayerLoginEvent $event)
  136. {
  137. $player = $event->getPlayer();
  138. $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML);
  139. if($playerlang->get($player->getName())==null)
  140. {
  141. $playerlang->set($player->getName(),"en");
  142. $playerlang->save();
  143. }
  144. $statistic = new Config($this->getDataFolder() . "/statistic.yml", Config::YAML);
  145. if($statistic->get($player->getName())==null)
  146. {
  147. $statistic->set($player->getName(),array(0,0));
  148. $statistic->save();
  149. }
  150. $player->getInventory()->clearAll();
  151. $spawn = $this->getServer()->getDefaultLevel()->getSafeSpawn();
  152. $this->getServer()->getDefaultLevel()->loadChunk($spawn->getFloorX(), $spawn->getFloorZ());
  153. $player->teleport($spawn,0,0);
  154. }
  155.  
  156. public function onBlockBreak(BlockBreakEvent $event)
  157. {
  158. $player = $event->getPlayer();
  159. $level = $player->getLevel()->getFolderName();
  160. if(in_array($level,$this->arenas))
  161. {
  162. $event->setCancelled(false);
  163. }
  164. }
  165.  
  166. public function onBlockPlace(BlockPlaceEvent $event)
  167. {
  168. $player = $event->getPlayer();
  169. $level = $player->getLevel()->getFolderName();
  170. if(in_array($level,$this->arenas))
  171. {
  172. $event->setCancelled(false);
  173. }
  174. }
  175.  
  176. public function onDamage(EntityDamageEvent $event)
  177. {
  178. if($event instanceof EntityDamageByEntityEvent)
  179. {
  180. $player = $event->getEntity();
  181. $damager = $event->getDamager();
  182. if($player instanceof Player)
  183. {
  184. if($damager instanceof Player)
  185. {
  186. $level = $player->getLevel()->getFolderName();
  187. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  188. if($config->get($level . "PlayTime") != null)
  189. {
  190. if($config->get($level . "PlayTime") > 765)
  191. {
  192. $event->setCancelled(true);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199.  
  200. public function onCommand(CommandSender $player, Command $cmd, $label, array $args) {
  201. $lang = new Config($this->getDataFolder() . "/lang.yml", Config::YAML);
  202. switch($cmd->getName()){
  203. case "sg":
  204. if($player->isOp())
  205. {
  206. if(!empty($args[0]))
  207. {
  208. if($args[0]=="make")
  209. {
  210. if(!empty($args[1]))
  211. {
  212. if(file_exists($this->getServer()->getDataPath() . "/worlds/" . $args[1]))
  213. {
  214. $this->getServer()->loadLevel($args[1]);
  215. $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ());
  216. array_push($this->arenas,$args[1]);
  217. $this->currentLevel = $args[1];
  218. $this->mode = 1;
  219. $player->sendMessage($this->prefix . "TAP SPAWNPOINTS TO LOAD INTO FILE");
  220. $player->setGamemode(1);
  221. $player->teleport($this->getServer()->getLevelByName($args[1])->getSafeSpawn(),0,0);
  222. }
  223. else
  224. {
  225. $player->sendMessage($this->prefix . "ERROR World not found.");
  226. }
  227. }
  228. else
  229. {
  230. $player->sendMessage($this->prefix . "ERROR Missing parameters.");
  231. }
  232. }
  233. else if($args[0]=="leave")
  234. {
  235. $spawn = $this->getServer()->getDefaultLevel()->getSafeSpawn();
  236. $this->getServer()->getDefaultLevel()->loadChunk($spawn->getFloorX(), $spawn->getFloorZ());
  237. $player->teleport($spawn,0,0);
  238. }
  239. else
  240. {
  241. $player->sendMessage($this->prefix . "WARNING There is no such command.");
  242. }
  243. }
  244. else
  245. {
  246. $player->sendMessage($this->prefix . "Missing parameters.");
  247. }
  248. }
  249. else
  250. {
  251. if(!empty($args[0]))
  252. {
  253. if($args[0]=="leave")
  254. {
  255. $spawn = $this->getServer()->getDefaultLevel()->getSafeSpawn();
  256. $this->getServer()->getDefaultLevel()->loadChunk($spawn->getFloorX(), $spawn->getFloorZ());
  257. $player->teleport($spawn,0,0);
  258. }
  259. }
  260. }
  261. return true;
  262.  
  263. case "lang":
  264. if(!empty($args[0]))
  265. {
  266. if($lang->get($args[0])!=null)
  267. {
  268. $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML);
  269. $playerlang->set($player->getName(),$args[0]);
  270. $playerlang->save();
  271. $player->sendMessage(TextFormat::GREEN . "Language: " . $args[0]);
  272. }
  273. else
  274. {
  275. $player->sendMessage(TextFormat::YELLOW . "Language not found!");
  276. }
  277. }
  278. return true;
  279.  
  280.  
  281. }
  282. }
  283.  
  284. public function onInteract(PlayerInteractEvent $event)
  285. {
  286. $player = $event->getPlayer();
  287. $block = $event->getBlock();
  288. $tile = $player->getLevel()->getTile($block);
  289.  
  290. if($tile instanceof Sign)
  291. {
  292. if($this->mode==26)
  293. {
  294. $tile->setText(TextFormat::AQUA . "[Enter]",TextFormat::YELLOW . "0 / 10",$this->currentLevel,$this->prefix);
  295. $this->refreshArenas();
  296. $this->currentLevel = "";
  297. $this->mode = 0;
  298. $player->sendMessage($this->prefix . "Arena Made!");
  299. }
  300. else
  301. {
  302. $text = $tile->getText();
  303. if($text[3] == $this->prefix)
  304. {
  305. if($text[0]==TextFormat::AQUA . "[Enter]")
  306. {
  307. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  308. $level = $this->getServer()->getLevelByName($text[2]);
  309. $aop = count($level->getPlayers());
  310. $thespawn = $config->get($text[2] . "Spawn" . ($aop+1));
  311. $spawn = new Position($thespawn[0]+0.5,$thespawn[1],$thespawn[2]+0.5,$level);
  312. $level->loadChunk($spawn->getFloorX(), $spawn->getFloorZ());
  313. $player->teleport($spawn,0,0);
  314. $player->setNameTag($player->getName());
  315. $player->getInventory()->clearAll();
  316. }
  317. else
  318. {
  319. $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML);
  320. $lang = new Config($this->getDataFolder() . "/lang.yml", Config::YAML);
  321. $toUse = $lang->get($playerlang->get($player->getName()));
  322. $player->sendMessage($this->prefix . $toUse["cannotjoin"]);
  323. }
  324. }
  325. }
  326. }
  327. else if($this->mode>=1&&$this->mode<=10)
  328. {
  329. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  330. $config->set($this->currentLevel . "Spawn" . $this->mode, array($block->getX(),$block->getY()+1,$block->getZ()));
  331. $player->sendMessage($this->prefix . "Spawn " . $this->mode . "Succesfully Created!");
  332. $this->mode++;
  333. if($this->mode==11)
  334. {
  335. $player->sendMessage($this->prefix . "Select Spawn For DeathMatch");
  336. }
  337. $config->save();
  338. }
  339. else if($this->mode==11)
  340. {
  341. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  342. $level = $this->getServer()->getLevelByName($this->currentLevel);
  343. $level->setSpawn(new Vector3($block->getX(),$block->getY()+2,$block->getZ()));
  344. $config->set("arenas",$this->arenas);
  345. $player->sendMessage($this->prefix . "Tap to Join");
  346. $spawn = $this->getServer()->getDefaultLevel()->getSafeSpawn();
  347. $this->getServer()->getDefaultLevel()->loadChunk($spawn->getFloorX(), $spawn->getFloorZ());
  348. $player->teleport($spawn,0,0);
  349. $config->save();
  350. $this->mode=26;
  351. }
  352. }
  353.  
  354. public function refreshArenas()
  355. {
  356. $config = new Config($this->getDataFolder() . "/config.yml", Config::YAML);
  357. $config->set("arenas",$this->arenas);
  358. foreach($this->arenas as $arena)
  359. {
  360. $config->set($arena . "PlayTime", 780);
  361. $config->set($arena . "StartTime", 60);
  362. }
  363. $config->save();
  364. }
  365. }
  366.  
  367. class RefreshSigns extends PluginTask {
  368. public $prefix = TextFormat::AQUA . "[" . TextFormat::YELLOW . TextFormat::BOLD . "SKYWARS" . TextFormat::YELLOW . "PE" . TextFormat::RESET . TextFormat::AQUA . "] ";
  369. public function __construct($plugin)
  370. {
  371. $this->plugin = $plugin;
  372. parent::__construct($plugin);
  373. }
  374.  
  375. public function onRun($tick)
  376. {
  377. $allplayers = $this->plugin->getServer()->getOnlinePlayers();
  378. $level = $this->plugin->getServer()->getDefaultLevel();
  379. $tiles = $level->getTiles();
  380. foreach($tiles as $t) {
  381. if($t instanceof Sign) {
  382. $text = $t->getText();
  383. if($text[3]==$this->prefix)
  384. {
  385. $aop = 0;
  386. foreach($allplayers as $player){if($player->getLevel()->getFolderName()==$text[2]){$aop=$aop+1;}}
  387. $ingame = TextFormat::AQUA . "[Enter]";
  388. $config = new Config($this->plugin->getDataFolder() . "/config.yml", Config::YAML);
  389. if($config->get($text[2] . "PlayTime")!=780)
  390. {
  391. $ingame = TextFormat::DARK_PURPLE . "[Running]";
  392. }
  393. else if($aop>=10)
  394. {
  395. $ingame = TextFormat::GOLD . "[Full]";
  396. }
  397. $t->setText($ingame,TextFormat::YELLOW . $aop . " / 10",$text[2],$this->prefix);
  398. }
  399. }
  400. }
  401. }
  402. }
  403.  
  404. class GameSender extends PluginTask {
  405. public $prefix = TextFormat::AQUA . "[" . TextFormat::YELLOW . TextFormat::BOLD . "SKYWARS" . TextFormat::YELLOW . "PE" . TextFormat::RESET . TextFormat::AQUA . "] ";
  406. public function __construct($plugin)
  407. {
  408. $this->plugin = $plugin;
  409. parent::__construct($plugin);
  410. }
  411.  
  412. public function onRun($tick)
  413. {
  414. $config = new Config($this->plugin->getDataFolder() . "/config.yml", Config::YAML);
  415. $arenas = $config->get("arenas");
  416. if(!empty($arenas))
  417. {
  418. foreach($arenas as $arena)
  419. {
  420. $time = $config->get($arena . "PlayTime");
  421. $timeToStart = $config->get($arena . "StartTime");
  422. $levelArena = $this->plugin->getServer()->getLevelByName($arena);
  423. if($levelArena instanceof Level)
  424. {
  425. $allplayers = $this->plugin->getServer()->getOnlinePlayers();
  426. $playersArena = array();
  427. foreach($allplayers as $play)
  428. {
  429. if($play->getLevel()->getFolderName() == $arena)
  430. {
  431. array_push($playersArena, $play);
  432. }
  433. }
  434. if(count($playersArena)==0)
  435. {
  436. $config->set($arena . "PlayTime", 780);
  437. $config->set($arena . "StartTime", 60);
  438. }
  439. else
  440. {
  441. if(count($playersArena)>=2)
  442. {
  443. if($timeToStart>0)
  444. {
  445. $timeToStart--;
  446. foreach($playersArena as $pl)
  447. {
  448. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  449. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  450. $toUse = $lang->get($playerlang->get($pl->getName()));
  451. $pl->sendPopup(TextFormat::GOLD . $timeToStart . " " . $toUse["seconds"]);
  452. }
  453. if($timeToStart<=0)
  454. {
  455. $this->refillChests($levelArena);
  456. }
  457. $config->set($arena . "StartTime", $timeToStart);
  458. }
  459. else
  460. {
  461. $aop = count($levelArena->getPlayers());
  462. if($aop==1)
  463. {
  464. foreach($playersArena as $pl)
  465. {
  466. foreach($this->plugin->getServer()->getOnlinePlayers() as $plpl)
  467. {
  468. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  469. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  470. $toUse = $lang->get($playerlang->get($plpl->getName()));
  471. $plpl->sendMessage($this->prefix . $pl->getName() . " " . $toUse["won"]);
  472. $command = "wreset restore sw1";
  473. $this->getServer()->dispatchCommand(new ConsoleCommandSender($command));
  474. }
  475. $statistic = new Config($this->getDataFolder() . "/statistic.yml", Config::YAML);
  476. $stats = $statistic->get($pl->getName());
  477. $soFarPlayer = $stats[1];
  478. $soFarPlayer++;
  479. $stats[1] = $soFarPlayer;
  480. $statistic->set($pl->getName(),$stats);
  481. $statistic->save();
  482. $pl->getInventory()->clearAll();
  483. $pl->removeAllEffects();
  484. $pl->setNameTag($pl->getName());
  485. $spawn = $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
  486. $this->plugin->getServer()->getDefaultLevel()->loadChunk($spawn->getX(), $spawn->getZ());
  487. $pl->teleport($spawn,0,0);
  488. }
  489. $config->set($arena . "PlayTime", 780);
  490. $config->set($arena . "StartTime", 60);
  491. }
  492. $time--;
  493. if($time == 765)
  494. {
  495. foreach($playersArena as $pl)
  496. {
  497. $pl->sendTip(TextFormat::GOLD . "Fight to The Death!");
  498. }
  499. }
  500. if($time>=180)
  501. {
  502. $time2 = $time - 180;
  503. $minutes = $time2 / 60;
  504. if(is_int($minutes) && $minutes>0)
  505. {
  506. foreach($playersArena as $pl)
  507. {
  508. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  509. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  510. $toUse = $lang->get($playerlang->get($pl->getName()));
  511. $pl->sendMessage($this->prefix . $minutes . " " . $toUse["deathmatchminutes"]);
  512. }
  513. }
  514. else if($time2 == 300)
  515. {
  516. foreach($playersArena as $pl)
  517. {
  518. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  519. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  520. $toUse = $lang->get($playerlang->get($pl->getName()));
  521. $pl->sendMessage($this->prefix . $toUse["chestrefill"]);
  522. }
  523. $this->refillChests($levelArena);
  524. }
  525. else if($time2 == 30 || $time2 == 15 || $time2 == 10 || $time2 ==5 || $time2 ==4 || $time2 ==3 || $time2 ==2 || $time2 ==1)
  526. {
  527. foreach($playersArena as $pl)
  528. {
  529. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  530. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  531. $toUse = $lang->get($playerlang->get($pl->getName()));
  532. $pl->sendMessage($this->prefix . $time2 . " " . $toUse["deathmatchseconds"]);
  533. }
  534. }
  535. if($time2 <= 0)
  536. {
  537. $spawn = $levelArena->getSafeSpawn();
  538. $levelArena->loadChunk($spawn->getX(), $spawn->getZ());
  539. foreach($playersArena as $pl)
  540. {
  541. $pl->teleport($spawn,0,0);
  542. }
  543. }
  544. }
  545. else
  546. {
  547. $minutes = $time / 60;
  548. if(is_int($minutes) && $minutes>0)
  549. {
  550. foreach($playersArena as $pl)
  551. {
  552. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  553. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  554. $toUse = $lang->get($playerlang->get($pl->getName()));
  555. $pl->sendMessage($this->prefix . $minutes . " " . $toUse["remainingminutes"]);
  556. }
  557. }
  558. else if($time == 30 || $time == 15 || $time == 10 || $time ==5 || $time ==4 || $time ==3 || $time ==2 || $time ==1)
  559. {
  560. foreach($playersArena as $pl)
  561. {
  562. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  563. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  564. $toUse = $lang->get($playerlang->get($pl->getName()));
  565. $pl->sendMessage($this->prefix . $time . " " . $toUse["remainingseconds"]);
  566. }
  567. }
  568. if($time <= 0)
  569. {
  570. $spawn = $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
  571. $this->plugin->getServer()->getDefaultLevel()->loadChunk($spawn->getX(), $spawn->getZ());
  572. foreach($playersArena as $pl)
  573. {
  574. $pl->teleport($spawn,0,0);
  575. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  576. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  577. $toUse = $lang->get($playerlang->get($pl->getName()));
  578. $pl->sendMessage($this->prefix . $toUse["nowinner"]);
  579. $pl->getInventory()->clearAll();
  580. }
  581. $time = 780;
  582. }
  583. }
  584. $config->set($arena . "PlayTime", $time);
  585. }
  586. }
  587. else
  588. {
  589. if($timeToStart<=0)
  590. {
  591. foreach($playersArena as $pl)
  592. {
  593. foreach($this->plugin->getServer()->getOnlinePlayers() as $plpl)
  594. {
  595. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  596. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  597. $toUse = $lang->get($playerlang->get($plpl->getName()));
  598. $plpl->sendMessage($this->prefix . $pl->getName() . " " . $toUse["won"]);
  599. }
  600. $statistic = new Config($this->plugin->getDataFolder() . "/statistic.yml", Config::YAML);
  601. $stats = $statistic->get($pl->getName());
  602. $soFarPlayer = $stats[1];
  603. $soFarPlayer++;
  604. $stats[1] = $soFarPlayer;
  605. $statistic->set($pl->getName(),$stats);
  606. $statistic->save();
  607. $spawn = $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
  608. $this->plugin->getServer()->getDefaultLevel()->loadChunk($spawn->getX(), $spawn->getZ());
  609. $pl->getInventory()->clearAll();
  610. $pl->teleport($spawn);
  611. }
  612. $config->set($arena . "PlayTime", 780);
  613. $config->set($arena . "StartTime", 60);
  614. }
  615. else
  616. {
  617. foreach($playersArena as $pl)
  618. {
  619. $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML);
  620. $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML);
  621. $toUse = $lang->get($playerlang->get($pl->getName()));
  622. $pl->sendPopup(TextFormat::YELLOW . $toUse["moreplayers"]);
  623. }
  624. $config->set($arena . "PlayTime", 780);
  625. $config->set($arena . "StartTime", 60);
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. $config->save();
  633. }
  634.  
  635. public function refillChests(Level $level)
  636. {
  637. $config = new Config($this->plugin->getDataFolder() . "/config.yml", Config::YAML);
  638. $tiles = $level->getTiles();
  639. foreach($tiles as $t) {
  640. if($t instanceof Chest)
  641. {
  642. $chest = $t;
  643. $chest->getInventory()->clearAll();
  644. if($chest->getInventory() instanceof ChestInventory)
  645. {
  646. for($i=0;$i<=26;$i++)
  647. {
  648. $rand = rand(1,3);
  649. if($rand==1)
  650. {
  651. $k = array_rand($config->get("chestitems"));
  652. $v = $config->get("chestitems")[$k];
  653. $chest->getInventory()->setItem($i, Item::get($v[0],$v[1],$v[2]));
  654. }
  655. }
  656. }
  657. }
  658. }
  659. }
  660. }
RAW Paste Data