2025-06-18 01:15:00 +10:00
From 62c732f95ad2e2cf5432fc5a5e75815e206e5c2f Mon Sep 17 00:00:00 2001
2014-04-13 14:41:33 +10:00
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.
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
2025-06-18 01:15:00 +10:00
index 40d074337..cc88c7784 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
+++ b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
2025-06-18 01:15:00 +10:00
@@ -83,10 +83,29 @@ public class WorldNBTStorage {
2024-04-24 01:15:00 +10:00
File file = this.playerDir;
// String s1 = entityhuman.getStringUUID(); // CraftBukkit - used above
File file1 = new File(file, s1 + s);
+ // Spigot Start
+ boolean usingWrongFile = false;
+ if ( !file1.exists() )
+ {
+ file1 = new File( file, java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + name ).getBytes( java.nio.charset.StandardCharsets.UTF_8 ) ).toString() + s );
+ if ( file1.exists() )
2014-04-13 14:41:33 +10:00
+ {
2024-04-24 01:15:00 +10:00
+ usingWrongFile = true;
+ org.bukkit.Bukkit.getServer().getLogger().warning( "Using offline mode UUID file for player " + name + " as it is the only copy we can find." );
2014-04-13 14:41:33 +10:00
+ }
2024-04-24 01:15:00 +10:00
+ }
+ // Spigot End
2014-04-13 14:41:33 +10:00
2024-04-24 01:15:00 +10:00
if (file1.exists() && file1.isFile()) {
try {
- return Optional.of(NBTCompressedStreamTools.readCompressed(file1.toPath(), NBTReadLimiter.unlimitedHeap()));
+ // Spigot Start
+ Optional<NBTTagCompound> optional = Optional.of(NBTCompressedStreamTools.readCompressed(file1.toPath(), NBTReadLimiter.unlimitedHeap()));
+ if ( usingWrongFile )
+ {
+ file1.renameTo( new File( file1.getPath() + ".offline-read" ) );
+ }
+ return optional;
+ // Spigot End
} catch (Exception exception) {
WorldNBTStorage.LOGGER.warn("Failed to load player data for {}", name); // CraftBukkit
2014-04-13 14:41:33 +10:00
}
--
2025-03-26 03:05:00 +11:00
2.49.0
2014-04-13 14:41:33 +10:00