From b7597142d3cbda96698dc6353c971d2d0175b592 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot 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. By: md_5 --- .../storage/PlayerDataStorage.java.patch | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/storage/PlayerDataStorage.java.patch b/paper-server/patches/sources/net/minecraft/world/level/storage/PlayerDataStorage.java.patch index d2bf4deb10..654eb8973c 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/storage/PlayerDataStorage.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/storage/PlayerDataStorage.java.patch @@ -11,7 +11,7 @@ import org.slf4j.Logger; public class PlayerDataStorage { -@@ -49,34 +51,36 @@ +@@ -49,34 +51,55 @@ } @@ -48,17 +48,37 @@ - File file1 = new File(file, s1 + extension); + // 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(NbtIo.readCompressed(file1.toPath(), NbtAccounter.unlimitedHeap())); +- return Optional.of(NbtIo.readCompressed(file1.toPath(), NbtAccounter.unlimitedHeap())); ++ // Spigot Start ++ Optional optional = Optional.of(NbtIo.readCompressed(file1.toPath(), NbtAccounter.unlimitedHeap())); ++ if ( usingWrongFile ) ++ { ++ file1.renameTo( new File( file1.getPath() + ".offline-read" ) ); ++ } ++ return optional; ++ // Spigot End } catch (Exception exception) { - PlayerDataStorage.LOGGER.warn("Failed to load player data for {}", player.getName().getString()); + PlayerDataStorage.LOGGER.warn("Failed to load player data for {}", name); // CraftBukkit } } -@@ -84,20 +88,44 @@ +@@ -84,20 +107,44 @@ } public Optional load(Player player) {