From f738448f2eed5939ad8bcbd98692bdb59d97b632 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 26 Feb 2026 16:45:58 +0100 Subject: [PATCH] [WIP] Refactoring --- system/src/Server/TOML/ItemsParser.php | 45 ++++++++++++++------------ system/src/Server/XML/Items.php | 2 +- system/src/Server/XML/Vocations.php | 8 ----- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/system/src/Server/TOML/ItemsParser.php b/system/src/Server/TOML/ItemsParser.php index d281cc67..cadc97fd 100644 --- a/system/src/Server/TOML/ItemsParser.php +++ b/system/src/Server/TOML/ItemsParser.php @@ -9,34 +9,39 @@ class ItemsParser $ret = []; $i = 0; - $handle = fopen($path, "r"); - if ($handle) { - $parse = ''; + $handle = fopen($path, 'r'); - while (($line = fgets($handle)) !== false) { - if (str_contains($line, '[[items]]') && $i++ != 0) { - //global $whoopsHandler; - //$whoopsHandler->addDataTable('ini', [$parse]); - $ret[] = parse_ini_string($parse); - $parse = ''; - continue; - } + if ($handle === false) { + throw new \RuntimeException('Failed to open items file: ' . $path); + } - // skip lines like this - // field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10} - // as it cannot be parsed by parse_ini_string - if (str_contains($line, 'field =')) { - continue; - } + $parse = ''; - $parse .= $line; + while (($line = fgets($handle)) !== false) { + if (str_contains($line, '[[items]]') && $i++ != 0) { + //global $whoopsHandler; + //$whoopsHandler->addDataTable('ini', [$parse]); + $ret[] = parse_ini_string($parse); + $parse = ''; + continue; } - $ret[] = parse_ini_string($parse); + // skip lines like this + // field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10} + // as it cannot be parsed by parse_ini_string + if (str_starts_with(ltrim($line), 'field =')) { + continue; + } - fclose($handle); + $parse .= $line; } + if ($parse !== '') { + $ret[] = parse_ini_string($parse); + } + + fclose($handle); + return $ret; } } diff --git a/system/src/Server/XML/Items.php b/system/src/Server/XML/Items.php index 608c756c..b6335a1b 100644 --- a/system/src/Server/XML/Items.php +++ b/system/src/Server/XML/Items.php @@ -6,7 +6,7 @@ use MyAAC\Cache\PHP as CachePHP; class Items { - private string $error; + private string $error = ''; public function getError(): string { return $this->error; diff --git a/system/src/Server/XML/Vocations.php b/system/src/Server/XML/Vocations.php index 64ad2f33..90b878ae 100644 --- a/system/src/Server/XML/Vocations.php +++ b/system/src/Server/XML/Vocations.php @@ -40,12 +40,4 @@ class Vocations public function getFrom(): array { return $this->vocationsFrom; } - - public static function getBase($includingRook = true): array { - return \MyAAC\Server\Vocations::getBase($includingRook); - } - - public static function getOriginal(int $id): ?int { - return \MyAAC\Server\Vocations::getOriginal($id); - } }