applied common formatting

This commit is contained in:
Steffen Schröder
2014-05-02 17:50:30 +02:00
parent ba720f46bf
commit a0f5421bea
48 changed files with 3539 additions and 3595 deletions

View File

@ -4,10 +4,10 @@ namespace ManiaControl\Commands;
/**
* Interface for Command Listeners
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
interface CommandListener {
}

View File

@ -9,9 +9,9 @@ use ManiaControl\ManiaControl;
/**
* Class for handling Chat Commands
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class CommandManager implements CallbackListener {
/*
@ -50,7 +50,7 @@ class CommandManager implements CallbackListener {
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = '') {
if (is_array($commandName)) {
$success = true;
foreach($commandName as $command) {
foreach ($commandName as $command) {
if (!$this->registerCommandListener($command, $listener, $method, $adminCommand, $description)) {
$success = false;
}
@ -92,16 +92,16 @@ class CommandManager implements CallbackListener {
*/
public function unregisterCommandListener(CommandListener $listener) {
$removed = false;
foreach($this->commandListeners as &$listeners) {
foreach($listeners as $key => &$listenerCallback) {
foreach ($this->commandListeners as &$listeners) {
foreach ($listeners as $key => &$listenerCallback) {
if ($listenerCallback[0] == $listener) {
unset($listeners[$key]);
$removed = true;
}
}
}
foreach($this->adminCommandListeners as &$listeners) {
foreach($listeners as $key => &$listenerCallback) {
foreach ($this->adminCommandListeners as &$listeners) {
foreach ($listeners as $key => &$listenerCallback) {
if ($listenerCallback[0] == $listener) {
unset($listeners[$key]);
$removed = true;
@ -152,7 +152,7 @@ class CommandManager implements CallbackListener {
// Compose uniformed message
$message = '//' . $command;
foreach($commandArray as $commandPart) {
foreach ($commandArray as $commandPart) {
$message .= ' ' . $commandPart;
}
$callback[1][2] = $message;
@ -167,7 +167,7 @@ class CommandManager implements CallbackListener {
}
// Inform command listeners
foreach($commandListeners[$command] as $listener) {
foreach ($commandListeners[$command] as $listener) {
call_user_func(array($listener[0], $listener[1]), $callback, $player);
}
}

View File

@ -7,19 +7,18 @@ use FML\Controls\Label;
use FML\Controls\Quads\Quad_BgsPlayerCard;
use FML\ManiaLink;
use FML\Script\Features\Paging;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Players\Player;
/**
* Help Manager
*
* @author kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class HelpManager implements CommandListener, CallbackListener {
/*
@ -59,24 +58,24 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player
*/
public function command_adminHelp(array $chat, Player $player) {
$showCommands = array();
$showCommands = array();
$registeredMethods = array();
foreach(array_reverse($this->adminCommands) as $command) {
if(array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
foreach (array_reverse($this->adminCommands) as $command) {
if (array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
$name = $registeredMethods[$command['Method']];
$showCommands[$name]['Name'] .= '|'.$command['Name'];
$showCommands[$name]['Name'] .= '|' . $command['Name'];
} else {
$showCommands[$command['Name']] = $command;
$showCommands[$command['Name']] = $command;
$registeredMethods[$command['Method']] = $command['Name'];
}
}
usort($showCommands, function($a, $b) {
usort($showCommands, function ($a, $b) {
return strcmp($a["Name"], $b["Name"]);
});
$message = 'Supported Admin Commands: ';
foreach($showCommands as $command) {
foreach ($showCommands as $command) {
$message .= $command['Name'] . ',';
}
$message = substr($message, 0, -1);
@ -90,24 +89,24 @@ class HelpManager implements CommandListener, CallbackListener {
* @param Player $player
*/
public function command_playerHelp(array $chat, Player $player) {
$showCommands = array();
$showCommands = array();
$registeredMethods = array();
foreach(array_reverse($this->playerCommands) as $command) {
if(array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
foreach (array_reverse($this->playerCommands) as $command) {
if (array_key_exists($command['Method'], $registeredMethods) && $showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
$name = $registeredMethods[$command['Method']];
$showCommands[$name]['Name'] .= '|'.$command['Name'];
$showCommands[$name]['Name'] .= '|' . $command['Name'];
} else {
$showCommands[$command['Name']] = $command;
$showCommands[$command['Name']] = $command;
$registeredMethods[$command['Method']] = $command['Name'];
}
}
usort($showCommands, function($a, $b) {
usort($showCommands, function ($a, $b) {
return strcmp($a["Name"], $b["Name"]);
});
$message = 'Supported Player Commands: ';
foreach($showCommands as $command) {
foreach ($showCommands as $command) {
$message .= $command['Name'] . ',';
}
$message = substr($message, 0, -1);
@ -124,16 +123,6 @@ class HelpManager implements CommandListener, CallbackListener {
$this->prepareHelpAll($this->playerCommands, $player);
}
/**
* Shows a ManiaLink list of Admin Commands
*
* @param array $chat
* @param Player $player
*/
public function command_adminHelpAll(array $chat, Player $player) {
$this->prepareHelpAll($this->adminCommands, $player);
}
/**
* Prepares the commands for the HelpAll ManiaLink.
*
@ -141,24 +130,24 @@ class HelpManager implements CommandListener, CallbackListener {
* @param $player
*/
private function prepareHelpAll($commands, $player) {
$showCommands = array();
$showCommands = array();
$registeredMethods = array();
foreach(array_reverse($commands) as $command) {
if(array_key_exists($command['Method'], $registeredMethods)) {
if($showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
foreach (array_reverse($commands) as $command) {
if (array_key_exists($command['Method'], $registeredMethods)) {
if ($showCommands[$registeredMethods[$command['Method']]]['Description'] == $command['Description']) {
$name = $registeredMethods[$command['Method']];
$showCommands[$name]['Name'] .= '|'.$command['Name'];
$showCommands[$name]['Name'] .= '|' . $command['Name'];
} else {
$showCommands[$command['Name']] = $command;
$showCommands[$command['Name']] = $command;
$registeredMethods[$command['Method']] = $command['Name'];
}
} else {
$showCommands[$command['Name']] = $command;
$showCommands[$command['Name']] = $command;
$registeredMethods[$command['Method']] = $command['Name'];
}
}
usort($showCommands, function($a, $b) {
usort($showCommands, function ($a, $b) {
return strcmp($a["Name"], $b["Name"]);
});
@ -177,8 +166,8 @@ class HelpManager implements CommandListener, CallbackListener {
// create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
// Main frame
@ -203,7 +192,7 @@ class HelpManager implements CommandListener, CallbackListener {
$i = 1;
$y = $y - 10;
$pageFrames = array();
foreach($commands as $command) {
foreach ($commands as $command) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -227,7 +216,7 @@ class HelpManager implements CommandListener, CallbackListener {
$lineQuad->setZ(0.001);
}
$array = array($command['Name'] => $x + 5, $command['Description'] => $x + 50);
$array = array($command['Name'] => $x + 5, $command['Description'] => $x + 50);
$labels = $this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
/** @var Label $label */
@ -245,6 +234,16 @@ class HelpManager implements CommandListener, CallbackListener {
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'HelpAllList');
}
/**
* Shows a ManiaLink list of Admin Commands
*
* @param array $chat
* @param Player $player
*/
public function command_adminHelpAll(array $chat, Player $player) {
$this->prepareHelpAll($this->adminCommands, $player);
}
/**
* Registers a new Command
*
@ -254,7 +253,7 @@ class HelpManager implements CommandListener, CallbackListener {
* @param $method
*/
public function registerCommand($name, $adminCommand = false, $description = '', $method) {
if($adminCommand) {
if ($adminCommand) {
array_push($this->adminCommands, array("Name" => $name, "Description" => $description, "Method" => $method));
} else {
array_push($this->playerCommands, array("Name" => $name, "Description" => $description, "Method" => $method));