non working commit help manager

This commit is contained in:
kremsy 2014-01-14 19:47:40 +01:00 committed by Steffen Schröder
parent 476e3464e5
commit 4c0d8270b3
3 changed files with 107 additions and 41 deletions

View File

@ -2,13 +2,14 @@
namespace ManiaControl\Commands; namespace ManiaControl\Commands;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
/** /**
* Class for handling Chat Commands * Class for handling Chat Commands
* *
* @property mixed commandListeners
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class CommandManager implements CallbackListener { class CommandManager implements CallbackListener {
@ -16,7 +17,7 @@ class CommandManager implements CallbackListener {
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $commandListeners = array(); private $helpManager = array();
private $adminCommandListeners = array(); private $adminCommandListeners = array();
/** /**
@ -27,6 +28,9 @@ class CommandManager implements CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
//Create help manager instance
$this->helpManager = new HelpManager($this->maniaControl, $this);
// Register for callback // Register for callback
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
} }
@ -62,8 +66,7 @@ class CommandManager implements CallbackListener {
} }
// Register admin command listener // Register admin command listener
array_push($this->adminCommandListeners[$command], array($listener, $method)); array_push($this->adminCommandListeners[$command], array($listener, $method));
} } else {
else {
if(!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) { if(!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
// Init listeners array // Init listeners array
$this->commandListeners[$command] = array(); $this->commandListeners[$command] = array();
@ -71,6 +74,10 @@ class CommandManager implements CallbackListener {
// Register command listener // Register command listener
array_push($this->commandListeners[$command], array($listener, $method)); array_push($this->commandListeners[$command], array($listener, $method));
} }
//TODO description
$this->helpManager->registerCommand($command, $adminCommand, '');
return true; return true;
} }
@ -108,18 +115,24 @@ class CommandManager implements CallbackListener {
*/ */
public function handleChatCallback(array $callback) { public function handleChatCallback(array $callback) {
// Check for command // Check for command
if (!$callback[1][3]) return; if(!$callback[1][3]) {
return;
}
// Check for valid player // Check for valid player
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player) return; if(!$player) {
return;
}
// Parse command // Parse command
$message = $callback[1][2]; $message = $callback[1][2];
$commandArray = explode(' ', $message); $commandArray = explode(' ', $message);
$command = ltrim(strtolower($commandArray[0]), '/'); $command = ltrim(strtolower($commandArray[0]), '/');
if (!$command) return; if(!$command) {
return;
}
if(substr($message, 0, 2) == '//' || $command == 'admin') { if(substr($message, 0, 2) == '//' || $command == 'admin') {
// Admin command // Admin command
@ -138,8 +151,7 @@ class CommandManager implements CallbackListener {
$message .= ' ' . $commandPart; $message .= ' ' . $commandPart;
} }
$callback[1][2] = $message; $callback[1][2] = $message;
} } else {
else {
// User command // User command
$commandListeners = $this->commandListeners; $commandListeners = $this->commandListeners;
} }

View File

@ -0,0 +1,53 @@
<?php
namespace ManiaControl\Commands;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
class HelpManager implements CommandListener {
/**
* Private Properties
*/
private $maniaControl = null;
private $playerCommands = array();
private $adminCommands = array();
/**
* Construct a new Commands Manager
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl, CommandManager $commandManager) {
$this->maniaControl = $maniaControl;
//Register the help command
$commandManager->registerCommandListener('help', $this, 'command_playerHelp', false);
}
public function command_playerHelp(array $chat, Player $player) {
$string = '';
foreach($this->playerCommands as $key => $value) {
var_dump($key, $value);
}
}
/**
* Registers a new Command
*
* @param $name
* @param $adminCommand
* @param $description
*/
public function registerCommand($name, $adminCommand = false, $description = '') {
if($adminCommand) {
array_push($this->adminCommands, array("Name" => $name, "Description" => $description));
} else {
array_push($this->playerCommands, array("Name" => $name, "Description" => $description));
}
}
}

View File

@ -25,6 +25,7 @@ require_once __DIR__ . '/Callbacks/CallbackManager.php';
require_once __DIR__ . '/Chat.php'; require_once __DIR__ . '/Chat.php';
require_once __DIR__ . '/ColorUtil.php'; require_once __DIR__ . '/ColorUtil.php';
require_once __DIR__ . '/Commands/CommandManager.php'; require_once __DIR__ . '/Commands/CommandManager.php';
require_once __DIR__ . '/Commands/HelpManager.php';
require_once __DIR__ . '/Configurators/Configurator.php'; require_once __DIR__ . '/Configurators/Configurator.php';
require_once __DIR__ . '/Database.php'; require_once __DIR__ . '/Database.php';
require_once __DIR__ . '/FileUtil.php'; require_once __DIR__ . '/FileUtil.php';