From fb22b22bd3c4928ef0d8c1009d5dc4451a757e66 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 31 Jul 2016 13:25:30 +0300 Subject: [PATCH] Working on games... --- .gitignore | 3 +++ games/Example.php | 10 ++++++++++ src/Ad5001/GameManager/Game.php | 3 +++ src/Ad5001/GameManager/GameManager.php | 2 +- src/Ad5001/GameManager/Main.php | 9 ++++++++- 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 games/Example.php diff --git a/.gitignore b/.gitignore index cd2946a..777e416 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk + +# VS Manager files: +*.vscode \ No newline at end of file diff --git a/games/Example.php b/games/Example.php new file mode 100644 index 0000000..9d3bfc8 --- /dev/null +++ b/games/Example.php @@ -0,0 +1,10 @@ +getLogger()->info("Game"); + } +} \ No newline at end of file diff --git a/src/Ad5001/GameManager/Game.php b/src/Ad5001/GameManager/Game.php index 08a9aeb..6dec1db 100644 --- a/src/Ad5001/GameManager/Game.php +++ b/src/Ad5001/GameManager/Game.php @@ -61,6 +61,9 @@ abstract class Game { public function onQuit(Player $player) {} + public function onInteract(\pocketmine\event\player\PlayerInteract $event) {} + + public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {} diff --git a/src/Ad5001/GameManager/GameManager.php b/src/Ad5001/GameManager/GameManager.php index 6944131..5a6dde8 100644 --- a/src/Ad5001/GameManager/GameManager.php +++ b/src/Ad5001/GameManager/GameManager.php @@ -22,7 +22,7 @@ class GameManager { public function __construct(Main $main) { $this->main = $main; $this->server = $main->getServer(); - $files = array_diff(scandir($this->getDataFolder() . "/games"), [".", ".."]); + $files = array_diff(scandir($main->getDataFolder() . "games"), [".", ".."]); $this->games = []; $this->levels = []; $this->startedgames = []; diff --git a/src/Ad5001/GameManager/Main.php b/src/Ad5001/GameManager/Main.php index 37af75d..c6057c4 100644 --- a/src/Ad5001/GameManager/Main.php +++ b/src/Ad5001/GameManager/Main.php @@ -6,6 +6,7 @@ use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\plugin\PluginBase; use pocketmine\Server; +use pocketmine\level\Level; use pocketmine\Player; use Ad5001\GameManager\GameManager; @@ -20,7 +21,13 @@ class Main extends PluginBase implements Listener { $this->reloadConfig(); $this->getServer()->getPluginManager()->registerEvents($this, $this); @mkdir($this->getServer()->getFilePath() . "worldsBackups/"); + @mkdir($this->getDataFolder() . "games"); $this->manager = new GameManager($this); + foreach(array_diff_key($this->getConfig()->getAll(), ["Game1" => "", "Game2" => "", "InGame3" => "", "InGame4" => "", "GameWait3" => "", "GameWait4" => ""]) as $worldname => $gamename) { + if($this->getServer()->getLevelByName($worldname) instanceof Level) { + $this->manager->registerLevel($this->getServer()->getLevelByName($worldname), $gamename); + } + } } @@ -32,7 +39,7 @@ class Main extends PluginBase implements Listener { $lvl = str_ireplace($lvlex[0], "", $t->getText()[1]); $lvl = str_ireplace($lvlex[1], "", $lvl); if($name == $lvl) { - if($this->gameManager->getLevels()[$lvl->getName()]->isStarted()) { + if($this->manager->getLevels()[$lvl->getName()]->isStarted()) { $event->getPlayer()->teleport($lvl->getDefaultSpawn()); $event->getPlayer()->setGamemode(3); } else {