Skip to content

Commit 50ea1f9

Browse files
committed
add InvalidDistDedicatedServerProblem
1 parent e302ead commit 50ea1f9

File tree

8 files changed

+1630
-0
lines changed

8 files changed

+1630
-0
lines changed

lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"mod-duplicate-problem-no-path": "There are multiple mod files for the mod name '{{mod-name}}'.",
2828
"mod-exception-problem": "The mod '{{mod-name}}' has thrown an exception.",
2929
"mod-fatal-problem": "The mod '{{mod-name}}' has a fatal error.",
30+
"mod-invalid-dist-dedicated-server-problem": "The mod '{{mod-name}}' tries to load clientside features on a dedicated server. It is probably a clientside only mod.",
3031
"world-missing-mod-problem": "The world was saved with mod '{{mod-name}}' which appears to be missing.",
3132
"world-mod-version-problem": "This world was saved with mod '{{mod-name}}' version {{mod-expected-version}} and it is now at version {{mod-current-version}}.",
3233
"plugin-incompatible-problem": "The plugin '{{plugin-name}}' is incompatible with your current server version.",

src/Analyser/NeoForgeAnalyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Aternos\Codex\Minecraft\Analysis\Information\NeoForge\NeoForgeVanillaVersionInformation;
77
use Aternos\Codex\Minecraft\Analysis\Information\NeoForge\NeoForgeVersionInformation;
88
use Aternos\Codex\Minecraft\Analysis\Information\Vanilla\VanillaVersionInformation;
9+
use Aternos\Codex\Minecraft\Analysis\Problem\Forge\InvalidDistDedicatedServerProblem;
910

1011
class NeoForgeAnalyser extends VanillaAnalyser
1112
{
@@ -15,5 +16,6 @@ public function __construct()
1516
$this->addPossibleInsightClass(NeoForgeVersionInformation::class);
1617
$this->overridePossibleInsightClass(VanillaVersionInformation::class, NeoForgeVanillaVersionInformation::class);
1718
$this->addPossibleInsightClass(NeoForgeJavaVersionInformation::class);
19+
$this->addPossibleInsightClass(InvalidDistDedicatedServerProblem::class);
1820
}
1921
}

src/Analyser/Report/CrashReport/ForgeCrashReportAnalyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Aternos\Codex\Minecraft\Analyser\Report\CrashReport;
44

55
use Aternos\Codex\Minecraft\Analysis\Information\Forge\CrashReport\ForgeVersionInformation;
6+
use Aternos\Codex\Minecraft\Analysis\Problem\Forge\InvalidDistDedicatedServerProblem;
67

78
/**
89
* Class ForgeCrashReportAnalyser
@@ -15,5 +16,6 @@ public function __construct()
1516
{
1617
parent::__construct();
1718
$this->addPossibleInsightClass(ForgeVersionInformation::class);
19+
$this->addPossibleInsightClass(InvalidDistDedicatedServerProblem::class);
1820
}
1921
}

src/Analyser/Report/CrashReport/NeoForgeCrashReportAnalyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace Aternos\Codex\Minecraft\Analyser\Report\CrashReport;
44

55
use Aternos\Codex\Minecraft\Analysis\Information\NeoForge\NeoForgeVersionInformation;
6+
use Aternos\Codex\Minecraft\Analysis\Problem\Forge\InvalidDistDedicatedServerProblem;
67

78
class NeoForgeCrashReportAnalyser extends MinecraftCrashReportAnalyser
89
{
910
public function __construct()
1011
{
1112
parent::__construct();
1213
$this->addPossibleInsightClass(NeoForgeVersionInformation::class);
14+
$this->addPossibleInsightClass(InvalidDistDedicatedServerProblem::class);
1315
}
1416
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Aternos\Codex\Minecraft\Analysis\Problem\Forge;
4+
5+
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
6+
use Aternos\Codex\Minecraft\Analysis\Solution\Forge\ModInstallDifferentVersionSolution;
7+
use Aternos\Codex\Minecraft\Translator\Translator;
8+
9+
class InvalidDistDedicatedServerProblem extends ModProblem
10+
{
11+
protected ?string $modFileName = null;
12+
protected ?string $modVersion = null;
13+
protected ?string $modId = null;
14+
15+
/**
16+
* Get a human-readable message
17+
*
18+
* @return string
19+
*/
20+
public function getMessage(): string
21+
{
22+
return Translator::getInstance()->getTranslation("mod-invalid-dist-dedicated-server-problem", ["mod-name" => $this->getModName()]);
23+
}
24+
25+
/**
26+
* Get an array of possible patterns
27+
*
28+
* The array key of the pattern will be passed to setMatches()
29+
*
30+
* @return string[]
31+
*/
32+
public static function getPatterns(): array
33+
{
34+
return [
35+
'/^\s*Mod file: (.*)'
36+
. '\n\s*Failure message: ([^\(\n]+) \(([^\)]+)\) has failed to load correctly'
37+
. '\n\s*java\.lang\.BootstrapMethodError: java\.lang\.RuntimeException: '
38+
. 'Attempted to load class [\w\/]+ for invalid dist DEDICATED_SERVER'
39+
. '\n\s*Mod version: (.*)/'
40+
];
41+
}
42+
43+
/**
44+
* Apply the matches from the pattern
45+
*
46+
* @param array $matches
47+
* @param mixed $patternKey
48+
* @return void
49+
*/
50+
public function setMatches(array $matches, mixed $patternKey): void
51+
{
52+
$this->modFileName = $matches[1];
53+
$this->modName = $matches[2];
54+
$this->modId = $matches[3];
55+
$this->modVersion = $matches[4];
56+
57+
$this->addSolution((new FileDeleteSolution())->setRelativePath("mods/" . $this->getModFileName()));
58+
$this->addSolution((new ModInstallDifferentVersionSolution())->setModName($this->getModName()));
59+
}
60+
61+
/**
62+
* @return string|null
63+
*/
64+
public function getModFileName(): ?string
65+
{
66+
return $this->modFileName;
67+
}
68+
69+
/**
70+
* @return string|null
71+
*/
72+
public function getModVersion(): ?string
73+
{
74+
return $this->modVersion;
75+
}
76+
77+
/**
78+
* @return string|null
79+
*/
80+
public function getModId(): ?string
81+
{
82+
return $this->modId;
83+
}
84+
}

0 commit comments

Comments
 (0)