mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 10:54:46 +02:00
Send event to check with Features
This commit is contained in:
parent
93fd41d983
commit
366a49dba3
@ -7,10 +7,15 @@ use Filament\Actions\Action;
|
|||||||
abstract class Feature
|
abstract class Feature
|
||||||
{
|
{
|
||||||
/** you need to agree to the eula in order to run the server */
|
/** 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 */
|
/** 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
48
app/Features/JavaVersion.php
Normal file
48
app/Features/JavaVersion.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -9,19 +9,19 @@ use Filament\Notifications\Notification;
|
|||||||
|
|
||||||
class MinecraftEula extends Feature
|
class MinecraftEula extends Feature
|
||||||
{
|
{
|
||||||
public function listeners(): array
|
public static function listeners(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'you need to agree to the eula in order to run the server',
|
'you need to agree to the eula in order to run the server',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function featureName(): string
|
public static function featureName(): string
|
||||||
{
|
{
|
||||||
return 'eula';
|
return 'eula';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action(): Action
|
public static function action(): Action
|
||||||
{
|
{
|
||||||
return Action::make('eula')
|
return Action::make('eula')
|
||||||
->form([
|
->form([
|
||||||
|
@ -10,7 +10,10 @@ use App\Services\Nodes\NodeJWTService;
|
|||||||
use App\Services\Servers\GetUserPermissionsService;
|
use App\Services\Servers\GetUserPermissionsService;
|
||||||
use Filament\Widgets\Widget;
|
use Filament\Widgets\Widget;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
|
use App\Features;
|
||||||
|
|
||||||
class ServerConsole extends Widget
|
class ServerConsole extends Widget
|
||||||
{
|
{
|
||||||
@ -104,4 +107,19 @@ class ServerConsole extends Widget
|
|||||||
cache()->put($cacheKey, $data, now()->addMinute());
|
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']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const checkListeners = (line) => {
|
const checkListeners = (line) => {
|
||||||
|
$dispatch('line-to-check', { line })
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleTransferStatus = (status) =>
|
const handleTransferStatus = (status) =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user