From 47628cbff6872a3da897477606297728e25c0783 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Mon, 22 Aug 2016 15:26:53 +0300 Subject: [PATCH] Starting 1.0.1 with DefaultScenarios and bugfixes --- config.yml | 5 ++- resources/config.yml | 3 +- scenarios/WorldReseter.php | 43 +++++++++++++++++++++ src/Ad5001/UHC/Main.php | 4 +- src/Ad5001/UHC/scenario/Scenario.php | 2 +- src/Ad5001/UHC/scenario/ScenarioInt.php | 2 +- src/Ad5001/UHC/scenario/ScenarioManager.php | 7 ++++ 7 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 scenarios/WorldReseter.php diff --git a/config.yml b/config.yml index 4b084bf..ce5b7f2 100644 --- a/config.yml +++ b/config.yml @@ -1,5 +1,6 @@ LobbyWorld: world worlds: uhc: - maxplayers: 8 - radius: 1000 \ No newline at end of file + maxplayers: 8 + radius: 1000 + default_scenarios: [UHCWorldReseter] \ No newline at end of file diff --git a/resources/config.yml b/resources/config.yml index 3a36dad..c9d13e8 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,11 +1,12 @@ --- +LobbyWorld: world # Set your worlds here ! worlds: # Example: # world: # radius: 1000 # maxplayers: 32 - + # default_scenarios: [] # Will be added if you add scenarios scenarios: [] diff --git a/scenarios/WorldReseter.php b/scenarios/WorldReseter.php new file mode 100644 index 0000000..f8b1e2d --- /dev/null +++ b/scenarios/WorldReseter.php @@ -0,0 +1,43 @@ +getMessage()); + if($args[0] == "/savelobby"){ + $bs = []; + if(isset($args[1])) { + @mkdir($this->getScenariosFoler() . "LobbysBackups"); + for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) { + for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) { + for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) { + $b = $this->world->getLevel()->getBlock(new \pocketmine\math\Vector3($x, $y, $z)); + array_push($bs, $b->getId() . ":" . $b->getDamage()); + } + } + } + file_put_contents($this->getScenariosFolder() . "LobbysBackups/" .$this->world->getName() . ".json", json_encode(["radius" => $args[1], "blocks" => $bs])); + $event->getPlayer()->sendMessage("Lobby saved in a radius of $args[1] of the spawn"); + $event->setCancelled(); + } + } + } + + + public function __construct(\pocketmine\Server $serv, \Ad5001\UHC\UHCWorld $w) { + parent::__construct($serv,$w); + if(file_exists($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json")) { + $bs = json_decode(file_get_contents($this->getScenariosFolder() . "LobbysBackups/" .$w->getName() . ".json"), true); + $i = 0; + for($x = $this->world->getLevel()->getSafeSpawn()->x + $args[1]; $x >= $this->world->getLevel()->getSafeSpawn()->x - $args[1];$x++) { + for($y = $this->world->getLevel()->getSafeSpawn()->y + $args[1]; $y >= $this->world->getLevel()->getSafeSpawn()->y - $args[1];$y++) { + for($z = $this->world->getLevel()->getSafeSpawn()->z + $args[1]; $z >= $this->world->getLevel()->getSafeSpawn()->z - $args[1];$z++) { + $w->getLevel()->setBlock(new \pocketmine\math\Vector3($x, $y, $z), new \pocketmine\block\Block(Item::fromString($bs[$i]))); + $i++; + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Ad5001/UHC/Main.php b/src/Ad5001/UHC/Main.php index 316bc53..100ab5b 100644 --- a/src/Ad5001/UHC/Main.php +++ b/src/Ad5001/UHC/Main.php @@ -93,7 +93,7 @@ class Main extends PluginBase implements Listener{ public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ -switch($cmd->getName()){ + switch($cmd->getName()){ case "uhc": if(isset($args[0]) and $sender instanceof Player) { switch($args[0]) { @@ -115,7 +115,7 @@ switch($cmd->getName()){ foreach($sender->getLevel()->getPlayers() as $player) { $player->sendMessage(self::PREFIX . "Starting game..."); } - $this->stopUHC($sender->getLevel()); + $this->UHCManager->stopUHC($sender->getLevel()); } else { $sender->sendMessage("You are not in a UHC world or UHC is already started"); } diff --git a/src/Ad5001/UHC/scenario/Scenario.php b/src/Ad5001/UHC/scenario/Scenario.php index 2279103..39f113a 100644 --- a/src/Ad5001/UHC/scenario/Scenario.php +++ b/src/Ad5001/UHC/scenario/Scenario.php @@ -173,7 +173,7 @@ abstract class Scenario implements ScenarioInt, Listener { - public function getScenarioFolder() { + public function getScenariosFolder() { return $this->getMain()->getDataFolder() . "scenarios/"; } } \ No newline at end of file diff --git a/src/Ad5001/UHC/scenario/ScenarioInt.php b/src/Ad5001/UHC/scenario/ScenarioInt.php index 5fb71dc..dad4b9b 100644 --- a/src/Ad5001/UHC/scenario/ScenarioInt.php +++ b/src/Ad5001/UHC/scenario/ScenarioInt.php @@ -33,7 +33,7 @@ interface ScenarioInt { /* Get the scenario folder */ - public function getScenarioFolder(); + public function getScenariosFolder(); /* Reload the config */ diff --git a/src/Ad5001/UHC/scenario/ScenarioManager.php b/src/Ad5001/UHC/scenario/ScenarioManager.php index 18a99b4..9c1b58b 100644 --- a/src/Ad5001/UHC/scenario/ScenarioManager.php +++ b/src/Ad5001/UHC/scenario/ScenarioManager.php @@ -42,6 +42,13 @@ class ScenarioManager { @mkdir($this->main->getDataFolder() . "scenarios/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]); } } + if(isset($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])) { + if(is_array($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"])){ + foreach($this->main->getConfig()->get($game->getLevel()->getName())["default_scenarios"] as $sc) { + $this->addScenario($sc); + } + } + } }