spigot/CraftBukkit-Patches/0049-Use-Offline-Player-Data-Once-if-Required.patch
md_5 ed9ba9a42d
Drop no longer required patch ignoring -o option
Ideally all misleading documentation has been removed in the last ~10 years and users should no longer be adding unknown startup flags.
2023-12-26 09:18:47 +11:00

43 lines
2.1 KiB
Diff

From 5bc76ec50acd098b17a5c5c9840424eaa3ccc14c Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 13 Apr 2014 14:41:23 +1000
Subject: [PATCH] Use Offline Player Data Once if Required.
If we are online mode and the only copy of player data we can find is the player's offline mode data, we will attempt a once off conversion by reading this data and then renaming the file so it won't be used again.
diff --git a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
index 689d28b5b9..d77142665d 100644
--- a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
+++ b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
@@ -57,10 +57,28 @@ public class WorldNBTStorage {
try {
File file = new File(this.playerDir, entityhuman.getStringUUID() + ".dat");
+ // Spigot Start
+ boolean usingWrongFile = false;
+ if ( !file.exists() )
+ {
+ file = new File( this.playerDir, java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + entityhuman.getScoreboardName() ).getBytes( "UTF-8" ) ).toString() + ".dat");
+ if ( file.exists() )
+ {
+ usingWrongFile = true;
+ org.bukkit.Bukkit.getServer().getLogger().warning( "Using offline mode UUID file for player " + entityhuman.getScoreboardName() + " as it is the only copy we can find." );
+ }
+ }
+ // Spigot End
if (file.exists() && file.isFile()) {
nbttagcompound = NBTCompressedStreamTools.readCompressed(file.toPath(), NBTReadLimiter.unlimitedHeap());
}
+ // Spigot Start
+ if ( usingWrongFile )
+ {
+ file.renameTo( new File( file.getPath() + ".offline-read" ) );
+ }
+ // Spigot End
} catch (Exception exception) {
WorldNBTStorage.LOGGER.warn("Failed to load player data for {}", entityhuman.getName().getString());
}
--
2.43.0