summaryrefslogtreecommitdiffstats
path: root/nms-patches/WorldNBTStorage.patch
blob: aff7c5d782e75ccab20da85cd3bbda051708499d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
--- ../work/decompile-8eb82bde//net/minecraft/server/WorldNBTStorage.java	2014-11-28 17:43:43.441707427 +0000
+++ src/main/java/net/minecraft/server/WorldNBTStorage.java	2014-11-28 17:38:19.000000000 +0000
@@ -11,6 +11,12 @@
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+// CraftBukkit start
+import java.util.UUID;
+
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+// CraftBukkit end
+
 public class WorldNBTStorage implements IDataManager, IPlayerFileData {
 
     private static final Logger a = LogManager.getLogger();
@@ -19,6 +25,7 @@
     private final File dataDir;
     private final long sessionId = MinecraftServer.ax();
     private final String f;
+    private UUID uuid = null; // CraftBukkit
 
     public WorldNBTStorage(File file, String s, boolean flag) {
         this.baseDir = new File(file, s);
@@ -55,7 +62,7 @@
         return this.baseDir;
     }
 
-    public void checkSession() {
+    public void checkSession() throws ExceptionWorldConflict { // CraftBukkit - throws ExceptionWorldConflict
         try {
             File file = new File(this.baseDir, "session.lock");
             DataInputStream datainputstream = new DataInputStream(new FileInputStream(file));
@@ -202,12 +209,39 @@
         }
 
         if (nbttagcompound != null) {
+            // CraftBukkit start
+            if (entityhuman instanceof EntityPlayer) {
+                CraftPlayer player = (CraftPlayer) entityhuman.getBukkitEntity();
+                // Only update first played if it is older than the one we have
+                long modified = new File(this.playerDir, entityhuman.getUniqueID().toString() + ".dat").lastModified();
+                if (modified < player.getFirstPlayed()) {
+                    player.setFirstPlayed(modified);
+                }
+            }
+            // CraftBukkit end
+
             entityhuman.f(nbttagcompound);
         }
 
         return nbttagcompound;
     }
 
+    // CraftBukkit start
+    public NBTTagCompound getPlayerData(String s) {
+        try {
+            File file1 = new File(this.playerDir, s + ".dat");
+
+            if (file1.exists()) {
+                return NBTCompressedStreamTools.a((InputStream) (new FileInputStream(file1)));
+            }
+        } catch (Exception exception) {
+            a.warn("Failed to load player data for " + s);
+        }
+
+        return null;
+    }
+    // CraftBukkit end
+
     public IPlayerFileData getPlayerFileData() {
         return this;
     }
@@ -237,4 +271,50 @@
     public String g() {
         return this.f;
     }
+
+    // CraftBukkit start
+    public UUID getUUID() {
+        if (uuid != null) return uuid;
+        File file1 = new File(this.baseDir, "uid.dat");
+        if (file1.exists()) {
+            DataInputStream dis = null;
+            try {
+                dis = new DataInputStream(new FileInputStream(file1));
+                return uuid = new UUID(dis.readLong(), dis.readLong());
+            } catch (IOException ex) {
+                a.warn("Failed to read " + file1 + ", generating new random UUID", ex);
+            } finally {
+                if (dis != null) {
+                    try {
+                        dis.close();
+                    } catch (IOException ex) {
+                        // NOOP
+                    }
+                }
+            }
+        }
+        uuid = UUID.randomUUID();
+        DataOutputStream dos = null;
+        try {
+            dos = new DataOutputStream(new FileOutputStream(file1));
+            dos.writeLong(uuid.getMostSignificantBits());
+            dos.writeLong(uuid.getLeastSignificantBits());
+        } catch (IOException ex) {
+            a.warn("Failed to write " + file1, ex);
+        } finally {
+            if (dos != null) {
+                try {
+                    dos.close();
+                } catch (IOException ex) {
+                    // NOOP
+                }
+            }
+        }
+        return uuid;
+    }
+
+    public File getPlayerDir() {
+        return playerDir;
+    }
+    // CraftBukkit end
 }