Skip to content

Commit

Permalink
feat: added update-datapack command
Browse files Browse the repository at this point in the history
  • Loading branch information
xane256 committed Jan 27, 2024
1 parent 4b89712 commit 2ddbe05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dependencies {
include modImplementation("com.squareup.moshi:moshi-kotlin:1.14.0")

include modImplementation("com.squareup.okio:okio-jvm:3.0.0")

// Redis database connection
implementation "redis.clients:jedis:5.0.0"
}

processResources {
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/org/trackedout/AgroNet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import org.trackedout.client.models.EventsPostRequest
import org.trackedout.commands.CardPurchasedCommand
import org.trackedout.commands.LogEventCommand
import org.trackedout.listeners.AgroNetServerPlayConnectionListener
import redis.clients.jedis.Jedis
import java.net.InetAddress
import java.util.concurrent.CompletableFuture
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration

Expand Down Expand Up @@ -116,6 +118,25 @@ object AgroNet : ModInitializer {
)
}

CommandRegistrationCallback.EVENT.register { dispatcher, _, _ ->
dispatcher.register(literal("update-datapack")
.requires { it.hasPermissionLevel(2) } // Player should have permission level of 2
.executes { _ ->
CompletableFuture.runAsync(Runnable {
try {
val redisIp = System.getenv("REDIS_IP") ?: "redis";
val redisPort = System.getenv("REDIS_PORT")?.toIntOrNull() ?: 6379;
val redisPassword = System.getenv("REDIS_PASSWORD");
val jedis = Jedis(redisIp, redisPort).apply { auth(redisPassword) }
jedis.use { it.publish("datapack-updates", "request-update") }
} catch (e: Exception) {
logger.error("Error publishing to Redis: ${e.message}");
}
})
1
})
}

ServerPlayConnectionEvents.JOIN.register(AgroNetServerPlayConnectionListener(addDeckToPlayerInventoryAction))

eventsApi.eventsPost(
Expand Down

0 comments on commit 2ddbe05

Please sign in to comment.