diff --git a/src/Ad5001/GameManager/Game.php b/src/Ad5001/GameManager/Game.php index e6053f5..465b09b 100644 --- a/src/Ad5001/GameManager/Game.php +++ b/src/Ad5001/GameManager/Game.php @@ -162,6 +162,9 @@ abstract class Game { } + public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd, $label, array $args) {} + + abstract public function getName() : string; @@ -177,4 +180,12 @@ abstract class Game { } + public function registerCommand(string $cmd, string $desc, string $usage, array $aliases, string $perm = "gamemanager.command.use") { + if(!isset($this->main->cmds[$cmd])) { + $this->main->cmds[$cmd] = new GameCommand($this->main, $cmd, $desc, $usage, $aliases, $this->gm->getGames()[$this->getName()], $perm); + $this->getServer()->getCommandMap()->register($cmd, $this->main->cmds[$cmds]); + } + } + + } \ No newline at end of file diff --git a/src/Ad5001/GameManager/GameCommand.php b/src/Ad5001/GameManager/GameCommand.php new file mode 100644 index 0000000..9d54b5d --- /dev/null +++ b/src/Ad5001/GameManager/GameCommand.php @@ -0,0 +1,21 @@ +setPermission($perm); + $this->main = $main; + $this->game = $game; + } + public function execute(CommandSender $sender, $label, array $args) { + return $this->game->onCommand($sender, $this, $label, $args); + } +} diff --git a/src/Ad5001/GameManager/GameManager.php b/src/Ad5001/GameManager/GameManager.php index 2911608..2c3a8e1 100644 --- a/src/Ad5001/GameManager/GameManager.php +++ b/src/Ad5001/GameManager/GameManager.php @@ -5,8 +5,6 @@ use pocketmine\Server; use pocketmine\Player; use pocketmine\level\Level; -use Ad5001\GameManager\Main; - class GameManager { @@ -30,8 +28,8 @@ class GameManager { if(!is_dir($this->main->getDataFolder() . "/games/" . $file)) { require($this->main->getDataFolder() . "/games/" . $file); $classn = $this->main->getClasses(file_get_contents($this->main->getDataFolder() . "/games/" . $file)); - $this->games[explode(".php", $file)[0]] = $classn; - @mkdir($this->main->getDataFolder() . "games/" . explode(".php", $file)[0]); + $this->games[explode("\\", $classn)[count(explode("\\", $classn)) - 1]] = $classn; + @mkdir($this->main->getDataFolder() . "games/" . explode("\\", $classn)[count(explode("\\", $classn)) - 1]); } } } diff --git a/src/Ad5001/GameManager/Main.php b/src/Ad5001/GameManager/Main.php index 4be248c..d409e36 100644 --- a/src/Ad5001/GameManager/Main.php +++ b/src/Ad5001/GameManager/Main.php @@ -49,9 +49,44 @@ class Main extends PluginBase implements Listener { public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ switch($cmd->getName()){ - case "default": + case "games": + if(!isset($args[0])) { + $games = []; + foreach($this->manager->getGames() as $g) { + array_push($games, explode("\\", $g)[count(explode("\\", $g)) - 1]); + } + $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current existings games: " . implode(", ", $games) . ". \nUse /games to get all the levels of a game."); + } else { + $sender->sendMessage("§l§o[§r§lGameManager§o]§r Current levels running $args[0]:"); + foreach($this->manager->getLevels() as $levelname => $game) { + if(strtolower($game->getName()) == strtolower($args[0])) { + $p = 0; + $s = 0; + foreach($game->getLevel()->getPlayers() as $pl) { + if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus") !== null) { + if($this->getServer()->getPluginManager()->getPlugin("SpectatorPlus")->isSpectator($pl)) { + array_push($s, $pl); + } else { + array_push($p, $pl); + } + } else { + if($pl->isSpectator()) { + array_push($s, $pl); + } else { + array_push($p, $pl); + } + } + } + $sender->sendMessage("§l§o[§r§lGameManager§o]§r§a " . $levelname . " Is started: " . $game->isStarted() . " Players: " . count($p) . " Spectators: " . count($s)); + } + } + } + return true; break; } + if(isset($this->cmds[$cmd->getName()])) { + $this->cmds[$cmd->getName()]->onCommand($sender, $cmd, $label, $args); + } return false; }