diff --git a/app/Features/Feature.php b/app/Features/Feature.php index c34a5b12b..a5d249b7b 100644 --- a/app/Features/Feature.php +++ b/app/Features/Feature.php @@ -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)); + } } diff --git a/app/Features/JavaVersion.php b/app/Features/JavaVersion.php new file mode 100644 index 000000000..4047bedf4 --- /dev/null +++ b/app/Features/JavaVersion.php @@ -0,0 +1,48 @@ +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(); + } + } + ); + } +} diff --git a/app/Features/MinecraftEula.php b/app/Features/MinecraftEula.php index 6a437de63..a3f681a54 100644 --- a/app/Features/MinecraftEula.php +++ b/app/Features/MinecraftEula.php @@ -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([ diff --git a/app/Filament/Server/Widgets/ServerConsole.php b/app/Filament/Server/Widgets/ServerConsole.php index 851b4b3a3..853d806ed 100644 --- a/app/Filament/Server/Widgets/ServerConsole.php +++ b/app/Filament/Server/Widgets/ServerConsole.php @@ -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'])); + } + } + } } diff --git a/resources/views/filament/components/server-console.blade.php b/resources/views/filament/components/server-console.blade.php index e3cc0b45c..1b6b65af3 100644 --- a/resources/views/filament/components/server-console.blade.php +++ b/resources/views/filament/components/server-console.blade.php @@ -105,7 +105,7 @@ } const checkListeners = (line) => { - + $dispatch('line-to-check', { line }) } const handleTransferStatus = (status) =>