An highly customisable UHC plugin for PocketMine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
2.5 KiB

  1. <?php
  2. USE pocketmine\item\Item;
  3. class UHCWorldReseter extends \Ad5001\UHC\scenario\Scenario{
  4. public function onPlayerCommand(\pocketmine\event\player\PlayerCommandPreprocessEvent $event) {
  5. $args = explode($event->getMessage());
  6. if($args[0] == "/savelobby"){
  7. $bs = [];
  8. if(isset($args[1])) {
  9. @mkdir($this->getScenariosFoler() . "LobbysBackups");
  10. for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) {
  11. for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) {
  12. for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) {
  13. $b = $this->world->getLevel()->getBlock(new \pocketmine\math\Vector3($x, $y, $z));
  14. array_push($bs, $b->getId() . ":" . $b->getDamage());
  15. }
  16. }
  17. }
  18. file_put_contents($this->getScenariosFolder() . "LobbysBackups/" .$this->world->getName() . ".json", json_encode(["radius" => $args[1], "blocks" => $bs]));
  19. $event->getPlayer()->sendMessage("Lobby saved in a radius of $args[1] of the spawn");
  20. $event->setCancelled();
  21. }
  22. }
  23. }
  24. public function __construct(\pocketmine\Server $serv, \Ad5001\UHC\UHCWorld $w) {
  25. parent::__construct($serv,$w);
  26. if(file_exists($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json")) {
  27. $bs = json_decode(file_get_contents($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json"), true);
  28. $i = 0;
  29. for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) {
  30. for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) {
  31. for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) {
  32. $w->getLevel()->setBlock(new \pocketmine\math\Vector3($x, $y, $z), new \pocketmine\block\Block(Item::fromString($bs[$i])));
  33. $i++;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }