Skip to content

Commit

Permalink
Use scoreboards.json (authored in Brilliance) to determine which obje…
Browse files Browse the repository at this point in the history
…ctives to store
  • Loading branch information
4Ply committed Aug 25, 2024
1 parent 56c9a16 commit 2e6b89a
Show file tree
Hide file tree
Showing 8 changed files with 3,215 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ jobs:
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: download scoreboard.json from brilliance
uses: robinraju/[email protected]
with:
repository: 'trackedout/Brilliance'
latest: true
fileName: 'scoreboards.json'
out-file-path: 'Brilliance'

- name: copy scoreboards.json
run: cp Brilliance/scoreboard.json src/main/resources/assets/agronet/scoreboards.json

- name: build
run: ./gradlew build

Expand Down
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.9.21"
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.20'
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.2.19"
}

Expand Down Expand Up @@ -45,16 +46,10 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"

// `modImplementation` makes it available in the development environment. `include` makes it available everywhere via JAR-in-JAR.
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1'

// https://square.github.io/okhttp/#releases
include modImplementation(platform("com.squareup.okhttp3:okhttp-bom:4.11.0"))
// Define any required OkHttp artifacts without version
include modImplementation("com.squareup.okhttp3:okhttp:4.11.0")
include modImplementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
include modImplementation("com.squareup.moshi:moshi:1.14.0")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/trackedout/AgroNet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
import net.fabricmc.fabric.api.networking.v1.PacketSender
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents
import net.fabricmc.fabric.api.resource.ResourceManagerHelper
import net.minecraft.resource.ResourceType
import net.minecraft.server.MinecraftServer
import net.minecraft.server.command.CommandManager.argument
import net.minecraft.server.command.CommandManager.literal
Expand Down Expand Up @@ -238,6 +240,7 @@ object AgroNet : ModInitializer {
val scoreListener = AgroNetPlayerConnectionListener(scoreApi, claimApi, runContext, addDeckToPlayerInventoryAction)
ServerPlayConnectionEvents.JOIN.register(scoreListener)
ServerPlayConnectionEvents.DISCONNECT.register(scoreListener)
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(scoreListener)
}

