Yatopia/patches/server/0061-Preload-ProtocolLib-EnumWrappers.patch
Simon Gardling 021f928c4d
Updated Upstream and Sidestream(s) (Paper/Purpur/AirplaneLite/Origami) (#382)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
0514fc4e2 Add missing effects
8f5d9effd Add getMainThreadExecutor to BukkitScheduler
313b5020b Allow adding items to BlockDropItemEvent (#5093)
9a556d9da [CI-SKIP] [Auto] Rebuild Patches
72b2768ad Inline shift fields in EnumDirection (#5082)
ffff53fa7 added option to disable pathfinding updates on block changes (#5123)
b67081fd7 add DragonEggFormEvent (fixes #5110) (#5112)
3eefafbaf Fix javadoc build
0081ed1c4 Add javadoc step to GH Actions
01082503e Add dropLeash variable to EntityUnleashEvent (#5130)
31f9f869a [CI-SKIP] Fix YourKit links in readme, fixes #5091
8ac27aa38 [Auto] Updated Upstream (CraftBukkit)
c4d9cc831 [Auto] Updated Upstream (Bukkit/CraftBukkit)
d0477d326 [Auto] Updated Upstream (CraftBukkit)
d9f5f7018 EntityMoveEvent (#4614)

Purpur Changes:
e581a73 Updated Upstream (Paper)

AirplaneLite Changes:
10c5810 Updated Upstream (Tuinity)

Origami Changes:
45d89cc Update Paper
578ef16 Automatically disable online-mode if bungeecord is enabled
de51baa Update Paper
5986aef Import Purpur patch to not send useless entity packets
2021-02-02 10:17:46 -05:00

68 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Wed, 27 Jan 2021 20:16:47 +0800
Subject: [PATCH] Preload ProtocolLib EnumWrappers
Currently, ProtocolLib load EnumWrappers lazily and causing memory effects issues. This patch preloads EnumWrappers to prevent further NPE.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 17a131b35c2be525d18bc1ba7800a0fe79c2b541..cc48769c4d6e2146244e510a0295308979636314 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -960,6 +960,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Paper end
PaperJvmChecker.checkJvm(); // Paper jvm version nag
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.fixProtocolLib) org.yatopiamc.yatopia.server.util.YatopiaPreloadProtocolLib.run(); // Yatopia
com.tuinity.tuinity.config.TuinityConfig.createWorldSections = false; // Tuinity - don't let plugin created worlds fill our config
org.spigotmc.WatchdogThread.tick(); // Paper
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
index c2dc5265552ebd429111253c70481003a4be29dd..15e2fa125bc293b954cceb5b1fbcec7fade3e4db 100644
--- a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
@@ -271,4 +271,9 @@ public class YatopiaConfig {
logPlayerLoginLoc = getBoolean("settings.log-player-login-location", logPlayerLoginLoc);
}
+ public static boolean fixProtocolLib = true;
+ private static void protocolLib() {
+ fixProtocolLib = getBoolean("settings.fix-protocollib", fixProtocolLib);
+ }
+
}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/util/YatopiaPreloadProtocolLib.java b/src/main/java/org/yatopiamc/yatopia/server/util/YatopiaPreloadProtocolLib.java
new file mode 100644
index 0000000000000000000000000000000000000000..85906aa00163a4626b16190e2e48385bc5eba801
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/util/YatopiaPreloadProtocolLib.java
@@ -0,0 +1,28 @@
+package org.yatopiamc.yatopia.server.util;
+
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.SimplePluginManager;
+
+import java.lang.reflect.Method;
+
+public class YatopiaPreloadProtocolLib {
+
+ public synchronized static void run() {
+ try {
+ final SimplePluginManager pluginManager = (SimplePluginManager) Bukkit.getPluginManager();
+ final Plugin protocolLib = pluginManager.getPlugin("ProtocolLib");
+ if(protocolLib != null && protocolLib.isEnabled()) {
+ MinecraftServer.LOGGER.info("Yatopia: Attempting to fix ProtocolLib");
+ final Method initialize = Class.forName("com.comphenix.protocol.wrappers.EnumWrappers", true, protocolLib.getClass().getClassLoader()).getDeclaredMethod("initialize");
+ initialize.setAccessible(true);
+ initialize.invoke(null);
+ synchronized (YatopiaPreloadProtocolLib.class) {
+ }
+ }
+ } catch (Throwable t) {
+ MinecraftServer.LOGGER.warn("Unable to fix ProtocolLib", t);
+ }
+ }
+}