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
17 changes: 12 additions & 5 deletions src/Log/Minecraft/Vanilla/Bukkit/CraftBukkit/CraftBukkitLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

namespace Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit\CraftBukkit;

use Aternos\Codex\Detective\SinglePatternDetector;
use Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit\BukkitLog;
use Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit\VersionLineDetectorTrait;

abstract class CraftBukkitLog extends BukkitLog
{
protected static string $logIdentifier = "CraftBukkit version git-Bukkit";
use VersionLineDetectorTrait;

/**
* Patterns for the server version that follows "This server is running " in the startup line,
* each one gets its own detector, e.g.
* [18:14:48] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-8b1588e (MC: 1.13.2)
*
* @var string[]
*/
protected static array $logIdentifiers = ["CraftBukkit version git-Bukkit"];

/**
* @inheritDoc
*/
public static function getDetectors(): array
{
return array_merge(parent::getDetectors(), [
(new SinglePatternDetector())->setPattern('/' . static::$prefixPattern . 'This server is running ' . static::$logIdentifier . '/')
]);
return [...parent::getDetectors(), ...static::getVersionLineDetectors()];
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/Log/Minecraft/Vanilla/Bukkit/CraftBukkit/OldCraftBukkitLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

namespace Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit\CraftBukkit;

use Aternos\Codex\Detective\SinglePatternDetector;
use Aternos\Codex\Minecraft\Analyser\BukkitAnalyser;
use Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit\VersionLineDetectorTrait;
use Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\OldVanillaLog;

abstract class OldCraftBukkitLog extends OldVanillaLog
{
protected static string $logIdentifier = "CraftBukkit version git-Bukkit";
use VersionLineDetectorTrait;

/**
* Patterns for the server version that follows "This server is running " in the startup line,
* each one gets its own detector, e.g.
* 2019-02-08 23:33:20 [INFO] This server is running CraftBukkit version git-Bukkit-1.1-R6-b1988jnks (MC: 1.1)
*
* @var string[]
*/
protected static array $logIdentifiers = ["CraftBukkit version git-Bukkit"];

/**
* @return BukkitAnalyser
Expand All @@ -23,9 +32,7 @@ public static function getDefaultAnalyser(): BukkitAnalyser
*/
public static function getDetectors(): array
{
return array_merge(parent::getDetectors(), [
(new SinglePatternDetector())->setPattern('/' . static::$prefixPattern . 'This server is running ' . static::$logIdentifier . '/')
]);
return [...parent::getDetectors(), ...static::getVersionLineDetectors()];
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/Log/Minecraft/Vanilla/Bukkit/Folia/FoliaLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@

abstract class FoliaLog extends PaperLog
{
protected static string $logIdentifier = "(?:Folia|CraftBukkit) version git-Folia"
. "|This server is running Folia version";
/**
* Matches the CraftBukkit name used by old versions as well as the Folia name, e.g.
* This server is running Folia version git-Folia-"d113346" (MC: 1.19.4)
* This server is running Folia version 1.20.6-5-master@d797082 (2024-06-19T22:19:29Z)
*
* @inheritDoc
*/
protected static array $logIdentifiers = [
"CraftBukkit version git-Folia",
"Folia version"
];

/**
* @return AnalyserInterface
Expand Down
14 changes: 12 additions & 2 deletions src/Log/Minecraft/Vanilla/Bukkit/Paper/PaperLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@

abstract class PaperLog extends SpigotLog
{
protected static string $logIdentifier = "(?:Paper|CraftBukkit) version git-Paper"
. "|This server is running Paper version";
/**
* PaperSpigot reported itself as CraftBukkit, later versions as Paper:
* This server is running CraftBukkit version git-PaperSpigot-"4c7641d" (MC: 1.8.8)
* This server is running Paper version git-Paper-794 (MC: 1.16.5)
* This server is running Paper version 1.21.1-116-master@e7e1ab5 (2024-09-30T23:17:54Z)
*
* @inheritDoc
*/
protected static array $logIdentifiers = [
"CraftBukkit version git-Paper",
"Paper version"
];

/**
* @return AnalyserInterface
Expand Down
13 changes: 11 additions & 2 deletions src/Log/Minecraft/Vanilla/Bukkit/Purpur/PurpurLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@

abstract class PurpurLog extends PaperLog
{
protected static string $logIdentifier = "(?:Purpur|CraftBukkit) version git-Purpur"
. "|This server is running Purpur version";
/**
* Matches the CraftBukkit name used by old versions as well as the Purpur name, e.g.
* This server is running Purpur version git-Purpur-1857 (MC: 1.19.2)
* This server is running Purpur version 1.20.6-2233-ver/1.20.6@0d6766e (2024-06-18T04:01:10Z)
*
* @inheritDoc
*/
protected static array $logIdentifiers = [
"CraftBukkit version git-Purpur",
"Purpur version"
];

/**
* @return string
Expand Down
5 changes: 4 additions & 1 deletion src/Log/Minecraft/Vanilla/Bukkit/Spigot/OldSpigotLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

abstract class OldSpigotLog extends OldCraftBukkitLog
{
protected static string $logIdentifier = "CraftBukkit version git-Spigot";
/**
* @inheritDoc
*/
protected static array $logIdentifiers = ["CraftBukkit version git-Spigot"];

/**
* @return string
Expand Down
5 changes: 4 additions & 1 deletion src/Log/Minecraft/Vanilla/Bukkit/Spigot/SpigotLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

abstract class SpigotLog extends CraftBukkitLog
{
protected static string $logIdentifier = "(?:CraftBukkit|Spigot) version (?:git|\d+(?:-[a-zA-Z]+)?)-Spigot";
/**
* @inheritDoc
*/
protected static array $logIdentifiers = ["(?:CraftBukkit|Spigot) version (?:git|\d+(?:-[a-zA-Z]+)?)-Spigot"];

/**
* @return string
Expand Down
28 changes: 28 additions & 0 deletions src/Log/Minecraft/Vanilla/Bukkit/VersionLineDetectorTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\Bukkit;

use Aternos\Codex\Detective\SinglePatternDetector;

/**
* Detects Bukkit servers by the version line they log on startup.
* The using class defines static::$logIdentifiers and static::$prefixPattern.
*/
trait VersionLineDetectorTrait
{
/**
* One detector per log identifier, each matching a line like
* [18:14:48] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-8b1588e (MC: 1.13.2)
*
* @return SinglePatternDetector[]
*/
protected static function getVersionLineDetectors(): array
{
$detectors = [];
foreach (static::$logIdentifiers as $logIdentifier) {
$pattern = '/' . static::$prefixPattern . 'This server is running ' . $logIdentifier . '/';
$detectors[] = (new SinglePatternDetector())->setPattern($pattern);
}
return $detectors;
}
}
Loading