small cleanup help-manager

This commit is contained in:
kremsy 2015-01-19 19:18:26 +01:00
parent f0a33ac5a2
commit 95a6e3e6a3

View File

@ -19,15 +19,14 @@ use ManiaControl\Players\Player;
* @copyright 2014-2015 ManiaControl Team * @copyright 2014-2015 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class HelpManager implements CommandListener, CallbackListener { class HelpManager implements CommandListener, CallbackListener {
/* /*
* Private properties * Private properties
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
private $playerCommands = array(); private $playerCommands = array();
private $adminCommands = array(); private $adminCommands = array();
/** /**
* Construct a new Commands Manager * Construct a new Commands Manager
@ -58,14 +57,14 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function command_adminHelp(array $chatCallback, Player $player) { public function command_adminHelp(array $chatCallback, Player $player) {
// Parse list from array // Parse list from array
$message = $this->parseHelpList($this->adminCommands); $message = $this->parseHelpList($this->adminCommands);
// Show message when it's not empty // Show message when it's not empty
if($message != NULL){ if ($message != null) {
$message = 'Supported Admin Commands: ' . $message; $message = 'Supported Admin Commands: ' . $message;
$this->maniaControl->getChat()->sendChat($message, $player); $this->maniaControl->getChat()->sendChat($message, $player);
} }
} }
/** /**
@ -75,14 +74,14 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function command_playerHelp(array $chatCallback, Player $player) { public function command_playerHelp(array $chatCallback, Player $player) {
// Parse list from array // Parse list from array
$message = $this->parseHelpList($this->playerCommands); $message = $this->parseHelpList($this->playerCommands);
// Show message when it's not empty // Show message when it's not empty
if($message != NULL){ if ($message != null) {
$message = 'Supported Player Commands: ' . $message; $message = 'Supported Player Commands: ' . $message;
$this->maniaControl->getChat()->sendChat($message, $player); $this->maniaControl->getChat()->sendChat($message, $player);
} }
} }
/** /**
@ -92,23 +91,24 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function command_playerHelpAll(array $chatCallback, Player $player) { public function command_playerHelpAll(array $chatCallback, Player $player) {
$this->parseHelpList($this->playerCommands, true, $player); $this->parseHelpList($this->playerCommands, true, $player);
} }
/** /**
* Parse list with commands from array * Parse list with commands from array
* @param array $commands *
* @param bool $isHelpAll * @param array $commands
* @param Player $player * @param bool $isHelpAll
* @return string|void * @param Player $player
*/ * @return string|void
*/
private function parseHelpList(array $commands, $isHelpAll = false, Player $player = null) { private function parseHelpList(array $commands, $isHelpAll = false, Player $player = null) {
$showCommands = array(); $showCommands = array();
$registeredMethods = array(); $registeredMethods = array();
$message = ''; $message = '';
foreach (array_reverse($commands) as $command) { foreach (array_reverse($commands) as $command) {
if (array_key_exists($command['Method'], $registeredMethods)) { if (array_key_exists($command['Method'], $registeredMethods)) {
if($showCommands[$registeredMethods[$command['Method']]]['Description'] === $command['Description']) { if ($showCommands[$registeredMethods[$command['Method']]]['Description'] === $command['Description']) {
$name = $registeredMethods[$command['Method']]; $name = $registeredMethods[$command['Method']];
$showCommands[$name]['Name'] .= '|' . $command['Name']; $showCommands[$name]['Name'] .= '|' . $command['Name'];
} else { } else {
@ -125,20 +125,17 @@ class HelpManager implements CommandListener, CallbackListener {
return strcmp($commandA['Name'], $commandB['Name']); return strcmp($commandA['Name'], $commandB['Name']);
}); });
if(!$isHelpAll){ if (!$isHelpAll) {
foreach ($showCommands as $command) { foreach ($showCommands as $command) {
$message .= $command['Name'] . ','; $message .= $command['Name'] . ',';
} }
$message = substr($message, 0, -1); $message = substr($message, 0, -1);
} else {
return $message; if ($player != null) {
}else{
if($player != NULL){
$this->showHelpAllList($showCommands, $player); $this->showHelpAllList($showCommands, $player);
} }
} }
return $message;
return;
} }
/** /**
@ -221,7 +218,7 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player * @param Player $player
*/ */
public function command_adminHelpAll(array $chatCallback, Player $player) { public function command_adminHelpAll(array $chatCallback, Player $player) {
$this->parseHelpList($this->adminCommands, true, $player); $this->parseHelpList($this->adminCommands, true, $player);
} }
/** /**