mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 03:17:36 +01:00
113 lines
3.6 KiB
Diff
113 lines
3.6 KiB
Diff
--- a/net/minecraft/server/WorldNBTStorage.java
|
|
+++ b/net/minecraft/server/WorldNBTStorage.java
|
|
@@ -12,6 +12,11 @@
|
|
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 b = LogManager.getLogger();
|
|
@@ -22,6 +27,7 @@
|
|
private final String g;
|
|
private final DefinedStructureManager h;
|
|
protected final DataConverterManager a;
|
|
+ private UUID uuid = null; // CraftBukkit
|
|
|
|
public WorldNBTStorage(File file, String s, boolean flag, DataConverterManager dataconvertermanager) {
|
|
this.a = dataconvertermanager;
|
|
@@ -168,12 +174,38 @@
|
|
}
|
|
|
|
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(this.a.a((DataConverterType) DataConverterTypes.PLAYER, 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) {
|
|
+ b.warn("Failed to load player data for " + s);
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public IPlayerFileData getPlayerFileData() {
|
|
return this;
|
|
}
|
|
@@ -203,4 +235,50 @@
|
|
public DefinedStructureManager h() {
|
|
return this.h;
|
|
}
|
|
+
|
|
+ // 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) {
|
|
+ b.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) {
|
|
+ b.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
|
|
}
|