spigot/CraftBukkit-Patches/0043-Use-Offline-Player-Data-Once-if-Required.patch

46 lines
2.3 KiB
Diff
Raw Normal View History

2024-12-04 03:20:00 +11:00
From 6317265a667c6f4d5afd02feacfdd9a4b824216c 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.
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
2024-12-04 03:20:00 +11:00
index 935acab0e..c79f0fbd9 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
2024-04-24 01:15:00 +10:00
@@ -75,10 +75,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() )
+ {
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." );
+ }
2024-04-24 01:15:00 +10:00
+ }
+ // Spigot End
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
}
--
2024-12-04 03:20:00 +11:00
2.47.1