Skip to content

Commit

Permalink
Fix mappings in ReflOnlineModeProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy committed Aug 12, 2022
1 parent f2dde41 commit f379323
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ess3.nms.refl.providers;

import net.ess3.nms.refl.ReflUtil;
import org.bukkit.Bukkit;

import java.lang.invoke.MethodHandle;
Expand All @@ -9,23 +10,35 @@
public class ReflOnlineModeProvider {
private final MethodHandle spigotBungeeGetter;
private final MethodHandle paperBungeeGetter;
private final Object paperProxiesInstance;
private final boolean fancyPaperCheck;

public ReflOnlineModeProvider() {
MethodHandle spigotBungeeGetter = null;
MethodHandle paperBungeeGetter = null;
Object paperProxiesInstance = null;
boolean fancyCheck = false;
try {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
spigotBungeeGetter = lookup.findStaticGetter(Class.forName("org.spigotmc.SpigotConfig"), "bungee", boolean.class);
final Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig");
paperBungeeGetter = lookup.findStaticGetter(paperConfig, "bungeeOnlineMode", boolean.class);
paperBungeeGetter = lookup.findStatic(paperConfig, "isProxyOnlineMode", MethodType.methodType(boolean.class));
fancyCheck = true;
final Class<?> newPaperConfigClass = ReflUtil.getClassCached("io.papermc.paper.configuration.GlobalConfiguration");
if (newPaperConfigClass != null) {
final Class<?> proxiesClass = Class.forName("io.papermc.paper.configuration.GlobalConfiguration$Proxies");
final Object globalConfig = lookup.findStatic(newPaperConfigClass, "get", MethodType.methodType(newPaperConfigClass)).invoke();
paperProxiesInstance = lookup.findGetter(newPaperConfigClass, "proxies", proxiesClass).invoke(globalConfig);
paperBungeeGetter = lookup.findVirtual(proxiesClass, "isProxyOnlineMode", MethodType.methodType(boolean.class));
fancyCheck = true;
} else {
final Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig");
paperBungeeGetter = lookup.findStaticGetter(paperConfig, "bungeeOnlineMode", boolean.class);
paperBungeeGetter = lookup.findStatic(paperConfig, "isProxyOnlineMode", MethodType.methodType(boolean.class));
fancyCheck = true;
}
} catch (Throwable ignored) {
}
this.spigotBungeeGetter = spigotBungeeGetter;
this.paperBungeeGetter = paperBungeeGetter;
this.paperProxiesInstance = paperProxiesInstance;
this.fancyPaperCheck = fancyCheck;
}

Expand Down

0 comments on commit f379323

Please sign in to comment.