Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
This commit is contained in:
		| @@ -36,21 +36,22 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | ||||
| 	 * Constants | ||||
| 	 */ | ||||
| 	const ID             = 8; | ||||
| 	const VERSION        = 0.5; | ||||
| 	const VERSION        = 0.6; | ||||
| 	const AUTHOR         = 'MCTeam'; | ||||
| 	const NAME           = 'Dedimania Plugin'; | ||||
| 	const MLID_DEDIMANIA = 'Dedimania.ManialinkId'; | ||||
|  | ||||
| 	const SETTING_WIDGET_ENABLE       = 'Enable Dedimania Widget'; | ||||
| 	const SETTING_WIDGET_TITLE        = 'Widget Title'; | ||||
| 	const SETTING_WIDGET_POSX         = 'Widget Position: X'; | ||||
| 	const SETTING_WIDGET_POSY         = 'Widget Position: Y'; | ||||
| 	const SETTING_WIDGET_WIDTH        = 'Widget Width'; | ||||
| 	const SETTING_WIDGET_LINE_COUNT   = 'Widget Displayed Lines Count'; | ||||
| 	const SETTING_WIDGET_LINE_HEIGHT  = 'Widget Line Height'; | ||||
| 	const SETTING_DEDIMANIA_CODE      = '$l[http://dedimania.net/tm2stats/?do=register]Dedimania Code for '; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records'; | ||||
| 	const SETTING_MAX_RECORDS         = 'Max Records, only increase if you bought a rank update from Dedimania!'; | ||||
| 	const SETTING_WIDGET_ENABLE               = 'Enable Dedimania Widget'; | ||||
| 	const SETTING_WIDGET_TITLE                = 'Widget Title'; | ||||
| 	const SETTING_WIDGET_POSX                 = 'Widget Position: X'; | ||||
| 	const SETTING_WIDGET_POSY                 = 'Widget Position: Y'; | ||||
| 	const SETTING_WIDGET_WIDTH                = 'Widget Width'; | ||||
| 	const SETTING_WIDGET_LINE_COUNT           = 'Widget Displayed Lines Count'; | ||||
| 	const SETTING_WIDGET_LINE_HEIGHT          = 'Widget Line Height'; | ||||
| 	const SETTING_DEDIMANIA_CODE              = '$l[http://dedimania.net/tm2stats/?do=register]Dedimania Code for '; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS_PUBLIC  = 'Notify Publicly only for the X Best Records'; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS_PRIVATE = 'Notify Privately only for the X Best Records'; | ||||
| 	const SETTING_MAX_RECORDS                 = 'Max Records, only increase if you bought a rank update from Dedimania!'; | ||||
|  | ||||
| 	const CB_DEDIMANIA_CHANGED        = 'Dedimania.Changed'; | ||||
| 	const CB_DEDIMANIA_UPDATED        = 'Dedimania.Updated'; | ||||
| @@ -103,7 +104,8 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 40); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_HEIGHT, 4); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINE_COUNT, 12); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, 30); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE, 30); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC, 15); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAX_RECORDS, 30); | ||||
|  | ||||
| 		// Callbacks | ||||
| @@ -361,8 +363,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | ||||
|  | ||||
| 				$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_DEDIMANIA_CHANGED, $newRecord); | ||||
|  | ||||
| 				$notifyOnlyBestRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS); | ||||
|  | ||||
| 				// Announce record | ||||
| 				if ($oldRecord->nullRecord || $newRecord->rank < $oldRecord->rank) { | ||||
| 					// Gained rank | ||||
| @@ -372,21 +372,22 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene | ||||
| 					$improvement = 'improved the'; | ||||
| 				} | ||||
|  | ||||
| 				if ($newRecord->rank <= $notifyOnlyBestRecords) { | ||||
| 				$notifyOnlyBestRecordsPrivate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE); | ||||
| 				$notifyOnlyBestRecordsPublic = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC); | ||||
| 				if ($newRecord->rank <= $notifyOnlyBestRecordsPublic) { | ||||
| 					$notifyName = $player->nickname; | ||||
| 				} else { | ||||
| 				} elseif ($newRecord->rank <= $notifyOnlyBestRecordsPrivate) { | ||||
| 					$notifyName = 'You'; | ||||
| 				} | ||||
|  | ||||
|  | ||||
| 				$message = '$390$<$fff' . $notifyName . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>'; | ||||
| 				if (!$oldRecord->nullRecord) { | ||||
| 					$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $recTime)) . '$>)'; | ||||
| 				} | ||||
|  | ||||
| 				if ($newRecord->rank <= $notifyOnlyBestRecords) { | ||||
| 				if ($newRecord->rank <= $notifyOnlyBestRecordsPublic) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message . '!'); | ||||
| 				} else { | ||||
| 				} elseif ($newRecord->rank <= $notifyOnlyBestRecordsPrivate) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message . '!', $player); | ||||
| 				} | ||||
|  | ||||
|   | ||||
| @@ -12,6 +12,7 @@ use FML\Script\Features\Paging; | ||||
| use ManiaControl\Admin\AuthenticationManager; | ||||
| use ManiaControl\Callbacks\CallbackListener; | ||||
| use ManiaControl\Callbacks\Callbacks; | ||||
| use ManiaControl\Callbacks\CallQueueListener; | ||||
| use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure; | ||||
| use ManiaControl\Callbacks\TimerListener; | ||||
| use ManiaControl\Commands\CommandListener; | ||||
| @@ -36,30 +37,33 @@ use MCTeam\Common\RecordWidget; | ||||
|  * @copyright 2014-2019 ManiaControl Team | ||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||
|  */ | ||||
| class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListener, CommandListener, TimerListener, Plugin { | ||||
| class LocalRecordsPlugin implements CallbackListener, CallQueueListener, CommandListener, ManialinkPageAnswerListener, TimerListener, Plugin { | ||||
| 	/* | ||||
| 	 * Constants | ||||
| 	 */ | ||||
| 	const ID                           = 7; | ||||
| 	const VERSION                      = 0.5; | ||||
| 	const NAME                         = 'Local Records Plugin'; | ||||
| 	const AUTHOR                       = 'MCTeam'; | ||||
| 	const MLID_RECORDS                 = 'ml_local_records'; | ||||
| 	const TABLE_RECORDS                = 'mc_localrecords'; | ||||
| 	const SETTING_MULTILAP_SAVE_SINGLE = 'Save every Lap as Record in Multilap'; | ||||
| 	const SETTING_WIDGET_TITLE         = 'Widget Title'; | ||||
| 	const SETTING_WIDGET_POSX          = 'Widget Position: X'; | ||||
| 	const SETTING_WIDGET_POSY          = 'Widget Position: Y'; | ||||
| 	const SETTING_WIDGET_WIDTH         = 'Widget Width'; | ||||
| 	const SETTING_WIDGET_LINESCOUNT    = 'Widget Displayed Lines Count'; | ||||
| 	const SETTING_WIDGET_LINEHEIGHT    = 'Widget Line Height'; | ||||
| 	const SETTING_WIDGET_ENABLE        = 'Enable Local Records Widget'; | ||||
| 	const SETTING_NOTIFY_ONLY_DRIVER   = 'Notify only the Driver on New Records'; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS  = 'Notify Publicly only for the X Best Records'; | ||||
| 	const SETTING_ADJUST_OUTER_BORDER  = 'Adjust outer Border to Number of actual Records'; | ||||
| 	const SETTING_RECORDS_BEFORE_AFTER = 'Number of Records displayed before and after a player'; | ||||
| 	const CB_LOCALRECORDS_CHANGED      = 'LocalRecords.Changed'; | ||||
| 	const ACTION_SHOW_RECORDSLIST      = 'LocalRecords.ShowRecordsList'; | ||||
| 	const ID                                  = 7; | ||||
| 	const VERSION                             = 0.8; | ||||
| 	const NAME                                = 'Local Records Plugin'; | ||||
| 	const AUTHOR                              = 'MCTeam'; | ||||
| 	const MLID_RECORDS                        = 'ml_local_records'; | ||||
| 	const TABLE_RECORDS                       = 'mc_localrecords'; | ||||
| 	const PERMISSION_DELETE_ANY_RECORD        = 'Permission remove any record'; | ||||
| 	const PERMISSION_DELETE_PERSONAL_RECORD   = 'Permission remove personal record'; | ||||
| 	const SETTING_MULTILAP_SAVE_SINGLE        = 'Save every Lap as Record in Multilap'; | ||||
| 	const SETTING_WIDGET_TITLE                = 'Widget Title'; | ||||
| 	const SETTING_WIDGET_POSX                 = 'Widget Position: X'; | ||||
| 	const SETTING_WIDGET_POSY                 = 'Widget Position: Y'; | ||||
| 	const SETTING_WIDGET_WIDTH                = 'Widget Width'; | ||||
| 	const SETTING_WIDGET_LINESCOUNT           = 'Widget Displayed Lines Count'; | ||||
| 	const SETTING_WIDGET_LINEHEIGHT           = 'Widget Line Height'; | ||||
| 	const SETTING_WIDGET_ENABLE               = 'Enable Local Records Widget'; | ||||
| 	const SETTING_NOTIFICATION_MESSAGE_PREFIX = 'Notification Message Prefix'; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS_PRIVATE = 'Notify privately for the X Best Records'; | ||||
| 	const SETTING_NOTIFY_BEST_RECORDS_PUBLIC  = 'Notify publicly for the X Best Records'; | ||||
| 	const SETTING_ADJUST_OUTER_BORDER         = 'Adjust outer Border to Number of actual Records'; | ||||
| 	const SETTING_RECORDS_BEFORE_AFTER        = 'Number of Records displayed before and after a player'; | ||||
| 	const CB_LOCALRECORDS_CHANGED             = 'LocalRecords.Changed'; | ||||
| 	const ACTION_SHOW_RECORDSLIST             = 'LocalRecords.ShowRecordsList'; | ||||
|  | ||||
|  | ||||
| 	/* | ||||
| @@ -126,6 +130,19 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 		$this->recordWidget = new RecordWidget($this->maniaControl); | ||||
|  | ||||
| 		// Settings | ||||
| 		$this->maniaControl->getAuthenticationManager()->definePluginPermissionLevel( | ||||
| 			$this, | ||||
| 			self::PERMISSION_DELETE_ANY_RECORD, | ||||
| 			AuthenticationManager::AUTH_LEVEL_SUPERADMIN, | ||||
| 			AuthenticationManager::AUTH_LEVEL_MODERATOR | ||||
| 		); | ||||
| 		$this->maniaControl->getAuthenticationManager()->definePluginPermissionLevel( | ||||
| 			$this, | ||||
| 			self::PERMISSION_DELETE_PERSONAL_RECORD, | ||||
| 			AuthenticationManager::AUTH_LEVEL_ADMIN, | ||||
| 			AuthenticationManager::AUTH_LEVEL_PLAYER | ||||
| 		); | ||||
|  | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records'); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -139.); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 75); | ||||
| @@ -133,8 +150,9 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 15); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_ENABLE, true); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, 10); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFICATION_MESSAGE_PREFIX, '$3c0'); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE, 100); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC, 10); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_RECORDS_BEFORE_AFTER, 2); | ||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MULTILAP_SAVE_SINGLE, false); | ||||
| @@ -154,7 +172,8 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONLAPFINISH, $this, 'handleFinishLapCallback'); | ||||
|  | ||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.'); | ||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.'); | ||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deletePersonalRecord', false, 'Removes your record from the database.'); | ||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteAnyRecord', true, 'Removes any record from the database.'); | ||||
|  | ||||
| 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SHOW_RECORDSLIST, $this, 'handleShowRecordsList'); | ||||
|  | ||||
| @@ -493,8 +512,9 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 		$checkpointsString                 = $this->getCheckpoints($player->login); | ||||
| 		$this->checkpoints[$player->login] = array(); | ||||
|  | ||||
| 		$notifyOnlyDriver      = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_ONLY_DRIVER); | ||||
| 		$notifyOnlyBestRecords = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS); | ||||
| 		$message           = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFICATION_MESSAGE_PREFIX); | ||||
| 		$notifyPrivatelyAt = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PRIVATE); | ||||
| 		$notifyPubliclyAt  = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_BEST_RECORDS_PUBLIC); | ||||
|  | ||||
| 		// Check old record of the player | ||||
| 		$oldRecord = $this->getLocalRecord($map, $player); | ||||
| @@ -502,23 +522,30 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 			if ($oldRecord->time < $time) { | ||||
| 				// Not improved | ||||
| 				return; | ||||
| 			} | ||||
| 			if ($oldRecord->time == $time) { | ||||
| 			} else if ($oldRecord->time == $time) { | ||||
| 				// Same time | ||||
| 				$message = '$3c0'; | ||||
| 				if ($notifyOnlyDriver) { | ||||
| 				if ($notifyPubliclyAt < $oldRecord->rank && $oldRecord->rank <= $notifyPrivatelyAt) { | ||||
| 					$message .= 'You'; | ||||
| 				} else { | ||||
| 					$message .= '$<$fff' . $player->nickname . '$>'; | ||||
| 				} | ||||
|  | ||||
| 				$message .= ' equalized the $<$ff0' . $oldRecord->rank . '.$> Local Record:'; | ||||
| 				$message .= ' $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!'; | ||||
|  | ||||
| 				if ($notifyOnlyDriver) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message, $player); | ||||
| 				} else if (!$notifyOnlyBestRecords || $oldRecord->rank <= $notifyOnlyBestRecords) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message); | ||||
| 				if ($oldRecord->rank <= $notifyPubliclyAt) { | ||||
| 					$this->maniaControl->getCallQueueManager()->registerListening( | ||||
| 						$this, | ||||
| 						function () use ($message) { | ||||
| 							$this->maniaControl->getChat()->sendInformation($message); | ||||
| 						} | ||||
| 					); | ||||
| 				} else if ($oldRecord->rank <= $notifyPrivatelyAt) { | ||||
| 					$this->maniaControl->getCallQueueManager()->registerListening( | ||||
| 						$this, | ||||
| 						function () use ($message, $player) { | ||||
| 							$this->maniaControl->getChat()->sendInformation($message, $player); | ||||
| 						} | ||||
| 					); | ||||
| 				} | ||||
| 				return; | ||||
| 			} | ||||
| @@ -548,16 +575,14 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
|  | ||||
| 		// Announce record | ||||
| 		$newRecord    = $this->getLocalRecord($map, $player); | ||||
| 		$improvedRank = (!$oldRecord || $newRecord->rank < $oldRecord->rank); | ||||
| 		$improvedRank = ($oldRecord && $newRecord->rank >= $oldRecord->rank); | ||||
|  | ||||
|  | ||||
| 		$message = '$3c0'; | ||||
| 		if ($notifyOnlyDriver) { | ||||
| 		if ($notifyPubliclyAt < $newRecord->rank && $newRecord->rank <= $notifyPrivatelyAt) { | ||||
| 			$message .= 'You'; | ||||
| 		} else { | ||||
| 			$message .= '$<$fff' . $player->nickname . '$>'; | ||||
| 		} | ||||
| 		$message .= ' ' . ($improvedRank ? 'gained' : 'improved') . ' the'; | ||||
| 		$message .= ' ' . ($improvedRank ? 'improved' : 'gained') . ' the'; | ||||
| 		$message .= ' $<$ff0' . $newRecord->rank . '.$> Local Record:'; | ||||
| 		$message .= ' $<$fff' . Formatter::formatTime($newRecord->time) . '$>!'; | ||||
| 		if ($oldRecord) { | ||||
| @@ -569,10 +594,20 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 			$message  .= '$<$fff-' . Formatter::formatTime($timeDiff) . '$>)'; | ||||
| 		} | ||||
|  | ||||
| 		if ($notifyOnlyDriver) { | ||||
| 			$this->maniaControl->getChat()->sendInformation($message, $player); | ||||
| 		} else if (!$notifyOnlyBestRecords || $newRecord->rank <= $notifyOnlyBestRecords) { | ||||
| 			$this->maniaControl->getChat()->sendInformation($message); | ||||
| 		if ($newRecord->rank <= $notifyPubliclyAt) { | ||||
| 			$this->maniaControl->getCallQueueManager()->registerListening( | ||||
| 				$this, | ||||
| 				function () use ($message) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message); | ||||
| 				} | ||||
| 			); | ||||
| 		} else if ($newRecord->rank <= $notifyPrivatelyAt) { | ||||
| 			$this->maniaControl->getCallQueueManager()->registerListening( | ||||
| 				$this, | ||||
| 				function () use ($message, $player) { | ||||
| 					$this->maniaControl->getChat()->sendInformation($message, $player); | ||||
| 				} | ||||
| 			); | ||||
| 		} | ||||
|  | ||||
| 		$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, $newRecord); | ||||
| @@ -753,29 +788,75 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Delete a Player's record | ||||
| 	 * Delete any record | ||||
| 	 * | ||||
| 	 * @internal | ||||
| 	 * @param array  $chat | ||||
| 	 * @param Player $player | ||||
| 	 */ | ||||
| 	public function deleteRecord(array $chat, Player $player) { | ||||
| 		if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { | ||||
| 	public function deleteAnyRecord(array $chat, Player $player) { | ||||
| 		if (!$this->maniaControl->getAuthenticationManager()->checkPluginPermission($this, $player, self::PERMISSION_DELETE_ANY_RECORD)) { | ||||
| 			$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		$commandParts = explode(' ', $chat[1][2]); | ||||
| 		if (count($commandParts) < 2) { | ||||
| 		if (count($commandParts) < 2 || strlen($commandParts[1]) == 0) { | ||||
| 			$this->maniaControl->getChat()->sendUsageInfo('Missing Record ID! (Example: //delrec 3)', $player); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		$recordId   = (int) $commandParts[1]; | ||||
| 		$recordRank   = (int) $commandParts[1]; | ||||
| 		$currentMap = $this->maniaControl->getMapManager()->getCurrentMap(); | ||||
| 		$records    = $this->getLocalRecords($currentMap); | ||||
| 		if (count($records) < $recordId) { | ||||
| 			$this->maniaControl->getChat()->sendError('Cannot remove record $<$fff' . $recordId . '$>!', $player); | ||||
| 		if ($recordRank <= 0 || count($records) < $recordRank) { | ||||
| 			$this->maniaControl->getChat()->sendError('Cannot remove record $<$fff' . $recordRank . '$>!', $player); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		assert($recordRank == $records[$recordRank-1]->rank); | ||||
| 		$playerIndex = $records[$recordRank-1]->playerIndex; | ||||
| 		$playerNick  = $records[$recordRank-1]->nickname; | ||||
|  | ||||
| 		$mysqli = $this->maniaControl->getDatabase()->getMysqli(); | ||||
| 		$query  = "DELETE FROM `" . self::TABLE_RECORDS . "` | ||||
| 				WHERE `mapIndex` = {$currentMap->index} | ||||
| 				AND `playerIndex` = {$playerIndex};"; | ||||
| 		$mysqli->query($query); | ||||
| 		if ($mysqli->error) { | ||||
| 			trigger_error($mysqli->error); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null); | ||||
| 		$this->maniaControl->getChat()->sendSuccess('Record no. $<$fff' . $recordRank . '$> by $<$fff' . $playerNick . '$> has been removed!'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Delete the personal record | ||||
| 	 * | ||||
| 	 * @internal | ||||
| 	 * @param array  $chat | ||||
| 	 * @param Player $player | ||||
| 	 */ | ||||
| 	public function deletePersonalRecord(array $chat, Player $player) { | ||||
| 		if (!$this->maniaControl->getAuthenticationManager()->checkPluginPermission($this, $player, self::PERMISSION_DELETE_PERSONAL_RECORD)) { | ||||
| 			$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		$currentMap = $this->maniaControl->getMapManager()->getCurrentMap(); | ||||
| 		$records    = $this->getLocalRecords($currentMap); | ||||
| 		$hasRecord  = true; | ||||
| 		foreach ($records as $record) { | ||||
| 			if ($record->login === $player->login) { | ||||
| 				$hasRecord = true; | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (!$hasRecord) { | ||||
| 			$this->maniaControl->getChat()->sendError('You have no personal record to remove!', $player); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| @@ -790,7 +871,7 @@ class LocalRecordsPlugin implements ManialinkPageAnswerListener, CallbackListene | ||||
| 		} | ||||
|  | ||||
| 		$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_LOCALRECORDS_CHANGED, null); | ||||
| 		$this->maniaControl->getChat()->sendInformation('Record no. $<$fff' . $recordId . '$> has been removed!'); | ||||
| 		$this->maniaControl->getChat()->sendSuccess('$<$fff'.$player->getEscapedNickname().'$> removed his personal record!'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user