117 lines
4.5 KiB
Diff
117 lines
4.5 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 935dac757280731bfeb0a8f033cbe315ecac46da..038f370ac2cb768e14fe7605b32b2ac811c33b8f 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 - Build fix
|
|
this.getIpBans().save();
|
|
- } catch (IOException var2) {
|
|
+ /*} catch (IOException var2) { // Plazma - Build fix
|
|
LOGGER.warn("Failed to save ip banlist: ", (Throwable)var2);
|
|
- }
|
|
+ }*/ // Plazma - Build fix
|
|
|
|
}
|
|
|
|
private void saveUserBanList() {
|
|
- try {
|
|
+ //try { // Plazma - Build fix
|
|
this.getBans().save();
|
|
- } catch (IOException var2) {
|
|
+ /*} catch (IOException var2) { // Plazma - Build fix
|
|
LOGGER.warn("Failed to save user banlist: ", (Throwable)var2);
|
|
- }
|
|
+ }*/ // Plazma - Build fix
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
index 78d2298d8cb0b028dc777106115d425b10cfd599..cb5fbe78a4c3bffe91a579b9d8c24e35cd3d1021 100644
|
|
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
@@ -44,11 +44,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 - Fix build
|
|
this.save();
|
|
- } catch (IOException ioexception) {
|
|
+ /*} catch (IOException ioexception) { // Plazma - Fix build
|
|
StoredUserList.LOGGER.warn("Could not save the list after adding a user.", ioexception);
|
|
- }
|
|
+ }*/ // Plazma - Fix build
|
|
|
|
}
|
|
|
|
@@ -66,11 +66,11 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
public void remove(K key) {
|
|
this.map.remove(this.getKeyForUser(key));
|
|
|
|
- try {
|
|
+ //try { // Plazma - Fix build
|
|
this.save();
|
|
- } catch (IOException ioexception) {
|
|
+ /*} catch (IOException ioexception) { // Plazma - Fix build
|
|
StoredUserList.LOGGER.warn("Could not save the list after removing a user.", ioexception);
|
|
- }
|
|
+ }*/ // Plazma - Fix build
|
|
|
|
}
|
|
|
|
@@ -125,7 +125,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
|
|
@@ -137,27 +140,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
|
|
|
|
public void load() throws IOException {
|
|
if (this.file.exists()) {
|