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 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2014-04-13 14:41:23 +10:00
parent c3318769cd
commit b7597142d3

View file

@ -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<CompoundTag> 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<CompoundTag> load(Player player) {