Skip to content

Commit bd706d4

Browse files
authored
Merge pull request #128 from aternosorg/code-of-conduct-folder-missing-problem
Add `CodeOfConductFolderMissingProblem` and `FolderCreateSolution`
2 parents 6af70c0 + 505ab39 commit bd706d4

File tree

13 files changed

+330
-11
lines changed

13 files changed

+330
-11
lines changed

lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"plugin-remove-solution": "Remove the plugin '{{plugin-name}}'.",
4242
"file-delete-solution": "Delete the file '{{file-path}}'.",
4343
"file-edit-solution": "Edit the file '{{file-path}}'.",
44+
"folder-create-solution": "Create the folder '{{folder-path}}'.",
4445
"mod-install-different-version-solution": "Install a different version of the mod '{{mod-name}}'.",
4546
"mod-install-solution": "Install the mod '{{mod-name}}'.",
4647
"mod-install-solution-with-version": "Install the mod '{{mod-name}}' with version {{mod-version}}.",
@@ -59,6 +60,7 @@
5960
"forge-install-different-version-solution": "Install a different Forge version.",
6061
"malformed-encoding-problem": "Something (probably the MOTD) contains malformed formatting codes.",
6162
"change-motd-solution": "Change the server MOTD.",
63+
"code-of-conduct-folder-missing-problem": "The Code of Conduct folder does not exist.",
6264
"bedrock-authentication-whitelist-problem": "Using a whitelist without online authentication is not allowed.",
6365
"bedrock-authentication-allowlist-problem": "Using an allowlist without online authentication is not allowed.",
6466
"disable-whitelist-solution": "Disable the whitelist.",

src/Analyser/VanillaAnalyser.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Aternos\Codex\Minecraft\Analysis\Information\Vanilla\VanillaVersionInformation;
66
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\AquaticWorldOnOlderVersionProblem;
77
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\AuthServerProblem;
8+
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\CodeOfConductFolderMissingProblem;
89
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\MalformedEncodingProblem;
910
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\OldPlayerDirectoryProblem;
1011
use Aternos\Codex\Minecraft\Analysis\Problem\Vanilla\OverworldSettingsMissingProblem;
@@ -14,13 +15,13 @@ class VanillaAnalyser extends MinecraftAnalyser
1415
{
1516
public function __construct()
1617
{
17-
$this->addPossibleInsightClass(VanillaVersionInformation::class);
18-
19-
$this->addPossibleInsightClass(OldPlayerDirectoryProblem::class);
2018
$this->addPossibleInsightClass(AquaticWorldOnOlderVersionProblem::class);
21-
$this->addPossibleInsightClass(TickingBlockEntityProblem::class);
22-
$this->addPossibleInsightClass(MalformedEncodingProblem::class);
2319
$this->addPossibleInsightClass(AuthServerProblem::class);
20+
$this->addPossibleInsightClass(CodeOfConductFolderMissingProblem::class);
21+
$this->addPossibleInsightClass(MalformedEncodingProblem::class);
22+
$this->addPossibleInsightClass(OldPlayerDirectoryProblem::class);
2423
$this->addPossibleInsightClass(OverworldSettingsMissingProblem::class);
24+
$this->addPossibleInsightClass(TickingBlockEntityProblem::class);
25+
$this->addPossibleInsightClass(VanillaVersionInformation::class);
2526
}
26-
}
27+
}

src/Analysis/Problem/Fabric/FabricDuplicateModProblem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public function setMatches(array $matches, mixed $patternKey): void
3535
$this->setModName($matches[3]);
3636
$this->addSolution(new FileDeleteSolution($matches[4], FilePathType::ABSOLUTE));
3737
}
38-
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Aternos\Codex\Minecraft\Analysis\Problem\Vanilla;
4+
5+
use Aternos\Codex\Minecraft\Analysis\Solution\Folder\FolderCreateSolution;
6+
use Aternos\Codex\Minecraft\Translator\Translator;
7+
8+
class CodeOfConductFolderMissingProblem extends VanillaProblem
9+
{
10+
/**
11+
* @inheritDoc
12+
*/
13+
public function getMessage(): string
14+
{
15+
return Translator::getInstance()->getTranslation("code-of-conduct-folder-missing-problem");
16+
}
17+
18+
/**
19+
* @inheritDoc
20+
*/
21+
public static function getPatterns(): array
22+
{
23+
return [
24+
'/Failed to start the minecraft server\njava\.lang\.IllegalArgumentException\: Code of Conduct folder does not exist: (.*)/'
25+
];
26+
}
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
public function setMatches(array $matches, mixed $patternKey): void
32+
{
33+
// usually "codeofconduct"
34+
$folder = $matches[1];
35+
$this->addSolution(new FolderCreateSolution($folder));
36+
}
37+
}

