mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
91 lines
3.8 KiB
Diff
91 lines
3.8 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 5dee29939421333caa51e1a659d8ad9f9c0358c9..1f629ec713333fae303b4b31422a880fc858172b 100644
|
|
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
@@ -24,6 +24,7 @@ import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
|
|
import me.titaniumtown.ArrayConstants;
|
|
+import io.papermc.paper.util.MCUtil;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.util.GsonHelper;
|
|
import org.slf4j.Logger;
|
|
@@ -149,37 +150,43 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
}
|
|
|
|
public void save() throws IOException {
|
|
- this.removeExpired(); // Paper - remove expired values before saving
|
|
- JsonArray jsonarray = new JsonArray();
|
|
- Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error
|
|
- JsonObject jsonobject = new JsonObject();
|
|
+ Runnable saveTask = ()->{ // 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
|
|
+ JsonObject jsonobject = new JsonObject();
|
|
+
|
|
+ Objects.requireNonNull(jsonlistentry);
|
|
+ return (JsonObject) Util.make(jsonobject, jsonlistentry::serialize);
|
|
+ });
|
|
+
|
|
+ Objects.requireNonNull(jsonarray);
|
|
+ stream.forEach(jsonarray::add);
|
|
+ try {
|
|
+ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
|
|
|
- Objects.requireNonNull(jsonlistentry);
|
|
- return (JsonObject) Util.make(jsonobject, jsonlistentry::serialize);
|
|
- });
|
|
+ try {
|
|
+ StoredUserList.GSON.toJson(jsonarray, bufferedwriter);
|
|
+ } catch (Throwable throwable) {
|
|
+ if (bufferedwriter != null) {
|
|
+ try {
|
|
+ bufferedwriter.close();
|
|
+ } catch (Throwable throwable1) {
|
|
+ throwable.addSuppressed(throwable1);
|
|
+ }
|
|
+ }
|
|
|
|
- Objects.requireNonNull(jsonarray);
|
|
- stream.forEach(jsonarray::add);
|
|
- BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
|
+ throw throwable;
|
|
+ }
|
|
|
|
- try {
|
|
- StoredUserList.GSON.toJson(jsonarray, bufferedwriter);
|
|
- } catch (Throwable throwable) {
|
|
- if (bufferedwriter != null) {
|
|
- try {
|
|
+ if (bufferedwriter != null) {
|
|
bufferedwriter.close();
|
|
- } catch (Throwable throwable1) {
|
|
- throwable.addSuppressed(throwable1);
|
|
}
|
|
+ }catch (Exception e){
|
|
+ StoredUserList.LOGGER.warn("Failed to async save " + this.file, e); // Akarin - Save json list async
|
|
}
|
|
-
|
|
- throw throwable;
|
|
- }
|
|
-
|
|
- if (bufferedwriter != null) {
|
|
- bufferedwriter.close();
|
|
- }
|
|
-
|
|
+ };
|
|
+ MCUtil.scheduleAsyncTask(saveTask); // Akarin - Save json list async
|
|
}
|
|
|
|
public void load() throws IOException {
|