Skip to content

Commit

Permalink
Use custom fields system
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen committed Jan 9, 2023
1 parent 98cb65d commit dfc1026
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
</div>
</div>
{else}
<div class="ui grid">
{foreach from=$MCSTATISTICS_FIELDS key=key item=field}

{foreach from=$MCSTATISTICS_SERVERS item=server}
<h3>{$server.name}</h3>
<hr>
<div class="ui grid">
{foreach from=$server.fields item=field}
<div class="four wide column">
<strong>{$field.title}</strong></br>
<p>{$field.value}</p>
</div>
{/foreach}
</div>
</div>
</br>
{/foreach}

</br>

<center>Statistics provided by <a href="https://mcstatistics.org/" target="_blank">MCStatistics</a></center>
{/if}
19 changes: 19 additions & 0 deletions upload/modules/MCStatistics/classes/MCStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public function fetchPlayerData($value) {
return null;
}

// Get player data
public function fetchPlayerFields($value) {
if($this->_secret_key) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mcstatistics.org/v1/player/' . $value . '/fields');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MCStatistics-Secret: ' . $this->_secret_key));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$ch_result = curl_exec($ch);
$result = json_decode($ch_result);
curl_close($ch);

return $result;
}

return null;
}

// Get player data
public function fetchPlayerSessions($value) {
if($this->_secret_key) {
Expand Down
3 changes: 2 additions & 1 deletion upload/modules/MCStatistics/language/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"general/search_for_player":"Search for player",
"general/ingame_statistics":"Ingame Statistics",
"general/player_not_found":"Player not found on MCStatistics",
"general/failed_to_fetch_player_data":"Failed to fetch player data from MCStatistics!",
"general/failed_to_fetch_player_data":"Failed to fetch player data from <a href=\"https://mcstatistics.org/dashboard\" target=\"_blank\">MCStatistics</a>!",
"general/no_fields_configurated": "No fields have been configurated, You can configurate it from <a href=\"https://mcstatistics.org/dashboard\" target=\"_blank\">MCStatistics</a> -> Dashboard -> Fields",
"general/first_join":"First Join",
"general/last_seen":"Last Seen",
"general/play_time":"Play Time",
Expand Down
62 changes: 20 additions & 42 deletions upload/modules/MCStatistics/profile_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
if(!$cache->isCached('user_' . $query->id)){
$integration = $profile_user->getIntegration('Minecraft');
if ($integration != null) {
$results = $mcstatistics->fetchPlayerData(ProfileUtils::formatUUID($integration->data()->identifier));
$results = $mcstatistics->fetchPlayerFields(ProfileUtils::formatUUID($integration->data()->identifier));
} else {
$results = $mcstatistics->fetchPlayerData($query->username);
$results = $mcstatistics->fetchPlayerFields($query->username);
}

$cache->setCache('mcstatistics');
Expand All @@ -28,55 +28,33 @@
if (isset($results->error) && $results->error == true) {
if ($results->code == 20) {
$statistics_error = $mcstatistics_language->get('general', 'player_not_found');
} else if ($results->code == 21) {
$statistics_error = $mcstatistics_language->get('general', 'no_fields_configurated');
} else {
$statistics_error = $mcstatistics_language->get('general', 'failed_to_fetch_player_data');
}
} else {
// Statistics fields
$fields = [];
$servers = [];
foreach ($results->servers as $server) {
$fields = [];

$hours = $results->play_time / 1000 / 3600;
$minutes = ($results->play_time / 1000 % 3600) / 60;
foreach ($server->fields as $field) {
$fields[] = [
'title' => $field->name,
'type' => 'text',
'value' => $field->value
];
}

$fields['first_join'] = [
'title' => $mcstatistics_language->get('general', 'first_join'),
'type' => 'text',
'value' => $timeago->inWords($results->registered / 1000, $language),
'tooltip' => date(DATE_FORMAT, $results->registered / 1000)
];
$fields['last_seen'] = [
'title' => $mcstatistics_language->get('general', 'last_seen'),
'type' => 'text',
'value' => $timeago->inWords($results->last_seen / 1000, $language),
'tooltip' => date(DATE_FORMAT, $results->last_seen / 1000)
];
$fields['play_time'] = [
'title' => $mcstatistics_language->get("general", 'play_time'),
'type' => 'text',
'value' => Output::getClean(sprintf("%d hours, %d min", $hours, $minutes))
];
$fields['kills'] = [
'title' => $mcstatistics_language->get("general", 'kills'),
'type' => 'text',
'value' => $results->kills
];
$fields['deaths'] = [
'title' => $mcstatistics_language->get("general", 'deaths'),
'type' => 'text',
'value' => $results->deaths
];
$fields['blocks_placed'] = [
'title' => $mcstatistics_language->get("general", 'blocks_placed'),
'type' => 'text',
'value' => $results->blocks_placed
];
$fields['blocks_destroyed'] = [
'title' => $mcstatistics_language->get("general", 'blocks_destroyed'),
'type' => 'text',
'value' => $results->blocks_destroyed
];
$servers[] = [
'name' => $server->name,
'fields' => $fields,
];
}

$smarty->assign('MCSTATISTICS_FIELDS', $fields);
$smarty->assign('MCSTATISTICS_SERVERS', $servers);
}
} else {
$statistics_error = $mcstatistics_language->get('general', 'failed_to_fetch_player_data');
Expand Down

0 comments on commit dfc1026

Please sign in to comment.