From 5fdf7317c15412d32a50e6041ff9567379d785d5 Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 14 Jan 2014 20:02:35 +0100 Subject: [PATCH] made help commands --- application/core/Commands/CommandManager.php | 3 +- application/core/Commands/HelpManager.php | 49 ++++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/application/core/Commands/CommandManager.php b/application/core/Commands/CommandManager.php index 94d09fd9..96f4308a 100644 --- a/application/core/Commands/CommandManager.php +++ b/application/core/Commands/CommandManager.php @@ -19,6 +19,7 @@ class CommandManager implements CallbackListener { private $maniaControl = null; private $helpManager = array(); private $adminCommandListeners = array(); + private $commandListeners = array(); /** * Construct a new Commands Manager @@ -29,7 +30,7 @@ class CommandManager implements CallbackListener { $this->maniaControl = $maniaControl; //Create help manager instance - $this->helpManager = new HelpManager($this->maniaControl, $this); + $this->helpManager = new HelpManager($this->maniaControl); // Register for callback $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback'); diff --git a/application/core/Commands/HelpManager.php b/application/core/Commands/HelpManager.php index b3b577e6..4cfc96ef 100644 --- a/application/core/Commands/HelpManager.php +++ b/application/core/Commands/HelpManager.php @@ -3,10 +3,12 @@ namespace ManiaControl\Commands; +use ManiaControl\Callbacks\CallbackListener; +use ManiaControl\Callbacks\CallbackManager; use ManiaControl\ManiaControl; use ManiaControl\Players\Player; -class HelpManager implements CommandListener { +class HelpManager implements CommandListener, CallbackListener { /** * Private Properties */ @@ -19,20 +21,49 @@ class HelpManager implements CommandListener { * * @param \ManiaControl\ManiaControl $maniaControl */ - public function __construct(ManiaControl $maniaControl, CommandManager $commandManager) { + public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - //Register the help command - $commandManager->registerCommandListener('help', $this, 'command_playerHelp', false); + // Register for callbacks + $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); } + public function handleOnInit(array $callback) { + //Register the help command + $this->maniaControl->commandManager->registerCommandListener('help', $this, 'command_playerHelp', false); + $this->maniaControl->commandManager->registerCommandListener('help', $this, 'command_adminHelp', true); + } - public function command_playerHelp(array $chat, Player $player) { - $string = ''; - - foreach($this->playerCommands as $key => $value) { - var_dump($key, $value); + /** + * Shows a list of Admin Commands + * + * @param array $chat + * @param Player $player + */ + public function command_adminHelp(array $chat, Player $player) { + //TODO only show first command in command arrays + $message = '$sSupported Admin Commands: '; + foreach(array_reverse($this->adminCommands) as $command) { + $message .= $command['Name'] . ','; } + $message = substr($message, 0, -1); + $this->maniaControl->chat->sendChat($message, $player->login); + } + + /** + * Shows a list of Player Commands + * + * @param array $chat + * @param Player $player + */ + public function command_playerHelp(array $chat, Player $player) { + //TODO only show first command in command arrays + $message = '$sSupported Player Commands: '; + foreach(array_reverse($this->playerCommands) as $command) { + $message .= $command['Name'] . ','; + } + $message = substr($message, 0, -1); + $this->maniaControl->chat->sendChat($message, $player->login); } /**