-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
140 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
plugins { | ||
id("xyz.jpenilla.run-paper") version "2.3.1" apply false | ||
id("io.papermc.paperweight.userdev") version "1.7.4" apply false | ||
kotlin("jvm") version "2.1.0" apply false | ||
} | ||
|
||
version = project.property("version") as String | ||
group = project.property("group") as String | ||
fun prop(name: String) = property("version") as String | ||
|
||
version = prop("version") | ||
group = prop("group") | ||
|
||
subprojects { | ||
version = prop("version") | ||
group = prop("version") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
kotlin("jvm") version "2.1.0" | ||
id("xyz.jpenilla.run-paper") | ||
id("com.gradleup.shadow") version "9.0.0-beta4" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://repo.papermc.io/repository/maven-public/") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":spigot")) | ||
implementation(project(":http")) | ||
implementation(project(":api")) | ||
implementation(project(":jetty")) | ||
implementation(project(":ktor")) { | ||
isTransitive = false | ||
} | ||
|
||
val ktorVersion = "3.0.2" | ||
implementation("io.ktor:ktor-server-core:$ktorVersion") | ||
implementation("io.ktor:ktor-server-jetty-jakarta:$ktorVersion") | ||
|
||
compileOnly("io.netty:netty-all:4.1.97.Final") | ||
compileOnly("org.slf4j:slf4j-api:1.7.30") | ||
|
||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") | ||
} | ||
|
||
tasks.runServer { | ||
minecraftVersion("1.21.4") | ||
} | ||
|
||
tasks.assemble { | ||
dependsOn(tasks.shadowJar) | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/ktor-example/src/main/kotlin/net/mcbrawls/inject/examples/ktor/InjectKtorExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.mcbrawls.inject.examples.ktor | ||
|
||
import io.ktor.server.engine.EmbeddedServer | ||
import io.ktor.server.jetty.jakarta.JettyApplicationEngine | ||
import io.ktor.server.jetty.jakarta.JettyApplicationEngineBase | ||
import io.ktor.server.response.respondText | ||
import io.ktor.server.routing.get | ||
import io.ktor.server.routing.routing | ||
import net.mcbrawls.inject.ktor.jettyKtorServer | ||
import net.mcbrawls.inject.ktor.startOnNewThread | ||
import net.mcbrawls.inject.spigot.InjectSpigot | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
class InjectKtorExample : JavaPlugin() { | ||
private var ktor: EmbeddedServer<JettyApplicationEngine, JettyApplicationEngineBase.Configuration>? = null | ||
|
||
private fun initKtor() { | ||
ktor = jettyKtorServer(InjectSpigot.INSTANCE) { | ||
routing { | ||
get("/") { | ||
call.respondText("Hello, from Ktor!") | ||
} | ||
} | ||
} | ||
|
||
ktor!!.startOnNewThread() | ||
} | ||
|
||
override fun onEnable() { | ||
initKtor() | ||
} | ||
|
||
override fun onDisable() { | ||
ktor?.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: "inject-ktor-example" | ||
version: "0.0" | ||
main: net.mcbrawls.inject.examples.ktor.InjectKtorExample | ||
api-version: "1.21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
plugins { | ||
kotlin("jvm") version "2.1.0" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
val ktorVersion = "3.0.2" | ||
|
||
implementation(project(":api")) | ||
implementation(project(":jetty")) | ||
|
||
compileOnly("io.ktor:ktor-server-core:$ktorVersion") | ||
compileOnly("io.ktor:ktor-server-jetty-jakarta:$ktorVersion") | ||
} |
30 changes: 30 additions & 0 deletions
30
ktor/src/main/kotlin/net/mcbrawls/inject/ktor/InjectKtor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.mcbrawls.inject.ktor | ||
|
||
import io.ktor.server.application.Application | ||
import io.ktor.server.engine.EmbeddedServer | ||
import io.ktor.server.engine.embeddedServer | ||
import io.ktor.server.jetty.jakarta.Jetty | ||
import io.ktor.server.jetty.jakarta.JettyApplicationEngine | ||
import io.ktor.server.jetty.jakarta.JettyApplicationEngineBase | ||
import net.mcbrawls.inject.api.InjectPlatform | ||
import net.mcbrawls.inject.jetty.JettyInjector | ||
import org.eclipse.jetty.server.LocalConnector | ||
|
||
fun jettyKtorServer(platform: InjectPlatform, module: Application.() -> Unit = {}) = embeddedServer( | ||
Jetty, | ||
configure = { | ||
configureServer = { | ||
val connector = LocalConnector(this) | ||
server.connectors = arrayOf(connector) | ||
|
||
platform.registerInjector(JettyInjector(connector)) | ||
} | ||
}, | ||
module = module, | ||
) | ||
|
||
fun EmbeddedServer<JettyApplicationEngine, JettyApplicationEngineBase.Configuration>.startOnNewThread() { | ||
Thread({ | ||
start(wait = true) | ||
}, "Ktor").start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters