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

View File

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

View File

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

View File

@ -252,9 +252,9 @@ class MapManager implements CallbackListener {
// Download the file
$self->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$self, &$login, &$mapInfo, &$update) {
if (!$file) {
if (!$file || $error) {
// Download error
$self->maniaControl->chat->sendError('Download failed!', $login);
$self->maniaControl->chat->sendError("Download failed: '{$error}'!", $login);
return;
}
$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
*
* @param array $chat
* @param \ManiaControl\Players\Player $admin
* @internal param \ManiaControl\Players\Player $player
* @param array $chatCallback
* @param Player $admin
*/
public function command_ClearMapQueue(array $chat, Player $admin) {
public function command_ClearMapQueue(array $chatCallback, Player $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)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
@ -121,11 +120,11 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* Handles the mapqueue/jukebox command
*
* @param array $chat
* @param array $chatCallback
* @param Player $player
*/
public function command_MapQueue(array $chat, Player $player) {
$chatCommands = explode(' ', $chat[1][2]);
public function command_MapQueue(array $chatCallback, Player $player) {
$chatCommands = explode(' ', $chatCallback[1][2]);
if (isset($chatCommands[1])) {
if ($chatCommands[1] == ' ' || $chatCommands[1] == 'list') {
@ -143,9 +142,9 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* 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) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return;
@ -164,9 +163,9 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* 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) {
$this->maniaControl->chat->sendError('$fa0There are no maps in the jukebox!', $player->login);
return;
@ -192,10 +191,10 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* Adds map as first map in queue (for /replay)
*
* @param $player
* @param $map
* @param Player $player
* @param Map $map
*/
public function addFirstMapToMapQueue($player, $map) {
public function addFirstMapToMapQueue(Player $player, Map $map) {
if ($map) {
if (array_key_exists($map->uid, $this->queuedMaps)) {
unset($this->queuedMaps[$map->uid]);
@ -208,8 +207,8 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* Adds a Map to the map-queue
*
* @param $login
* @param $uid
* @param string $login
* @param string $uid
*/
public function addMapToMapQueue($login, $uid) {
$player = $this->maniaControl->playerManager->getPlayer($login);
@ -270,9 +269,8 @@ class MapQueue implements CallbackListener, CommandListener {
/**
* Revmoes a Map from the Map queue
*
* @param \ManiaControl\Players\Player $player
* @param $uid
* @internal param $login
* @param Player $player
* @param string $uid
*/
public function removeFromMapQueue(Player $player, $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
*
* @return null
* @return Map
*/
public function getNextMap() {
return $this->nextMap;

View File

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

View File

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

View File

@ -245,6 +245,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
usort($pluginClasses, function ($a, $b) {
/** @var Plugin $a */
/** @var Plugin $b */
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) {
$self = $this;
$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');
$actionVerb = ($update ? 'Updating' : 'Installing');
$actionVerbDone = ($update ? 'updated' : 'installed');

View File

@ -303,6 +303,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$self = $this;
$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();
$updateFileName = $tempDir . basename($updateData->url);