From 02c5dd0dfa6894e2f1fef17adb286416fdad3c07 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 7 Jul 2015 12:36:32 +1000 Subject: [PATCH] world deletion --- .../game/components/world/WorldComponent.php | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php index 84d3caba1..6a5395a26 100644 --- a/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php +++ b/Pocket/plugins/Mineplex/src/mineplex/plugin/gameengine/game/components/world/WorldComponent.php @@ -13,6 +13,7 @@ use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent; use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent; use mineplex\plugin\util\UtilArray; use mineplex\plugin\util\UtilString; +use mineplex\plugin\util\UtilFile; use pocketmine\event\Listener; use pocketmine\level\Position; use pocketmine\math\Vector3; @@ -26,8 +27,9 @@ class WorldComponent implements Listener private $arena; private $gameId; - private $gameFolder; + private $worldNameFolder; + /** @var \pocketmine\level\Level */ private $world; private $mapName; @@ -71,6 +73,23 @@ class WorldComponent implements Listener // } // } + private function unloadWorld() + { + if (is_null($this->world) || !$this->arena->getPlugin()->getServer()->isLevelLoaded($this->worldNameFolder)) + return; + + foreach ($this->world->getPlayers() as $player) + { + $player->kick("Dead World"); + } + + $this->arena->getPlugin()->getServer()->unloadLevel($this->world); + + UtilFile::deleteDir('worlds/' . $this->worldNameFolder); + + print("Successfully Deleted: " . $this->worldNameFolder . "\n"); + } + private function loadWorld($gameName) { $files = scandir('../update/maps/' . $gameName . '/'); @@ -92,20 +111,20 @@ class WorldComponent implements Listener print_r($worldName . "\n"); - $this->gameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName; + $this->worldNameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName; //Unzip World $zip = new ZipArchive; $res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip'); if ($res === TRUE) { - $zip->extractTo('worlds/' . $this->gameFolder . '/'); + $zip->extractTo('worlds/' . $this->worldNameFolder . '/'); $zip->close(); - print("Successfully Extracted: " . $this->gameFolder . "\n"); + print("Successfully Extracted: " . $this->worldNameFolder . "\n"); } else { - print("Error Extracting: " . $this->gameFolder . "\n"); + print("Error Extracting: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena)); @@ -113,9 +132,9 @@ class WorldComponent implements Listener } //Load World - if ($this->arena->getPlugin()->getServer()->loadLevel($this->gameFolder)) + if ($this->arena->getPlugin()->getServer()->loadLevel($this->worldNameFolder)) { - $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->gameFolder); + $this->world = $this->arena->getPlugin()->getServer()->getLevelByName($this->worldNameFolder); $this->world->setSpawnLocation(new Vector3(0,200,0)); @@ -123,13 +142,13 @@ class WorldComponent implements Listener $this->ready = true; - print("Successfully Loaded World: " . $this->gameFolder . "\n"); + print("Successfully Loaded World: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadSuccessEvent($this->arena, $this->world)); } else { - print("Error Loading World: " . $this->gameFolder . "\n"); + print("Error Loading World: " . $this->worldNameFolder . "\n"); Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));