2021-06-11 12:02:28 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 16 May 2016 20:47:41 -0400
|
2022-03-18 03:53:36 +00:00
|
|
|
Subject: [PATCH] Async GameProfileCache saving
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-06-12 05:20:08 +00:00
|
|
|
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-06-07 19:55:39 +00:00
|
|
|
index b62d7b2e974f9eafb8e60ddb9ed58273b0393185..9e5271d39e4a15a71c59a8560edd59c75ec6dd52 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2022-06-07 19:55:39 +00:00
|
|
|
@@ -942,7 +942,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-06-11 12:02:28 +00:00
|
|
|
} catch (java.lang.InterruptedException ignored) {} // Paper
|
|
|
|
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
2021-06-12 05:20:08 +00:00
|
|
|
MinecraftServer.LOGGER.info("Saving usercache.json");
|
2021-06-11 12:02:28 +00:00
|
|
|
- this.getProfileCache().save();
|
2021-06-12 05:20:08 +00:00
|
|
|
+ this.getProfileCache().save(false); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2022-06-07 19:55:39 +00:00
|
|
|
index 9e7fb3e2d423ba1db22819aa8b666ca886d98cf6..576fc01b902acaf2a217db3fb39b799f2f57ce01 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2022-06-07 19:55:39 +00:00
|
|
|
@@ -250,7 +250,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.convertOldUsers()) {
|
|
|
|
- this.getProfileCache().save();
|
2021-06-12 05:20:08 +00:00
|
|
|
+ this.getProfileCache().save(false); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
2022-06-07 19:55:39 +00:00
|
|
|
index fb110ecb7fa8d0de7d8ce8e239d1db341a333203..717a0d1c1f4df7ebd5f4cdd5e24cabe3fb66bf06 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
|
2022-03-18 03:53:36 +00:00
|
|
|
@@ -127,7 +127,7 @@ public class GameProfileCache {
|
2021-06-12 05:20:08 +00:00
|
|
|
GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date);
|
2021-06-11 12:02:28 +00:00
|
|
|
|
|
|
|
this.safeAdd(usercache_usercacheentry);
|
|
|
|
- if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(); // Spigot - skip saving if disabled
|
2021-06-12 05:20:08 +00:00
|
|
|
+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - async
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private long getNextOperation() {
|
2021-06-12 05:20:08 +00:00
|
|
|
@@ -160,7 +160,7 @@ public class GameProfileCache {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
|
|
|
|
- this.save();
|
2021-06-12 05:20:08 +00:00
|
|
|
+ this.save(true); // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 06:52:40 +00:00
|
|
|
return optional;
|
2021-11-23 13:22:49 +00:00
|
|
|
@@ -274,7 +274,7 @@ public class GameProfileCache {
|
2021-06-11 12:02:28 +00:00
|
|
|
return arraylist;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public void save() {
|
2021-06-12 05:20:08 +00:00
|
|
|
+ public void save(boolean asyncSave) { // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
JsonArray jsonarray = new JsonArray();
|
2021-06-12 05:20:08 +00:00
|
|
|
DateFormat dateformat = GameProfileCache.createDateFormat();
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-11-23 13:22:49 +00:00
|
|
|
@@ -282,6 +282,7 @@ public class GameProfileCache {
|
2021-06-12 05:20:08 +00:00
|
|
|
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
|
2021-06-11 12:02:28 +00:00
|
|
|
});
|
|
|
|
String s = this.gson.toJson(jsonarray);
|
|
|
|
+ Runnable save = () -> { // Paper
|
|
|
|
|
|
|
|
try {
|
|
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
2022-03-18 03:53:36 +00:00
|
|
|
@@ -306,6 +307,14 @@ public class GameProfileCache {
|
2021-06-11 12:02:28 +00:00
|
|
|
} catch (IOException ioexception) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ };
|
|
|
|
+ if (asyncSave) {
|
2021-06-12 05:20:08 +00:00
|
|
|
+ net.minecraft.server.MCUtil.scheduleAsyncTask(save);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ } else {
|
|
|
|
+ save.run();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2022-03-18 03:53:36 +00:00
|
|
|
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|