Paper/nms-patches/WorldNBTStorage.patch

114 lines
3.8 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/WorldNBTStorage.java
+++ b/net/minecraft/server/WorldNBTStorage.java
2019-04-23 04:00:00 +02:00
@@ -13,6 +13,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
+
2019-04-23 04:00:00 +02:00
public class WorldNBTStorage implements IPlayerFileData {
2016-02-29 22:32:46 +01:00
private static final Logger b = LogManager.getLogger();
2019-04-23 04:00:00 +02:00
@@ -22,6 +27,7 @@
2018-08-26 04:00:00 +02:00
private final String f;
private final DefinedStructureManager g;
2018-07-15 02:00:00 +02:00
protected final DataFixer a;
+ private UUID uuid = null; // CraftBukkit
2018-07-15 02:00:00 +02:00
public WorldNBTStorage(File file, String s, @Nullable MinecraftServer minecraftserver, DataFixer datafixer) {
this.a = datafixer;
2019-04-23 04:00:00 +02:00
@@ -165,6 +171,16 @@
}
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
2018-07-15 02:00:00 +02:00
int i = nbttagcompound.hasKeyOfType("DataVersion", 3) ? nbttagcompound.getInt("DataVersion") : -1;
2018-07-15 02:00:00 +02:00
entityhuman.f(GameProfileSerializer.a(this.a, DataFixTypes.PLAYER, nbttagcompound, i));
2019-04-23 04:00:00 +02:00
@@ -173,6 +189,22 @@
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) {
2016-02-29 22:32:46 +01:00
+ b.warn("Failed to load player data for " + s);
+ }
+
+ return null;
+ }
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public String[] getSeenPlayers() {
String[] astring = this.playerDir.list();
@@ -196,4 +228,50 @@
public DataFixer getDataFixer() {
2018-07-15 02:00:00 +02:00
return this.a;
}
+
+ // 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) {
2016-02-29 22:32:46 +01:00
+ 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) {
2016-02-29 22:32:46 +01:00
+ 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
}