mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-21 07:59:26 +00:00
45 lines
2.0 KiB
Diff
45 lines
2.0 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, 5 Jan 2023 09:08:17 +0800
|
|
Subject: [PATCH] Akarin: Save Json list asynchronously
|
|
|
|
Original license: GPL v3
|
|
Original project: https://github.com/Akarin-project/Akarin
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
index 97737da3c2f13e1bd29dc119133c7267f5d10117..6030e760c07cc90a06403a364d898a6259a40214 100644
|
|
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
@@ -103,6 +103,7 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
}
|
|
|
|
public void save() throws IOException {
|
|
+ Runnable saveTask = () -> {// Leaf - Akarin - Save json list async
|
|
this.removeExpired(); // Paper - remove expired values before saving
|
|
JsonArray jsonarray = new JsonArray();
|
|
Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error
|
|
@@ -114,6 +115,8 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
|
|
Objects.requireNonNull(jsonarray);
|
|
stream.forEach(jsonarray::add);
|
|
+
|
|
+ try {// Leaf - Akarin - Save json list async
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
|
|
|
try {
|
|
@@ -134,6 +137,13 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
bufferedwriter.close();
|
|
}
|
|
|
|
+ // Leaf start - Akarin - Save json list async
|
|
+ } catch (Exception e) {
|
|
+ StoredUserList.LOGGER.warn("Failed to async save " + this.file, e);
|
|
+ }
|
|
+ };
|
|
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(saveTask);
|
|
+ // Leaf end - Akarin - Save json list async
|
|
}
|
|
|
|
public void load() throws IOException {
|