|
1 | 1 | package net.ess3.nms.refl.providers; |
2 | 2 |
|
| 3 | +import net.ess3.nms.refl.ReflUtil; |
3 | 4 | import org.bukkit.Bukkit; |
4 | 5 |
|
5 | 6 | import java.lang.invoke.MethodHandle; |
|
9 | 10 | public class ReflOnlineModeProvider { |
10 | 11 | private final MethodHandle spigotBungeeGetter; |
11 | 12 | private final MethodHandle paperBungeeGetter; |
| 13 | + private final Object paperProxiesInstance; |
12 | 14 | private final boolean fancyPaperCheck; |
13 | 15 |
|
14 | 16 | public ReflOnlineModeProvider() { |
15 | 17 | MethodHandle spigotBungeeGetter = null; |
16 | 18 | MethodHandle paperBungeeGetter = null; |
| 19 | + Object paperProxiesInstance = null; |
17 | 20 | boolean fancyCheck = false; |
18 | 21 | try { |
19 | 22 | final MethodHandles.Lookup lookup = MethodHandles.lookup(); |
20 | 23 | spigotBungeeGetter = lookup.findStaticGetter(Class.forName("org.spigotmc.SpigotConfig"), "bungee", boolean.class); |
21 | | - final Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig"); |
22 | | - paperBungeeGetter = lookup.findStaticGetter(paperConfig, "bungeeOnlineMode", boolean.class); |
23 | | - paperBungeeGetter = lookup.findStatic(paperConfig, "isProxyOnlineMode", MethodType.methodType(boolean.class)); |
24 | | - fancyCheck = true; |
| 24 | + final Class<?> newPaperConfigClass = ReflUtil.getClassCached("io.papermc.paper.configuration.GlobalConfiguration"); |
| 25 | + if (newPaperConfigClass != null) { |
| 26 | + final Class<?> proxiesClass = Class.forName("io.papermc.paper.configuration.GlobalConfiguration$Proxies"); |
| 27 | + final Object globalConfig = lookup.findStatic(newPaperConfigClass, "get", MethodType.methodType(newPaperConfigClass)).invoke(); |
| 28 | + paperProxiesInstance = lookup.findGetter(newPaperConfigClass, "proxies", proxiesClass).invoke(globalConfig); |
| 29 | + paperBungeeGetter = lookup.findVirtual(proxiesClass, "isProxyOnlineMode", MethodType.methodType(boolean.class)); |
| 30 | + fancyCheck = true; |
| 31 | + } else { |
| 32 | + final Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig"); |
| 33 | + paperBungeeGetter = lookup.findStaticGetter(paperConfig, "bungeeOnlineMode", boolean.class); |
| 34 | + paperBungeeGetter = lookup.findStatic(paperConfig, "isProxyOnlineMode", MethodType.methodType(boolean.class)); |
| 35 | + fancyCheck = true; |
| 36 | + } |
25 | 37 | } catch (Throwable ignored) { |
26 | 38 | } |
27 | 39 | this.spigotBungeeGetter = spigotBungeeGetter; |
28 | 40 | this.paperBungeeGetter = paperBungeeGetter; |
| 41 | + this.paperProxiesInstance = paperProxiesInstance; |
29 | 42 | this.fancyPaperCheck = fancyCheck; |
30 | 43 | } |
31 | 44 |
|
|
0 commit comments