From d178f73bb8c42bdc7615c8d08e021147c2179ac9 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 12 Aug 2018 02:33:39 -0400 Subject: [PATCH] Use a Queue for Queueing Commands Lists are bad as Queues mmmkay. --- .../dedicated/DedicatedServer.java.patch | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch index 748c832eb4..b21347294d 100644 --- a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java -@@ -54,11 +54,22 @@ +@@ -54,20 +54,31 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; @@ -24,8 +24,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface { static final Logger LOGGER = LogUtils.getLogger(); -@@ -67,7 +78,7 @@ - private final List consoleInput = Collections.synchronizedList(Lists.newArrayList()); + private static final int CONVERSION_RETRY_DELAY_MS = 5000; + private static final int CONVERSION_RETRIES = 2; +- private final List consoleInput = Collections.synchronizedList(Lists.newArrayList()); ++ private final java.util.Queue serverCommandQueue = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - Perf: use a proper queue @Nullable private QueryThreadGs4 queryThreadGs4; - private final RconConsoleSource rconConsoleSource; @@ -171,16 +173,17 @@ DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); InetAddress inetaddress = null; -@@ -156,21 +247,34 @@ +@@ -155,22 +246,35 @@ + DedicatedServer.LOGGER.warn("Perhaps a server is already running on that port?"); return false; } - ++ + // CraftBukkit start + // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up + this.server.loadPlugins(); + this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP); + // CraftBukkit end -+ + if (!this.usesAuthentication()) { DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); @@ -234,20 +237,19 @@ Thread thread1 = new Thread(new ServerWatchdog(this)); thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER)); -@@ -213,7 +317,13 @@ - - return true; +@@ -215,6 +319,12 @@ } -+ } -+ + } + + // Paper start + public java.io.File getPluginsFolder() { + return (java.io.File) this.options.valueOf("plugins"); - } ++ } + // Paper end - ++ @Override public boolean isSpawningMonsters() { + return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters(); @@ -293,6 +403,7 @@ this.queryThreadGs4.stop(); } @@ -256,7 +258,7 @@ } @Override -@@ -302,8 +413,8 @@ +@@ -302,19 +413,29 @@ } @Override @@ -267,9 +269,17 @@ } public void handleConsoleInput(String command, CommandSourceStack commandSource) { -@@ -314,7 +425,15 @@ - while (!this.consoleInput.isEmpty()) { - ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0); +- this.consoleInput.add(new ConsoleInput(command, commandSource)); ++ this.serverCommandQueue.add(new ConsoleInput(command, commandSource)); // Paper - Perf: use proper queue + } + + public void handleConsoleInputs() { +- while (!this.consoleInput.isEmpty()) { +- ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0); ++ // Paper start - Perf: use proper queue ++ ConsoleInput servercommand; ++ while ((servercommand = this.serverCommandQueue.poll()) != null) { ++ // Paper end - Perf: use proper queue - this.getCommands().performPrefixedCommand(servercommand.source, servercommand.msg); + // CraftBukkit start - ServerCommand for preprocessing @@ -284,7 +294,7 @@ } } -@@ -383,7 +502,7 @@ +@@ -383,7 +504,7 @@ @Override public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) { @@ -293,7 +303,7 @@ return false; } else if (this.getPlayerList().getOps().isEmpty()) { return false; -@@ -453,7 +572,11 @@ +@@ -453,7 +574,11 @@ public boolean enforceSecureProfile() { DedicatedServerProperties dedicatedserverproperties = this.getProperties(); @@ -306,7 +316,7 @@ } @Override -@@ -541,16 +664,52 @@ +@@ -541,16 +666,52 @@ @Override public String getPluginNames() { @@ -363,7 +373,7 @@ } public void storeUsingWhiteList(boolean useWhitelist) { -@@ -660,4 +819,15 @@ +@@ -660,4 +821,15 @@ } } }