Skip to content

Commit

Permalink
WIP Standalone Loader Fix
Browse files Browse the repository at this point in the history
* Removed SoftwareType test
* Make SoftwareType.display not null
* Make StandaloneLoader available to be initialized using jar -jar SimpleCoreAPI.jar

Signed-off-by: Francisco Solis <imfran@duck.com>
  • Loading branch information
Im-Fran committed Apr 13, 2023
1 parent 99fbb5e commit b659fd5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val env = project.rootProject.file(".env").let { file ->
if(file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap()
}.toMutableMap().apply { putAll(System.getenv()) }

val projectVersion = env["VERSION"] ?: "0.6.3.25-SNAPSHOT"
val projectVersion = env["VERSION"] ?: "0.6.3.35-SNAPSHOT"

group = "xyz.theprogramsrc"
version = projectVersion.replaceFirst("v", "").replace("/", "")
Expand Down Expand Up @@ -60,6 +60,10 @@ blossom {

tasks {
named<ShadowJar>("shadowJar") {
manifest {
attributes["Main-Class"] = "xyz.theprogramsrc.simplecoreapi.standalone.StandaloneLoaderKt"
}

relocate("org.apache.commons", "xyz.theprogramsrc.simplecoreapi.libs.apache.commons")
relocate("org.checkerframework", "xyz.theprogramsrc.simplecoreapi.libs.checkerframework")
relocate("org.intellij", "xyz.theprogramsrc.simplecoreapi.libs.intellij")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import xyz.theprogramsrc.simplecoreapi.global.utils.SoftwareType
import xyz.theprogramsrc.simplecoreapi.global.utils.update.GitHubUpdateChecker
import xyz.theprogramsrc.simplecoreapi.standalone.StandaloneLoader
import java.io.File
import java.util.*

/**
* Class used to initialize SimpleCoreAPI (DO NOT CALL IT FROM EXTERNAL PLUGINS, IT MAY CRASH)
Expand Down Expand Up @@ -53,7 +52,7 @@ class SimpleCoreAPI(logger: ILogger) {
}

softwareType = SoftwareType.values().firstOrNull { it.check() } ?: SoftwareType.UNKNOWN
if(softwareType != SoftwareType.UNKNOWN && softwareType.display != null) {
if(softwareType != SoftwareType.UNKNOWN) {
logger.info("Running API with software ${softwareType.display}")
} else {
logger.info("Running on unknown server software. Some features might not work as expected!")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package xyz.theprogramsrc.simplecoreapi.global.utils

import xyz.theprogramsrc.simplecoreapi.standalone.StandaloneLoader
import java.util.Objects
import java.util.*

/**
* Representation of a ServerSoftware
* @param check The function to check if the software is running the server or not.
*/
enum class SoftwareType(val check: () -> Boolean = { false }, val display: String? = null) {
enum class SoftwareType(val check: () -> Boolean = { false }, val display: String) {
// Servers
BUKKIT(check = {
try {
Expand Down Expand Up @@ -90,5 +90,7 @@ enum class SoftwareType(val check: () -> Boolean = { false }, val display: Strin
StandaloneLoader.isRunning
}, "Standalone"),

UNKNOWN;
UNKNOWN(
display = "Unknown"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import xyz.theprogramsrc.simplecoreapi.global.SimpleCoreAPI
import xyz.theprogramsrc.simplecoreapi.global.utils.logger.JavaLogger
import java.util.logging.Logger

class StandaloneLoader(logger: Logger){
fun main() {
StandaloneLoader().init()
}

open class StandaloneLoader() {

companion object {
lateinit var instance: StandaloneLoader
Expand All @@ -14,16 +18,23 @@ class StandaloneLoader(logger: Logger){
private set
}

init {
fun init() {
check(!isRunning) { "SimpleCoreAPI Standalone is already running! Please avoid trying to initialize it twice." }

instance = this
isRunning = true
SimpleCoreAPI(JavaLogger(logger))
SimpleCoreAPI(JavaLogger(Logger.getAnonymousLogger()))
SimpleCoreAPI.instance.moduleManager?.enableModules()

Runtime.getRuntime().addShutdownHook(Thread {
onDisable()
SimpleCoreAPI.instance.moduleManager?.disableModules()
}.apply {
name = "SimpleCoreAPI Shutdown Hook"
})
}

open fun onEnable() { }

open fun onDisable() { }
}

This file was deleted.

0 comments on commit b659fd5

Please sign in to comment.