Skip to content

Commit 45c1d13

Browse files
committed
add setting to use alias as query ip
1 parent 4838e4e commit 45c1d13

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'use_alias' => env('PLAYER_COUNTER_USE_ALIAS', false),
5+
];

player-counter/lang/en/query.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
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

player-counter/src/Models/GameQuery.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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 = [

player-counter/src/PlayerCounterPlugin.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace Boy132\PlayerCounter;
44

5+
use App\Contracts\Plugins\HasPluginSettings;
6+
use App\Traits\EnvironmentWriterTrait;
57
use Filament\Contracts\Plugin;
8+
use Filament\Forms\Components\Toggle;
9+
use Filament\Notifications\Notification;
610
use 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
}

0 commit comments

Comments
 (0)