Skip to content

Commit

Permalink
update Velocity detection for 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 14, 2022
1 parent bf5eb70 commit 856e6de
Showing 1 changed file with 32 additions and 3 deletions.
Expand Up @@ -17,6 +17,7 @@

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
Expand Down Expand Up @@ -119,9 +120,9 @@ else if (id.version() == 0) {
proxied = true;
}
else if (Denizen.supportsPaper) {
if (getPaperConfigKey("settings.velocity-support.enabled")) {
boolean velocityOnline = getPaperConfigKey("settings.velocity-support.online-mode");
modeSuffix = velocityOnline ? ChatColor.GREEN + " (Velocity: online)" : ChatColor.RED + " (Velocity: offline)";
String paperMode = getPaperOnlineMode();
if (paperMode != null) {
modeSuffix = paperMode;
proxied = true;
}
}
Expand Down Expand Up @@ -158,6 +159,34 @@ else if (Denizen.supportsPaper) {

public static YamlConfiguration paperConfig;

public static String getPaperOnlineMode() {
boolean isEnabled, isOnline;
try {
Class config = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");
Object instance = ReflectionHelper.getFieldValue(config, "instance", null);
Object proxies = ReflectionHelper.getFieldValue(config, "proxies", instance);
Object velocity = ReflectionHelper.getFieldValue(proxies.getClass(), "velocity", proxies);
Field velField = ReflectionHelper.getFields(velocity.getClass()).get("enabled");
velField.setAccessible(true);
isEnabled = velField.getBoolean(velocity);
Field onlineField = ReflectionHelper.getFields(velocity.getClass()).get("onlineMode");
onlineField.setAccessible(true);
isOnline = onlineField.getBoolean(velocity);
}
catch (ClassNotFoundException ignore) {
isEnabled = getPaperConfigKey("settings.velocity-support.enabled");
isOnline = getPaperConfigKey("settings.velocity-support.online-mode");
}
catch (Throwable ex) {
Debug.echoError(ex);
return null;
}
if (isEnabled) {
return isOnline ? ChatColor.GREEN + " (Velocity: online)" : ChatColor.RED + " (Velocity: offline)";
}
return null;
}

public static boolean getPaperConfigKey(String key) {
if (!Denizen.supportsPaper) {
return false;
Expand Down

0 comments on commit 856e6de

Please sign in to comment.