Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper: Detect problem "Plugin API version ... is lower than the minimum allowed version. " #84

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading