diff --git a/build.gradle.kts b/build.gradle.kts index 60f0b927..94e69d6a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,16 +34,12 @@ repositories { } dependencies { - // SPIGOT compileOnly("org.spigotmc", "spigot", "1.16.5-R0.1-SNAPSHOT") testCompileOnly("org.spigotmc", "spigot", "1.16.5-R0.1-SNAPSHOT") - // ANVIL GUI api("com.github.WesJD.AnvilGUI", "anvilgui", "master-SNAPSHOT") - - // KOTLINX - // serialization api("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.1.0") + api("org.json", "json", "20210307") } java.sourceCompatibility = jvmVersion diff --git a/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt b/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt index 8a533775..30448180 100644 --- a/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt +++ b/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt @@ -1,10 +1,11 @@ package net.axay.kspigot.ipaddress import net.axay.kspigot.ipaddress.badipdetectionservices.GetIPIntel -import net.axay.kspigot.ipaddress.badipdetectionservices.IPHub import org.bukkit.entity.Player import org.json.JSONException import org.json.JSONObject +import java.net.HttpURLConnection +import java.net.URL /** * Checks if the IP address of the player is not a @@ -104,17 +105,17 @@ abstract class BadIPDetectionService( fun isBad(ip: String): BadIPDetectionResult { - val response = khttp.get( - requestString(ip), - headers = requestHeaders() - ) + val con = URL(requestString(ip)).openConnection() as HttpURLConnection + con.requestMethod = "GET" + requestHeaders().forEach { (field, value) -> con.setRequestProperty(field, value) } + con.connect() - if (response.statusCode == 429) + if (con.responseCode == 429) return BadIPDetectionResult.LIMIT else { val result = try { - response.jsonObject + con.inputStream.use { JSONObject(it.readAllBytes().decodeToString()) } } catch (exc: JSONException) { null } ?: return BadIPDetectionResult.ERROR