Remove khttp, add json as dependency, update BadIPDetection
This commit is contained in:
@@ -34,16 +34,12 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// SPIGOT
|
|
||||||
compileOnly("org.spigotmc", "spigot", "1.16.5-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc", "spigot", "1.16.5-R0.1-SNAPSHOT")
|
||||||
testCompileOnly("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")
|
api("com.github.WesJD.AnvilGUI", "anvilgui", "master-SNAPSHOT")
|
||||||
|
|
||||||
// KOTLINX
|
|
||||||
// serialization
|
|
||||||
api("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.1.0")
|
api("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.1.0")
|
||||||
|
api("org.json", "json", "20210307")
|
||||||
}
|
}
|
||||||
|
|
||||||
java.sourceCompatibility = jvmVersion
|
java.sourceCompatibility = jvmVersion
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
package net.axay.kspigot.ipaddress
|
package net.axay.kspigot.ipaddress
|
||||||
|
|
||||||
import net.axay.kspigot.ipaddress.badipdetectionservices.GetIPIntel
|
import net.axay.kspigot.ipaddress.badipdetectionservices.GetIPIntel
|
||||||
import net.axay.kspigot.ipaddress.badipdetectionservices.IPHub
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the IP address of the player is not a
|
* Checks if the IP address of the player is not a
|
||||||
@@ -104,17 +105,17 @@ abstract class BadIPDetectionService(
|
|||||||
|
|
||||||
fun isBad(ip: String): BadIPDetectionResult {
|
fun isBad(ip: String): BadIPDetectionResult {
|
||||||
|
|
||||||
val response = khttp.get(
|
val con = URL(requestString(ip)).openConnection() as HttpURLConnection
|
||||||
requestString(ip),
|
con.requestMethod = "GET"
|
||||||
headers = requestHeaders()
|
requestHeaders().forEach { (field, value) -> con.setRequestProperty(field, value) }
|
||||||
)
|
con.connect()
|
||||||
|
|
||||||
if (response.statusCode == 429)
|
if (con.responseCode == 429)
|
||||||
return BadIPDetectionResult.LIMIT
|
return BadIPDetectionResult.LIMIT
|
||||||
else {
|
else {
|
||||||
|
|
||||||
val result = try {
|
val result = try {
|
||||||
response.jsonObject
|
con.inputStream.use { JSONObject(it.readAllBytes().decodeToString()) }
|
||||||
} catch (exc: JSONException) {
|
} catch (exc: JSONException) {
|
||||||
null
|
null
|
||||||
} ?: return BadIPDetectionResult.ERROR
|
} ?: return BadIPDetectionResult.ERROR
|
||||||
|
Reference in New Issue
Block a user