PaperMC/patches/server/0229-Use-a-Queue-for-Queueing-Commands.patch

40 lines
2.3 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 12 Aug 2018 02:33:39 -0400
Subject: [PATCH] Use a Queue for Queueing Commands
Lists are bad as Queues mmmkay.
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2024-06-13 21:04:27 +02:00
index baf93b5d5883d0a5c360f1a475949804b7907636..b15cee6f21ff300b596922a8eed35a5f8a89fe22 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2024-06-13 21:04:27 +02:00
@@ -78,7 +78,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2022-06-07 23:45:11 +02:00
static final Logger LOGGER = LogUtils.getLogger();
2021-06-13 01:45:00 +02:00
private static final int CONVERSION_RETRY_DELAY_MS = 5000;
private static final int CONVERSION_RETRIES = 2;
2021-06-11 14:02:28 +02:00
- private final List<ConsoleInput> consoleInput = Collections.synchronizedList(Lists.newArrayList());
+ private final java.util.Queue<ConsoleInput> serverCommandQueue = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - Perf: use a proper queue
2021-11-23 16:04:41 +01:00
@Nullable
2021-06-11 14:02:28 +02:00
private QueryThreadGs4 queryThreadGs4;
2023-09-22 00:01:00 +02:00
// private final RemoteControlCommandListener rconConsoleSource; // CraftBukkit - remove field
2024-06-13 21:04:27 +02:00
@@ -438,13 +438,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
public void handleConsoleInput(String command, CommandSourceStack commandSource) {
2021-06-11 14:02:28 +02:00
- this.consoleInput.add(new ConsoleInput(command, commandSource));
+ this.serverCommandQueue.add(new ConsoleInput(command, commandSource)); // Paper - Perf: use proper queue
2021-06-11 14:02:28 +02:00
}
public void handleConsoleInputs() {
MinecraftTimings.serverCommandTimer.startTiming(); // Spigot
- while (!this.consoleInput.isEmpty()) {
- ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0);
+ // Paper start - Perf: use proper queue
2021-06-11 14:02:28 +02:00
+ ConsoleInput servercommand;
+ while ((servercommand = this.serverCommandQueue.poll()) != null) {
+ // Paper end - Perf: use proper queue
2021-06-11 14:02:28 +02:00
// CraftBukkit start - ServerCommand for preprocessing
2023-10-27 01:34:58 +02:00
ServerCommandEvent event = new ServerCommandEvent(this.console, servercommand.msg);