mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
@ -71,25 +71,43 @@ public class ConnectListener implements Listener {
|
|||||||
private static final String UUID_FIELD_NAME = "uniqueId";
|
private static final String UUID_FIELD_NAME = "uniqueId";
|
||||||
protected static final MethodHandle UNIQUE_ID_SETTER;
|
protected static final MethodHandle UNIQUE_ID_SETTER;
|
||||||
|
|
||||||
|
private static final String REWRITE_ID_NAME = "rewriteId";
|
||||||
|
protected static final MethodHandle REWRITE_ID_SETTER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
MethodHandle setHandle = null;
|
MethodHandle uniqueIdHandle = null;
|
||||||
|
MethodHandle rewriterHandle = null;
|
||||||
try {
|
try {
|
||||||
Lookup lookup = MethodHandles.lookup();
|
Lookup lookup = MethodHandles.lookup();
|
||||||
|
|
||||||
|
// test for implementation class availability
|
||||||
Class.forName("net.md_5.bungee.connection.InitialHandler");
|
Class.forName("net.md_5.bungee.connection.InitialHandler");
|
||||||
|
uniqueIdHandle = getHandlerSetter(lookup, UUID_FIELD_NAME);
|
||||||
Field uuidField = InitialHandler.class.getDeclaredField(UUID_FIELD_NAME);
|
try {
|
||||||
uuidField.setAccessible(true);
|
rewriterHandle = getHandlerSetter(lookup, REWRITE_ID_NAME);
|
||||||
setHandle = lookup.unreflectSetter(uuidField);
|
} catch (NoSuchFieldException noSuchFieldEx) {
|
||||||
|
Logger logger = LoggerFactory.getLogger(ConnectListener.class);
|
||||||
|
logger.error(
|
||||||
|
"Rewrite field not found. Setting only legacy BungeeCord field"
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (ReflectiveOperationException reflectiveOperationException) {
|
} catch (ReflectiveOperationException reflectiveOperationException) {
|
||||||
Logger logger = LoggerFactory.getLogger(ConnectListener.class);
|
Logger logger = LoggerFactory.getLogger(ConnectListener.class);
|
||||||
logger.error(
|
logger.error(
|
||||||
"Cannot find Bungee initial handler; Disabling premium UUID and skin won't work.",
|
"Cannot find Bungee UUID field implementation; Disabling premium UUID and skin won't work.",
|
||||||
reflectiveOperationException
|
reflectiveOperationException
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNIQUE_ID_SETTER = setHandle;
|
UNIQUE_ID_SETTER = uniqueIdHandle;
|
||||||
|
REWRITE_ID_SETTER = rewriterHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MethodHandle getHandlerSetter(Lookup lookup, String fieldName)
|
||||||
|
throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field uuidField = InitialHandler.class.getDeclaredField(fieldName);
|
||||||
|
uuidField.setAccessible(true);
|
||||||
|
return lookup.unreflectSetter(uuidField);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final FastLoginBungee plugin;
|
private final FastLoginBungee plugin;
|
||||||
@ -179,6 +197,12 @@ public class ConnectListener implements Listener {
|
|||||||
// So we have to do it with reflection
|
// So we have to do it with reflection
|
||||||
UNIQUE_ID_SETTER.invokeExact(connection, offlineUUID);
|
UNIQUE_ID_SETTER.invokeExact(connection, offlineUUID);
|
||||||
|
|
||||||
|
// if available set rewrite id to forward the UUID for newer BungeeCord versions since
|
||||||
|
// https://github.com/SpigotMC/BungeeCord/commit/1be25b6c74ec2be4b15adf8ca53a0497f01e2afe
|
||||||
|
if (REWRITE_ID_SETTER != null) {
|
||||||
|
REWRITE_ID_SETTER.invokeExact(connection, offlineUUID);
|
||||||
|
}
|
||||||
|
|
||||||
String format = "Overridden UUID from {} to {} (based of {}) on {}";
|
String format = "Overridden UUID from {} to {} (based of {}) on {}";
|
||||||
plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection);
|
plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Reference in New Issue
Block a user