Files
PlazmaBukkitMC/patches/server/0039-Save-Json-list-asynchronously.patch
2024-02-25 13:00:05 +09:00

117 lines
4.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaKR93 <dev@alpha93.kr>
Date: Thu, 11 Jan 2024 13:40:41 +0900
Subject: [PATCH] Save Json list asynchronously
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java
index 1c9cf5e1c4ee05724ffcdbd77a19bca1ab2be4d3..bc3b251a3f8ad345bdaaf67be59ff2c143d4d130 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java
@@ -60,20 +60,20 @@ public class DedicatedPlayerList extends PlayerList {
}
private void saveIpBanList() {
- try {
+ //try { // Plazma - Save Json list asynchronously
this.getIpBans().save();
- } catch (IOException var2) {
+ /*} catch (IOException var2) { // Plazma - Save Json list asynchronously
LOGGER.warn("Failed to save ip banlist: ", (Throwable)var2);
- }
+ }*/ // Plazma - Save Json list asynchronously
}
private void saveUserBanList() {
- try {
+ //try { // Plazma - Save Json list asynchronously
this.getBans().save();
- } catch (IOException var2) {
+ /*} catch (IOException var2) { // Plazma - Save Json list asynchronously
LOGGER.warn("Failed to save user banlist: ", (Throwable)var2);
- }
+ }*/ // Plazma - Save Json list asynchronously
}
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
index 1289e8e9c54a584f5037ea8e852df37376af093d..2014e0c4f412bead5881de588ec941a9a5ae3565 100644
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
@@ -43,11 +43,11 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
public void add(V entry) {
this.map.put(this.getKeyForUser(entry.getUser()), entry);
- try {
+ //try { // Plazma - Save Json list asynchronously
this.save();
- } catch (IOException ioexception) {
+ /*} catch (IOException ioexception) { // Plazma - Save Json list asynchronously
StoredUserList.LOGGER.warn("Could not save the list after adding a user.", ioexception);
- }
+ }*/ // Plazma - Save Json list asynchronously
}
@@ -63,11 +63,11 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
public void remove(K key) {
this.map.remove(this.getKeyForUser(key));
- try {
+ //try { // Plazma - Save Json list asynchronously
this.save();
- } catch (IOException ioexception) {
+ /*} catch (IOException ioexception) { // Plazma - Save Json list asynchronously
StoredUserList.LOGGER.warn("Could not save the list after removing a user.", ioexception);
- }
+ }*/ // Plazma - Save Json list asynchronously
}
@@ -102,7 +102,10 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
return this.map.values();
}
- public void save() throws IOException {
+ // Plazma start - Save Json list asynchronously
+ public void save()/* throws IOException*/ {
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(() -> {
+
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,27 +117,16 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
Objects.requireNonNull(jsonarray);
stream.forEach(jsonarray::add);
- BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
- try {
+ try (BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8)) {
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 (IOException e) {
+ StoredUserList.LOGGER.warn("Failed to asynchronously save file " + this.file, e);
}
+ });
}
+ // Plazma end - Save Json list asynchronously
public void load() throws IOException {
if (this.file.exists()) {