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, 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> { } 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> { 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> { } } + } 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 }