ServerTickEvents.START_SERVER_TICK.register {
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/org/trackedout/data/BrillianceScoreboards.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.trackedout.data

import kotlinx.serialization.Serializable

@Serializable
data class BrillianceScoreboardDescription(
val auto: Int,
val target: String,
val category: String,
val description: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import net.fabricmc.fabric.api.networking.v1.PacketSender
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener
import net.minecraft.resource.ResourceManager
import net.minecraft.server.MinecraftServer
import net.minecraft.server.network.ServerPlayNetworkHandler
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
import net.minecraft.world.GameRules
import org.slf4j.LoggerFactory
import org.trackedout.RunContext
Expand All @@ -15,8 +18,10 @@ import org.trackedout.actions.AddDeckToPlayerInventoryAction
import org.trackedout.client.apis.ClaimApi
import org.trackedout.client.apis.ScoreApi
import org.trackedout.client.models.Score
import org.trackedout.data.BrillianceScoreboardDescription
import org.trackedout.fullRunType
import org.trackedout.sendMessage
import java.nio.charset.StandardCharsets

class AgroNetPlayerConnectionListener(
private val scoreApi: ScoreApi,
Expand All @@ -25,17 +30,41 @@ class AgroNetPlayerConnectionListener(
private val addDeckToPlayerInventoryAction: AddDeckToPlayerInventoryAction,
) :
ServerPlayConnectionEvents.Join,
ServerPlayConnectionEvents.Disconnect {
ServerPlayConnectionEvents.Disconnect,
SimpleSynchronousResourceReloadListener {
private val logger = LoggerFactory.getLogger("ServerPlayConnectionJoin")

private val objectivesToStore =
"do2.artifacts.ASV,do2.artifacts.BAP,do2.artifacts.BED,do2.artifacts.CF1,do2.artifacts.CUS,do2.artifacts.DLP,do2.artifacts.GDE,do2.artifacts.GGR,do2.artifacts.GGS,do2" +
".artifacts.HAY,do2.artifacts.HGT,do2.artifacts.HST,do2.artifacts.HYB,do2.artifacts.JSS,do2.artifacts.KNH,do2.artifacts.MDM,do2.artifacts.MGW,do2.artifacts.MKY,do2" +
".artifacts.OFP,do2.artifacts.PCL,do2.artifacts.PPS,do2.artifacts.PWS,do2.artifacts.SHD,do2.artifacts.SKA,do2.artifacts.SPS,do2.artifacts.THL,do2.artifacts.TSL," +
"do2.artifacts.WGG,do2.artifakes.ASV,do2.artifakes.BAP,do2.artifakes.BED,do2.artifakes.CF1,do2.artifakes.CUS,do2.artifakes.DLP,do2.artifakes.GDE,do2.artifakes" +
".GGR,do2.artifakes.GGS,do2.artifakes.HAY,do2.artifakes.HGT,do2.artifakes.HST,do2.artifakes.HYB,do2.artifakes.JSS,do2.artifakes.KNH,do2.artifakes.MDM,do2" +
".artifakes.MGW,do2.artifakes.MKY,do2.artifakes.OFP,do2.artifakes.PCL,do2.artifakes.PPS,do2.artifakes.PWS,do2.artifakes.SHD,do2.artifakes.SKA,do2.artifakes.SPS,do2.artifakes.THL,do2.artifakes.TSL,do2.artifakes.WGG,do2.cards.available.ADR,do2.cards.available.BES,do2.cards.available.BRI,do2.cards.available.BST,do2.cards.available.CHS,do2.cards.available.COS,do2.cards.available.DEF,do2.cards.available.DUR,do2.cards.available.EES,do2.cards.available.EOP,do2.cards.available.EVA,do2.cards.available.FBS,do2.cards.available.FRF,do2.cards.available.LAS,do2.cards.available.NIL,do2.cards.available.PIB,do2.cards.available.QUI,do2.cards.available.REC,do2.cards.available.SAG,do2.cards.available.SEW,do2.cards.available.SIR,do2.cards.available.SPR,do2.cards.available.SPT,do2.cards.available.SUU,do2.cards.available.SWA,do2.cards.available.TRL,do2.cards.bought.ADR,do2.cards.bought.BES,do2.cards.bought.BRI,do2.cards.bought.BST,do2.cards.bought.CHS,do2.cards.bought.COS,do2.cards.bought.DEF,do2.cards.bought.DUL,do2.cards.bought.DUR,do2.cards.bought.EES,do2.cards.bought.EMS,do2.cards.bought.EOP,do2.cards.bought.EVA,do2.cards.bought.FBS,do2.cards.bought.FRF,do2.cards.bought.LAS,do2.cards.bought.MOC,do2.cards.bought.NIL,do2.cards.bought.P2W,do2.cards.bought.PCP,do2.cards.bought.PIB,do2.cards.bought.QUI,do2.cards.bought.REC,do2.cards.bought.SAG,do2.cards.bought.SEW,do2.cards.bought.SIR,do2.cards.bought.SNE,do2.cards.bought.SPR,do2.cards.bought.SPT,do2.cards.bought.STA,do2.cards.bought.STU,do2.cards.bought.SUU,do2.cards.bought.SWA,do2.cards.bought.TAA,do2.cards.bought.TRH,do2.cards.bought.TRL,do2.cards.played.ADR,do2.cards.played.BES,do2.cards.played.BRI,do2.cards.played.BST,do2.cards.played.CHS,do2.cards.played.COS,do2.cards.played.DEF,do2.cards.played.DUL,do2.cards.played.DUR,do2.cards.played.EES,do2.cards.played.EMS,do2.cards.played.EOP,do2.cards.played.EVA,do2.cards.played.FBS,do2.cards.played.FRF,do2.cards.played.LAS,do2.cards.played.MOC,do2.cards.played.NIL,do2.cards.played.P2W,do2.cards.played.PCP,do2.cards.played.PIB,do2.cards.played.QUI,do2.cards.played.REC,do2.cards.played.SAG,do2.cards.played.SEW,do2.cards.played.SIR,do2.cards.played.SNE,do2.cards.played.SPR,do2.cards.played.SPT,do2.cards.played.STA,do2.cards.played.STU,do2.cards.played.SUU,do2.cards.played.SWA,do2.cards.played.TAA,do2.cards.played.TRH,do2.cards.played.TRL,do2.depth_charge_success,do2.eggs.bdubs,do2.eggs.beef,do2.eggs.cleo,do2.eggs.cub,do2.eggs.docm,do2.eggs.false,do2.eggs.gold,do2.eggs.grian,do2.eggs.hypno,do2.eggs.impulse,do2.eggs.iskall,do2.eggs.jevin,do2.eggs.joe,do2.eggs.pearl,do2.eggs.scar,do2.eggs.stress,do2.eggs.total,do2.eggs.wels,do2.eggs.xb,do2.eggs.xisuma,do2.eggs.zedaph,do2.highest_loss_streak,do2.highest_win_streak,do2.lifetime.coinsconverted,do2.lifetime.escaped.crowns,do2.lifetime.escaped.embers,do2.lifetime.pickedup.coins,do2.lifetime.pickedup.crowns,do2.lifetime.pickedup.embers,do2.lifetime.spent.crowns,do2.lifetime.spent.embers,do2.loss_streak,do2.losses,do2.runs,do2.systems.clank.blocked,do2.systems.clank.generated,do2.systems.embers.released,do2.systems.hazard.activated,do2.systems.hazard.blocked,do2.systems.hazard.generated,do2.systems.maxclank.released,do2.systems.treasure.released,do2.win_streak,do2.wins"
.split(",")
private var objectivesToStore = listOf<String>()

override fun getFabricId(): Identifier {
return Identifier("agronet", "scoreboard")
}

// Use scoreboards.json (authored in Brilliance) to determine which objectives to store
override fun reload(resourceManager: ResourceManager) {
val resourceId = Identifier("agronet", "scoreboards.json")

try {
// Obtain the resource as an InputStream
val resource = resourceManager.getResource(resourceId).orElseThrow {
throw IllegalStateException("Resource not found: $resourceId")
}

// Read and parse the JSON file using Gson
resource.inputStream.use { inputStream ->
val jsonData = inputStream.bufferedReader(StandardCharsets.UTF_8).use { it.readText() }
val scoreboardDescriptionMap: Map<String, BrillianceScoreboardDescription> = Json.decodeFromString(jsonData)

objectivesToStore = scoreboardDescriptionMap
.filter { it.value.category == "totals" }
.keys.toList()

println("Updated objectives to store to: $objectivesToStore")
}
} catch (e: Exception) {
println("Failed to load JSON: ${e.message}")
}
}

override fun onPlayReady(handler: ServerPlayNetworkHandler, sender: PacketSender, server: MinecraftServer) {
val playerName = handler.player.entityName
Expand Down
Loading

0 comments on commit 2e6b89a

Please sign in to comment.