Use a Queue for Queueing Commands

Lists are bad as Queues mmmkay.
This commit is contained in:
Aikar 2018-08-12 02:33:39 -04:00
parent f6519a79fe
commit d178f73bb8

View file

@ -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> 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> consoleInput = Collections.synchronizedList(Lists.newArrayList());
+ private final java.util.Queue<ConsoleInput> 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 @@
}
}
}