mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Support newer Paper configuration with clearer error messages
This commit is contained in:
@ -33,6 +33,7 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -88,33 +89,62 @@ public class BungeeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
try {
|
enabled = detectProxy();
|
||||||
enabled = detectProxy();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
plugin.getLog().warn("Cannot check proxy support. Fallback to non-proxy mode", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
proxyIds = loadBungeeCordIds();
|
proxyIds = loadBungeeCordIds();
|
||||||
registerPluginChannels();
|
registerPluginChannels();
|
||||||
|
plugin.getLog().info("Found enabled proxy configuration");
|
||||||
|
plugin.getLog().info("Remember to follow the proxy guide to complete your setup");
|
||||||
|
} else {
|
||||||
|
plugin.getLog().warn("Disabling Minecraft proxy configuration. Assuming direct connections from now on.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProxySupported(String className, String fieldName) {
|
private boolean isProxySupported(String className, String fieldName)
|
||||||
|
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||||
|
return Class.forName(className).getDeclaredField(fieldName).getBoolean(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isVelocityEnabled()
|
||||||
|
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException,
|
||||||
|
NoSuchMethodException, InvocationTargetException {
|
||||||
try {
|
try {
|
||||||
return Class.forName(className).getDeclaredField(fieldName).getBoolean(null);
|
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
|
||||||
} catch (ClassNotFoundException notFoundEx) {
|
return true;
|
||||||
//ignore server has no proxy support
|
}
|
||||||
} catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) {
|
} catch (ClassNotFoundException classNotFoundException) {
|
||||||
plugin.getLog().warn("Cannot access proxy field", noSuchFieldException);
|
// try again using the newer Paper configuration
|
||||||
|
Class<?> globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");
|
||||||
|
Object global = globalConfig.getDeclaredMethod("get").invoke(null);
|
||||||
|
Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global);
|
||||||
|
Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration);
|
||||||
|
|
||||||
|
return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean detectProxy() {
|
private boolean detectProxy() {
|
||||||
return isProxySupported("org.spigotmc.SpigotConfig", "bungee")
|
try {
|
||||||
|| isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport");
|
if (isProxySupported("org.spigotmc.SpigotConfig", "bungee")) return true;
|
||||||
|
} catch (ClassNotFoundException classNotFoundException) {
|
||||||
|
// leave stacktrace for class not found out
|
||||||
|
plugin.getLog().warn("Cannot check for BungeeCord support: {}", classNotFoundException.getMessage());
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||||
|
plugin.getLog().warn("Cannot check for BungeeCord support", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return isVelocityEnabled();
|
||||||
|
} catch (ClassNotFoundException classNotFoundException) {
|
||||||
|
plugin.getLog().warn("Cannot check for Velocity support in Paper: {}", classNotFoundException.getMessage());
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
|
||||||
|
plugin.getLog().warn("Cannot check for Velocity support in Paper", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPluginChannels() {
|
private void registerPluginChannels() {
|
||||||
@ -148,9 +178,7 @@ public class BungeeManager {
|
|||||||
|
|
||||||
Files.deleteIfExists(legacyFile);
|
Files.deleteIfExists(legacyFile);
|
||||||
try (Stream<String> lines = Files.lines(proxiesFile)) {
|
try (Stream<String> lines = Files.lines(proxiesFile)) {
|
||||||
return lines.map(String::trim)
|
return lines.map(String::trim).map(UUID::fromString).collect(toSet());
|
||||||
.map(UUID::fromString)
|
|
||||||
.collect(toSet());
|
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
plugin.getLog().error("Failed to read proxies", ex);
|
plugin.getLog().error("Failed to read proxies", ex);
|
||||||
@ -177,7 +205,7 @@ public class BungeeManager {
|
|||||||
/**
|
/**
|
||||||
* Check if the event fired including with the task delay. This necessary to restore the order of processing the
|
* Check if the event fired including with the task delay. This necessary to restore the order of processing the
|
||||||
* BungeeCord messages after the PlayerJoinEvent fires including the delay.
|
* BungeeCord messages after the PlayerJoinEvent fires including the delay.
|
||||||
*
|
* <p>
|
||||||
* If the join event fired, the delay exceeded, but it ran earlier and couldn't find the recently started login
|
* If the join event fired, the delay exceeded, but it ran earlier and couldn't find the recently started login
|
||||||
* session. If not fired, we can start a new force login task. This will still match the requirement that we wait
|
* session. If not fired, we can start a new force login task. This will still match the requirement that we wait
|
||||||
* a certain time after the player join event fired.
|
* a certain time after the player join event fired.
|
||||||
|
Reference in New Issue
Block a user