Remove khttp, add json as dependency, update BadIPDetection
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user