File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ return [
4+ 'use_alias ' => env ('PLAYER_COUNTER_USE_ALIAS ' , false ),
5+ ];
Original file line number Diff line number Diff line change 2121 'add_to_ops ' => 'Add to OPs ' ,
2222 'remove_from_ops ' => 'Remove from OPs ' ,
2323
24+ 'use_alias ' => 'Use allocation alias? ' ,
25+ 'use_alias_hint ' => 'If checked the allocation alias will be used instead of the ip for queries ' ,
26+
2427 'table ' => [
2528 'no_players ' => 'No players found ' ,
2629 'no_players_description ' => 'Either no players are online or query is disabled on this server ' ,
2730 'server_offline ' => 'Server is offline ' ,
2831 ],
2932
3033 'notifications ' => [
34+ 'settings_saved ' => 'Setting saved ' ,
35+
3136 'player_kicked ' => 'Player kicked from server ' ,
3237 'player_kick_failed ' => 'Could not kick player ' ,
3338
Original file line number Diff line number Diff line change @@ -44,7 +44,10 @@ public function eggs(): BelongsToMany
4444 /** @return array<string, mixed> */
4545 public function runQuery (Allocation $ allocation ): array
4646 {
47- $ host = (is_ipv6 ($ allocation ->ip ) ? '[ ' . $ allocation ->ip . '] ' : $ allocation ->ip ) . ': ' . $ allocation ->port ;
47+ $ ip = config ('player-counter.use_alias ' ) && is_ip ($ allocation ->alias ) ? $ allocation ->alias : $ allocation ->ip ;
48+ $ ip = is_ipv6 ($ ip ) ? '[ ' . $ ip . '] ' : $ ip ;
49+
50+ $ host = $ ip . ': ' . $ allocation ->port ;
4851
4952 try {
5053 $ data = [
Original file line number Diff line number Diff line change 22
33namespace Boy132 \PlayerCounter ;
44
5+ use App \Contracts \Plugins \HasPluginSettings ;
6+ use App \Traits \EnvironmentWriterTrait ;
57use Filament \Contracts \Plugin ;
8+ use Filament \Forms \Components \Toggle ;
9+ use Filament \Notifications \Notification ;
610use Filament \Panel ;
711
8- class PlayerCounterPlugin implements Plugin
12+ class PlayerCounterPlugin implements HasPluginSettings, Plugin
913{
14+ use EnvironmentWriterTrait;
15+
1016 public function getId (): string
1117 {
1218 return 'player-counter ' ;
@@ -22,4 +28,28 @@ public function register(Panel $panel): void
2228 }
2329
2430 public function boot (Panel $ panel ): void {}
31+
32+ public function getSettingsForm (): array
33+ {
34+ return [
35+ Toggle::make ('use_alias ' )
36+ ->label (trans ('player-counter::query.use_alias ' ))
37+ ->hintIcon ('tabler-question-mark ' )
38+ ->hintIconTooltip (trans ('player-counter::query.use_alias_hint ' ))
39+ ->inline (false )
40+ ->default (fn () => config ('player-counter.use_alias ' )),
41+ ];
42+ }
43+
44+ public function saveSettings (array $ data ): void
45+ {
46+ $ this ->writeToEnvironment ([
47+ 'PLAYER_COUNTER_USE_ALIAS ' => $ data ['use_alias ' ],
48+ ]);
49+
50+ Notification::make ()
51+ ->title (trans ('player-counter::query.notifications.settings_saved ' ))
52+ ->success ()
53+ ->send ();
54+ }
2555}
You can’t perform that action at this time.
0 commit comments