diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 58ebc02d1..d5a6ba0b5 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -21,6 +21,7 @@ val modId: String by project val fabricLoaderVersion: String by project val kotlinxCoroutinesVersion: String by project val discordIPCVersion: String by project +val fuelVersion: String by project base.archivesName = "${base.archivesName.get()}-api" @@ -45,6 +46,10 @@ dependencies { implementation("com.github.Edouard127:KDiscordIPC:$discordIPCVersion") implementation("com.pngencoder:pngencoder:0.15.0") + // Fuel HTTP library + implementation("com.github.kittinunf.fuel:fuel:$fuelVersion") + implementation("com.github.kittinunf.fuel:fuel-gson:$fuelVersion") + // Add Kotlin implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph/EmojiGlyphs.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph/EmojiGlyphs.kt index bbf113885..ab22c5db0 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph/EmojiGlyphs.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/glyph/EmojiGlyphs.kt @@ -17,12 +17,18 @@ package com.lambda.graphics.renderer.gui.font.glyph +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.core.FuelManager +import com.github.kittinunf.fuel.core.Method +import com.github.kittinunf.fuel.core.await +import com.github.kittinunf.fuel.core.awaitResponse +import com.github.kittinunf.fuel.core.awaitUnit +import com.github.kittinunf.fuel.core.responseUnit import com.google.common.math.IntMath.pow import com.lambda.Lambda.LOG import com.lambda.graphics.texture.MipmapTexture -import com.lambda.http.Method -import com.lambda.http.request import com.lambda.module.modules.client.RenderSettings +import com.lambda.util.FolderRegister.cache import com.lambda.util.math.Vec2d import java.awt.Color import java.awt.Graphics2D @@ -33,7 +39,6 @@ import javax.imageio.ImageIO import kotlin.math.ceil import kotlin.math.log2 import kotlin.math.sqrt -import kotlin.time.Duration.Companion.days class EmojiGlyphs(zipUrl: String) { private val emojiMap = mutableMapOf() @@ -54,9 +59,11 @@ class EmojiGlyphs(zipUrl: String) { } private fun downloadAndProcessZip(zipUrl: String) { - val file = request(zipUrl) { - method(Method.GET) - }.maybeDownload("emojis.zip", maxAge = 30.days) + val file = cache.resolve("emojis.zip").toFile() + + Fuel.download(zipUrl, Method.GET) + .fileDestination { _, _ -> file } + .responseUnit() fontTexture = MipmapTexture(processZip(file)) } diff --git a/common/src/main/kotlin/com/lambda/http/Extensions.kt b/common/src/main/kotlin/com/lambda/http/Extensions.kt deleted file mode 100644 index c95013217..000000000 --- a/common/src/main/kotlin/com/lambda/http/Extensions.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.http - -import com.lambda.Lambda -import java.net.URLEncoder - -/** - * Extension property to convert a map to a URL query string. - */ -val Map.query: String - get() = map { (key, value) -> "$key=${value.urlEncoded}" }.joinToString("&") - -/** - * Extension property to URL encode a string. - */ -val Any.urlEncoded: String get() = URLEncoder.encode(toString(), "UTF-8") - -/** - * Extension function to convert a map to a JSON string. - */ -fun Map.toJson(): String = Lambda.gson.toJson(this) - -/** - * Try-catch block wrapped with a default value. - */ -fun tryOrDefault(default: T, block: () -> T): T = try { - block() -} catch (e: Exception) { - default -} diff --git a/common/src/main/kotlin/com/lambda/http/Method.kt b/common/src/main/kotlin/com/lambda/http/Method.kt deleted file mode 100644 index 693bdbf89..000000000 --- a/common/src/main/kotlin/com/lambda/http/Method.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.http - -/** - * Enum representing HTTP methods. - */ -enum class Method { - GET, - HEAD, - POST, - PUT, - DELETE, - OPTIONS, - TRACE, - PATCH; -} diff --git a/common/src/main/kotlin/com/lambda/http/Request.kt b/common/src/main/kotlin/com/lambda/http/Request.kt deleted file mode 100644 index 1cc08d04b..000000000 --- a/common/src/main/kotlin/com/lambda/http/Request.kt +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.http - -import com.lambda.Lambda -import com.lambda.util.FolderRegister.cache -import com.lambda.util.FolderRegister.createIfNotExists -import java.io.File -import java.net.HttpURLConnection -import java.net.URI -import kotlin.time.Duration -import kotlin.time.Duration.Companion.days - -/** - * Represents an HTTP request. - * - * @property url The URL to which the request will be made. - * @property method The HTTP method to be used for the request. Default is [Method.GET]. - * @property parameters A map of query parameters to be included in the request. Default is an empty map. - * @property headers A map of headers to be included in the request. Default is an empty map. - * @property config A lambda function to configure the HTTP connection. Default is an empty lambda. - */ -data class Request( - val url: String, - val method: Method = Method.GET, - val parameters: Map = mapOf(), - val headers: Map = mapOf(), - val config: ((HttpURLConnection) -> Unit) = {}, -) { - val exceptionFormat = "HTTP request failed with status code %d\nResponse: %s" - - val canBeEncoded: Boolean - get() = method != Method.POST && method != Method.PUT && method != Method.PATCH - - /** - * Downloads the resource at the specified path and caches it for future use. - * - * @param name The full name of the file to be cached. - * @param maxAge The maximum age of the cached resource. Default is 4 days. - */ - fun maybeDownload(name: String, maxAge: Duration = 7.days): File { - val file = cache.resolve(name).toFile().createIfNotExists() - - if ( - System.currentTimeMillis() - file.lastModified() < maxAge.inWholeMilliseconds - && file.length() > 0 - ) return file - - file.writeText("") // Clear the file before writing to it. - - val url = URI( - if (parameters.isNotEmpty() && canBeEncoded) "$url?${parameters.query}" - else url - ).toURL() - - val connection = url.openConnection() as HttpURLConnection - config.invoke(connection) - - connection.requestMethod = method.name - - headers.forEach { (key, value) -> connection.setRequestProperty(key, value) } - - connection.connect() - - connection.inputStream.use { input -> - file.outputStream().use { output -> - input.copyTo(output) - } - } - - return file - } - - /** - * Executes the HTTP request synchronously. - */ - inline fun json(): Response { - val url = URI( - if (parameters.isNotEmpty() && canBeEncoded) "$url?${parameters.query}" - else url - ).toURL() - - val connection = url.openConnection() as HttpURLConnection - config.invoke(connection) - - connection.requestMethod = method.name - - headers.forEach { (key, value) -> connection.setRequestProperty(key, Lambda.gson.toJson(value)) } - - // For the moment we are only supporting JSON requests. - connection.setRequestProperty("Content-Type", "application/json") - - runCatching { - if (!canBeEncoded) { - connection.doOutput = true - connection.outputStream.use { - it.write(parameters.toJson().toByteArray()) - } - } else connection.connect() - }.onFailure { - println("Failed to execute HTTP request: $it") - return Response( - connection = connection, - data = null, - error = it - ) - } - - if (connection.responseCode !in 200..299) { - return Response( - connection = connection, - data = null, - error = Throwable( - exceptionFormat.format( - connection.responseCode, - tryOrDefault( - "A critical error causes the remote client to abruptly close the connection.\n" + - "No action is required on your side." - ) { - connection.errorStream.bufferedReader().readText() - } - ) - ) - ) - } - - var error: Throwable? = null - val data = runCatching { - Lambda.gson.fromJson( - connection.inputStream.bufferedReader().readText(), - Success::class.java - ) - } - .onFailure { error = it } - .getOrNull() - - return Response( - connection = connection, - data = data, - error = error, - ) - } -} diff --git a/common/src/main/kotlin/com/lambda/http/RequestBuilder.kt b/common/src/main/kotlin/com/lambda/http/RequestBuilder.kt deleted file mode 100644 index fbc56e849..000000000 --- a/common/src/main/kotlin/com/lambda/http/RequestBuilder.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.http - -import java.net.HttpURLConnection - -@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE) -@DslMarker -annotation class RequestDsl - -@RequestDsl -class RequestBuilder( - private val url: String, -) { - private var method: Method = Method.GET - private val parameters: MutableMap = mutableMapOf() - private val headers: MutableMap = mutableMapOf() - private var config: ((HttpURLConnection) -> Unit) = {} - - /** - * Sets the HTTP method to be used for the request. - */ - fun method(method: Method): RequestBuilder { - this.method = method - return this - } - - /** - * Sets the query parameters to be included in the request. - */ - fun parameters(parameters: Map): RequestBuilder { - this.parameters.putAll(parameters) - return this - } - - /** - * Sets the headers to be included in the request. - */ - fun headers(headers: Map): RequestBuilder { - this.headers.putAll(headers) - return this - } - - /** - * Sets the lambda function to configure the HTTP connection. - */ - fun config(config: (HttpURLConnection) -> Unit): RequestBuilder { - this.config = config - return this - } - - fun build() = Request(url, method, parameters, headers, config) -} - -/** - * Creates an HTTP request. - * - * @param url The URL to which the request will be made. - * @param block A lambda function to configure the request. - */ -inline fun request(url: String, block: (@RequestDsl RequestBuilder).() -> Unit) = - RequestBuilder(url).apply(block).build() diff --git a/common/src/main/kotlin/com/lambda/http/Response.kt b/common/src/main/kotlin/com/lambda/http/Response.kt deleted file mode 100644 index a15d741fb..000000000 --- a/common/src/main/kotlin/com/lambda/http/Response.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.http - -import java.net.HttpURLConnection - -/** - * Represents an HTTP response. - */ -class Response( - /** - * The response - */ - var data: Success? = null, - - /** - * The error - */ - var error: Throwable? = null, - - /** - * The HTTP connection associated with the response. - */ - var connection: HttpURLConnection? = null, -) { - /** - * Indicates whether the request was successful (HTTP status code 2xx). - */ - val success: Boolean - get() = connection?.let { return it.responseCode in 200..299 } ?: false -} diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/CreateParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/CreateParty.kt index bdd09c9f3..fae958bf2 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/CreateParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/CreateParty.kt @@ -17,9 +17,9 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun createParty( endpoint: String, @@ -35,17 +35,7 @@ fun createParty( // example: true public: Boolean = true, ) = - request("$endpoint/api/$version/party/create") { - method(Method.POST) - - parameters( - mapOf( - "max_players" to maxPlayers, - "public" to public, - ) - ) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.post("$endpoint/api/$version/party/create", listOf( + "max_players" to maxPlayers, + "public" to public, + )).responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/DeleteParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/DeleteParty.kt index 075c70a05..786c59084 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/DeleteParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/DeleteParty.kt @@ -17,19 +17,13 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun deleteParty( endpoint: String, version: String, - accessToken: String, ) = - request("$endpoint/api/$version/party/delete") { - method(Method.DELETE) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.delete("$endpoint/api/$version/party/delete") + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/GetParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/GetParty.kt index 88770f3c2..f957b7095 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/GetParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/GetParty.kt @@ -17,19 +17,14 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun createParty( endpoint: String, version: String, accessToken: String, ) = - request("$endpoint/api/$version/party") { - method(Method.POST) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.get("$endpoint/api/$version/party") + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/JoinParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/JoinParty.kt index db6d33a82..25dc8c291 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/JoinParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/JoinParty.kt @@ -17,9 +17,9 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun joinParty( endpoint: String, @@ -30,16 +30,5 @@ fun joinParty( // example: "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6" partyId: String, ) = - request("$endpoint/api/$version/party/join") { - method(Method.PUT) - - parameters( - mapOf( - "id" to partyId, - ) - ) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.put("$endpoint/api/$version/party/join", listOf("id" to partyId)) + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/LeaveParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/LeaveParty.kt index 6f232b577..8763924db 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/LeaveParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/LeaveParty.kt @@ -17,19 +17,14 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun leaveParty( endpoint: String, version: String, accessToken: String, ) = - request("$endpoint/api/$version/party/leave") { - method(Method.PUT) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.put("$endpoint/api/$version/party/leave") + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/Login.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/Login.kt index 232b71be2..42335c5d0 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/Login.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/Login.kt @@ -17,9 +17,9 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Authentication -import com.lambda.http.request fun login( endpoint: String, @@ -37,14 +37,5 @@ fun login( // example: 069a79f444e94726a5befca90e38aaf5 hash: String, ) = - request("$endpoint/api/$version/login") { - method(Method.POST) - - parameters( - mapOf( - "token" to discordToken, - "username" to username, - "hash" to hash - ) - ) - }.json() + Fuel.post("$endpoint/api/$version/login", listOf("token" to discordToken, "username" to username, "hash" to hash)) + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/UpdateParty.kt b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/UpdateParty.kt index 7679d2f8b..25f38f82c 100644 --- a/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/UpdateParty.kt +++ b/common/src/main/kotlin/com/lambda/http/api/rpc/v1/endpoints/UpdateParty.kt @@ -17,9 +17,9 @@ package com.lambda.http.api.rpc.v1.endpoints -import com.lambda.http.Method +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.http.api.rpc.v1.models.Party -import com.lambda.http.request fun editParty( endpoint: String, @@ -35,14 +35,5 @@ fun editParty( // example: true // public: Boolean = true, ) = - request("$endpoint/api/$version/party/edit") { - method(Method.PATCH) - - parameters( - mapOf("max_players" to maxPlayers) - ) - - headers( - mapOf("Authorization" to "Bearer $accessToken") - ) - }.json() + Fuel.patch("$endpoint/api/$version/party/edit", listOf("max_players" to maxPlayers)) + .responseObject().third diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt b/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt index dba2c907b..29228e4ae 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/DiscordRPC.kt @@ -121,33 +121,30 @@ object DiscordRPC : Module( fun createParty() { if (!isPartyInteractionAllowed) return - createParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, maxPlayers, true) - .also { response -> - if (response.error != null) warn(response.toString()) - currentParty = response.data - } + val (party, error) = createParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, maxPlayers, true) + if (error != null) warn(error.toString()) // TODO: Replace with network manager + + currentParty = party } // Join a party using the ID fun join(id: String) { if (!isPartyInteractionAllowed) return - joinParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, id) - .also { response -> - response.error?.let { return@also warn("Failed to join the party", it.toString()) } - currentParty = response.data - } + val (party, error) = joinParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, id) + if (error != null) warn("Failed to join the party", error.toString()) + + currentParty = party } // Edit the current party if you are the owner private fun edit() { if (!isPartyInteractionAllowed) return - editParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, maxPlayers) - .also { response -> - response.error?.let { return@also warn("Failed to edit the party", it.toString()) } - currentParty = response.data - } + val (party, error) = editParty(rpcServer, apiVersion.value, rpcAuth?.accessToken ?: return, maxPlayers) + if (error != null) warn("Failed to edit the party", error.toString()) + + currentParty = party } private fun connect() { @@ -220,11 +217,10 @@ object DiscordRPC : Module( // Prompt the user to authorize discordAuth = rpc.applicationManager.authenticate() - login(rpcServer, apiVersion.value, discordAuth?.accessToken ?: "", mc.session.username, hash) - .also { response -> - response.error?.let { warn("Failed to authenticate with the RPC server: ${it.message}") } - rpcAuth = response.data - } + val (authResponse, error) = login(rpcServer, apiVersion.value, discordAuth?.accessToken ?: "", mc.session.username, hash) + if (error != null) warn("Failed to authenticate with the RPC server: ${error.message}") + + rpcAuth = authResponse if (enableParty) createParty() } diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt index 349859704..e4f0c55f7 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/FakePlayer.kt @@ -17,11 +17,11 @@ package com.lambda.module.modules.combat +import com.github.kittinunf.fuel.Fuel +import com.github.kittinunf.fuel.gson.responseObject import com.lambda.event.events.ConnectionEvent import com.lambda.event.events.TickEvent import com.lambda.event.listener.SafeListener.Companion.listen -import com.lambda.http.Method -import com.lambda.http.request import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.threading.onShutdown @@ -88,10 +88,9 @@ object FakePlayer : Module( period = 2000L ) { cachedProfiles[fetchKey] ?: runSafe { - val requestedProfile = - request("https://api.mojang.com/users/profiles/minecraft/$fetchKey") { - method(Method.GET) - }.json().data + val (requestedProfile, _) = + Fuel.get("https://api.mojang.com/users/profiles/minecraft/$fetchKey") + .responseObject().third val uuid = requestedProfile?.id ?: nilUuid diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 6901511b3..b6bcce2fe 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -22,6 +22,7 @@ val fabricApiVersion: String by project val kotlinFabricVersion: String by project val discordIPCVersion: String by project val kotlinVersion: String by project +val fuelVersion: String by project base.archivesName = "${base.archivesName.get()}-fabric" @@ -88,6 +89,10 @@ dependencies { includeLib("com.github.Edouard127:KDiscordIPC:$discordIPCVersion") includeLib("com.pngencoder:pngencoder:0.15.0") + // Fuel HTTP library + includeLib("com.github.kittinunf.fuel:fuel:$fuelVersion") + includeLib("com.github.kittinunf.fuel:fuel-gson:$fuelVersion") + // Add mods to the mod jar includeMod("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion+$minecraftVersion") includeMod("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion.$kotlinVersion") diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 34c16b7b8..51613fab3 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -21,6 +21,7 @@ val forgeVersion: String by project val mixinExtrasVersion: String by project val kotlinForgeVersion: String by project val discordIPCVersion: String by project +val fuelVersion: String by project base.archivesName = "${base.archivesName.get()}-forge" @@ -99,6 +100,10 @@ dependencies { includeLib("com.github.Edouard127:KDiscordIPC:$discordIPCVersion") includeLib("com.pngencoder:pngencoder:0.15.0") + // Fuel HTTP library + includeLib("com.github.kittinunf.fuel:fuel:$fuelVersion") + includeLib("com.github.kittinunf.fuel:fuel-gson:$fuelVersion") + // Add mods to the mod jar includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion") includeMod("baritone-api:baritone-unoptimized-forge:1.10.2") diff --git a/gradle.properties b/gradle.properties index e6b81c37b..dd7d3f16f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,6 +32,7 @@ kotlinxCoroutinesVersion=1.9.0-RC javaVersion=17 baritoneVersion=1.10.2 discordIPCVersion=7ab2e77312 +fuelVersion=2.3.1 # Fabric https://fabricmc.net/develop/ fabricLoaderVersion=0.16.9