code refactoring

This commit is contained in:
Steffen Schröder 2014-05-02 18:21:38 +02:00
parent fa5752d9ce
commit ac5bbbeafa
11 changed files with 77 additions and 70 deletions

View File

@ -52,7 +52,7 @@ class Chat {
*/ */
public function sendInformation($message, $login = null, $prefix = true) { public function sendInformation($message, $login = null, $prefix = true) {
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION); $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
return $this->sendChat($format . $message, $login); return $this->sendChat($format . $message, $login, $prefix);
} }
/** /**
@ -111,7 +111,7 @@ class Chat {
*/ */
public function sendSuccess($message, $login = null, $prefix = true) { public function sendSuccess($message, $login = null, $prefix = true) {
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_SUCCESS); $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_SUCCESS);
return $this->sendChat($format . $message, $login); return $this->sendChat($format . $message, $login, $prefix);
} }
/** /**
@ -137,7 +137,7 @@ class Chat {
*/ */
public function sendError($message, $login = null, $prefix = true) { public function sendError($message, $login = null, $prefix = true) {
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR); $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
return $this->sendChat($format . $message, $login); return $this->sendChat($format . $message, $login, $prefix);
} }
/** /**
@ -150,6 +150,6 @@ class Chat {
*/ */
public function sendUsageInfo($message, $login = null, $prefix = false) { public function sendUsageInfo($message, $login = null, $prefix = false) {
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_USAGEINFO); $format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_USAGEINFO);
return $this->sendChat($format . $message, $login); return $this->sendChat($format . $message, $login, $prefix);
} }
} }

View File

@ -54,10 +54,10 @@ class HelpManager implements CommandListener, CallbackListener {
/** /**
* Shows a list of Admin Commands * Shows a list of Admin Commands
* *
* @param array $chat * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_adminHelp(array $chat, Player $player) { public function command_adminHelp(array $chatCallback, Player $player) {
$showCommands = array(); $showCommands = array();
$registeredMethods = array(); $registeredMethods = array();
foreach (array_reverse($this->adminCommands) as $command) { foreach (array_reverse($this->adminCommands) as $command) {
@ -85,10 +85,10 @@ class HelpManager implements CommandListener, CallbackListener {
/** /**
* Shows a list of Player Commands * Shows a list of Player Commands
* *
* @param array $chat * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_playerHelp(array $chat, Player $player) { public function command_playerHelp(array $chatCallback, Player $player) {
$showCommands = array(); $showCommands = array();
$registeredMethods = array(); $registeredMethods = array();
foreach (array_reverse($this->playerCommands) as $command) { foreach (array_reverse($this->playerCommands) as $command) {
@ -116,10 +116,10 @@ class HelpManager implements CommandListener, CallbackListener {
/** /**
* Shows a ManiaLink list of Player Commands * Shows a ManiaLink list of Player Commands
* *
* @param array $chat * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_playerHelpAll(array $chat, Player $player) { public function command_playerHelpAll(array $chatCallback, Player $player) {
$this->prepareHelpAll($this->playerCommands, $player); $this->prepareHelpAll($this->playerCommands, $player);
} }
@ -237,10 +237,10 @@ class HelpManager implements CommandListener, CallbackListener {
/** /**
* Shows a ManiaLink list of Admin Commands * Shows a ManiaLink list of Admin Commands
* *
* @param array $chat * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_adminHelpAll(array $chat, Player $player) { public function command_adminHelpAll(array $chatCallback, Player $player) {
$this->prepareHelpAll($this->adminCommands, $player); $this->prepareHelpAll($this->adminCommands, $player);
} }

View File

@ -203,37 +203,29 @@ class ErrorHandler {
* @return string * @return string
*/ */
public function getErrorTag($errorLevel) { public function getErrorTag($errorLevel) {
if ($errorLevel == E_NOTICE) { switch ($errorLevel) {
return '[PHP NOTICE]'; case E_NOTICE:
return '[PHP NOTICE]';
case E_WARNING:
return '[PHP WARNING]';
case E_ERROR:
return '[PHP ERROR]';
case E_CORE_ERROR:
return '[PHP CORE ERROR]';
case E_COMPILE_ERROR:
return '[PHP COMPILE ERROR]';
case E_RECOVERABLE_ERROR:
return '[PHP RECOVERABLE ERROR]';
case E_USER_NOTICE:
return '[ManiaControl NOTICE]';
case E_USER_WARNING:
return '[ManiaControl WARNING]';
case E_USER_ERROR:
return '[ManiaControl ERROR]';
case self::MC_DEBUG_NOTICE:
return '[ManiaControl DEBUG]';
} }
if ($errorLevel == E_WARNING) { return "[PHP ERROR '{$errorLevel}']";
return '[PHP WARNING]';
}
if ($errorLevel == E_ERROR) {
return '[PHP ERROR]';
}
if ($errorLevel == E_CORE_ERROR) {
return '[PHP CORE ERROR]';
}
if ($errorLevel == E_COMPILE_ERROR) {
return '[PHP COMPILE ERROR]';
}
if ($errorLevel == E_RECOVERABLE_ERROR) {
return '[PHP RECOVERABLE ERROR]';
}
if ($errorLevel == E_USER_NOTICE) {
return '[ManiaControl NOTICE]';
}
if ($errorLevel == E_USER_WARNING) {
return '[ManiaControl WARNING]';
}
if ($errorLevel == E_USER_ERROR) {
return '[ManiaControl ERROR]';
}
if ($errorLevel == self::MC_DEBUG_NOTICE) {
return '[ManiaControl DEBUG]';
}
return "[PHP {$errorLevel}]";
} }
/** /**

View File

@ -472,7 +472,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Map $b * @param Map $b
* @return mixed * @return mixed
*/ */
private function sortByKarma($a, $b) { private function sortByKarma(Map $a, Map $b) {
return ($a->karma - $b->karma); return ($a->karma - $b->karma);
} }
} }

