Skip to content

Commit

Permalink
reinitialize scorehud settings if configs are updated and validate co…
Browse files Browse the repository at this point in the history
…nfigs before calling can load
  • Loading branch information
Ifera committed May 4, 2021
1 parent 95b7c0c commit 7fa5e05
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Ifera/ScoreHud/ScoreHud.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public function onEnable(): void{
UpdateNotifier::checkUpdate($this->getDescription()->getName(), $this->getDescription()->getVersion());
ScoreHudSettings::init($this);

$this->validateConfigs();

if(!$this->canLoad()){
return;
}

$this->validateConfigs();

if(ScoreHudSettings::isTimezoneChanged()){
if(Utils::setTimezone()){
$this->getLogger()->notice("Server timezone successfully set to " . ScoreHudSettings::getTimezone());
Expand Down Expand Up @@ -119,13 +119,22 @@ private function loadConfigs(): void{
}

private function validateConfigs(): void{
$updated = false;

if(ConfigUpdater::checkUpdate($this, $this->getConfig(), "config-version", self::CONFIG_VERSION)){
$updated = true;
$this->reloadConfig();
}

if(ConfigUpdater::checkUpdate($this, $this->scoreConfig, "scorehud-version", self::SCOREHUD_VERSION)){
$updated = true;
$this->scoreConfig = new Config($this->getDataFolder() . "scorehud.yml", Config::YAML);
}

if($updated){
ScoreHudSettings::destroy();
ScoreHudSettings::init($this);
}
}

private function canLoad(): bool{
Expand Down

0 comments on commit 7fa5e05

Please sign in to comment.