diff --git a/lang/en.json b/lang/en.json index 284b352..a1a05b4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -41,6 +41,7 @@ "plugin-remove-solution": "Remove the plugin '{{plugin-name}}'.", "file-delete-solution": "Delete the file '{{file-path}}'.", "file-edit-solution": "Edit the file '{{file-path}}'.", + "folder-create-solution": "Create the folder '{{folder-path}}'.", "mod-install-different-version-solution": "Install a different version of the mod '{{mod-name}}'.", "mod-install-solution": "Install the mod '{{mod-name}}'.", "mod-install-solution-with-version": "Install the mod '{{mod-name}}' with version {{mod-version}}.", @@ -59,6 +60,7 @@ "forge-install-different-version-solution": "Install a different Forge version.", "malformed-encoding-problem": "Something (probably the MOTD) contains malformed formatting codes.", "change-motd-solution": "Change the server MOTD.", + "code-of-conduct-folder-missing-problem": "The Code of Conduct folder does not exist.", "bedrock-authentication-whitelist-problem": "Using a whitelist without online authentication is not allowed.", "bedrock-authentication-allowlist-problem": "Using an allowlist without online authentication is not allowed.", "disable-whitelist-solution": "Disable the whitelist.", diff --git a/src/Analyser/VanillaAnalyser.php b/src/Analyser/VanillaAnalyser.php index 3c341b8..3c75e02 100644 --- a/src/Analyser/VanillaAnalyser.php +++ b/src/Analyser/VanillaAnalyser.php @@ -5,6 +5,7 @@ use Aternos\Codex\Minecraft\Analysis\Information\Vanilla\VanillaVersionInformation; use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\AquaticWorldOnOlderVersionProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\AuthServerProblem; +use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\CodeOfConductFolderMissingProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\MalformedEncodingProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\OldPlayerDirectoryProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\OverworldSettingsMissingProblem; @@ -14,13 +15,13 @@ class VanillaAnalyser extends MinecraftAnalyser { public function __construct() { - $this->addPossibleInsightClass(VanillaVersionInformation::class); - - $this->addPossibleInsightClass(OldPlayerDirectoryProblem::class); $this->addPossibleInsightClass(AquaticWorldOnOlderVersionProblem::class); - $this->addPossibleInsightClass(TickingBlockEntityProblem::class); - $this->addPossibleInsightClass(MalformedEncodingProblem::class); $this->addPossibleInsightClass(AuthServerProblem::class); + $this->addPossibleInsightClass(CodeOfConductFolderMissingProblem::class); + $this->addPossibleInsightClass(MalformedEncodingProblem::class); + $this->addPossibleInsightClass(OldPlayerDirectoryProblem::class); $this->addPossibleInsightClass(OverworldSettingsMissingProblem::class); + $this->addPossibleInsightClass(TickingBlockEntityProblem::class); + $this->addPossibleInsightClass(VanillaVersionInformation::class); } -} \ No newline at end of file +} diff --git a/src/Analysis/Problem/Fabric/FabricDuplicateModProblem.php b/src/Analysis/Problem/Fabric/FabricDuplicateModProblem.php index 617e29a..7e052aa 100644 --- a/src/Analysis/Problem/Fabric/FabricDuplicateModProblem.php +++ b/src/Analysis/Problem/Fabric/FabricDuplicateModProblem.php @@ -35,4 +35,4 @@ public function setMatches(array $matches, mixed $patternKey): void $this->setModName($matches[3]); $this->addSolution(new FileDeleteSolution($matches[4], FilePathType::ABSOLUTE)); } -} \ No newline at end of file +} diff --git a/src/Analysis/Problem/Vanilla/CodeOfConductFolderMissingProblem.php b/src/Analysis/Problem/Vanilla/CodeOfConductFolderMissingProblem.php new file mode 100644 index 0000000..8c5b0a9 --- /dev/null +++ b/src/Analysis/Problem/Vanilla/CodeOfConductFolderMissingProblem.php @@ -0,0 +1,37 @@ +getTranslation("code-of-conduct-folder-missing-problem"); + } + + /** + * @inheritDoc + */ + public static function getPatterns(): array + { + return [ + '/Failed to start the minecraft server\njava\.lang\.IllegalArgumentException\: Code of Conduct folder does not exist: (.*)/' + ]; + } + + /** + * @inheritDoc + */ + public function setMatches(array $matches, mixed $patternKey): void + { + // usually "codeofconduct" + $folder = $matches[1]; + $this->addSolution(new FolderCreateSolution($folder)); + } +} diff --git a/src/Analysis/Solution/Bukkit/Plugin/AuthMeShutdownSolution.php b/src/Analysis/Solution/Bukkit/Plugin/AuthMeShutdownSolution.php index 6b02771..490171f 100644 --- a/src/Analysis/Solution/Bukkit/Plugin/AuthMeShutdownSolution.php +++ b/src/Analysis/Solution/Bukkit/Plugin/AuthMeShutdownSolution.php @@ -25,4 +25,4 @@ public function getMessage(): string { return parent::getMessage() . " " . Translator::getInstance()->getTranslation("authme-shutdown-solution"); } -} \ No newline at end of file +} diff --git a/src/Analysis/Solution/File/FileEditSolution.php b/src/Analysis/Solution/File/FileEditSolution.php index b6ecf59..e579c35 100644 --- a/src/Analysis/Solution/File/FileEditSolution.php +++ b/src/Analysis/Solution/File/FileEditSolution.php @@ -79,4 +79,4 @@ public function processEdit(string $fileContent): ?string { return preg_replace($this->getPattern(), $this->getReplacement(), $fileContent); } -} \ No newline at end of file +} diff --git a/src/Analysis/Solution/File/FilePathType.php b/src/Analysis/Solution/File/FilePathType.php index e4c07fb..8e6a4f0 100644 --- a/src/Analysis/Solution/File/FilePathType.php +++ b/src/Analysis/Solution/File/FilePathType.php @@ -6,4 +6,4 @@ enum FilePathType { case RELATIVE; case ABSOLUTE; -} \ No newline at end of file +} diff --git a/src/Analysis/Solution/File/FileSolution.php b/src/Analysis/Solution/File/FileSolution.php index e801582..ee33d49 100644 --- a/src/Analysis/Solution/File/FileSolution.php +++ b/src/Analysis/Solution/File/FileSolution.php @@ -86,4 +86,4 @@ public function isAbsolutePath(): bool { return $this->getType() === FilePathType::ABSOLUTE; } -} \ No newline at end of file +} diff --git a/src/Analysis/Solution/Folder/FolderCreateSolution.php b/src/Analysis/Solution/Folder/FolderCreateSolution.php new file mode 100644 index 0000000..d8093e6 --- /dev/null +++ b/src/Analysis/Solution/Folder/FolderCreateSolution.php @@ -0,0 +1,17 @@ +getTranslation("folder-create-solution", ["folder-path" => $this->getPath()]); + } +} diff --git a/src/Analysis/Solution/Folder/FolderSolution.php b/src/Analysis/Solution/Folder/FolderSolution.php new file mode 100644 index 0000000..e6803c9 --- /dev/null +++ b/src/Analysis/Solution/Folder/FolderSolution.php @@ -0,0 +1,90 @@ +path = $path; + $this->type = FilePathType::RELATIVE; + return $this; + } + + /** + * Set the absolute path + * + * @param string $path + * @return $this + */ + public function setAbsolutePath(string $path): static + { + $this->path = $path; + $this->type = FilePathType::ABSOLUTE; + return $this; + } + + /** + * Get the path + * If isRelative() the path is relative to the Minecraft server root directory without a starting slash + * + * @return string + */ + public function getPath(): string + { + return $this->path; + } + + /** + * Get the type of the path (absolute or relative) + * + * @return FilePathType + */ + public function getType(): FilePathType + { + return $this->type; + } + + /** + * Check if the path is relative + * The path is relative to the Minecraft server root directory without a starting slash + * + * @return bool + */ + public function isRelative(): bool + { + return $this->getType() === FilePathType::RELATIVE; + } + + /** + * Check if the path is absolute + * + * @return bool + */ + public function isAbsolutePath(): bool + { + return $this->getType() === FilePathType::ABSOLUTE; + } +} diff --git a/test/data/Vanilla/vanilla-code-of-conduct.json b/test/data/Vanilla/vanilla-code-of-conduct.json new file mode 100644 index 0000000..ef186ef --- /dev/null +++ b/test/data/Vanilla/vanilla-code-of-conduct.json @@ -0,0 +1,150 @@ +{ + "id": "vanilla\/server", + "name": "Vanilla", + "type": "Server Log", + "version": null, + "title": "Vanilla Server Log", + "entries": [ + { + "level": 6, + "time": null, + "prefix": "[14:20:38] [ServerMain\/INFO]:", + "lines": [ + { + "number": 1, + "content": "[14:20:38] [ServerMain\/INFO]: Environment: Environment[sessionHost=https:\/\/sessionserver.mojang.com, servicesHost=https:\/\/api.minecraftservices.com, profilesHost=https:\/\/api.mojang.com, name=PROD]" + } + ] + }, + { + "level": 6, + "time": null, + "prefix": "[14:20:41] [ServerMain\/INFO]:", + "lines": [ + { + "number": 2, + "content": "[14:20:41] [ServerMain\/INFO]: Loaded 1461 recipes" + } + ] + }, + { + "level": 6, + "time": null, + "prefix": "[14:20:41] [ServerMain\/INFO]:", + "lines": [ + { + "number": 3, + "content": "[14:20:41] [ServerMain\/INFO]: Loaded 1574 advancements" + } + ] + }, + { + "level": 3, + "time": null, + "prefix": "[14:20:41] [ServerMain\/ERROR]:", + "lines": [ + { + "number": 4, + "content": "[14:20:41] [ServerMain\/ERROR]: Failed to start the minecraft server" + }, + { + "number": 5, + "content": "java.lang.IllegalArgumentException: Code of Conduct folder does not exist: codeofconduct" + }, + { + "number": 6, + "content": "\tat aro.bU(SourceFile:119) ~[server-1.21.10.jar:?]" + }, + { + "number": 7, + "content": "\tat aro.(SourceFile:110) ~[server-1.21.10.jar:?]" + }, + { + "number": 8, + "content": "\tat net.minecraft.server.Main.a(SourceFile:221) ~[server-1.21.10.jar:?]" + }, + { + "number": 9, + "content": "\tat net.minecraft.server.MinecraftServer.a(SourceFile:304) ~[server-1.21.10.jar:?]" + }, + { + "number": 10, + "content": "\tat net.minecraft.server.Main.main(SourceFile:220) ~[server-1.21.10.jar:?]" + }, + { + "number": 11, + "content": "\tat net.minecraft.bundler.Main.lambda$run$0(Main.java:54) ~[?:?]" + }, + { + "number": 12, + "content": "\tat java.base\/java.lang.Thread.run(Thread.java:1583) [?:?]" + }, + { + "number": 13, + "content": "" + } + ] + } + ], + "analysis": { + "problems": [ + { + "message": "The Code of Conduct folder does not exist.", + "counter": 1, + "entry": { + "level": 3, + "time": null, + "prefix": "[14:20:41] [ServerMain\/ERROR]:", + "lines": [ + { + "number": 4, + "content": "[14:20:41] [ServerMain\/ERROR]: Failed to start the minecraft server" + }, + { + "number": 5, + "content": "java.lang.IllegalArgumentException: Code of Conduct folder does not exist: codeofconduct" + }, + { + "number": 6, + "content": "\tat aro.bU(SourceFile:119) ~[server-1.21.10.jar:?]" + }, + { + "number": 7, + "content": "\tat aro.(SourceFile:110) ~[server-1.21.10.jar:?]" + }, + { + "number": 8, + "content": "\tat net.minecraft.server.Main.a(SourceFile:221) ~[server-1.21.10.jar:?]" + }, + { + "number": 9, + "content": "\tat net.minecraft.server.MinecraftServer.a(SourceFile:304) ~[server-1.21.10.jar:?]" + }, + { + "number": 10, + "content": "\tat net.minecraft.server.Main.main(SourceFile:220) ~[server-1.21.10.jar:?]" + }, + { + "number": 11, + "content": "\tat net.minecraft.bundler.Main.lambda$run$0(Main.java:54) ~[?:?]" + }, + { + "number": 12, + "content": "\tat java.base\/java.lang.Thread.run(Thread.java:1583) [?:?]" + }, + { + "number": 13, + "content": "" + } + ] + }, + "solutions": [ + { + "message": "Create the folder 'codeofconduct'." + } + ] + } + ], + "information": [] + } +} \ No newline at end of file diff --git a/test/data/Vanilla/vanilla-code-of-conduct.log b/test/data/Vanilla/vanilla-code-of-conduct.log new file mode 100644 index 0000000..dd8a61e --- /dev/null +++ b/test/data/Vanilla/vanilla-code-of-conduct.log @@ -0,0 +1,12 @@ +[14:20:38] [ServerMain/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, profilesHost=https://api.mojang.com, name=PROD] +[14:20:41] [ServerMain/INFO]: Loaded 1461 recipes +[14:20:41] [ServerMain/INFO]: Loaded 1574 advancements +[14:20:41] [ServerMain/ERROR]: Failed to start the minecraft server +java.lang.IllegalArgumentException: Code of Conduct folder does not exist: codeofconduct + at aro.bU(SourceFile:119) ~[server-1.21.10.jar:?] + at aro.(SourceFile:110) ~[server-1.21.10.jar:?] + at net.minecraft.server.Main.a(SourceFile:221) ~[server-1.21.10.jar:?] + at net.minecraft.server.MinecraftServer.a(SourceFile:304) ~[server-1.21.10.jar:?] + at net.minecraft.server.Main.main(SourceFile:220) ~[server-1.21.10.jar:?] + at net.minecraft.bundler.Main.lambda$run$0(Main.java:54) ~[?:?] + at java.base/java.lang.Thread.run(Thread.java:1583) [?:?] diff --git a/test/tests/Logs/AutoLogsTest.php b/test/tests/Logs/AutoLogsTest.php index 22aef32..f748e23 100644 --- a/test/tests/Logs/AutoLogsTest.php +++ b/test/tests/Logs/AutoLogsTest.php @@ -1754,6 +1754,16 @@ public function test_vanilla_client_1_19_2(): void $this->assertStringEqualsFile($log->getExpectedPath(), $log->getOutput(), $log->getLogPath()); } + /** + * @return void + * @throws Exception + */ + public function test_vanilla_code_of_conduct(): void + { + $log = new TestLog('Vanilla/vanilla-code-of-conduct.log'); + $this->assertStringEqualsFile($log->getExpectedPath(), $log->getOutput(), $log->getLogPath()); + } + /** * @return void * @throws Exception