View File

@ -252,9 +252,9 @@ class MapManager implements CallbackListener {
// Download the file // Download the file
$self->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) { $self->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) {
if (!$file) { if (!$file || $error) {
// Download error // Download error
$self->maniaControl->chat->sendError('Download failed!', $login); $self->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
return; return;
} }
$self->processMapFile($file, $mapInfo, $login, $update); $self->processMapFile($file, $mapInfo, $login, $update);

View File

@ -82,20 +82,19 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Clears the map-queue via admin command clearmap queue * Clears the map-queue via admin command clearmap queue
* *
* @param array $chat * @param array $chatCallback
* @param \ManiaControl\Players\Player $admin * @param Player $admin
* @internal param \ManiaControl\Players\Player $player
*/ */
public function command_ClearMapQueue(array $chat, Player $admin) { public function command_ClearMapQueue(array $chatCallback, Player $admin) {
$this->clearMapQueue($admin); $this->clearMapQueue($admin);
} }
/** /**
* Clears the Map Queue * Clear the Map Queue
* *
* @param $admin * @param Player $admin
*/ */
public function clearMapQueue($admin) { public function clearMapQueue(Player $admin) {
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) { if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
@ -121,11 +120,11 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Handles the mapqueue/jukebox command * Handles the mapqueue/jukebox command
* *
* @param array $chat * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_MapQueue(array $chat, Player $player) { public function command_MapQueue(array $chatCallback, Player $player) {
$chatCommands = explode(' ', $chat[1][2]); $chatCommands = explode(' ', $chatCallback[1][2]);
if (isset($chatCommands[1])) { if (isset($chatCommands[1])) {
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') { if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
@ -143,9 +142,9 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Shows current mapqueue in the chat * Shows current mapqueue in the chat
* *
* @param $player * @param Player $player
*/ */
public function showMapQueue($player) { public function showMapQueue(Player $player) {
if (count($this->queuedMaps) == 0) { if (count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login); $this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return; return;
@ -164,9 +163,9 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Shows current mapqueue in a manialink * Shows current mapqueue in a manialink
* *
* @param $player * @param Player $player
*/ */
public function showMapQueueManialink($player) { public function showMapQueueManialink(Player $player) {
if (count($this->queuedMaps) == 0) { if (count($this->queuedMaps) == 0) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login); $this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return; return;
@ -192,10 +191,10 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Adds map as first map in queue (for /replay) * Adds map as first map in queue (for /replay)
* *
* @param $player * @param Player $player
* @param $map * @param Map $map
*/ */
public function addFirstMapToMapQueue($player, $map) { public function addFirstMapToMapQueue(Player $player, Map $map) {
if ($map) { if ($map) {
if (array_key_exists($map->uid, $this->queuedMaps)) { if (array_key_exists($map->uid, $this->queuedMaps)) {
unset($this->queuedMaps[$map->uid]); unset($this->queuedMaps[$map->uid]);
@ -208,8 +207,8 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Adds a Map to the map-queue * Adds a Map to the map-queue
* *
* @param $login * @param string $login
* @param $uid * @param string $uid
*/ */
public function addMapToMapQueue($login, $uid) { public function addMapToMapQueue($login, $uid) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
@ -270,9 +269,8 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Revmoes a Map from the Map queue * Revmoes a Map from the Map queue
* *
* @param \ManiaControl\Players\Player $player * @param Player $player
* @param $uid * @param string $uid
* @internal param $login
*/ */
public function removeFromMapQueue(Player $player, $uid) { public function removeFromMapQueue(Player $player, $uid) {
if (!isset($this->queuedMaps[$uid])) { if (!isset($this->queuedMaps[$uid])) {
@ -355,7 +353,7 @@ class MapQueue implements CallbackListener, CommandListener {
/** /**
* Returns the next Map if the next map is a queuedmap or null if it's not * Returns the next Map if the next map is a queuedmap or null if it's not
* *
* @return null * @return Map
*/ */
public function getNextMap() { public function getNextMap() {
return $this->nextMap; return $this->nextMap;

View File

@ -14,7 +14,6 @@ use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Statistics\StatisticManager; use ManiaControl\Statistics\StatisticManager;
use Maniaplanet\DedicatedServer\Structures\Player;
/** /**
* Player Detailed Page * Player Detailed Page

View File

@ -22,7 +22,6 @@ use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use Maniaplanet\DedicatedServer\Structures\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException; use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException; use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
use MCTeam\CustomVotesPlugin; use MCTeam\CustomVotesPlugin;

View File

@ -245,6 +245,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates(); $pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
usort($pluginClasses, function ($a, $b) { usort($pluginClasses, function ($a, $b) {
/** @var Plugin $a */
/** @var Plugin $b */
return strcmp($a::getName(), $b::getName()); return strcmp($a::getName(), $b::getName());
}); });

View File

@ -242,6 +242,14 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
$self = $this; $self = $this;
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$self, &$pluginUpdateData, &$player, &$update) { $this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (&$self, &$pluginUpdateData, &$player, &$update) {
if (!$updateFileContent || $error) {
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
if ($player) {
$self->maniaControl->chat->sendInformation($message, $player);
}
$self->maniaControl->log($message);
return;
}
$actionNoun = ($update ? 'Update' : 'Install'); $actionNoun = ($update ? 'Update' : 'Install');
$actionVerb = ($update ? 'Updating' : 'Installing'); $actionVerb = ($update ? 'Updating' : 'Installing');
$actionVerbDone = ($update ? 'updated' : 'installed'); $actionVerbDone = ($update ? 'updated' : 'installed');

View File

@ -303,6 +303,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$self = $this; $self = $this;
$this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) { $this->maniaControl->fileReader->loadFile($this->coreUpdateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) {
if (!$updateFileContent || !$error) {
$message = "Update failed: Couldn't load Update zip!";
if ($player) {
$self->maniaControl->chat->sendError($message, $player);
}
logMessage($message);
return;
}
$tempDir = FileUtil::getTempFolder(); $tempDir = FileUtil::getTempFolder();
$updateFileName = $tempDir . basename($updateData->url); $updateFileName = $tempDir . basename($updateData->url);