Moving forward...

This commit is contained in:
Ad5001 2016-07-28 10:31:52 +03:00
parent 3e400f65c4
commit 794bea7fd2
3 changed files with 66 additions and 2 deletions

3
config.yml Normal file
View file

@ -0,0 +1,3 @@
---
# This is the default config generated with ImagicalPlugCreator. (C) ImagicalPlugCreator - Ad5001 2016
...

View file

@ -22,6 +22,7 @@ abstract class Game {
$this->level = $level;
$this->name = $name;
$this->main = $this->server->getPlugin("GameManager");
$this->main->backup($level);
}
@ -43,7 +44,13 @@ abstract class Game {
public function onGameStart();
public function stopGame();
public function onGameStop();
public function stopGame() {
$this->main->getGameManager()->reloadLevel($this->level);
return true;
}
public function onJoin(Player $player) {}
@ -81,5 +88,9 @@ abstract class Game {
public function useEvent(\pocketmine\event\Event $event) : bool;
public function getDataFolder() {
return $this->main->getDataFolder() . "games/$this->name";
}
}

View file

@ -43,8 +43,58 @@ class GameManager {
public function registerLevel(Level $level, string $game) {
if(!array_key_exists($level->getName(), $this->levels)) {
if(isset($this->games[$game])) {
$this->levels[$level->getName()] = new $this->games[$game]($level)
$this->levels[$level->getName()] = new $this->games[$game]($level);
} else {
$this->main->getLogger()->warn("No game found with name $game");
}
}
}
public function reloadLevel(Level $level) {
$this->backup($level);
rrmdir($this->main->getFilePath() . "worlds/{$level->getName()}");
$this->restore($level);
}
private function rrmdir($dir) { // This is from PHP.NET
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
private function copydir( $source, $target ) {
if ( is_dir( $source ) ) {
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) {
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) ) {
full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
} else {
copy( $source, $target );
}
}
}