Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Analyser/FabricAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricIncompatibleModsProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricMixinProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricModDependencyProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricModIncompatibleMinecraftVersionProblem;

class FabricAnalyser extends VanillaAnalyser
{
Expand All @@ -21,6 +22,7 @@ public function __construct()
$this->overridePossibleInsightClass(VanillaVersionInformation::class, FabricVanillaVersionInformation::class);
$this->addPossibleInsightClass(FabricJavaVersionInformation::class);
$this->addPossibleInsightClass(FabricModDependencyProblem::class);
$this->addPossibleInsightClass(FabricModIncompatibleMinecraftVersionProblem::class);
$this->addPossibleInsightClass(FabricMixinProblem::class);
$this->addPossibleInsightClass(FabricIncompatibleModsProblem::class);
$this->addPossibleInsightClass(FabricDuplicateModProblem::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Problem\Fabric;

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Information\Fabric\FabricVanillaVersionInformation;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\ServerInstallDifferentVersionSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\Forge\ModInstallDifferentVersionSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

class FabricModIncompatibleMinecraftVersionProblem extends FabricModProblem
{
protected string $minecraftVersion;

/**
* @return string
*/
public function getMinecraftVersion(): string
{
return $this->minecraftVersion;
}

/**
* @param string $minecraftVersion
* @return $this
*/
protected function setMinecraftVersion(string $minecraftVersion): static
{
$this->minecraftVersion = $minecraftVersion;
return $this;
}

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("mod-wrong-minecraft-version-problem", [
"mod-name" => $this->getModName(),
"minecraft-version" => $this->getMinecraftVersion()
]);
}

/**
* @inheritDoc
*/
public static function getPatterns(): array
{
return [
'any' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version of (?:mod )?'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
'minimum' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires version ([^ ]+) or later of (?:mod )'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
'any-after' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version after ([^ ]+) of (?:mod )?'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
'any-before' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version before ([^ ]+) of (?:mod )?'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
'specific' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires version ([^ ]+) of (?:mod )?'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
'between' => "/\s*- Mod " . static::$modNamePattern . "(?: [^ ]+)? requires any version between ([^ ]+) \((inclusive|exclusive)\) and ([^ ]+) \((inclusive|exclusive)\) of (?:mod )?'Minecraft' \(minecraft\), but only the wrong version is present: (" . FabricVanillaVersionInformation::getVersionPattern() . ")!/",
];
}

/**
* @inheritDoc
*/
public function setMatches(array $matches, mixed $patternKey): void
{
switch ($patternKey) {
case 'any':
$wrongVersion = $matches[2];
$this->setMinecraftVersion($wrongVersion);

$this->setModName($matches[1]);
$this->addSolution(new ModInstallDifferentVersionSolution($this->getModName()));
return;

case 'minimum':
$symbol = ">=";
break;

case 'any-after':
$symbol = ">";
break;

case 'any-before':
$symbol = "<";
break;

case 'between':
$wrongVersion = $matches[7];
$this->setMinecraftVersion($wrongVersion);

$this->setModName($matches[1]);

$firstSymbol = $matches[4] === "exclusive" ? ">" : ">=";
$secondSymbol = $matches[6] === "exclusive" ? "<" : "<=";
$version = $firstSymbol . $matches[3] . ", " . $secondSymbol . $matches[5];

$this->addSolution(new ServerInstallDifferentVersionSolution($version));
$this->addSolution(new ModInstallDifferentVersionSolution($this->getModName()));
return;

default:
$symbol = "";
break;
}

$wrongVersion = $matches[4];
$this->setMinecraftVersion($wrongVersion);

$this->setModName($matches[1]);
$version = $symbol . $matches[3];

$this->addSolution(new ServerInstallDifferentVersionSolution($version));
$this->addSolution(new ModInstallDifferentVersionSolution($this->getModName()));
}

/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static
&& parent::isEqual($insight)
&& $this->getMinecraftVersion() === $insight->getMinecraftVersion();
}
}
2 changes: 1 addition & 1 deletion src/Analysis/Problem/Fabric/FabricModProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class FabricModProblem extends FabricProblem
*/
protected const array MOD_NAME_REPLACEMENTS = ["fabric" => "FabricAPI"];

protected static string $modNamePattern = "(?:'([^\']+)' \((?:[^\)]+)\)|([\w-]+))";
protected static string $modNamePattern = "(?:'(?!Minecraft')([^']+)' \((?:[^\)]+)\)|([\w-]+))";
protected static string $modIDPattern = "([^ ,]+)";

protected string $modName;
Expand Down
Loading
Loading