240 lines
11 KiB
Diff
240 lines
11 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/com/destroystokyo/paper/util/maplist/ChunkList.java b/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java
|
|
index 554f4d4e63c1431721989e6f502a32ccc53a8807..b85bc5834d90f20d46f640621abec891456b47a0 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java
|
|
@@ -17,7 +17,7 @@ public final class ChunkList implements Iterable<LevelChunk> {
|
|
this.chunkToIndex.defaultReturnValue(Integer.MIN_VALUE);
|
|
}
|
|
|
|
- protected static final LevelChunk[] EMPTY_LIST = new LevelChunk[0];
|
|
+ protected static final LevelChunk[] EMPTY_LIST = new LevelChunk[0]; // Plazma - Reduce allocations (mark)
|
|
|
|
protected LevelChunk[] chunks = EMPTY_LIST;
|
|
protected int count;
|
|
diff --git a/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java b/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java
|
|
index aef19b44075a3b2e8696315baa89117dd8ebb513..6370d3f4451de4ca12a8bcc2661e4b2b4833fc0e 100644
|
|
--- a/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java
|
|
+++ b/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java
|
|
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|
@ApiStatus.Internal
|
|
public class DummyBukkitPluginLoader implements PluginLoader {
|
|
|
|
- private static final Pattern[] PATTERNS = new Pattern[0];
|
|
+ private static final Pattern[] PATTERNS = new Pattern[0]; // Plazma - Reduce allocations (mark)
|
|
|
|
@Override
|
|
public @NotNull Plugin loadPlugin(@NotNull File file) throws InvalidPluginException, UnknownDependencyException {
|
|
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 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()) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Endermite.java b/src/main/java/net/minecraft/world/entity/monster/Endermite.java
|
|
index 965362c281315c15fb70a83a6949d7825bebf15b..e463df132c9b3cbb2217e7019b1bd9a0e0027c10 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Endermite.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Endermite.java
|
|
@@ -94,7 +94,7 @@ public class Endermite extends Monster {
|
|
this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 8.0F));
|
|
this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
|
|
this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur
|
|
- this.targetSelector.addGoal(1, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers());
|
|
+ this.targetSelector.addGoal(1, (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers()); // Plazma - Reduce allocations
|
|
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
index 6b9cd8543a5bfc2b936ba18f66ffd60f2f792e43..d99c56194d1a16c34a62d8f2f01026974a242921 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
@@ -832,7 +832,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
// Paper start - Perf: Optimize Hoppers
|
|
static final AABB HOPPER_ITEM_SUCK_OVERALL = Hopper.SUCK.bounds();
|
|
- static final AABB[] HOPPER_ITEM_SUCK_INDIVIDUAL = Hopper.SUCK.toAabbs().toArray(new AABB[0]);
|
|
+ static final AABB[] HOPPER_ITEM_SUCK_INDIVIDUAL = Hopper.SUCK.toAabbs().toArray(new AABB[0]); // Plazma - Reduce allocations (mark)
|
|
// Paper end - Perf: Optimize Hoppers
|
|
|
|
public static List<ItemEntity> getItemsAtAndAbove(Level world, Hopper hopper) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java b/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java
|
|
index 8a4f95049c63afb28bef6719c77b7a7092e75aae..e117350504e0c37b27f10ff102781ed78210cad2 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java
|
|
@@ -50,7 +50,7 @@ public class Main {
|
|
System.exit(0);
|
|
}
|
|
|
|
- URLClassLoader classLoader = new URLClassLoader(extractedUrls.toArray(new URL[0]));
|
|
+ URLClassLoader classLoader = new URLClassLoader(extractedUrls.toArray(new URL[0])); // Plazma - Reduce allocations (mark)
|
|
|
|
System.out.println("Starting server");
|
|
Thread runThread = new Thread(() -> {
|
|
diff --git a/src/main/java/org/plazmamc/plazma/commands/plazma/subcommand/VersionCommand.java b/src/main/java/org/plazmamc/plazma/commands/plazma/subcommand/VersionCommand.java
|
|
index b6664ba0fce55f5cfa0c8d3051dc8c2be0fd0703..ccb5008987dff2365fe58eddc86227e4515cbbfc 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/commands/plazma/subcommand/VersionCommand.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/commands/plazma/subcommand/VersionCommand.java
|
|
@@ -7,6 +7,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
|
import org.plazmamc.plazma.commands.PlazmaSubCommand;
|
|
+import org.plazmamc.plazma.constants.Empty;
|
|
|
|
@DefaultQualifier(NonNull.class)
|
|
public class VersionCommand implements PlazmaSubCommand {
|
|
@@ -14,7 +15,7 @@ public class VersionCommand implements PlazmaSubCommand {
|
|
@Override
|
|
public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
|
|
final @Nullable Command ver = MinecraftServer.getServer().server.getCommandMap().getCommand("version");
|
|
- if (ver != null) return ver.execute(sender, "plazma", new String[0]);
|
|
+ if (ver != null) return ver.execute(sender, "plazma", Empty.STRING);
|
|
return false;
|
|
}
|
|
|