Send event to check with Features

This commit is contained in:
Vehikl 2025-01-09 17:02:38 -05:00
parent 93fd41d983
commit 366a49dba3
5 changed files with 78 additions and 7 deletions

View File

@ -7,10 +7,15 @@ use Filament\Actions\Action;
abstract class Feature
{
/** you need to agree to the eula in order to run the server */
abstract public function listeners(): array;
abstract static public function listeners(): array;
/** eula */
abstract public function featureName(): string;
abstract static public function featureName(): string;
abstract public function action(): Action;
abstract static public function action(): Action;
public function matchesListeners(string $line): bool
{
return collect(static::listeners())->contains(fn ($value) => str($line)->lower->contains($value));
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Features;
use App\Repositories\Daemon\DaemonFileRepository;
use Filament\Actions\Action;
use Filament\Forms\Components\Placeholder;
use Filament\Notifications\Notification;
class JavaVersion extends Feature
{
public static function listeners(): array
{
return [
'minecraft 1.17 requires running the server with java 16 or above',
'minecraft 1.18 requires running the server with java 17 or above',
'java.lang.unsupportedclassversionerror',
'unsupported major.minor version',
'has been compiled by a more recent version of the java runtime',
];
}
public static function featureName(): string
{
return 'java_version';
}
public static function action(): Action
{
return Action::make('eula')
->form([
Placeholder::make('eula')
->label('By pressing I Accept below you are indicating your agreement to the Minecraft® EULA.'),
])
->action(function (DaemonFileRepository $fileRepository) {
try {
$fileRepository->putContent('eula.txt', 'eula=true');
} catch (\Exception $e) {
Notification::make()
->title('Error')
->body($e->getMessage())
->danger()
->send();
}
}
);
}
}

View File

@ -9,19 +9,19 @@ use Filament\Notifications\Notification;
class MinecraftEula extends Feature
{
public function listeners(): array
public static function listeners(): array
{
return [
'you need to agree to the eula in order to run the server',
];
}
public function featureName(): string
public static function featureName(): string
{
return 'eula';
}
public function action(): Action
public static function action(): Action
{
return Action::make('eula')
->form([

View File

@ -10,7 +10,10 @@ use App\Services\Nodes\NodeJWTService;
use App\Services\Servers\GetUserPermissionsService;
use Filament\Widgets\Widget;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Livewire\Attributes\On;
use App\Features;
class ServerConsole extends Widget
{
@ -104,4 +107,19 @@ class ServerConsole extends Widget
cache()->put($cacheKey, $data, now()->addMinute());
}
}
public function getActiveFeatures(): array
{
return [new Features\MinecraftEula(), new Features\JavaVersion()];
}
#[On('line-to-check')]
public function lineToCheck(string $line)
{
foreach ($this->getActiveFeatures() as $feature) {
if ($feature->matchesListeners($line)) {
Log::info('Feature listens for this', compact(['feature', 'line']));
}
}
}
}

View File

@ -105,7 +105,7 @@
}
const checkListeners = (line) => {
$dispatch('line-to-check', { line })
}
const handleTransferStatus = (status) =>