Skip to content

Commit 6ce15fe

Browse files
committed
Second attempt to support bedrock skins
This time the bedrock skin support should be fully OK. Thanks to UUID stored by mcMMO we can easily know if a player is a bedrock player or not. If it is, then we use the TydiumAPI with his UUID to display his skin. Otherwise we still use player name to show his skin.
1 parent 844c867 commit 6ce15fe

File tree

14 files changed

+49
-62
lines changed

14 files changed

+49
-62
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ You must provide :
1919
| server_name | Your minecraft server name | Hypixel |
2020
| server_ip | Your minecraft server IP address | 192.168.1.1 |
2121
| server_port | Your minecraft server IP address's port | 25565 |
22-
| server_allow_bedrock | Is your minecraft server allowing bedrock players to connect ? | 0 |
2322
| db_ip | mcMMO database's IP address | 192.168.1.2 |
2423
| db_port | mcMMO database's port | 3306 |
2524
| db_name | mcMMO database's name | mcmmo_data |

comparison.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<!-- chartjs -->
1010
<script src="https://cdn.jsdelivr.net/npm/chart.js" defer></script>
1111
<!-- script of the project -->
12-
<script src="resources/js/common.js" defer></script>
1312
<script src="resources/js/main.js" defer></script>
1413
<script src="resources/js/comparison.js" defer></script>
1514
</head>

config/config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
'server_name' => 'your_server_name',
1414
'server_ip' => 'your_server_ip_here',
1515
'server_port' => '25565',
16-
'server_allow_bedrock' => 'is_your_server_allowing_bedrock_players_to_connect_?', // 1 = yes, 0 = no
1716
# About your database
1817
'db_ip' => 'ip_of_your_database_here',
1918
'db_port' => 'port_of_your_database_here',

index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<!-- chartjs -->
1010
<script src="https://cdn.jsdelivr.net/npm/chart.js" defer></script>
1111
<!-- script of the project -->
12-
<script src="resources/js/common.js" defer></script>
1312
<script src="resources/js/main.js" defer></script>
1413
<script src="resources/js/index.js" defer></script>
1514
<!-- css style used to correctly display data tables -->

resources/js/common.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

resources/js/index.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,31 @@ function chartEachAbilities(player){
481481
}
482482

483483
function addBP(player){
484-
const content_bp = document.querySelector('.content_bp')
485-
const col1 = createElement('div', 'col')
486-
for (let i = 0; i < 2; i++) {
487-
const el = createCard(player.players[i], i + 1)
488-
col1.appendChild(el)
489-
content_bp.appendChild(col1)
490-
}
491-
const col2 = createElement('div', 'col')
492-
for (let i = 2; i < 4; i++) {
493-
const el = createCard(player.players[i], i + 1)
494-
col2.appendChild(el)
495-
content_bp.appendChild(col2)
484+
const content_bp = document.querySelector('.content_bp');
485+
486+
const createColAndCards = (start, end, container) => {
487+
const col = document.createElement('div');
488+
col.className = 'col';
489+
for (let i = start; i < end; i++) {
490+
if (player.players[i]) {
491+
const el = createCard(player.players[i], i + 1);
492+
col.appendChild(el);
493+
}
494+
}
495+
container.appendChild(col);
496+
};
497+
498+
const playerCount = player.players.length;
499+
500+
if (playerCount >= 2) {
501+
createColAndCards(0, 2, content_bp);
502+
if (playerCount >= 4) {
503+
createColAndCards(2, 4, content_bp);
504+
} else {
505+
createColAndCards(2, playerCount, content_bp);
506+
}
507+
} else {
508+
createColAndCards(0, playerCount, content_bp);
496509
}
497510

498511
function createCard(player, rank = null){

resources/js/shared.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,25 @@ function generateColors(numColors, value = 0) {
482482
return colors;
483483
}
484484

485+
}
486+
487+
488+
function getSkinURL(player, type) {
489+
let types = {
490+
'BODY': 'player',
491+
'BODY_3D': 'body',
492+
'BODY_3D_REVERSE': 'body',
493+
'HEAD': 'avatar',
494+
'HEAD_3D': 'head'
495+
};
496+
if (!types[type]) {
497+
throw new Error(`Invalid type "${type}". Type must be one of ${Object.keys(types).join(', ')}.`);
498+
}
499+
if (player.bedrock === 0) {
500+
// Not a bedrock player, so we can directly use mc-heads API
501+
return 'https://mc-heads.net/' + types[type] + '/' + player.name + (type === 'BODY_3D_REVERSE' ? '/left' : '');
502+
} else {
503+
// Bedrock player, so we should use Tydium API with uuid
504+
return 'https://api.tydiumcraft.net/v1/players/skin?uuid=' + player.uuid + '&type=' + types[type] + (type === 'BODY_3D_REVERSE' ? '&direction=left' : '');
505+
}
485506
}

resources/js/user.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ function createLabel(array){
309309
}
310310

311311
function userData(player){
312-
console.log(player)
313312
const last_connection_user = document.querySelector('.last-connection-user')
314313
const last_connection = player.last_connection
315314
const date = getHM(last_connection)

resources/php/includes/bedrock.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

resources/php/scripts/get_all_leaderboard.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
require "../includes/secure.php";
44

5-
require "../includes/bedrock.php";
6-
/** @var ARRAY $allow_bedrock */
7-
85
require "../includes/db_connect.php";
96
/** @var OBJECT $dbh */
107

@@ -25,7 +22,7 @@
2522
"rank" => $rank,
2623
"name" => $row['user'],
2724
"uuid" => $row['uuid'],
28-
"bedrock" => $allow_bedrock,
25+
"bedrock" => str_starts_with($row['uuid'], '00000000') ? 1 : 0,
2926
"total" => $row['total'],
3027
"last_connection" => $row['lastlogin']
3128
);

0 commit comments

Comments
 (0)