From 268aee6dc662e17e9e62b17b119552c60bc411f3 Mon Sep 17 00:00:00 2001 From: Francisco Solis Date: Fri, 8 Apr 2022 21:32:12 -0400 Subject: [PATCH] Fixed SoftwareType Checker --- CHANGELOG.md | 3 +++ build.gradle | 2 +- .../global/utils/SoftwareType.kt | 20 +++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2de0e..0a151c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.3.4 - Snapshot +* Fixed SoftwareType Checker + ## v0.3.3 - Snapshot * Configured Renovate * Updated dependencies diff --git a/build.gradle b/build.gradle index 851798e..df893eb 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { id 'org.jetbrains.dokka' version '1.6.10' } -def projectVersion = (System.getenv("VERSION") ?: '0.3.3-SNAPSHOT').replaceFirst("v", "").replace('/', '') +def projectVersion = (System.getenv("VERSION") ?: '0.3.4-SNAPSHOT').replaceFirst("v", "").replace('/', '') group 'xyz.theprogramsrc' version projectVersion diff --git a/src/main/kotlin/xyz/theprogramsrc/simplecoreapi/global/utils/SoftwareType.kt b/src/main/kotlin/xyz/theprogramsrc/simplecoreapi/global/utils/SoftwareType.kt index c8b9261..a0dcc9c 100644 --- a/src/main/kotlin/xyz/theprogramsrc/simplecoreapi/global/utils/SoftwareType.kt +++ b/src/main/kotlin/xyz/theprogramsrc/simplecoreapi/global/utils/SoftwareType.kt @@ -1,5 +1,7 @@ package xyz.theprogramsrc.simplecoreapi.global.utils +import java.util.Objects + /** * Representation of a ServerSoftware * @param check The function to check if the software is running the server or not. @@ -49,9 +51,12 @@ enum class SoftwareType(val check: () -> Boolean = { false }, val display: Strin // Proxies BUNGEE(check = { try { - val proxyServerInstance = Class.forName("net.md_5.bungee.api.ProxyServer").getMethod("getInstance").invoke(null) as Class<*> - val name = proxyServerInstance.getMethod("getName").invoke(proxyServerInstance) as String - name.equals("BungeeCord") + val proxyServer = Class.forName("net.md_5.bungee.api.ProxyServer") + val proxyServerInstanceValue = proxyServer.getDeclaredField("instance").apply { + isAccessible = true + }.get(null) + val proxyServerName = proxyServer.getMethod("getName").invoke(proxyServerInstanceValue) as String + Objects.equals(proxyServerName, "BungeeCord") } catch (e: Exception) { false } @@ -59,9 +64,12 @@ enum class SoftwareType(val check: () -> Boolean = { false }, val display: Strin WATERFALL(check = { try { - val proxyServerInstance = Class.forName("net.md_5.bungee.api.ProxyServer").getMethod("getInstance").invoke(null) as Class<*> - val name = proxyServerInstance.getMethod("getName").invoke(proxyServerInstance) as String - name.equals("Waterfall") + val proxyServer = Class.forName("net.md_5.bungee.api.ProxyServer") + val proxyServerInstanceValue = proxyServer.getDeclaredField("instance").apply { + isAccessible = true + }.get(null) + val proxyServerName = proxyServer.getMethod("getName").invoke(proxyServerInstanceValue) as String + Objects.equals(proxyServerName, "Waterfall") } catch (e: Exception) { false }