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 --- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/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.entity.player.Player;
import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType; import net.minecraft.world.level.GameType;
@@ -24,8 +24,10 @@
public class DedicatedServer extends MinecraftServer implements ServerInterface { public class DedicatedServer extends MinecraftServer implements ServerInterface {
static final Logger LOGGER = LogUtils.getLogger(); static final Logger LOGGER = LogUtils.getLogger();
@@ -67,7 +78,7 @@ private static final int CONVERSION_RETRY_DELAY_MS = 5000;
private final List<ConsoleInput> consoleInput = Collections.synchronizedList(Lists.newArrayList()); 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 @Nullable
private QueryThreadGs4 queryThreadGs4; private QueryThreadGs4 queryThreadGs4;
- private final RconConsoleSource rconConsoleSource; - private final RconConsoleSource rconConsoleSource;
@@ -171,16 +173,17 @@
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null; 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; return false;
} }
+
+ // CraftBukkit start + // CraftBukkit start
+ // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up + // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
+ this.server.loadPlugins(); + this.server.loadPlugins();
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP); + this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
+ // CraftBukkit end + // CraftBukkit end
+
if (!this.usesAuthentication()) { if (!this.usesAuthentication()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
@@ -234,20 +237,19 @@
Thread thread1 = new Thread(new ServerWatchdog(this)); Thread thread1 = new Thread(new ServerWatchdog(this));
thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER)); thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER));
@@ -213,7 +317,13 @@ @@ -215,6 +319,12 @@
return true;
} }
+ } }
+
+ // Paper start + // Paper start
+ public java.io.File getPluginsFolder() { + public java.io.File getPluginsFolder() {
+ return (java.io.File) this.options.valueOf("plugins"); + return (java.io.File) this.options.valueOf("plugins");
} + }
+ // Paper end + // Paper end
+
@Override @Override
public boolean isSpawningMonsters() { public boolean isSpawningMonsters() {
return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters();
@@ -293,6 +403,7 @@ @@ -293,6 +403,7 @@
this.queryThreadGs4.stop(); this.queryThreadGs4.stop();
} }
@@ -256,7 +258,7 @@
} }
@Override @Override
@@ -302,8 +413,8 @@ @@ -302,19 +413,29 @@
} }
@Override @Override
@@ -267,9 +269,17 @@
} }
public void handleConsoleInput(String command, CommandSourceStack commandSource) { public void handleConsoleInput(String command, CommandSourceStack commandSource) {
@@ -314,7 +425,15 @@ - this.consoleInput.add(new ConsoleInput(command, commandSource));
while (!this.consoleInput.isEmpty()) { + this.serverCommandQueue.add(new ConsoleInput(command, commandSource)); // Paper - Perf: use proper queue
ConsoleInput servercommand = (ConsoleInput) this.consoleInput.remove(0); }
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); - this.getCommands().performPrefixedCommand(servercommand.source, servercommand.msg);
+ // CraftBukkit start - ServerCommand for preprocessing + // CraftBukkit start - ServerCommand for preprocessing
@@ -284,7 +294,7 @@
} }
} }
@@ -383,7 +502,7 @@ @@ -383,7 +504,7 @@
@Override @Override
public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) { public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) {
@@ -293,7 +303,7 @@
return false; return false;
} else if (this.getPlayerList().getOps().isEmpty()) { } else if (this.getPlayerList().getOps().isEmpty()) {
return false; return false;
@@ -453,7 +572,11 @@ @@ -453,7 +574,11 @@
public boolean enforceSecureProfile() { public boolean enforceSecureProfile() {
DedicatedServerProperties dedicatedserverproperties = this.getProperties(); DedicatedServerProperties dedicatedserverproperties = this.getProperties();
@@ -306,7 +316,7 @@
} }
@Override @Override
@@ -541,16 +664,52 @@ @@ -541,16 +666,52 @@
@Override @Override
public String getPluginNames() { public String getPluginNames() {
@@ -363,7 +373,7 @@
} }
public void storeUsingWhiteList(boolean useWhitelist) { public void storeUsingWhiteList(boolean useWhitelist) {
@@ -660,4 +819,15 @@ @@ -660,4 +821,15 @@
} }
} }
} }