*/ private $propertyCache = []; public function __construct(Config $pocketmineYml, Config $serverProperties){ $this->pocketmineYml = $pocketmineYml; $this->serverProperties = $serverProperties; } /** * @param mixed $defaultValue * * @return mixed */ public function getProperty(string $variable, $defaultValue = null){ if(!array_key_exists($variable, $this->propertyCache)){ $v = getopt("", ["$variable::"]); if(isset($v[$variable])){ $this->propertyCache[$variable] = $v[$variable]; }else{ $this->propertyCache[$variable] = $this->pocketmineYml->getNested($variable); } } return $this->propertyCache[$variable] ?? $defaultValue; } public function getConfigString(string $variable, string $defaultValue = "") : string{ $v = getopt("", ["$variable::"]); if(isset($v[$variable])){ return (string) $v[$variable]; } return $this->serverProperties->exists($variable) ? (string) $this->serverProperties->get($variable) : $defaultValue; } public function setConfigString(string $variable, string $value) : void{ $this->serverProperties->set($variable, $value); } public function getConfigInt(string $variable, int $defaultValue = 0) : int{ $v = getopt("", ["$variable::"]); if(isset($v[$variable])){ return (int) $v[$variable]; } return $this->serverProperties->exists($variable) ? (int) $this->serverProperties->get($variable) : $defaultValue; } public function setConfigInt(string $variable, int $value) : void{ $this->serverProperties->set($variable, $value); } public function getConfigBool(string $variable, bool $defaultValue = false) : bool{ $v = getopt("", ["$variable::"]); if(isset($v[$variable])){ $value = $v[$variable]; }else{ $value = $this->serverProperties->exists($variable) ? $this->serverProperties->get($variable) : $defaultValue; } if(is_bool($value)){ return $value; } switch(strtolower($value)){ case "on": case "true": case "1": case "yes": return true; } return false; } public function setConfigBool(string $variable, bool $value) : void{ $this->serverProperties->set($variable, $value ? "1" : "0"); } public function save() : void{ if($this->serverProperties->hasChanged()){ $this->serverProperties->save(); } if($this->pocketmineYml->hasChanged()){ $this->pocketmineYml->save(); } } }