2025-04-24 18:24:18 -04:00
< ? php
2025-07-01 21:33:11 -04:00
namespace App\Extensions\Features\Schemas ;
2025-04-24 18:24:18 -04:00
2025-07-01 21:33:11 -04:00
use App\Extensions\Features\FeatureSchemaInterface ;
2025-04-24 18:24:18 -04:00
use App\Models\Server ;
use App\Repositories\Daemon\DaemonFileRepository ;
2025-09-08 08:56:59 +02:00
use App\Repositories\Daemon\DaemonServerRepository ;
2025-04-24 18:24:18 -04:00
use Exception ;
use Filament\Actions\Action ;
use Filament\Facades\Filament ;
use Filament\Notifications\Notification ;
use Illuminate\Support\Facades\Blade ;
use Illuminate\Support\HtmlString ;
2025-07-01 21:33:11 -04:00
class MinecraftEulaSchema implements FeatureSchemaInterface
2025-04-24 18:24:18 -04:00
{
/** @return array<string> */
public function getListeners () : array
{
return [
2025-05-06 13:01:34 +02:00
'you need to agree to the eula in order to run the server' ,
2025-04-24 18:24:18 -04:00
];
}
public function getId () : string
{
return 'eula' ;
}
public function getAction () : Action
{
return Action :: make ( $this -> getId ())
-> requiresConfirmation ()
-> modalHeading ( 'Minecraft EULA' )
2025-05-06 13:01:34 +02:00
-> modalDescription ( new HtmlString ( Blade :: render ( 'By pressing "I Accept" below you are indicating your agreement to the <x-filament::link href="https://minecraft.net/eula" target="_blank">Minecraft EULA </x-filament::link>.' )))
2025-04-24 18:24:18 -04:00
-> modalSubmitActionLabel ( 'I Accept' )
2025-09-08 08:56:59 +02:00
-> action ( function ( DaemonFileRepository $fileRepository , DaemonServerRepository $serverRepository ) {
2025-04-24 18:24:18 -04:00
try {
/** @var Server $server */
$server = Filament :: getTenant ();
2025-05-06 13:01:34 +02:00
$fileRepository -> setServer ( $server ) -> putContent ( 'eula.txt' , 'eula=true' );
2025-09-08 08:56:59 +02:00
$serverRepository -> setServer ( $server ) -> power ( 'restart' );
2025-04-24 18:24:18 -04:00
Notification :: make ()
2025-05-06 13:01:34 +02:00
-> title ( 'Minecraft EULA accepted' )
-> body ( 'Server will restart now.' )
2025-04-24 18:24:18 -04:00
-> success ()
-> send ();
2025-05-06 13:01:34 +02:00
} catch ( Exception $exception ) {
2025-04-24 18:24:18 -04:00
Notification :: make ()
2025-05-06 13:01:34 +02:00
-> title ( 'Could not accept Minecraft EULA' )
-> body ( $exception -> getMessage ())
2025-04-24 18:24:18 -04:00
-> danger ()
-> send ();
}
2025-05-06 13:01:34 +02:00
});
2025-04-24 18:24:18 -04:00
}
}