diff --git a/src/Exceptions/VersionNotSupportedException.php b/src/Exceptions/VersionNotSupportedException.php new file mode 100644 index 0000000..18098dd --- /dev/null +++ b/src/Exceptions/VersionNotSupportedException.php @@ -0,0 +1,25 @@ +version = $version; + parent::__construct("Version " . $version . " is not supported."); + } + + /** + * @return string + */ + public function getVersion(): string + { + return $this->version; + } +} \ No newline at end of file diff --git a/src/VersionHelper.php b/src/VersionHelper.php index 622e20b..a3a8b7f 100644 --- a/src/VersionHelper.php +++ b/src/VersionHelper.php @@ -3,6 +3,7 @@ namespace Aternos\Hawk; +use Aternos\Hawk\Exceptions\VersionNotSupportedException; use Aternos\Hawk\Versions\v2566\BlockChunkV2566; use Aternos\Hawk\Versions\v2567\BlockChunkV2567; use Aternos\Hawk\Versions\v2578\BlockChunkV2578; @@ -116,8 +117,8 @@ class VersionHelper */ protected static function versionSupported(int $version): void { - if (!array_key_exists($version, self::VERSIONS)) { - throw new Exception("Version " . $version . " is not supported."); + if (!array_key_exists($version, static::VERSIONS)) { + throw new VersionNotSupportedException(static::VERSIONS[$version]["name"]); } } @@ -129,7 +130,7 @@ protected static function versionSupported(int $version): void public static function getChunkClassFromVersion(int $version): string { self::versionSupported($version); - return self::VERSIONS[$version]["class"]; + return static::VERSIONS[$version]["class"]; } /** @@ -140,7 +141,7 @@ public static function getChunkClassFromVersion(int $version): string public static function hasLevelTag(int $version): bool { self::versionSupported($version); - return self::VERSIONS[$version]["level"]; + return static::VERSIONS[$version]["level"]; } /** @@ -151,6 +152,6 @@ public static function hasLevelTag(int $version): bool public static function hasEntitiesTag(int $version): bool { self::versionSupported($version); - return self::VERSIONS[$version]["entities"]; + return static::VERSIONS[$version]["entities"]; } } \ No newline at end of file