0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2025-07-03 06:17:31 +00:00
Files
spigot/CraftBukkit-Patches/0043-Use-Offline-Player-Data-Once-if-Required.patch
2025-06-18 01:15:00 +10:00

46 lines
2.3 KiB
Diff

From 62c732f95ad2e2cf5432fc5a5e75815e206e5c2f 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 40d074337..cc88c7784 100644
--- a/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
+++ b/src/main/java/net/minecraft/world/level/storage/WorldNBTStorage.java
@@ -83,10 +83,29 @@ public class WorldNBTStorage {
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() )
+ {
+ 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." );
+ }
+ }
+ // Spigot End
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
}
--
2.49.0