Files
AkarinMC/patches-1.16.5/server/0010-Save-Json-list-asynchronously.patch
2025-02-18 18:18:07 +11:00

46 lines
1.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E3=84=97=E3=84=A0=CB=8B=20=E3=84=91=E3=84=A7=CB=8A?=
<tsao-chi@the-lingo.org>
Date: Thu, 2 Apr 2020 11:16:18 +0800
Subject: [PATCH] Save Json list asynchronously
diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
index 8da5f976109accc84b26ec4045776aa8a9799f3d..8d00a54ed22dd974dadc7159c7c3d7265ec42649 100644
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
@@ -146,6 +146,7 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
}
public void save() throws IOException {
+ Runnable runnable = () -> { // Akarin - Save json list async
this.removeStaleEntries(); // Paper - remove expired values before saving
JsonArray jsonarray = new JsonArray();
@@ -155,11 +156,13 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
jsonlistentry.getClass();
return (JsonObject) SystemUtils.a(jsonobject, jsonlistentry::a); // CraftBukkit - decompile error
}).forEach(jsonarray::add);
+ try {
BufferedWriter bufferedwriter = Files.newWriter(this.c, StandardCharsets.UTF_8);
Throwable throwable = null;
try {
JsonList.b.toJson(jsonarray, bufferedwriter);
+
} catch (Throwable throwable1) {
throwable = throwable1;
throw throwable1;
@@ -177,6 +180,11 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
}
}
+ } catch (IOException e) { // Akarin - Save json list async
+ JsonList.LOGGER.warn("Failed to save " + this.c, e); // Akarin - Save json list async
+ }
+ }; // Akarin - Save json list async
+ MCUtil.scheduleAsyncTask(runnable); // Akarin - Save json list async
}