world deletion
This commit is contained in:
parent
769d50f1c7
commit
02c5dd0dfa
@ -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\gameengine\game\components\world\event\WorldLoadSuccessEvent;
|
||||||
use mineplex\plugin\util\UtilArray;
|
use mineplex\plugin\util\UtilArray;
|
||||||
use mineplex\plugin\util\UtilString;
|
use mineplex\plugin\util\UtilString;
|
||||||
|
use mineplex\plugin\util\UtilFile;
|
||||||
use pocketmine\event\Listener;
|
use pocketmine\event\Listener;
|
||||||
use pocketmine\level\Position;
|
use pocketmine\level\Position;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -26,8 +27,9 @@ class WorldComponent implements Listener
|
|||||||
private $arena;
|
private $arena;
|
||||||
|
|
||||||
private $gameId;
|
private $gameId;
|
||||||
private $gameFolder;
|
private $worldNameFolder;
|
||||||
|
|
||||||
|
/** @var \pocketmine\level\Level */
|
||||||
private $world;
|
private $world;
|
||||||
|
|
||||||
private $mapName;
|
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)
|
private function loadWorld($gameName)
|
||||||
{
|
{
|
||||||
$files = scandir('../update/maps/' . $gameName . '/');
|
$files = scandir('../update/maps/' . $gameName . '/');
|
||||||
@ -92,20 +111,20 @@ class WorldComponent implements Listener
|
|||||||
|
|
||||||
print_r($worldName . "\n");
|
print_r($worldName . "\n");
|
||||||
|
|
||||||
$this->gameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName;
|
$this->worldNameFolder = "Game" . $this->gameId . "_" . $gameName . "_" . $worldName;
|
||||||
|
|
||||||
//Unzip World
|
//Unzip World
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
$res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip');
|
$res = $zip->open('../update/maps/' . $gameName . '/' . $worldName . '.zip');
|
||||||
if ($res === TRUE)
|
if ($res === TRUE)
|
||||||
{
|
{
|
||||||
$zip->extractTo('worlds/' . $this->gameFolder . '/');
|
$zip->extractTo('worlds/' . $this->worldNameFolder . '/');
|
||||||
$zip->close();
|
$zip->close();
|
||||||
print("Successfully Extracted: " . $this->gameFolder . "\n");
|
print("Successfully Extracted: " . $this->worldNameFolder . "\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print("Error Extracting: " . $this->gameFolder . "\n");
|
print("Error Extracting: " . $this->worldNameFolder . "\n");
|
||||||
|
|
||||||
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
|
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
|
||||||
|
|
||||||
@ -113,9 +132,9 @@ class WorldComponent implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Load World
|
//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));
|
$this->world->setSpawnLocation(new Vector3(0,200,0));
|
||||||
|
|
||||||
@ -123,13 +142,13 @@ class WorldComponent implements Listener
|
|||||||
|
|
||||||
$this->ready = true;
|
$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));
|
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadSuccessEvent($this->arena, $this->world));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print("Error Loading World: " . $this->gameFolder . "\n");
|
print("Error Loading World: " . $this->worldNameFolder . "\n");
|
||||||
|
|
||||||
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
|
Server::getInstance()->getPluginManager()->callEvent(new WorldLoadFailEvent($this->arena));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user