Files
PlazmaBukkitMC/patches/server/0028-Save-Json-list-asynchronously.patch
AlphaKR93 3f15d7a684 Updated Upstream (Paper, Pufferfish, Purpur)
Upstream has released updates that appear to apply and compile correctly.

[Purpur Changes]
PurpurMC/Purpur@e86a1b6: Updated Upstream (Paper)
PurpurMC/Purpur@962ee30: Updated Upstream (Paper)
PurpurMC/Purpur@74d1b4c: Updated Upstream (Paper)
PurpurMC/Purpur@e2e8c61: Updated Upstream (Paper)
PurpurMC/Purpur@7a01fd8: Updated Upstream (Paper)
PurpurMC/Purpur@34c18f0: Updated Upstream (Paper)
PurpurMC/Purpur@ca668ab: Updated Upstream (Paper)
PurpurMC/Purpur@200178d: Updated Upstream (Paper)
PurpurMC/Purpur@9968cbb: Updated Upstream (Paper)
PurpurMC/Purpur@db09358: Fix clamp-levels option not being true by default (#1609)
PurpurMC/Purpur@f289b6a: Updated Upstream (Paper)
PurpurMC/Purpur@959c29d: Fix Tridents giving errors without having an Elytra equipped (#1612)
PurpurMC/Purpur@68c1612: Fix villagers not spawning when the `follow-emerald-blocks` option is enabled (#1611)
PurpurMC/Purpur@5b75c68: fix `bypass-mob-griefing` not being the inverse of mobgriefing gamerule, closes #1603
PurpurMC/Purpur@55d4309: Updated Upstream (Paper)
PurpurMC/Purpur@0601f87: Updated Upstream (Paper)
PurpurMC/Purpur@06dde9d: Add Ridable and Attribute options for Creaking mob (#1613)
PurpurMC/Purpur@420a1ce: Set the bee's `takes-damage-from-water` option to true by default (#1614)
PurpurMC/Purpur@2b6f273: Updated Upstream (Paper)
PurpurMC/Purpur@504f311: Updated Upstream (Paper)
PurpurMC/Purpur@2b694c9: Updated Upstream (Paper)
PurpurMC/Purpur@96d7ef7: Updated Upstream (Paper)
PurpurMC/Purpur@e141f68: Updated Upstream (Paper)
PurpurMC/Purpur@7f6f667: Updated Upstream (Pufferfish)
PurpurMC/Purpur@de20ba9: ignore `minecart.max-speed` config value if using minecart experiment, closes #1618
PurpurMC/Purpur@03062a8: fix ridable mobs not being controllable, closes #1620
PurpurMC/Purpur@0493ac3: Updated Upstream (Paper)
PurpurMC/Purpur@16ce24a: fix(ridables/creaking): override tick method in look/move control
2024-12-14 01:59:42 +09:00

153 lines
5.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 22c4f8dea99f92a1eb3da2baf0a15bf9d2ca0462..20c531f11b310dab0a867e589c769393ed835df5 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedPlayerList.java
@@ -58,21 +58,23 @@ public class DedicatedPlayerList extends PlayerList {
this.loadWhiteList();
}
+ // Plazma start - Save JSON list asynchronously
private void saveIpBanList() {
- try {
- this.getIpBans().save();
- } catch (IOException var2) {
- LOGGER.warn("Failed to save ip banlist: ", (Throwable)var2);
- }
+ this.getIpBans().save();
}
private void saveUserBanList() {
- try {
- this.getBans().save();
- } catch (IOException var2) {
- LOGGER.warn("Failed to save user banlist: ", (Throwable)var2);
- }
+ this.getBans().save();
+ }
+
+ private void saveOps() {
+ this.getOps().save();
+ }
+
+ private void saveWhiteList() {
+ this.getWhiteList().save();
}
+ // Plazma end - Save JSON list asynchronously
private void loadIpBanList() {
try {
@@ -98,14 +100,6 @@ public class DedicatedPlayerList extends PlayerList {
}
}
- private void saveOps() {
- try {
- this.getOps().save();
- } catch (Exception var2) {
- LOGGER.warn("Failed to save operators list: ", (Throwable)var2);
- }
- }
-
private void loadWhiteList() {
try {
this.getWhiteList().load();
@@ -114,14 +108,6 @@ public class DedicatedPlayerList extends PlayerList {
}
}
- private void saveWhiteList() {
- try {
- this.getWhiteList().save();
- } catch (Exception var2) {
- LOGGER.warn("Failed to save white-list: ", (Throwable)var2);
- }
- }
-
@Override
public boolean isWhiteListed(GameProfile profile) {
return !this.isUsingWhitelist() || this.isOp(profile) || this.getWhiteList().isWhiteListed(profile);
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
index c038da20b76c0b7b1c18471b20be01e849d29f3a..0735a0bd182635e1969d19336b46bc72b14e555f 100644
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
@@ -42,13 +42,7 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
public void add(V entry) {
this.map.put(this.getKeyForUser(entry.getUser()), entry);
-
- try {
- this.save();
- } catch (IOException ioexception) {
- StoredUserList.LOGGER.warn("Could not save the list after adding a user.", ioexception);
- }
-
+ this.save(); // Plazma - Save Json list asynchronously
}
@Nullable
@@ -62,13 +56,7 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
public void remove(K key) {
this.map.remove(this.getKeyForUser(key));
-
- try {
- this.save();
- } catch (IOException ioexception) {
- StoredUserList.LOGGER.warn("Could not save the list after removing a user.", ioexception);
- }
-
+ this.save(); // Plazma - Save Json list asynchronously
}
public void remove(StoredUserEntry<K> entry) {
@@ -102,7 +90,9 @@ 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 +104,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, StoredUserList.GSON.newJsonWriter(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()) {