Skip to content

Commit

Permalink
more playerdata for papi
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Jun 29, 2024
1 parent c62d775 commit cab0e79
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/Http/Controllers/Api/ApiPlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function postWhoisPlayer(Request $request)
if ($playerFoundCount && $onlyExactResult) {
$playerFoundCount = 1;
}
if (! $playerFoundCount && ! $onlyExactResult) {
$playerFoundCount = Player::where($columnName, 'LIKE', '%'.$username.'%')->whereNotNull($columnName)->count();
if (!$playerFoundCount && !$onlyExactResult) {
$playerFoundCount = Player::where($columnName, 'LIKE', '%' . $username . '%')->whereNotNull($columnName)->count();
}

$whoisData['count'] = $playerFoundCount;
Expand All @@ -53,15 +53,15 @@ public function postWhoisPlayer(Request $request)
case 0:
break;
case 1:
$player = Player::with('users:id,name,username')->where($columnName, 'LIKE', '%'.$username.'%')->whereNotNull($columnName)->orderBy('position')->first();
$player = Player::with('users:id,name,username')->where($columnName, 'LIKE', '%' . $username . '%')->whereNotNull($columnName)->orderBy('position')->first();
if ($player->users->count()) {
$player->user = $player->users->first();
unset($player->users);
}
$players = $players->push($player);
break;
default:
$players = Player::where($columnName, 'LIKE', '%'.$username.'%')->whereNotNull($columnName)->limit(10)->orderBy('position')->get();
$players = Player::where($columnName, 'LIKE', '%' . $username . '%')->whereNotNull($columnName)->limit(10)->orderBy('position')->get();
break;
}

Expand All @@ -77,7 +77,7 @@ public function postWhoisPlayer(Request $request)
'last_seen_at' => $pl->last_seen_at?->diffForHumans(),
'rank' => $pl->rank ? $pl->rank->name : null,
'country' => $pl->country ? $pl->country->name : 'Terra Incognita',
'user' => $pl->user ? '@'.$pl->user->username : null,
'user' => $pl->user ? '@' . $pl->user->username : null,
'url' => route('player.show', [$pl->username ?? $pl->uuid]),
];
});
Expand Down Expand Up @@ -128,6 +128,11 @@ public function postFetchPlayerData(Request $request)
$responseData['player_id'] = $player->id;
$responseData['rating'] = $player->rating;
$responseData['total_score'] = $player->total_score;
$responseData['total_mob_kills'] = $player->total_mob_kills;
$responseData['total_player_kills'] = $player->total_player_kills;
$responseData['total_deaths'] = $player->total_deaths;
$responseData['play_time'] = $player->play_time;
$responseData['afk_time'] = $player->afk_time;
$responseData['position'] = $player->position;
$responseData['first_seen_at'] = $player->first_seen_at?->diffForHumans();
$responseData['last_seen_at'] = $player->last_seen_at?->diffForHumans();
Expand Down

0 comments on commit cab0e79

Please sign in to comment.