maniaControl = $maniaControl; $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SCHEDULE, '', 'format: "timestamp:mapuid,timestamp:mapuid"'); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEBOUCEMAPCHANGEDELAY, 30, 'delay between 2 map change requests', 110); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000); } /** * @see \ManiaControl\Plugins\Plugin::unload() */ public function unload() { } /** * handle1Second * @return void */ public function handle1Second() { $now = time(); if ($this->debounceMapChangeTime > $now) return; $schedule = trim($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SCHEDULE)); if ($schedule === '') return; $matchingTimestamp = -1; $matchingMapUid = ''; foreach (explode(',', $schedule) as $pair) { list($timestampText, $mapuid) = explode(':', $pair); if (!is_numeric($timestampText)) { $this->maniaControl->getChat()->sendErrorToAdmins('invalid timestamp in pair: '. $pair); Logger::logWarning('invalid timestamp in pair: '. $pair); continue; } $timestamp = intval($timestampText); if ($this->maniaControl->getMapManager()->getMapByUid($mapuid) === null) { $this->maniaControl->getChat()->sendErrorToAdmins('map not loaded in pair: '. $pair); Logger::logWarning('map not loaded in pair: '. $pair); continue; } if ($matchingTimestamp < $timestamp && $now > $timestamp) { $matchingTimestamp = $timestamp; $matchingMapUid = $mapuid; } } if ($matchingMapUid !== '' && $matchingMapUid !== $this->maniaControl->getMapManager()->getCurrentMap()->uid) { $this->debounceMapChangeTime = time() + $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEBOUCEMAPCHANGEDELAY); $nextmap = $this->maniaControl->getMapManager()->getMapByUid($matchingMapUid); $this->maniaControl->getChat()->sendSuccess('Automatic switching to map: $z'. $nextmap->name); Logger::logWarning('Automatic switching to map: '. $matchingMapUid); $this->maniaControl->getMapManager()->getMapActions()->skipToMapByUid($matchingMapUid); } } }