Skip to content

Commit

Permalink
Refactor and split builds
Browse files Browse the repository at this point in the history
-host
-scripting-runtime
-api
-script-definition
  • Loading branch information
DrZoddiak committed Sep 27, 2023
1 parent 473729d commit 23b15cf
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 69 deletions.
18 changes: 18 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("common")
}

dependencies {
compileOnly("org.spongepowered:spongeapi:8.1.0")
compileOnly("net.kyori:adventure-api:4.14.0")
}

tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
16 changes: 16 additions & 0 deletions api/src/main/kotlin/me/zodd/API.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.zodd

import org.apache.logging.log4j.Logger
import org.spongepowered.plugin.PluginContainer

class API(container: PluginContainer, logger: Logger) {
companion object {
lateinit var container: PluginContainer
lateinit var logger: Logger
}

init {
Companion.container = container
Companion.logger = logger
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.zodd.dsl.command
package me.zodd

import me.zodd.annotations.ScriptDsl
import net.kyori.adventure.text.Component
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions api/src/main/kotlin/me/zodd/Managers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.zodd

import org.apache.logging.log4j.Logger
import org.spongepowered.api.Server
import org.spongepowered.api.Sponge
import org.spongepowered.api.command.manager.CommandManager
import org.spongepowered.api.event.EventManager
import org.spongepowered.api.plugin.PluginManager
import org.spongepowered.api.scheduler.Scheduler
import org.spongepowered.api.service.ServiceProvider
import org.spongepowered.plugin.PluginContainer

inline val SpongeServer: Server get() = Sponge.server()
inline val SpongePluginManager: PluginManager get() = Sponge.pluginManager()
inline val SpongeCommandManager: CommandManager get() = Sponge.server().commandManager()
inline val SpongeEventManager: EventManager get() = Sponge.eventManager()
inline val SpongeServerServiceManager: ServiceProvider.ServerScoped get() = Sponge.server().serviceProvider()
inline val SpongeGameServiceManager: ServiceProvider.GameScoped get() = Sponge.serviceProvider()
inline val Scheduler: Scheduler get() = Sponge.server().scheduler()
inline val SpongeAsyncScheduler: Scheduler get() = Sponge.asyncScheduler()
inline val Container: PluginContainer get() = API.container
inline val Logger: Logger get() = API.logger
inline val ScriptCommandManager: me.zodd.CommandManager get() = CommandManager()
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.zodd

import io.leangen.geantyref.TypeToken
import me.zodd.dsl.command.DslCommand
import org.spongepowered.api.Sponge
import org.spongepowered.api.command.Command
import org.spongepowered.api.event.Event
Expand All @@ -17,7 +16,7 @@ object RegistrationHelper {
EventListenerRegistration.builder(eventClass)
.order(Order.DEFAULT)
.listener(executor::invoke)
.plugin(Host.container)
.plugin(API.container)
.build()
)
}
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/common.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
plugins {
kotlin("jvm")
}

group = "me.zodd"
version = "0.1.0"

repositories {
mavenCentral()
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
31 changes: 13 additions & 18 deletions host/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import org.spongepowered.plugin.metadata.model.PluginDependency

plugins {
id("common")
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.spongepowered.gradle.plugin") version "2.2.0"
}

group = "me.zodd"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}
version = "0.1.0"

sponge {
apiVersion("8.2.0-SNAPSHOT")
Expand All @@ -22,24 +19,23 @@ sponge {
displayName("scripting-host")
entrypoint("me.zodd.Host")
description("A host plugin for running Kotlin Scripts")
dependency("kruntime") {
loadOrder(PluginDependency.LoadOrder.AFTER)
version("0.4.0")
optional(false)
}
}
}

dependencies {

implementation("org.spongepowered:configurate-extra-kotlin:4.1.2") {
isTransitive = false
}

shadow(kotlin("reflect"))
shadow(project(":script-definition"))
kotlinScriptDef(project(":script-definition"))
shadow(kotlin("scripting-jvm-host"))
shadow(kotlin("scripting-jvm"))
shadow(kotlin("script-runtime"))

//Allows scripts to build certain bits of API that requires Adventure
shadow("net.kyori:adventure-api:4.14.0")
implementation(project(":api"))
api("net.kyori:adventure-api:4.14.0")
}

tasks.jar.get().enabled = false
Expand All @@ -48,11 +44,10 @@ tasks.shadowJar {
archiveClassifier.set("")
configurations.add(project.configurations.shadow.get())
listOf(
"io.github.classgraph", "javaslang", "nonapi.io.github.classgraph",
"org.spongepowered.configurate.kotlin", "org.jetbrains.annotations",
"org.jetbrains.concurrency", "org.jetbrains.jps", "org.jetbrains.org",
"org.intellij", "gnu.trove", "com.sun.jna", "messages",
"org.spongepowered.configurate.kotlin", "org.jetbrains.org.objectweb.asm",
"org.jetbrains.jps", "javaslang", "gnu.trove", "com.sun.jna", "messages", "misc"
).forEach { relocate(it, "me.zodd.shaded.$it") }
mergeServiceFiles()
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import java.time.Duration
onServerStarted {
val time = 5L
val seconds = Duration.ofSeconds(time)
ScriptPlugin.logger.info("Server has started! -- $time Second delay test begin --")
Logger.info("Server has started! -- $time Second delay test begin --")

val task = Task.builder()
.execute { ->
ScriptPlugin.logger.info("Task Test Message -- $time second delay")
Logger.info("Task Test Message -- $time second delay")
}
.delay(seconds)
.plugin(ScriptPlugin.container)
.plugin(Container)
.build()

Scheduler.submit(task)
Expand Down
5 changes: 2 additions & 3 deletions host/run/config/scripting-host/scripts/helloworld.plugin.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import me.zodd.ScriptCommandManager
import me.zodd.ScriptPlugin
import me.zodd.*

//Scripts automatically execute during plugin construction
ScriptPlugin.logger.info("Hello World!")
Logger.info("Hello World!")

ScriptCommandManager {
command("foo") {
Expand Down
4 changes: 2 additions & 2 deletions host/run/config/scripting-host/scripts/playerjoin.plugin.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.spongepowered.api.data.Keys

onPlayerJoin {
Logger.info("Player joined the server")
//Scripts can use methods available fron the event
//Scripts can use methods available from the event
val player = player()
val name = player.get(Keys.DISPLAY_NAME).get()
player.sendMessage(Component.text("Welcome ").append(name))
Server.broadcastAudience().sendMessage(name.append(Component.text(" joined the server!")))
SpongeServer.broadcastAudience().sendMessage(name.append(Component.text(" joined the server!")))
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import me.zodd.ScriptPlugin
import me.zodd.onServerStarted
import me.zodd.*

onServerStarted {
ScriptPlugin.logger.info("Server Started!")
Logger.info("Server Started!")
}

9 changes: 6 additions & 3 deletions host/src/main/kotlin/me/zodd/Host.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ import org.spongepowered.plugin.builtin.jvm.Plugin
@Plugin("scripting-host")
class Host @Inject internal constructor(
container: PluginContainer,
logger: Logger,
private val logger: Logger,
@DefaultConfig(sharedRoot = false)
private val reference: ConfigurationReference<CommentedConfigurationNode>,
) {

companion object {
lateinit var container: PluginContainer
lateinit var logger: Logger
lateinit var plugin: PluginContainer
lateinit var config: ScriptingConfig
}

init {
Companion.container = container
plugin = container
Companion.logger = logger

//Plugin references
API(container, logger)
}

private fun loadConfig(): ScriptingConfig {
Expand Down
13 changes: 12 additions & 1 deletion host/src/main/kotlin/me/zodd/KotlinScript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ internal data class KotlinScript(val script: String) {
"org.apache.logging.log4j.Logger",
//Kyori
"net.kyori.adventure.text.*",
"me.zodd.*"
"me.zodd.*",
"me.zodd.Manager.Server",
"me.zodd.Manager.Plugin",
"me.zodd.Manager.PluginManager",
"me.zodd.Manager.CommandManager",
"me.zodd.Manager.EventManager",
"me.zodd.Manager.ServerServiceManager",
"me.zodd.Manager.GameServiceManager",
"me.zodd.Manager.Scheduler",
"me.zodd.Manager.AsyncScheduler",
"me.zodd.Manager.Logger",
"me.zodd.Manager.ScriptCommandManager",
)

private fun mergeImports(): List<String> {
Expand Down
2 changes: 1 addition & 1 deletion host/src/main/kotlin/me/zodd/KotlinScriptLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object KotlinScriptLoader {
onFailure {
LogInfo(name, it.reports).printLog()
}.onSuccess {
if (ScriptPlugin.config.extraLogging) {
if (Host.config.extraLogging) {
Logger.info("Script: $name successfully loaded!")
}
asSuccess()
Expand Down
2 changes: 1 addition & 1 deletion host/src/main/kotlin/me/zodd/LogInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal data class LogInfo(

fun printLog() {
val logTitle = "[${id}]"
Logger.info(
Host.logger.info(
"\n" + """
################$logTitle###############
${generateReport()}
Expand Down
23 changes: 0 additions & 23 deletions host/src/main/kotlin/me/zodd/Managers.kt

This file was deleted.

6 changes: 0 additions & 6 deletions script-definition/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ plugins {
id("common")
}

group = "me.zodd"

repositories {
mavenCentral()
}

dependencies {
api(kotlin("scripting-jvm"))
}
21 changes: 21 additions & 0 deletions script-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("common")
id("com.github.johnrengelman.shadow") version "7.1.2"
}

dependencies {
shadow(project(":script-definition"))
shadow(kotlin("script-runtime"))
shadow(project(":api"))
shadow("org.spongepowered:spongeapi:8.1.0")
shadow("net.kyori:adventure-api:4.14.0")
}

tasks.jar {
enabled = false
finalizedBy("shadowJar")
}

tasks.shadowJar {
configurations.add(project.configurations.shadow.get())
}
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ plugins {

rootProject.name = "KotlinScript"
include("script-definition")
include("host")
include("host")
include("api")
include("script-runtime")

0 comments on commit 23b15cf

Please sign in to comment.