Skip to content

Commit

Permalink
revert: use http injectors again
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Dec 16, 2024
2 parents 23963e4 + f2cead3 commit e1c5db1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
23 changes: 6 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id "fabric-loom" version "1.9-SNAPSHOT"
id "org.jetbrains.kotlin.jvm"
id "maven-publish"
id "com.gradleup.shadow"
}

version = mod_version
Expand All @@ -14,8 +15,8 @@ base {

repositories {
maven {
name = "Andante"
url = "https://maven.andante.dev/releases/"
name = "MC Brawls Maven"
url = "https://maven.mcbrawls.net/releases/"
}
}

Expand Down Expand Up @@ -61,9 +62,8 @@ dependencies {
include modImplementation ("com.github.yundom:kache:$kache_version")

include modImplementation ("net.mcbrawls.inject:api:$inject_version")
include modImplementation ("net.mcbrawls.inject:http:$inject_version")
include modImplementation ("net.mcbrawls.inject:fabric:$inject_version")
include modImplementation ("net.mcbrawls.inject:javalin:$inject_version")
shadow modCompileOnly ("io.javalin:javalin:$javalin_version")

testImplementation sourceSets.main.output
}
Expand All @@ -80,7 +80,7 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = 21
}
Expand All @@ -99,17 +99,6 @@ jar {
}
}

shadowJar {
configurations = [ project.configurations.shadow ]
exclude("META-INF")
}

remapJar {
dependsOn(shadowJar)
mustRunAfter(shadowJar)
inputFile = file(shadowJar.archivePath)
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ kotlin_version=2.0.21
fabric_kotlin_version=1.12.3

# mod properties
mod_version=3.3
mod_version=3.4
maven_group=net.mcbrawls
mod_id=audience

# dependencies

kache_version=1.0.5
javalin_version=6.3.0
inject_version=3.0.0
shadow_version=9.0.0-beta4
inject_version=3.0.1
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pluginManagement {

plugins {
id "org.jetbrains.kotlin.jvm" version kotlin_version
id "com.gradleup.shadow" version shadow_version
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/kotlin/dev/andante/audience/AudienceInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.andante.audience
import dev.andante.audience.resource.ResourcePackInjectHandler
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
import net.mcbrawls.inject.fabric.InjectFabric
import net.minecraft.server.MinecraftServer

object AudienceInitializer : ModInitializer {
Expand All @@ -14,16 +15,11 @@ object AudienceInitializer : ModInitializer {
val server: MinecraftServer get() = _minecraftServer

override fun onInitialize() {
val javalin = ResourcePackInjectHandler.createJavalin()

// register event to capture server
ServerLifecycleEvents.SERVER_STARTING.register { server ->
_minecraftServer = server
javalin.start(server.serverPort)
}

ServerLifecycleEvents.SERVER_STOPPING.register {
javalin.stop()
}
InjectFabric.INSTANCE.registerInjector(ResourcePackInjectHandler)
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package dev.andante.audience.resource

import io.javalin.Javalin
import io.javalin.http.Context
import net.mcbrawls.inject.fabric.InjectFabric
import net.mcbrawls.inject.javalin.InjectJavalinFactory
import io.netty.channel.ChannelHandlerContext
import net.mcbrawls.inject.http.HttpByteBuf
import net.mcbrawls.inject.http.HttpByteBuf.httpBuf
import net.mcbrawls.inject.http.HttpInjector
import net.mcbrawls.inject.http.HttpRequest

object ResourcePackInjectHandler {
object ResourcePackInjectHandler : HttpInjector() {
private val resourcePacks: MutableMap<String, ByteArray> = mutableMapOf()

fun createJavalin(): Javalin {
return InjectJavalinFactory.create(InjectFabric.INSTANCE).apply {
get("/packs/{hash}", ::handleRequest)
}
}
override fun intercept(ctx: ChannelHandlerContext, request: HttpRequest): HttpByteBuf? {
val path = request.requestURI.removePrefix("/")
val pack = resourcePacks[path] ?: return null

fun handleRequest(context: Context) {
val hash = context.pathParam("hash")

val pack = resourcePacks[hash]
if (pack == null) {
context.status(404)
return
if (!ctx.channel().isActive) {
return null
}

context.result(pack)
val response = httpBuf(ctx)
response.writeStatusLine("1.1", 200, "OK")
response.writeHeader("Content-Type", "application/zip")
response.writeHeader("Content-Length", pack.size.toString())
response.writeBytes(pack)

return response
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/dev/andante/audience/test/AudienceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object AudienceTest : ModInitializer {
}

ServerConfigurationConnectionEvents.CONFIGURE.register { handler, server ->
handler.addTask(SendResourcePackTask(MinecraftServer.ServerResourcePackProperties(UUID.randomUUID(), "http://localhost:25565/packs/${packOne.hash}", packOne.hash, true, Text.literal("EEEE"))))
handler.addTask(SendResourcePackTask(MinecraftServer.ServerResourcePackProperties(UUID.randomUUID(), "http://localhost:25565/${packOne.hash}", packOne.hash, true, Text.literal("EEEE"))))
}
}
}

0 comments on commit e1c5db1

Please sign in to comment.