-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from pavog/paper-plugin-api-version-lower-than…
…-allowed Paper: Detect problem "Plugin API version ... is lower than the minimum allowed version. "
- Loading branch information
Showing
7 changed files
with
696 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Analysis/Problem/Paper/ApiVersionLowerThanAllowedProblem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Aternos\Codex\Minecraft\Analysis\Problem\Paper; | ||
|
||
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution; | ||
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginRemoveSolution; | ||
use Aternos\Codex\Minecraft\Analysis\Solution\Paper\ChangeMinimumAllowedApiVersionSolution; | ||
use Aternos\Codex\Minecraft\Translator\Translator; | ||
|
||
/** | ||
* Class ApiVersionLowerThanAllowedProblem | ||
* | ||
* @package Aternos\Codex\Minecraft\Analysis\Problem\Paper | ||
*/ | ||
class ApiVersionLowerThanAllowedProblem extends PaperProblem | ||
{ | ||
protected ?string $pluginName = null; | ||
protected ?string $pluginApiVersion = null; | ||
|
||
/** | ||
* Get a human-readable message | ||
* | ||
* @return string | ||
*/ | ||
public function getMessage(): string | ||
{ | ||
return Translator::getInstance()->getTranslation("plugin-api-version-lower-than-allowed-problem", [ | ||
"plugin-name" => $this->getPluginName() | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getPatterns(): array | ||
{ | ||
return [ | ||
'/Could not load plugin \'((?!\.jar).*)\.jar\' in folder \'[^\']+\'' | ||
. '\norg.bukkit.plugin.InvalidPluginException: Plugin API version (\d+\.\d+) is lower than the minimum allowed version\. Please update or replace it\./' | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function setMatches(array $matches, mixed $patternKey): void | ||
{ | ||
$this->pluginName = $matches[1]; | ||
$this->pluginApiVersion = $matches[2]; | ||
|
||
$this->addSolution((new PluginRemoveSolution())->setPluginName($this->getPluginName())); | ||
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName())); | ||
$this->addSolution((new ChangeMinimumAllowedApiVersionSolution())->setApiVersion($this->getPluginApiVersion())); | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getPluginName(): ?string | ||
{ | ||
return $this->pluginName; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getPluginApiVersion(): ?string | ||
{ | ||
return $this->pluginApiVersion; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Analysis/Solution/Paper/ChangeMinimumAllowedApiVersionSolution.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Aternos\Codex\Minecraft\Analysis\Solution\Paper; | ||
|
||
use Aternos\Codex\Minecraft\Translator\Translator; | ||
|
||
/** | ||
* Class ChangeMinimumAllowedApiVersionSolution | ||
* | ||
* @package Aternos\Codex\Minecraft\Analysis\Solution\Paper | ||
*/ | ||
class ChangeMinimumAllowedApiVersionSolution extends PaperSolution | ||
{ | ||
|
||
protected ?string $apiVersion = null; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getApiVersion(): ?string | ||
{ | ||
return $this->apiVersion; | ||
} | ||
|
||
/** | ||
* @param string $apiVersion | ||
* @return $this | ||
*/ | ||
public function setApiVersion(string $apiVersion): static | ||
{ | ||
$this->apiVersion = $apiVersion; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get the solution as a human-readable message | ||
* | ||
* @return string | ||
*/ | ||
public function getMessage(): string | ||
{ | ||
return Translator::getInstance()->getTranslation("change-minimum-api-version-solution", [ | ||
"api-version" => $this->getApiVersion() | ||
]); | ||
} | ||
} |
Oops, something went wrong.