Skip to content

Commit

Permalink
Fetch from remote config
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Oct 25, 2024
1 parent 904fcde commit c4c123c
Show file tree
Hide file tree
Showing 61 changed files with 477 additions and 382 deletions.
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val sharedGroup = "com.projectcitybuild.pcbridge"
val sharedVersion = "6.1.0"
val sharedVersion = "6.2.0"

group = sharedGroup
version = sharedVersion

plugins {
kotlin("jvm") version "1.9.22"
kotlin("plugin.serialization") version "2.0.21"

id("org.jlleitschuh.gradle.ktlint") version "12.1.1"
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}

Expand All @@ -29,11 +29,11 @@ subprojects {
dependencies {
// Kotlin
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")

// Tests
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:2.0.21")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0")
Expand All @@ -53,7 +53,7 @@ subprojects {

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
jvmTarget = "21"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.projectcitybuild.pcbridge.http

import com.projectcitybuild.pcbridge.http.clients.PCBClientFactory
import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.services.pcb.RegisterHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.PlayerHttpService
import com.projectcitybuild.pcbridge.http.services.pcb.TelemetryHttpService
import com.projectcitybuild.pcbridge.http.services.ConfigHttpService
import com.projectcitybuild.pcbridge.http.services.RegisterHttpService
import com.projectcitybuild.pcbridge.http.services.PlayerHttpService
import com.projectcitybuild.pcbridge.http.services.TelemetryHttpService

class HttpService(
private val authToken: String,
Expand All @@ -22,12 +23,15 @@ class HttpService(
private val responseParser: ResponseParser
get() = ResponseParser()

val config
get() = ConfigHttpService(pcbClient, responseParser)

val player
get() = PlayerHttpService(pcbClient, responseParser)

val telemetry
get() = TelemetryHttpService(pcbClient, responseParser)

val register
get() = RegisterHttpService(pcbClient, responseParser)

val telemetry
get() = TelemetryHttpService(pcbClient, responseParser)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import com.projectcitybuild.pcbridge.http.serialization.serializable.LocalDateTimeSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import com.projectcitybuild.pcbridge.http.serialization.serializable.LocalDateTimeSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import com.projectcitybuild.pcbridge.http.serialization.serializable.LocalDateTimeSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import com.projectcitybuild.pcbridge.http.serialization.serializable.LocalDateTimeSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.responses
package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@file:Suppress("ktlint:standard:max-line-length")

package com.projectcitybuild.pcbridge.http.models

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.Serializable

/**
* Key-values for the plugin fetched from the PCB web backend
*/
@Serializable
data class RemoteConfigKeyValues(
val localization: Localization = Localization(),
val chat: Chat = Chat(),
val warps: Warps = Warps(),
val integrations: Integrations = Integrations(),
val announcements: Announcements = Announcements(),
val messages: Messages = Messages(),
) {
@Serializable
data class Localization(
@SerializedName("time_zone")
val timeZone: String = "UTC",
val locale: String = "en-us",
)

@Serializable
data class Chat(
@SerializedName("badge_icon")
val badgeIcon: String = "<color:yellow>★</color>",
)

@Serializable
data class Warps(
@SerializedName("items_per_page")
val itemsPerPage: Int = 15,
)

@Serializable
data class Integrations(
@SerializedName("dynmap_warp_icon_name")
val dynmapWarpIconName: String = "portal",
)

@Serializable
data class Announcements(
@SerializedName("interval_in_mins")
val intervalInMins: Int = 30,
val messages: List<String> = emptyList(),
)

@Serializable
data class Messages(
val join: String = "<color:green><b>+</b></color> <name> <color:gray>joined the server</color>",
val leave: String = "<color:red><b>-</b></color> <name> <color:gray>left the server (online for <time_online>)</color>",
@SerializedName("first_time_join")
val firstTimeJoin: String = "<color:AA00AA><b>✦ Welcome §f%name%§d to the server!</b></color>",
val welcome: String = "<b>Welcome to PCB!</b>",
)
}

@Serializable
data class RemoteConfigVersion(
val version: Int,
val config: RemoteConfigKeyValues,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.projectcitybuild.pcbridge.http.requests

import com.projectcitybuild.pcbridge.http.responses.PlayerData
import com.projectcitybuild.pcbridge.http.models.PlayerData
import com.projectcitybuild.pcbridge.http.models.RemoteConfigVersion
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
Expand Down Expand Up @@ -52,4 +53,11 @@ internal interface PCBRequest {
@Field(value = "uuid") playerUUID: String,
@Field(value = "alias") playerName: String,
)

/**
* Fetches the latest Minecraft config
*/
@POST("v2/minecraft/config")
@FormUrlEncoded
suspend fun getConfig(): RemoteConfigVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.projectcitybuild.pcbridge.http.services

import com.projectcitybuild.pcbridge.http.models.RemoteConfigVersion
import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.pcb
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.Retrofit

class ConfigHttpService(
private val retrofit: Retrofit,
private val responseParser: ResponseParser,
) {
suspend fun get(): RemoteConfigVersion =
withContext(Dispatchers.IO) {
responseParser.parse(retrofit.pcb()::getConfig)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.projectcitybuild.pcbridge.http.services.pcb
package com.projectcitybuild.pcbridge.http.services

import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.pcb
import com.projectcitybuild.pcbridge.http.responses.PlayerData
import com.projectcitybuild.pcbridge.http.models.PlayerData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.Retrofit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.services.pcb
package com.projectcitybuild.pcbridge.http.services

import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.pcb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.http.services.pcb
package com.projectcitybuild.pcbridge.http.services

import com.projectcitybuild.pcbridge.http.parsing.ResponseParser
import com.projectcitybuild.pcbridge.http.pcb
Expand Down
Loading

0 comments on commit c4c123c

Please sign in to comment.