Skip to content

Commit

Permalink
Merge pull request #84 from pavog/paper-plugin-api-version-lower-than…
Browse files Browse the repository at this point in the history
…-allowed

Paper: Detect problem "Plugin API version ... is lower than the minimum allowed version. "
  • Loading branch information
matthi4s authored Jul 8, 2024
2 parents 2a3946a + eeb99c9 commit 44e1fa2
Show file tree
Hide file tree
Showing 7 changed files with 696 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@
"type-crash-report": "Crash Report",
"type-network-protocol-error-report": "Network Protocol Error Report",
"type-unknown": "Unknown Log",
"forge-language-provider-version-problem": "The mod '{{mod-file}}' requires '{{required-version}}', but '{{found-version}}' is installed."
"forge-language-provider-version-problem": "The mod '{{mod-file}}' requires '{{required-version}}', but '{{found-version}}' is installed.",
"plugin-api-version-lower-than-allowed-problem": "The plugin '{{plugin-name}}' has an API version specified that is lower than the minimum allowed version.",
"change-minimum-api-version-solution": "Change 'minimum-api' in bukkit.yml to {{api-version}}, lower or even 'none'."
}
2 changes: 2 additions & 0 deletions src/Analyser/PaperAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Aternos\Codex\Minecraft\Analyser;

use Aternos\Codex\Minecraft\Analysis\Problem\Paper\ApiVersionLowerThanAllowedProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\VersionDowngradeProblem;

/**
Expand All @@ -15,5 +16,6 @@ public function __construct()
{
parent::__construct();
$this->addPossibleInsightClass(VersionDowngradeProblem::class);
$this->addPossibleInsightClass(ApiVersionLowerThanAllowedProblem::class);
}
}
71 changes: 71 additions & 0 deletions src/Analysis/Problem/Paper/ApiVersionLowerThanAllowedProblem.php
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;
}
}
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()
]);
}
}
Loading

0 comments on commit 44e1fa2

Please sign in to comment.