diff --git a/patches/removed/server/1.21/0018-Akarin-Save-Json-list-asynchronously.patch b/patches/removed/server/1.21/0018-Akarin-Save-Json-list-asynchronously.patch new file mode 100644 index 00000000..7bff6533 --- /dev/null +++ b/patches/removed/server/1.21/0018-Akarin-Save-Json-list-asynchronously.patch @@ -0,0 +1,90 @@ +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?= + +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 +Original project: https://github.com/Winds-Studio/Leaf + +diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java +index 7e133752ccb1ea7c0b4fa781feb1a88e2cfdcf6d..c06a0e8fe3f9a8f67e6a92e10ba9d8e47525bbfb 100644 +--- a/src/main/java/net/minecraft/server/players/StoredUserList.java ++++ b/src/main/java/net/minecraft/server/players/StoredUserList.java +@@ -22,6 +22,7 @@ import java.util.Objects; + import java.util.stream.Stream; + import javax.annotation.Nullable; + import net.minecraft.Util; ++import io.papermc.paper.util.MCUtil; + import net.minecraft.util.GsonHelper; + import org.slf4j.Logger; + +@@ -103,37 +104,43 @@ public abstract class StoredUserList> { + } + + public void save() throws IOException { +- this.removeExpired(); // Paper - remove expired values before saving +- JsonArray jsonarray = new JsonArray(); +- Stream 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 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(jsonlistentry); ++ return (JsonObject) Util.make(jsonobject, jsonlistentry::serialize); ++ }); + +- Objects.requireNonNull(jsonarray); +- stream.forEach(jsonarray::add); +- BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); ++ Objects.requireNonNull(jsonarray); ++ stream.forEach(jsonarray::add); ++ try { ++ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); + +- try { +- StoredUserList.GSON.toJson(jsonarray, bufferedwriter); +- } catch (Throwable throwable) { +- if (bufferedwriter != null) { + try { ++ StoredUserList.GSON.toJson(jsonarray, bufferedwriter); ++ } catch (Throwable throwable) { ++ if (bufferedwriter != null) { ++ try { ++ bufferedwriter.close(); ++ } catch (Throwable throwable1) { ++ throwable.addSuppressed(throwable1); ++ } ++ } ++ ++ throw throwable; ++ } ++ ++ 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 {