Skip to content
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
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@
"paper-world-config-reset-solution": "Back up and delete the file 'paper-world.yml' of the world '{{world-name}}'. Paper creates it again with default settings.",
"paper-install-newer-version-solution": "Install the newer Paper version that created this config file.",
"mod-fabric-loader-version-problem": "The mod '{{mod-name}}' requires Fabric Loader version {{loader-version}} or later, but version {{installed-version}} is installed.",
"fabric-loader-update-solution": "Update Fabric Loader to version {{loader-version}} or later."
"fabric-loader-update-solution": "Update Fabric Loader to version {{loader-version}} or later.",
"paper-config-not-writable-problem": "The configuration file '{{path}}' could not be saved. Settings missing from the file use their default values."
}
2 changes: 2 additions & 0 deletions src/Analyser/PaperAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\CircularPluginDependencyProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\RestrictedPluginNameProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\NewerConfigVersionProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\ConfigNotWritableProblem;

class PaperAnalyser extends BukkitAnalyser
{
Expand All @@ -36,5 +37,6 @@ public function __construct()
$this->addPossibleInsightClass(CircularPluginDependencyProblem::class);
$this->addPossibleInsightClass(RestrictedPluginNameProblem::class);
$this->addPossibleInsightClass(NewerConfigVersionProblem::class);
$this->addPossibleInsightClass(ConfigNotWritableProblem::class);
}
}
68 changes: 68 additions & 0 deletions src/Analysis/Problem/Paper/ConfigNotWritableProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

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

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Paper\PaperCheckPermissionsSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

/**
* Paper could not save one of its configuration files because access was denied.
* Settings that are missing from the file only exist in memory with their default values.
*
* Paper only logs this message for an AccessDeniedException, other save errors are thrown instead.
*/
class ConfigNotWritableProblem extends PaperProblem
{
protected string $path;

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("paper-config-not-writable-problem", [
"path" => $this->path
]);
}

/**
* Matches the warning Paper logs when saving a configuration file fails, for example:
* [16:52:55 WARN]: [Configurations] Could not save config/paper-global.yml: Paper could not persist the full set of configuration settings in the configuration file.
*
* @inheritDoc
*/
public static function getPatterns(): array
{
return ['/Could not save (?<path>[^:\n]+): Paper could not persist the full set of configuration settings/'];
}

/**
* @inheritDoc
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->path = $matches["path"];
// Configurate saves atomically through a temporary file next to the configuration file,
// so the file and its folder both need to be writable.
$this->addSolution(new PaperCheckPermissionsSolution($this->path));
}

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

/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static
&& $this->getPath() === $insight->getPath();
}
}
Loading
Loading