39 private array $propertyCache = [];
41 public function __construct(
42 private Config $pocketmineYml,
43 private Config $serverProperties
46 public function getProperty(
string $variable, mixed $defaultValue =
null) : mixed{
47 if(!array_key_exists($variable, $this->propertyCache)){
48 $v = getopt(
"", [
"$variable::"]);
49 if(isset($v[$variable])){
50 $this->propertyCache[$variable] = $v[$variable];
52 $this->propertyCache[$variable] = $this->pocketmineYml->getNested($variable);
56 return $this->propertyCache[$variable] ?? $defaultValue;
59 public function getPropertyBool(
string $variable,
bool $defaultValue) :
bool{
60 return (
bool) $this->getProperty($variable, $defaultValue);
63 public function getPropertyInt(
string $variable,
int $defaultValue) :
int{
64 return (
int) $this->getProperty($variable, $defaultValue);
67 public function getPropertyString(
string $variable,
string $defaultValue) :
string{
68 return (
string) $this->getProperty($variable, $defaultValue);
71 public function getConfigString(
string $variable,
string $defaultValue =
"") :
string{
72 $v = getopt(
"", [
"$variable::"]);
73 if(isset($v[$variable])){
74 return (
string) $v[$variable];
77 return $this->serverProperties->exists($variable) ? (string) $this->serverProperties->get($variable) : $defaultValue;
80 public function setConfigString(
string $variable,
string $value) :
void{
81 $this->serverProperties->set($variable, $value);
84 public function getConfigInt(
string $variable,
int $defaultValue = 0) :
int{
85 $v = getopt(
"", [
"$variable::"]);
86 if(isset($v[$variable])){
87 return (
int) $v[$variable];
90 return $this->serverProperties->exists($variable) ? (int) $this->serverProperties->get($variable) : $defaultValue;
93 public function setConfigInt(
string $variable,
int $value) :
void{
94 $this->serverProperties->set($variable, $value);
97 public function getConfigBool(
string $variable,
bool $defaultValue =
false) :
bool{
98 $v = getopt(
"", [
"$variable::"]);
99 if(isset($v[$variable])){
100 $value = $v[$variable];
102 $value = $this->serverProperties->exists($variable) ? $this->serverProperties->get($variable) : $defaultValue;
110 if(is_string($value)){
111 switch(strtolower($value)){
123 public function setConfigBool(
string $variable,
bool $value) :
void{
124 $this->serverProperties->set($variable, $value ?
"1" :
"0");
127 public function save() :
void{
128 if($this->serverProperties->hasChanged()){
129 $this->serverProperties->save();
131 if($this->pocketmineYml->hasChanged()){
132 $this->pocketmineYml->save();