diff --git a/mc-player-history.php b/mc-player-history.php index 2d11557..8964237 100644 --- a/mc-player-history.php +++ b/mc-player-history.php @@ -2,8 +2,8 @@ /* Plugin Name: MC Player History Description: Spielerverlauf deines Minecraft Servers. -Version: 1.1.0 -Author: Dein Name +Version: 1.1.1 +Author: M_Viper */ if ( ! defined( 'ABSPATH' ) ) { @@ -119,10 +119,33 @@ function mcph_sync_from_statusapi() { foreach ( $players as $p ) { $name = isset( $p->name ) ? sanitize_text_field( $p->name ) : ''; $prefix = isset( $p->prefix ) ? sanitize_text_field( $p->prefix ) : ''; - $uuid = 'legacy-' . md5( strtolower( trim( $name ) ) ); + // UUID aus API übernehmen, falls vorhanden, sonst legacy-Hash + if ( isset( $p->uuid ) && !empty( $p->uuid ) ) { + $uuid = sanitize_text_field( $p->uuid ); + } else { + $uuid = 'legacy-' . md5( strtolower( trim( $name ) ) ); + } if ( empty( $name ) ) continue; + // Prüfe ob Spieler bereits existiert (nach UUID ODER Username) $exists = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $table_name WHERE uuid = %s", $uuid ) ); + + // Falls nicht per UUID gefunden, prüfe nach Username (für Migration alter Einträge) + if ( ! $exists ) { + $old_entry = $wpdb->get_row( $wpdb->prepare( "SELECT id, uuid FROM $table_name WHERE username = %s", $name ) ); + if ( $old_entry ) { + // Alter Eintrag gefunden - UUID aktualisieren statt neuen Eintrag + $wpdb->update( + $table_name, + array( 'uuid' => $uuid, 'prefix' => $prefix, 'last_seen' => current_time( 'mysql' ), 'is_online' => 1 ), + array( 'id' => $old_entry->id ), + array( '%s', '%s', '%s', '%d' ), + array( '%d' ) + ); + continue; + } + } + $now = current_time( 'mysql' ); if ( $exists ) { @@ -181,7 +204,12 @@ function mcph_generate_player_html( $limit = 500, $only_online = false, $is_ajax $has_live_data = true; foreach ( $api_response as $p ) { if ( isset( $p->name ) ) { - $uuid = 'legacy-' . md5( strtolower( trim( $p->name ) ) ); + // UUID aus API übernehmen, falls vorhanden, sonst legacy-Hash + if ( isset( $p->uuid ) && !empty( $p->uuid ) ) { + $uuid = sanitize_text_field( $p->uuid ); + } else { + $uuid = 'legacy-' . md5( strtolower( trim( $p->name ) ) ); + } $live_online_uuids[ $uuid ] = true; } } @@ -218,7 +246,18 @@ function mcph_generate_player_html( $limit = 500, $only_online = false, $is_ajax $username = esc_html( $row->username ); $prefix = mcph_parse_minecraft_colors( $row->prefix ); - $avatar = 'https://minotar.net/avatar/' . $username . '/80'; + + // Avatar-Logik: Moderne 3D-Köpfe (alle in gleiche Richtung) + $avatar = ''; + if ( strpos( $username, '.' ) !== false || ( isset($row->uuid) && strpos($row->uuid, 'xuid') === 0 ) ) { + // Bedrock: mc-heads.net mit 3D Head + $avatar = isset($row->uuid) && !empty($row->uuid) + ? 'https://mc-heads.net/head/' . esc_attr($row->uuid) . '/100' + : 'https://mc-heads.net/head/' . $username . '/100'; + } else { + // Java: mc-heads.net mit 3D Head (gleiche Richtung wie Bedrock) + $avatar = 'https://mc-heads.net/head/' . $username . '/100'; + } $anim_style = ''; if ( ! $is_ajax ) { @@ -235,7 +274,7 @@ function mcph_generate_player_html( $limit = 500, $only_online = false, $is_ajax // STRUKTUR: Bild -> Prefix -> Name -> Spacer -> Status echo '
' . $cleaned . ' Duplikate wurden entfernt.