Use Chat::formatMessage in Updates/*

This commit is contained in:
Alexander Nell 2020-05-30 23:28:39 +02:00
parent ec93e56869
commit 965ee220ba
2 changed files with 64 additions and 17 deletions

View File

@ -269,9 +269,12 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
&$pluginUpdateData, &$player, &$update &$pluginUpdateData, &$player, &$update
) { ) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; $message = $this->maniaControl->getChat()->formatMessage(
"Error loading Update Data for %s: {$error}!",
$pluginUpdateData->pluginName
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendInformation($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
@ -281,7 +284,10 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$actionVerb = ($update ? 'Updating' : 'Installing'); $actionVerb = ($update ? 'Updating' : 'Installing');
$actionVerbDone = ($update ? 'updated' : 'installed'); $actionVerbDone = ($update ? 'updated' : 'installed');
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; $message = $this->maniaControl->getChat()->formatMessage(
"Now {$actionVerb} %s ...",
$pluginUpdateData->pluginName
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendInformation($message, $player); $this->maniaControl->getChat()->sendInformation($message, $player);
} }
@ -320,7 +326,10 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if ($update) { if ($update) {
$messageExtra = ' (Restart ManiaControl to load the new Version!)'; $messageExtra = ' (Restart ManiaControl to load the new Version!)';
} }
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; $message = $this->maniaControl->getChat()->formatMessage(
"Successfully {$actionVerbDone} %s!{$messageExtra}",
$pluginUpdateData->pluginName
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
@ -330,13 +339,19 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins();
if (empty($newPluginClasses)) { if (empty($newPluginClasses)) {
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed, try to restart ManiaControl!"; $message = $this->maniaControl->getChat()->formatMessage(
"Loading fresh installed Plugin %s failed, try to restart ManiaControl!",
$pluginUpdateData->pluginName
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::log($message); Logger::log($message);
} else { } else {
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; $message = $this->maniaControl->getChat()->formatMessage(
"Successfully loaded fresh installed Plugin %s!",
$pluginUpdateData->pluginName
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }

View File

@ -402,7 +402,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
// Set the build date // Set the build date
$this->setBuildDate($updateData->releaseDate); $this->setBuildDate($updateData->releaseDate);
$message = 'Update finished! See what we updated with $<$fff//chatlog$>!'; $message = $this->maniaControl->getChat()->formatMessage(
'Update finished! See what we updated with %s!',
'//changelog'
);
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
@ -442,11 +445,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
return; return;
} }
$message = '';
if ($this->isNightlyUpdateChannel()) { if ($this->isNightlyUpdateChannel()) {
$this->maniaControl->getChat()->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'New Nightly Build (%s) available!',
$this->coreUpdateData->releaseDate
);
} else { } else {
$this->maniaControl->getChat()->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'New ManiaControl Version (%s) available!',
$this->coreUpdateData->version
);
} }
$this->maniaControl->getChat()->sendInformation($message, $player);
} }
/** /**
@ -480,12 +492,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) { $this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
if (!$this->checkUpdateData($updateData)) { if (!$this->checkUpdateData($updateData)) {
$this->maniaControl->getChat()->sendInformation('No Update available!', $player->login); $this->maniaControl->getChat()->sendInformation('No Update available!', $player);
return; return;
} }
if (!$this->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
$this->maniaControl->getChat()->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
'Please update your server to %s in order to receive further ManiaControl updates!',
$updateData->minDedicatedBuild
);
$this->maniaControl->getChat()->sendError($message, $player);
return; return;
} }
@ -494,16 +510,32 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
$buildDate = $this->getBuildDate(); $buildDate = $this->getBuildDate();
if ($buildDate) { if ($buildDate) {
if ($updateData->isNewerThan($buildDate)) { if ($updateData->isNewerThan($buildDate)) {
$this->maniaControl->getChat()->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login); $message = $this->maniaControl->getChat()->formatMessage(
return; 'No new Build available! (Current Build: %s)',
$buildDate
);
$this->maniaControl->getChat()->sendInformation($message, $player);
} else { } else {
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login); $message = $this->maniaControl->getChat()->formatMesssage(
'New Nightly Build (%s) available! (Current Build: %s)',
$updateData->releaseDate,
$buildDate
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
} else { } else {
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login); $message = $this->maniaControl->getChat()->formatMesssage(
'New Nightly Build (%s) available!',
$updateData->releaseDate
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
} else { } else {
$this->maniaControl->getChat()->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login); $message = $this->maniaControl->getChat()->formatMesssage(
'Update for Version %s available!',
$updateData->version
);
$this->maniaControl->getChat()->sendSuccess($message, $player);
} }
$this->coreUpdateData = $updateData; $this->coreUpdateData = $updateData;
@ -540,7 +572,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
} }
if (!$this->checkUpdateDataBuildVersion($updateData)) { if (!$this->checkUpdateDataBuildVersion($updateData)) {
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player); $this->maniaControl->getChat()->sendError('The Next ManiaControl Update requires a newer Dedicated Server Version!', $player);
} }
return; return;
} }