From 3c79f09c7708e272ede5f5b5896f07db00d54e2f Mon Sep 17 00:00:00 2001 From: Beu Date: Mon, 4 Sep 2023 01:51:35 +0200 Subject: [PATCH] Add GameModeLoader --- .gitignore | 3 +- Beu/GameModeLoader.php | 109 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 Beu/GameModeLoader.php diff --git a/.gitignore b/.gitignore index 29dc9be..ff0927f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ !Beu/MoreModesTools.php !Beu/SimpleChatColorer.php !Beu/SimpleSkinsRemover.php -!Beu/BeuDonationButton.php \ No newline at end of file +!Beu/BeuDonationButton.php +!Beu/GameModeLoader.php \ No newline at end of file diff --git a/Beu/GameModeLoader.php b/Beu/GameModeLoader.php new file mode 100644 index 0000000..549d3fc --- /dev/null +++ b/Beu/GameModeLoader.php @@ -0,0 +1,109 @@ +maniaControl = $maniaControl; + + $this->maniaControl->getCommandManager()->registerCommandListener('mode', $this, 'commandMode', true, 'Add all connected players to the guestlist'); + } + + /** + * Handle when a player connects + * + * @param Player $player + */ + public function commandMode(array $chatCallback, Player $player) { + $params = explode(' ', $chatCallback[1][2]); + if (array_key_exists(1, $params) && $params[1] !== "") { + try { + $this->maniaControl->getClient()->setScriptName($params[1]); + $this->maniaControl->getChat()->sendSuccess("Game mode loaded, restart or skip the map", $player->login); + Logger::log("Game mode " . $params[1] . " loaded by " . $player->login); + } catch (Exception $e) { + $this->maniaControl->getChat()->sendError("Can't load the game mode: " . $e->getMessage(), $player->login); + Logger::log("Can't load the game mode: " . $e->getMessage()); + } + } else { + $this->maniaControl->getChat()->sendError("usage: //mode TrackMania/TM_TimeAttack_Online.Script.txt", $player->login); + } + } + + /** + * Unload the plugin and its Resources + */ + public function unload() { + } +}