From 3e400f65c4b740b8d83bc2602bf87a45bd2ec37f Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Thu, 28 Jul 2016 09:39:24 +0300 Subject: [PATCH] Starting --- plugin.yml | 9 +++ resources/config.yml | 3 + src/Ad5001/GameManager/Game.php | 85 ++++++++++++++++++++++++++ src/Ad5001/GameManager/GameManager.php | 50 +++++++++++++++ src/Ad5001/GameManager/Main.php | 50 +++++++++++++++ 5 files changed, 197 insertions(+) create mode 100644 plugin.yml create mode 100644 resources/config.yml create mode 100644 src/Ad5001/GameManager/Game.php create mode 100644 src/Ad5001/GameManager/GameManager.php create mode 100644 src/Ad5001/GameManager/Main.php diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..bd3d3b4 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,9 @@ +--- +name: GameManager +author: Ad5001 +version: 1.0 +api: [2.0.0] +main: Ad5001\GameManager\Main +commands: [] +permissions: [] +... \ No newline at end of file diff --git a/resources/config.yml b/resources/config.yml new file mode 100644 index 0000000..22d7e6e --- /dev/null +++ b/resources/config.yml @@ -0,0 +1,3 @@ +--- +# This is the default config generated with ImagicalPlugCreator. (C) ImagicalPlugCreator - Ad5001 2016 +... \ No newline at end of file diff --git a/src/Ad5001/GameManager/Game.php b/src/Ad5001/GameManager/Game.php new file mode 100644 index 0000000..e27bff8 --- /dev/null +++ b/src/Ad5001/GameManager/Game.php @@ -0,0 +1,85 @@ +server = $level->getServer(); + $this->level = $level; + $this->name = $name; + $this->main = $this->server->getPlugin("GameManager"); + } + + + public function getPlugin() { + return $this->main; + } + + + public function getLevel() { + return $this->main; + } + + + public function getLevel() { + return $this->main; + } + + + public function onGameStart(); + + + public function stopGame(); + + + public function onJoin(Player $player) {} + + + public function onQuit(Player $player) {} + + + public function onBlockBreak(Player $player, Block $block) {} + + + public function onBlockPlace(Player $player, Block $block) {} + + + public function getConfig() { + return new Config($this->main->getDataFolder() . "games/$this->name"); + } + + + public function saveDefaultConfig() { + $this->main->saveResource("/games/$this->name/config.yml"); + } + + + + public function getName() : string; + + + public function getMinPlayers() : int; + + + public function getMaxPlayers() : int; + + + public function useEvent(\pocketmine\event\Event $event) : bool; + + + +} \ No newline at end of file diff --git a/src/Ad5001/GameManager/GameManager.php b/src/Ad5001/GameManager/GameManager.php new file mode 100644 index 0000000..1d3baca --- /dev/null +++ b/src/Ad5001/GameManager/GameManager.php @@ -0,0 +1,50 @@ +main = $main; + $this->server = $main->getServer(); + $files = array_diff(scandir($this->getDataFolder() . "/games"), [".", ".."]); + $this->games = []; + $this->levels = []; + $this->startedgames = []; + foreach ($files as $file) { + require($file); + $classn = getClasses(file_get_contents($this->getDataFolder() . "/games/" . $file)); + $this->games[explode(".php", $file)[0]] = $classn; + @mkdir($this->main->getDataFolder() . "games/$classn"); + } + } + + + + public function startGame(Level $level) { + if(isset($this->levels[$level->getName()]) and !isset($this->startedgames[$level->getName()])) { + $this->startedgames[$level->getName()] = true; + $this->levels[$level->getName()]->onGameStart(); + return true; + } + return false; + } + + + + 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) + } + } + } +} \ No newline at end of file diff --git a/src/Ad5001/GameManager/Main.php b/src/Ad5001/GameManager/Main.php new file mode 100644 index 0000000..07ffdcf --- /dev/null +++ b/src/Ad5001/GameManager/Main.php @@ -0,0 +1,50 @@ +reloadConfig(); + $this->getServer()->getPluginManager()->registerEvents($this, $this); + $this->manager = new GameManager($this); + + } + + + public function onLoad(){ + $this->saveDefaultConfig(); + } + + + public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ + switch($cmd->getName()){ + case "default": + break; + } + return false; + } + + + public function getClasses(string $file) { + $tokens = token_get_all($php_file); + $class_token = false; + foreach ($tokens as $token) { + if (is_array($token)) { + if ($token[0] == T_CLASS) { + $class_token = true; + } else if ($class_token && $token[0] == T_STRING) { + return $token[1]; + } + } + } + } +} \ No newline at end of file