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
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@
"event-listener-missing-class-problem": "The plugin '{{plugin-name}}' could not register the event listener '{{listener}}', because the class '{{missing-class}}' it references does not exist.",
"client-only-mod-problem": "The mod '{{mod-name}}' cannot run on a server. It is either a client-only mod or uses client-only code.",
"circular-plugin-dependency-problem": "Circular plugin dependencies detected: {{cycle}}.",
"restricted-plugin-name-problem": "A plugin has a name that is not allowed."
"restricted-plugin-name-problem": "A plugin has a name that is not allowed.",
"paper-world-defaults-missing-problem": "The file '{{path}}' with the default world settings does not exist. Paper cannot load new worlds without it.",
"paper-world-defaults-restore-solution": "Restore the file '{{path}}' from a backup or restart the server to create it again with default values."
}
2 changes: 2 additions & 0 deletions src/Analyser/PaperAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\EventListenerMissingClassProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\CircularPluginDependencyProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\RestrictedPluginNameProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Paper\WorldDefaultsMissingProblem;

class PaperAnalyser extends BukkitAnalyser
{
Expand All @@ -34,5 +35,6 @@ public function __construct()
$this->addPossibleInsightClass(EventListenerMissingClassProblem::class);
$this->addPossibleInsightClass(CircularPluginDependencyProblem::class);
$this->addPossibleInsightClass(RestrictedPluginNameProblem::class);
$this->addPossibleInsightClass(WorldDefaultsMissingProblem::class);
}
}
9 changes: 8 additions & 1 deletion src/Analysis/Problem/Bukkit/PluginRuntimeProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Aternos\Codex\Minecraft\Analysis\Problem\Paper\WorldDefaultsMissingProblem;
use Aternos\Codex\Minecraft\Translator\Translator;

class PluginRuntimeProblem extends PluginProblem
Expand All @@ -15,13 +16,19 @@ public function getMessage(): string
}

/**
* Matches exceptions in event handlers and scheduled tasks of a plugin, for example:
* Task #15 for Multiverse-Core v4.3.1 generated an exception
*
* Tasks that fail because Paper's world defaults file is missing are skipped,
* because {@see WorldDefaultsMissingProblem} reports the actual cause.
*
* @inheritDoc
*/
public static function getPatterns(): array
{
return [
'/Could not pass event \w+ to (' . static::PLUGIN_NAME . ') .*/',
'/Task \S+ for (' . static::PLUGIN_NAME . ') \S+ generated an exception/'
'/Task \S+ for (' . static::PLUGIN_NAME . ') \S+ generated an exception(?!\n' . WorldDefaultsMissingProblem::EXCEPTION . ')/'
];
}
}
74 changes: 74 additions & 0 deletions src/Analysis/Problem/Paper/WorldDefaultsMissingProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

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

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

/**
* Paper could not create the configuration of a world, because config/paper-world-defaults.yml does not exist.
*
* Paper creates the file on startup and on /paper reload, so it is usually missing because it was
* removed while the server was running, and a plugin then created a new world.
*/
class WorldDefaultsMissingProblem extends PaperProblem
{
/**
* Start of the exception Paper throws when the world defaults file is missing, for example:
* java.lang.IllegalStateException: World defaults configuration file 'config/paper-world-defaults.yml' doesn't exist
*
* Used to keep generic plugin problems from reporting the plugin that created the world.
*/
public const string EXCEPTION = "java\.lang\.IllegalStateException: World defaults configuration file '";

protected string $path;

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

/**
* Matches the exception Paper throws when it creates a world configuration without the defaults file, for example:
* java.lang.IllegalStateException: World defaults configuration file 'config/paper-world-defaults.yml' doesn't exist
*
* @inheritDoc
*/
public static function getPatterns(): array
{
return ["/World defaults configuration file '(?<path>[^'\n]+)' doesn't exist/"];
}

/**
* @inheritDoc
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->path = $matches["path"];
$this->addSolution(new WorldDefaultsRestoreSolution($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();
}
}
37 changes: 37 additions & 0 deletions src/Analysis/Solution/Paper/WorldDefaultsRestoreSolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

use Aternos\Codex\Minecraft\Translator\Translator;

/**
* Restore the missing world defaults file, either from a backup or by restarting the server,
* which creates it again with default values.
*/
class WorldDefaultsRestoreSolution extends PaperSolution
{
/**
* @param string $path
*/
public function __construct(protected string $path)
{
}

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("paper-world-defaults-restore-solution", [
"path" => $this->path
]);
}

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