Flip velocity check to scan for newer Paper configurations first

The PaperConfig class file still exists in newer versions
This commit is contained in:
games647
2022-07-08 16:43:02 +02:00
parent e89cb3293a
commit adfae507ac
2 changed files with 9 additions and 8 deletions

View File

@ -110,17 +110,17 @@ public class BungeeManager {
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException,
NoSuchMethodException, InvocationTargetException {
try {
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
return true;
}
} catch (ClassNotFoundException classNotFoundException) {
// 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);
} catch (ClassNotFoundException classNotFoundException) {
// try again using the older Paper configuration, because the old class file still exists in newer versions
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
return true;
}
}
return false;

View File

@ -142,7 +142,7 @@ public class EncryptionUtilTest {
assertThat(decryptSharedKey, is(secretKey));
}
private static byte[] encrypt(PublicKey receiverKey, byte[] message)
private static byte[] encrypt(PublicKey receiverKey, byte... message)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
IllegalBlockSizeException, BadPaddingException {
var encryptCipher = Cipher.getInstance(receiverKey.getAlgorithm());
@ -169,13 +169,14 @@ public class EncryptionUtilTest {
assertThat(EncryptionUtil.getServerIdHashString(serverId, sharedSecret, serverPK), is(sessionHash));
}
private static String getServerHash(String serverId, SecretKey sharedSecret, PublicKey serverPK) {
private static String getServerHash(CharSequence serverId, SecretKey sharedSecret, PublicKey serverPK) {
// https://wiki.vg/Protocol_Encryption#Client
// sha1 := Sha1()
// sha1.update(ASCII encoding of the server id string from Encryption Request)
// sha1.update(shared secret)
// sha1.update(server's encoded public key from Encryption Request)
// hash := sha1.hexdigest() # String of hex characters
@SuppressWarnings("deprecation")
var hasher = Hashing.sha1().newHasher();
hasher.putString(serverId, StandardCharsets.US_ASCII);
hasher.putBytes(sharedSecret.getEncoded());
@ -197,7 +198,7 @@ public class EncryptionUtilTest {
}
@Test
public void testServerIdHashWrongServerKey() throws Exception {
public void testServerIdHashWrongServerKey() {
var serverId = "";
var sharedSecret = generateSharedKey();
var serverPK = EncryptionUtil.generateKeyPair().getPublic();