files should have the same name as their classes
who renamed this class?..
This commit is contained in:
		@@ -32,7 +32,7 @@ use ManiaControl\Plugins\Plugin;
 | 
			
		||||
 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
			
		||||
 */
 | 
			
		||||
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin {
 | 
			
		||||
	/**
 | 
			
		||||
	/*
 | 
			
		||||
	 * Constants
 | 
			
		||||
	 */
 | 
			
		||||
	const ID = 7;
 | 
			
		||||
@@ -56,6 +56,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	 * Private Properties
 | 
			
		||||
	 */
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @var maniaControl $maniaControl
 | 
			
		||||
	 */
 | 
			
		||||
	private $maniaControl = null;
 | 
			
		||||
@@ -69,10 +70,11 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	 * @return mixed
 | 
			
		||||
	 */
 | 
			
		||||
	public static function prepare(ManiaControl $maniaControl) {
 | 
			
		||||
		//do nothing
 | 
			
		||||
		// do nothing
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::load()
 | 
			
		||||
	 */
 | 
			
		||||
	public function load(ManiaControl $maniaControl) {
 | 
			
		||||
@@ -107,12 +109,12 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::unload()
 | 
			
		||||
	 */
 | 
			
		||||
	public function unload() {
 | 
			
		||||
		$this->maniaControl->callbackManager->unregisterCallbackListener($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");
 | 
			
		||||
		if ($mysqli->error) {
 | 
			
		||||
			if(!strstr($mysqli->error, 'Duplicate')) {
 | 
			
		||||
			if (!strstr($mysqli->error, 'Duplicate')) {
 | 
			
		||||
				trigger_error($mysqli->error, E_USER_ERROR);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::getId()
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getId() {
 | 
			
		||||
@@ -150,6 +153,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::getName()
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getName() {
 | 
			
		||||
@@ -157,6 +161,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::getVersion()
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getVersion() {
 | 
			
		||||
@@ -164,6 +169,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::getAuthor()
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getAuthor() {
 | 
			
		||||
@@ -171,6 +177,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 * @see \ManiaControl\Plugins\Plugin::getDescription()
 | 
			
		||||
	 */
 | 
			
		||||
	public static function getDescription() {
 | 
			
		||||
@@ -195,20 +202,20 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		$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();
 | 
			
		||||
			$this->maniaControl->manialinkManager->sendManialink($manialink);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	public function handleSettingsChanged($class, $settingName, $value) {
 | 
			
		||||
		if (!$class = get_class()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		if ($settingName == 'Enable Local Records Widget' && $value == 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);
 | 
			
		||||
			$mltext = $ml->render()->saveXML();
 | 
			
		||||
			$this->maniaControl->manialinkManager->sendManialink($mltext);
 | 
			
		||||
@@ -224,7 +231,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		$data = $callback[1];
 | 
			
		||||
		$login = $data[1];
 | 
			
		||||
		$time = $data[2];
 | 
			
		||||
		//$lap     = $data[3];
 | 
			
		||||
		// $lap = $data[3];
 | 
			
		||||
		$cpIndex = $data[4];
 | 
			
		||||
		if (!isset($this->checkpoints[$login]) || $cpIndex <= 0) {
 | 
			
		||||
			$this->checkpoints[$login] = array();
 | 
			
		||||
@@ -283,8 +290,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
			}
 | 
			
		||||
			if ($oldRecord->time == $time) {
 | 
			
		||||
				// Same time
 | 
			
		||||
				$message = '$<' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time).'$>!';
 | 
			
		||||
				$this->maniaControl->chat->sendInformation('$3c0'.$message);
 | 
			
		||||
				$message = '$<' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
 | 
			
		||||
				$this->maniaControl->chat->sendInformation('$3c0' . $message);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -320,15 +327,16 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
 | 
			
		||||
			$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved your');
 | 
			
		||||
			$message = 'You ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time);
 | 
			
		||||
			if($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank.'. ';
 | 
			
		||||
			if($oldRecord) $message .= '$> ($<$ff0'.$oldRank.'$>$<$fff-'.Formatter::formatTime(($oldRecord->time-$newRecord->time)).'$>)!';
 | 
			
		||||
			$this->maniaControl->chat->sendInformation('$3c0'.$message, $player->login);
 | 
			
		||||
		} else {
 | 
			
		||||
			if ($oldRecord) $oldRank = ($improvement == 'improved your') ? '' : $oldRecord->rank . '. ';
 | 
			
		||||
			if ($oldRecord) $message .= '$> ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)!';
 | 
			
		||||
			$this->maniaControl->chat->sendInformation('$3c0' . $message, $player->login);
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
 | 
			
		||||
			$message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($newRecord->time);
 | 
			
		||||
			if($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank.'. ';
 | 
			
		||||
			if($oldRecord) $message .= '$> ($<$ff0'.$oldRank.'$>$<$fff-'.Formatter::formatTime(($oldRecord->time-$newRecord->time)).'$>)!';
 | 
			
		||||
			$this->maniaControl->chat->sendInformation('$3c0'.$message);
 | 
			
		||||
			if ($oldRecord) $oldRank = ($improvement == 'improved the') ? '' : $oldRecord->rank . '. ';
 | 
			
		||||
			if ($oldRecord) $message .= '$> ($<$ff0' . $oldRank . '$>$<$fff-' . Formatter::formatTime(($oldRecord->time - $newRecord->time)) . '$>)!';
 | 
			
		||||
			$this->maniaControl->chat->sendInformation('$3c0' . $message);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -343,39 +351,46 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		$login = $callback[1][1];
 | 
			
		||||
		$player = $this->maniaControl->playerManager->getPlayer($login);
 | 
			
		||||
		
 | 
			
		||||
		if($actionId == self::ACTION_SHOW_RECORDSLIST) {
 | 
			
		||||
		if ($actionId == self::ACTION_SHOW_RECORDSLIST) {
 | 
			
		||||
			$this->showRecordsList(array(), $player);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Delete a Player's record
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param array $chat
 | 
			
		||||
	 * @param 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);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		$chatCommand = explode(' ', $chat[1][2]);
 | 
			
		||||
		$recordId = (int)$chatCommand[1];
 | 
			
		||||
		if(is_integer($recordId)) {
 | 
			
		||||
		$recordId = (int) $chatCommand[1];
 | 
			
		||||
		if (is_integer($recordId)) {
 | 
			
		||||
			$currentMap = $this->maniaControl->mapManager->getCurrentMap();
 | 
			
		||||
			$records = $this->getLocalRecords($currentMap);
 | 
			
		||||
			if(count($records) < $recordId) {
 | 
			
		||||
				$this->maniaControl->chat->sendError('Cannot remove record $<$fff'.$recordId.'$>!', $player);
 | 
			
		||||
			if (count($records) < $recordId) {
 | 
			
		||||
				$this->maniaControl->chat->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			$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);
 | 
			
		||||
			if ($mysqli->error) {
 | 
			
		||||
				trigger_error($mysqli->error);
 | 
			
		||||
				return null;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			$this->maniaControl->callbackManager->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null);
 | 
			
		||||
			$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);
 | 
			
		||||
			$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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -397,7 +412,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
			$pagesId = 'RecordsListPages';
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//create manialink
 | 
			
		||||
		// create manialink
 | 
			
		||||
		$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
 | 
			
		||||
		$script = $maniaLink->getScript();
 | 
			
		||||
		$paging = new Paging();
 | 
			
		||||
@@ -425,7 +440,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		$i = 0;
 | 
			
		||||
		$y = $height / 2 - 10;
 | 
			
		||||
		$pageFrames = array();
 | 
			
		||||
		foreach($records as $listRecord) {
 | 
			
		||||
		foreach ($records as $listRecord) {
 | 
			
		||||
			if (!isset($pageFrame)) {
 | 
			
		||||
				$pageFrame = new Frame();
 | 
			
		||||
				$frame->add($pageFrame);
 | 
			
		||||
@@ -449,8 +464,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
				$lineQuad->setZ(0.001);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			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);
 | 
			
		||||
			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);
 | 
			
		||||
			$this->maniaControl->manialinkManager->labelLine($recordFrame, $array);
 | 
			
		||||
			
 | 
			
		||||
			$recordFrame->setY($y);
 | 
			
		||||
@@ -478,7 +494,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		}
 | 
			
		||||
		$string = '';
 | 
			
		||||
		$count = count($this->checkpoints[$login]);
 | 
			
		||||
		foreach($this->checkpoints[$login] as $index => $check) {
 | 
			
		||||
		foreach ($this->checkpoints[$login] as $index => $check) {
 | 
			
		||||
			$string .= $check;
 | 
			
		||||
			if ($index < $count - 1) {
 | 
			
		||||
				$string .= ',';
 | 
			
		||||
@@ -538,7 +554,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		$titleLabel->setTranslate(true);
 | 
			
		||||
		
 | 
			
		||||
		// Times
 | 
			
		||||
		foreach($records as $index => $record) {
 | 
			
		||||
		foreach ($records as $index => $record) {
 | 
			
		||||
			if ($index >= $lines) {
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
@@ -549,10 +565,9 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
			$frame->add($recordFrame);
 | 
			
		||||
			$recordFrame->setPosition(0, $y);
 | 
			
		||||
			
 | 
			
		||||
			/*$backgroundQuad = new Quad();
 | 
			
		||||
			$recordFrame->add($backgroundQuad);
 | 
			
		||||
			$backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4);
 | 
			
		||||
			$backgroundQuad->setStyles($quadStyle, $quadSubstyle);*/
 | 
			
		||||
			/*
 | 
			
		||||
			 * $backgroundQuad = new Quad(); $recordFrame->add($backgroundQuad); $backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
 | 
			
		||||
			 */
 | 
			
		||||
			
 | 
			
		||||
			$rankLabel = new Label();
 | 
			
		||||
			$recordFrame->add($rankLabel);
 | 
			
		||||
@@ -609,7 +624,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		$records = array();
 | 
			
		||||
		while($record = $result->fetch_object()) {
 | 
			
		||||
		while ($record = $result->fetch_object()) {
 | 
			
		||||
			array_push($records, $record);
 | 
			
		||||
		}
 | 
			
		||||
		$result->free();
 | 
			
		||||
@@ -640,4 +655,3 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
 | 
			
		||||
		return $record;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user