diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2014-04-10 20:04:38 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2014-04-11 22:28:35 -0500 |
commit | 8f771c737850130534b0fade70494f7ce3cbc8fd (patch) | |
tree | e4180121cdaf4f15b325aa059469b44975fca8a4 /src/main/java/net/minecraft/server/PlayerDatFileConverter.java | |
parent | 0df7555cecff17ffab68b8280dcf8471b10f020c (diff) | |
download | craftbukkit-8f771c737850130534b0fade70494f7ce3cbc8fd.tar craftbukkit-8f771c737850130534b0fade70494f7ce3cbc8fd.tar.gz craftbukkit-8f771c737850130534b0fade70494f7ce3cbc8fd.tar.lz craftbukkit-8f771c737850130534b0fade70494f7ce3cbc8fd.tar.xz craftbukkit-8f771c737850130534b0fade70494f7ce3cbc8fd.zip |
Update CraftBukkit to Minecraft 1.7.8
Diffstat (limited to 'src/main/java/net/minecraft/server/PlayerDatFileConverter.java')
-rw-r--r-- | src/main/java/net/minecraft/server/PlayerDatFileConverter.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/PlayerDatFileConverter.java b/src/main/java/net/minecraft/server/PlayerDatFileConverter.java new file mode 100644 index 00000000..27651b5a --- /dev/null +++ b/src/main/java/net/minecraft/server/PlayerDatFileConverter.java @@ -0,0 +1,98 @@ +package net.minecraft.server; + +import java.io.File; +import java.util.UUID; + +import net.minecraft.util.com.mojang.authlib.GameProfile; +import net.minecraft.util.com.mojang.authlib.ProfileLookupCallback; +import net.minecraft.util.com.mojang.authlib.yggdrasil.ProfileNotFoundException; + +final class PlayerDatFileConverter implements ProfileLookupCallback { + + final DedicatedServer a; + final File b; + final File c; + final File d; + final String[] e; + + PlayerDatFileConverter(DedicatedServer dedicatedserver, File file1, File file2, File file3, String[] astring) { + this.a = dedicatedserver; + this.b = file1; + this.c = file2; + this.d = file3; + this.e = astring; + } + + public void onProfileLookupSucceeded(GameProfile gameprofile) { + this.a.getUserCache().a(gameprofile); + UUID uuid = gameprofile.getId(); + + if (uuid == null) { + throw new FileConversionException("Missing UUID for user profile " + gameprofile.getName(), (PredicateEmptyList) null); + } else { + this.a(this.b, this.a(gameprofile), uuid.toString()); + } + } + + public void onProfileLookupFailed(GameProfile gameprofile, Exception exception) { + NameReferencingFileConverter.a().warn("Could not lookup user uuid for " + gameprofile.getName(), exception); + if (exception instanceof ProfileNotFoundException) { + String s = this.a(gameprofile); + + this.a(this.c, s, s); + } else { + throw new FileConversionException("Could not request user " + gameprofile.getName() + " from backend systems", exception, (PredicateEmptyList) null); + } + } + + private void a(File file1, String s, String s1) { + File file2 = new File(this.d, s + ".dat"); + File file3 = new File(file1, s1 + ".dat"); + + // CraftBukkit start - Use old file name to seed lastKnownName + NBTTagCompound root = null; + + try { + root = NBTCompressedStreamTools.a(new java.io.FileInputStream(file2)); + } catch (Exception exception) { + exception.printStackTrace(); + } + + if (root != null) { + if (!root.hasKey("bukkit")) { + root.set("bukkit", new NBTTagCompound()); + } + NBTTagCompound data = root.getCompound("bukkit"); + data.setString("lastKnownName", s); + + try { + NBTCompressedStreamTools.a(root, new java.io.FileOutputStream(file2)); + } catch (Exception exception) { + exception.printStackTrace(); + } + } + // CraftBukkit end + + NameReferencingFileConverter.a(file1); + if (!file2.renameTo(file3)) { + throw new FileConversionException("Could not convert file for " + s, (PredicateEmptyList) null); + } + } + + private String a(GameProfile gameprofile) { + String s = null; + + for (int i = 0; i < this.e.length; ++i) { + if (this.e[i] != null && this.e[i].equalsIgnoreCase(gameprofile.getName())) { + s = this.e[i]; + break; + } + } + + if (s == null) { + throw new FileConversionException("Could not find the filename for " + gameprofile.getName() + " anymore", (PredicateEmptyList) null); + } else { + return s; + } + } +} |