src/Analysis/Solution/Bukkit/Plugin/AuthMeShutdownSolution.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ public function getMessage(): string
2525
{
2626
return parent::getMessage() . " " . Translator::getInstance()->getTranslation("authme-shutdown-solution");
2727
}
28-
}
28+
}

src/Analysis/Solution/File/FileEditSolution.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ public function processEdit(string $fileContent): ?string
7979
{
8080
return preg_replace($this->getPattern(), $this->getReplacement(), $fileContent);
8181
}
82-
}
82+
}

src/Analysis/Solution/File/FilePathType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ enum FilePathType
66
{
77
case RELATIVE;
88
case ABSOLUTE;
9-
}
9+
}

src/Analysis/Solution/File/FileSolution.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ public function isAbsolutePath(): bool
8686
{
8787
return $this->getType() === FilePathType::ABSOLUTE;
8888
}
89-
}
89+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Aternos\Codex\Minecraft\Analysis\Solution\Folder;
4+
5+
use Aternos\Codex\Analysis\AutomatableSolutionInterface;
6+
use Aternos\Codex\Minecraft\Translator\Translator;
7+
8+
class FolderCreateSolution extends FolderSolution implements AutomatableSolutionInterface
9+
{
10+
/**
11+
* @inheritDoc
12+
*/
13+
public function getMessage(): string
14+
{
15+
return Translator::getInstance()->getTranslation("folder-create-solution", ["folder-path" => $this->getPath()]);
16+
}
17+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Aternos\Codex\Minecraft\Analysis\Solution\Folder;
4+
5+
use Aternos\Codex\Minecraft\Analysis\Solution\File\FilePathType;
6+
use Aternos\Codex\Minecraft\Analysis\Solution\MinecraftSolution;
7+
8+
abstract class FolderSolution extends MinecraftSolution
9+
{
10+
/**
11+
* @param string $path The relative path (without a starting slash) or absolute path to the folder.
12+
* If the path is relative, it will be treated as relative to the Minecraft server root directory.
13+
* @param FilePathType $type Is the path relative or absolute?
14+
*/
15+
public function __construct(
16+
protected string $path,
17+
protected FilePathType $type = FilePathType::RELATIVE
18+
)
19+
{
20+
}
21+
22+
/**
23+
* Set the relative path
24+
* The path is relative to the Minecraft server root directory without a starting slash
25+
*
26+
* @param string $path
27+
* @return $this
28+
*/
29+
public function setRelativePath(string $path): static
30+
{
31+
$this->path = $path;
32+
$this->type = FilePathType::RELATIVE;
33+
return $this;
34+
}
35+
36+
/**
37+
* Set the absolute path
38+
*
39+
* @param string $path
40+
* @return $this
41+
*/
42+
public function setAbsolutePath(string $path): static
43+
{
44+
$this->path = $path;
45+
$this->type = FilePathType::ABSOLUTE;
46+
return $this;
47+
}
48+
49+
/**
50+
* Get the path
51+
* If isRelative() the path is relative to the Minecraft server root directory without a starting slash
52+
*
53+
* @return string
54+
*/
55+
public function getPath(): string
56+
{
57+
return $this->path;
58+
}
59+
60+
/**
61+
* Get the type of the path (absolute or relative)
62+
*
63+
* @return FilePathType
64+
*/
65+
public function getType(): FilePathType
66+
{
67+
return $this->type;
68+
}
69+
70+
/**
71+
* Check if the path is relative
72+
* The path is relative to the Minecraft server root directory without a starting slash
73+
*
74+
* @return bool
75+
*/
76+
public function isRelative(): bool
77+
{
78+
return $this->getType() === FilePathType::RELATIVE;
79+
}
80+
81+
/**
82+
* Check if the path is absolute
83+
*
84+
* @return bool
85+
*/
86+
public function isAbsolutePath(): bool
87+
{
88+
return $this->getType() === FilePathType::ABSOLUTE;
89+
}
90+
}

0 commit comments

Comments
 (0)