Skip to content

Commit

Permalink
add VersionNotSupportedException
Browse files Browse the repository at this point in the history
  • Loading branch information
rico132 committed Jul 26, 2022
1 parent 874f6cb commit c0f2be0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/Exceptions/VersionNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Aternos\Hawk\Exceptions;

class VersionNotSupportedException extends \Exception
{
protected string $version;

/**
* @param string $version
*/
public function __construct(string $version)
{
$this->version = $version;
parent::__construct("Version " . $version . " is not supported.");
}

/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
}
11 changes: 6 additions & 5 deletions src/VersionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"]);
}
}

Expand All @@ -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"];
}

/**
Expand All @@ -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"];
}

/**
Expand All @@ -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"];
}
}

0 comments on commit c0f2be0

Please sign in to comment.