Skip to content

Commit

Permalink
Add chat and sync features
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed May 5, 2024
1 parent 8511805 commit d1bbcf3
Show file tree
Hide file tree
Showing 72 changed files with 1,160 additions and 1,257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import com.projectcitybuild.pcbridge.http.services.pcb.PlayerGroupHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.PlayerWarningHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.TelemetryHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.UUIDBanHttpService
import kotlin.coroutines.CoroutineContext

class HttpService(
private val authToken: String,
private val baseURL: String,
private val withLogging: Boolean,
private val contextBuilder: () -> CoroutineContext,
) {
private val pcbClient by lazy {
PCBClientFactory(
Expand All @@ -33,9 +31,8 @@ class HttpService(
).build()
}

private val responseParser: ResponseParser by lazy {
ResponseParser(contextBuilder)
}
private val responseParser: ResponseParser
get() = ResponseParser()

val playerUuid
get() = PlayerUUIDHttpService(mojangClient, responseParser)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.projectcitybuild.pcbridge.http.parsing

import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.HttpException
import java.io.IOException
import kotlin.coroutines.CoroutineContext

class ResponseParser(
private val getCoroutineContext: () -> CoroutineContext
) {
class ResponseParser {
data class ErrorBody(val error: ApiError)

class HTTPError(val errorBody: ApiError?) : Exception(
Expand All @@ -20,18 +18,16 @@ class ResponseParser(
"Failed to contact PCB auth server"
)

suspend fun <T> parse(apiCall: suspend () -> T): T {
return withContext(getCoroutineContext()) {
try {
apiCall.invoke()
} catch (_: IOException) {
throw NetworkError()
} catch (e: HttpException) {
val code = e.code()
throw HTTPError(errorBody = convertErrorBody(e, code))
} catch (e: Exception) {
throw e
}
suspend fun <T> parse(apiCall: suspend () -> T): T = withContext(Dispatchers.IO) {
try {
apiCall.invoke()
} catch (_: IOException) {
throw NetworkError()
} catch (e: HttpException) {
val code = e.code()
throw HTTPError(errorBody = convertErrorBody(e, code))
} catch (e: Exception) {
throw e
}
}

Expand Down
2 changes: 1 addition & 1 deletion pcbridge-spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")

// Integrations
// compileOnly("net.luckperms:api:5.4")
compileOnly("net.luckperms:api:5.4")
compileOnly("net.essentialsx:EssentialsX:2.20.1")
compileOnly("us.dynmap:dynmap-api:3.3")
compileOnly("us.dynmap:DynmapCoreAPI:3.3")
Expand Down
Loading

0 comments on commit d1bbcf3

Please sign in to comment.