files should have the same name as their classes

who renamed this class?..
This commit is contained in:
Steffen Schröder 2014-04-28 17:54:25 +02:00
parent cf78a2a141
commit 5cac6b4cd1

View File

@ -32,7 +32,7 @@ use ManiaControl\Plugins\Plugin;
* @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 LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin { class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
/** /*
* Constants * Constants
*/ */
const ID = 7; const ID = 7;
@ -56,6 +56,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* Private Properties * Private Properties
*/ */
/** /**
*
* @var maniaControl $maniaControl * @var maniaControl $maniaControl
*/ */
private $maniaControl = null; private $maniaControl = null;
@ -69,10 +70,11 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
* @return mixed * @return mixed
*/ */
public static function prepare(ManiaControl $maniaControl) { public static function prepare(ManiaControl $maniaControl) {
//do nothing // do nothing
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::load() * @see \ManiaControl\Plugins\Plugin::load()
*/ */
public function load(ManiaControl $maniaControl) { public function load(ManiaControl $maniaControl) {
@ -107,12 +109,12 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::unload() * @see \ManiaControl\Plugins\Plugin::unload()
*/ */
public function unload() { public function unload() {
$this->maniaControl->callbackManager->unregisterCallbackListener($this); $this->maniaControl->callbackManager->unregisterCallbackListener($this);
$this->maniaControl->timerManager->unregisterTimerListenings($this); $this->maniaControl->timerManager->unregisterTimerListenings($this);
unset($this->maniaControl);
} }
/** /**
@ -136,13 +138,14 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$mysqli->query("ALTER TABLE `" . self::TABLE_RECORDS . "` ADD `checkpoints` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); $mysqli->query("ALTER TABLE `" . self::TABLE_RECORDS . "` ADD `checkpoints` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
if ($mysqli->error) { if ($mysqli->error) {
if(!strstr($mysqli->error, 'Duplicate')) { if (!strstr($mysqli->error, 'Duplicate')) {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
} }
} }
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getId() * @see \ManiaControl\Plugins\Plugin::getId()
*/ */
public static function getId() { public static function getId() {
@ -150,6 +153,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getName() * @see \ManiaControl\Plugins\Plugin::getName()
*/ */
public static function getName() { public static function getName() {
@ -157,6 +161,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getVersion() * @see \ManiaControl\Plugins\Plugin::getVersion()
*/ */
public static function getVersion() { public static function getVersion() {
@ -164,6 +169,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getAuthor() * @see \ManiaControl\Plugins\Plugin::getAuthor()
*/ */
public static function getAuthor() { public static function getAuthor() {
@ -171,6 +177,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
/** /**
*
* @see \ManiaControl\Plugins\Plugin::getDescription() * @see \ManiaControl\Plugins\Plugin::getDescription()
*/ */
public static function getDescription() { public static function getDescription() {
@ -195,20 +202,20 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
$this->updateManialink = false; $this->updateManialink = false;
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_ENABLE)) {
$manialink = $this->buildManialink(); $manialink = $this->buildManialink();
$this->maniaControl->manialinkManager->sendManialink($manialink); $this->maniaControl->manialinkManager->sendManialink($manialink);
} }
} }
public function handleSettingsChanged($class, $settingName, $value) { public function handleSettingsChanged($class, $settingName, $value) {
if (!$class = get_class()) { if (!$class = get_class()) {
return; return;
} }
if ($settingName == 'Enable Local Records Widget' && $value == true) { if ($settingName == 'Enable Local Records Widget' && $value == true) {
$this->updateManialink = true; $this->updateManialink = true;
} elseif ($settingName == 'Enable Local Records Widget' && $value == false) { }
elseif ($settingName == 'Enable Local Records Widget' && $value == false) {
$ml = new ManiaLink(self::MLID_RECORDS); $ml = new ManiaLink(self::MLID_RECORDS);
$mltext = $ml->render()->saveXML(); $mltext = $ml->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($mltext); $this->maniaControl->manialinkManager->sendManialink($mltext);
@ -224,7 +231,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$data = $callback[1]; $data = $callback[1];
$login = $data[1]; $login = $data[1];
$time = $data[2]; $time = $data[2];
//$lap = $data[3]; // $lap = $data[3];
$cpIndex = $data[4]; $cpIndex = $data[4];
if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) { if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) {
$this->checkpoints[$login] = array(); $this->checkpoints[$login] = array();
@ -283,8 +290,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
if ($oldRecord->time == $time) { if ($oldRecord->time == $time) {
// Same time // Same time
$message = '$<' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time).'$>!'; $message = '$<' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
$this->maniaControl->chat->sendInformation('$3c0'.$message); $this->maniaControl->chat->sendInformation('$3c0' . $message);
return; return;
} }
} }
@ -320,15 +327,16 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) { if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved your'); $improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved your');
$message = 'You ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time); $message = 'You ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time);
if($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank.'. '; if ($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank . '. ';
if($oldRecord) $message .= '$> ($<$ff0'.$oldRank.'$>$<$fff-'.Formatter::formatTime(($oldRecord->time-$newRecord->time)).'$>)!'; if ($oldRecord) $message .= '$> ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)!';
$this->maniaControl->chat->sendInformation('$3c0'.$message, $player->login); $this->maniaControl->chat->sendInformation('$3c0' . $message, $player->login);
} else { }
else {
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the'); $improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
$message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time); $message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time);
if($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank.'. '; if ($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank . '. ';
if($oldRecord) $message .= '$> ($<$ff0'.$oldRank.'$>$<$fff-'.Formatter::formatTime(($oldRecord->time-$newRecord->time)).'$>)!'; if ($oldRecord) $message .= '$> ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)!';
$this->maniaControl->chat->sendInformation('$3c0'.$message); $this->maniaControl->chat->sendInformation('$3c0' . $message);
} }
} }
@ -343,39 +351,46 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if($actionId == self::ACTION_SHOW_RECORDSLIST) { if ($actionId == self::ACTION_SHOW_RECORDSLIST) {
$this->showRecordsList(array(), $player); $this->showRecordsList(array(), $player);
} }
} }
/**
* Delete a Player's record
*
* @param array $chat
* @param Player $player
*/
public function deleteRecord(array $chat, Player $player) { public function deleteRecord(array $chat, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$chatCommand = explode(' ', $chat[1][2]); $chatCommand = explode(' ', $chat[1][2]);
$recordId = (int)$chatCommand[1]; $recordId = (int) $chatCommand[1];
if(is_integer($recordId)) { if (is_integer($recordId)) {
$currentMap = $this->maniaControl->mapManager->getCurrentMap(); $currentMap = $this->maniaControl->mapManager->getCurrentMap();
$records = $this->getLocalRecords($currentMap); $records = $this->getLocalRecords($currentMap);
if(count($records) < $recordId) { if (count($records) < $recordId) {
$this->maniaControl->chat->sendError('Cannot remove record $<$fff'.$recordId.'$>!', $player); $this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
return; return;
} }
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "DELETE FROM `" . self::TABLE_RECORDS . "` WHERE `mapIndex` = ".$currentMap->index." AND `playerIndex` = ".$player->index.""; $query = "DELETE FROM `" . self::TABLE_RECORDS . "` WHERE `mapIndex` = " . $currentMap->index . " AND `playerIndex` = " . $player->index . "";
$mysqli->query($query); $mysqli->query($query);
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return null; return;
} }
$this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null); $this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
$this->maniaControl->chat->sendInformation('Record no. $<$fff'.$recordId.'$> has been removed!'); $this->maniaControl->chat->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!');
} else { }
$this->maniaControl->chat->sendError('Cannot remove record $<$fff'.$recordId.'$>, because it\'s not an integer!', $player); else {
$this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>, because it\'s not an integer!', $player);
} }
} }
@ -397,7 +412,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$pagesId = 'RecordsListPages'; $pagesId = 'RecordsListPages';
} }
//create manialink // create manialink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
$paging = new Paging(); $paging = new Paging();
@ -425,7 +440,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$i = 0; $i = 0;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrames = array();
foreach($records as $listRecord) { foreach ($records as $listRecord) {
if (!isset($pageFrame)) { if (!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
@ -449,8 +464,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$lineQuad->setZ(0.001); $lineQuad->setZ(0.001);
} }
if(strlen($listRecord->nickname) < 2) $listRecord->nickname = $listRecord->login; if (strlen($listRecord->nickname) < 2) $listRecord->nickname = $listRecord->login;
$array = array($listRecord->rank => $x + 5, '$fff'.$listRecord->nickname => $x + 18, $listRecord->login => $x + 70, Formatter::formatTime($listRecord->time) => $x + 101); $array = array($listRecord->rank => $x + 5, '$fff' . $listRecord->nickname => $x + 18, $listRecord->login => $x + 70,
Formatter::formatTime($listRecord->time) => $x + 101);
$this->maniaControl->manialinkManager->labelLine($recordFrame, $array); $this->maniaControl->manialinkManager->labelLine($recordFrame, $array);
$recordFrame->setY($y); $recordFrame->setY($y);
@ -478,7 +494,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
} }
$string = ''; $string = '';
$count = count($this->checkpoints[$login]); $count = count($this->checkpoints[$login]);
foreach($this->checkpoints[$login] as $index => $check) { foreach ($this->checkpoints[$login] as $index => $check) {
$string .= $check; $string .= $check;
if ($index < $count - 1) { if ($index < $count - 1) {
$string .= ','; $string .= ',';
@ -538,7 +554,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$titleLabel->setTranslate(true); $titleLabel->setTranslate(true);
// Times // Times
foreach($records as $index => $record) { foreach ($records as $index => $record) {
if ($index >= $lines) { if ($index >= $lines) {
break; break;
} }
@ -549,10 +565,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$frame->add($recordFrame); $frame->add($recordFrame);
$recordFrame->setPosition(0, $y); $recordFrame->setPosition(0, $y);
/*$backgroundQuad = new Quad(); /*
$recordFrame->add($backgroundQuad); * $backgroundQuad = new Quad(); $recordFrame->add($backgroundQuad); $backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4); */
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);*/
$rankLabel = new Label(); $rankLabel = new Label();
$recordFrame->add($rankLabel); $recordFrame->add($rankLabel);
@ -609,7 +624,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return null; return null;
} }
$records = array(); $records = array();
while($record = $result->fetch_object()) { while ($record = $result->fetch_object()) {
array_push($records, $record); array_push($records, $record);
} }
$result->free(); $result->free();
@ -640,4 +655,3 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return $record; return $record;
} }
} }