Paper/Spigot-Server-Patches/0381-Allow-login-events-to-fire-only-after-the-server-plu.patch
Zach Brown 27c7749f42
More compile fixes
- Re-removes Bukkit#getServerName - This was (hopefully?) only added back
  for Timings v2. It should be kept in that scope.

- Intend to let PlayerViewDistance API slip. Given the scope of the
  changes in this area it seems best to let this slip past initial
  release. It can be re-added when there is additional time to focus on it
  and the changed systems it relies on. If it is fixed prior to release
  this is implemented as a single shim patch that can be dropped.
2019-05-06 03:20:16 -04:00

73 lines
3.0 KiB
Diff

From 742bd11b5bddb1ee5ed829051c28834955bffd73 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 31 Mar 2019 22:02:24 -0700
Subject: [PATCH] Allow login events to fire only after the server plugins are
enabled
Event threads will simply block until they're ready to accept.
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
index 9e4bc2405..028c23dbe 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -285,6 +285,36 @@ public class LoginListener implements PacketLoginInListener {
}
}
+ // Paper start - Delay async prelogin until plugins are ready
+ private static volatile Object blockingLogins = new Object();
+
+ public static void checkStartupAndBlock() {
+ final Object lock = LoginListener.blockingLogins;
+ if (lock != null) {
+ synchronized (lock) {
+ for (;;) {
+ if (LoginListener.blockingLogins == null) {
+ return;
+ }
+ try {
+ lock.wait();
+ } catch (final InterruptedException ignore) {// handled by the if statement above
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+ }
+
+ public static void allowLogins() {
+ final Object lock = LoginListener.blockingLogins;
+ synchronized (lock) {
+ LoginListener.blockingLogins = null;
+ lock.notifyAll();
+ }
+ }
+ // Paper end
+
// Spigot start
public class LoginHandler {
@@ -295,6 +325,7 @@ public class LoginListener implements PacketLoginInListener {
return;
}
// Paper end
+ LoginListener.checkStartupAndBlock(); // Paper - Delay async login events until plugins are ready
String playerName = i.getName();
java.net.InetAddress address = ((java.net.InetSocketAddress) networkManager.getSocketAddress()).getAddress();
java.util.UUID uniqueId = i.getId();
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 3fc232431..93c014c39 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -463,6 +463,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Paper end
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ LoginListener.allowLogins(); // Paper - Allow logins once postworld
this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
// CraftBukkit end
--
2.21.0