diff --git a/src/main/kotlin/cf/wayzer/SuperItem/ItemManager.kt b/src/main/kotlin/cf/wayzer/SuperItem/ItemManager.kt index e751bb0..8e96186 100644 --- a/src/main/kotlin/cf/wayzer/SuperItem/ItemManager.kt +++ b/src/main/kotlin/cf/wayzer/SuperItem/ItemManager.kt @@ -64,7 +64,7 @@ object ItemManager { val res = result.resultOrNull()!!.returnValue if(res is ResultValue.Value && res.value is Item) { item = (res.value as Item) - result.reports.forEachIndexed { index, rep -> + result.reports.filterNot { it.severity==ScriptDiagnostic.Severity.DEBUG }.forEachIndexed { index, rep -> logger.log(Level.WARNING,"##$index##"+rep.message,rep.exception) } return@onSuccess ResultWithDiagnostics.Success(ResultValue.Unit) diff --git a/src/main/kotlin/cf/wayzer/SuperItem/ScriptSupporter.kt b/src/main/kotlin/cf/wayzer/SuperItem/ScriptSupporter.kt index 78fbb8b..7c86bce 100644 --- a/src/main/kotlin/cf/wayzer/SuperItem/ScriptSupporter.kt +++ b/src/main/kotlin/cf/wayzer/SuperItem/ScriptSupporter.kt @@ -3,52 +3,24 @@ package cf.wayzer.SuperItem import cf.wayzer.SuperItem.scripts.SuperItemScript import cf.wayzer.libraryManager.Dependency import cf.wayzer.libraryManager.LibraryManager -import org.bukkit.Bukkit -import org.jetbrains.kotlin.script.util.DependsOn import java.io.File import java.nio.file.Paths -import kotlin.reflect.KClass -import kotlin.script.experimental.api.* +import kotlin.script.experimental.api.EvaluationResult +import kotlin.script.experimental.api.ResultWithDiagnostics +import kotlin.script.experimental.api.ScriptEvaluationConfiguration +import kotlin.script.experimental.api.constructorArgs import kotlin.script.experimental.host.ScriptingHostConfiguration import kotlin.script.experimental.host.configurationDependencies import kotlin.script.experimental.host.toScriptSource -import kotlin.script.experimental.jvm.* -import kotlin.script.experimental.jvm.util.classpathFromClass +import kotlin.script.experimental.jvm.JvmDependency +import kotlin.script.experimental.jvm.baseClassLoader +import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration +import kotlin.script.experimental.jvm.jvm import kotlin.script.experimental.jvm.util.classpathFromClassloader import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate object ScriptSupporter { - private fun JvmScriptCompilationConfigurationBuilder.dependenciesFromClass(classLoader: ClassLoader,vararg classes:KClass) { - classes.flatMap {c-> - classpathFromClass(classLoader,c)?:let { - val clp = "${c.java.canonicalName.replace('.', '/')}.class" - val url = classLoader.getResource(clp) - url?.toURI()?.schemeSpecificPart?.let { listOf(File(it.removePrefix("file:").split("!")[0])) } - }?: emptyList() - }.let(this::updateClasspath) - } - - object Configuration:ScriptCompilationConfiguration({ - jvm { - dependenciesFromClass(ScriptSupporter::class.java.classLoader,Bukkit::class,Item::class) - } - defaultImports(Item::class, DependsOn::class) - defaultImports.append("cf.wayzer.SuperItem.features.*") - refineConfiguration{ - onAnnotations(DependsOn::class){ context-> - val annotations = context.collectedData?.get(ScriptCollectedData.foundAnnotations)?.filter { it.annotationClass== DependsOn::class }?: listOf() - val classes = annotations.map { Class.forName((it as DependsOn).value).kotlin} - val diagnostics = classes.map { ScriptDiagnostic("[Info]PluginDependency: ${it.java.name}") } - ScriptCompilationConfiguration(context.compilationConfiguration) { - jvm{ - dependenciesFromClass(ScriptSupporter::class.java.classLoader, *classes.toTypedArray()) - } - }.asSuccess(diagnostics) - } - } - }) - fun loadFile(f: File):ResultWithDiagnostics{ LibraryManager(Paths.get("./libs/")).apply { addMavenCentral() diff --git a/src/main/kotlin/cf/wayzer/SuperItem/scripts/CompilationConfiguration.kt b/src/main/kotlin/cf/wayzer/SuperItem/scripts/CompilationConfiguration.kt new file mode 100644 index 0000000..8ca1429 --- /dev/null +++ b/src/main/kotlin/cf/wayzer/SuperItem/scripts/CompilationConfiguration.kt @@ -0,0 +1,41 @@ +package cf.wayzer.SuperItem.scripts + +import cf.wayzer.SuperItem.Item +import cf.wayzer.SuperItem.ScriptSupporter +import org.bukkit.Bukkit +import java.io.File +import kotlin.reflect.KClass +import kotlin.script.experimental.api.* +import kotlin.script.experimental.jvm.JvmScriptCompilationConfigurationBuilder +import kotlin.script.experimental.jvm.jvm +import kotlin.script.experimental.jvm.updateClasspath +import kotlin.script.experimental.jvm.util.classpathFromClass + +object CompilationConfiguration: ScriptCompilationConfiguration({ + jvm { + dependenciesFromClass(ScriptSupporter::class.java.classLoader, Bukkit::class, Item::class) + } + defaultImports(Item::class, ImportClass::class) + defaultImports.append("cf.wayzer.SuperItem.features.*") + refineConfiguration{ + onAnnotations(JvmName::class){ context-> + val annotations = context.collectedData?.get(ScriptCollectedData.foundAnnotations)?.filter { it.annotationClass== JvmName::class }?: listOf() + val classes = annotations.map { Class.forName((it as JvmName).name).kotlin} + val diagnostics = classes.map { ScriptDiagnostic("[Info]PluginDependency: ${it.java.name}",ScriptDiagnostic.Severity.INFO) } + ScriptCompilationConfiguration(context.compilationConfiguration) { + jvm { + dependenciesFromClass(ScriptSupporter::class.java.classLoader, *classes.toTypedArray()) + } + }.asSuccess(diagnostics) + } + } +}) +private fun JvmScriptCompilationConfigurationBuilder.dependenciesFromClass(classLoader: ClassLoader, vararg classes: KClass) { + classes.flatMap {c-> + classpathFromClass(classLoader,c) ?:let { + val clp = "${c.java.canonicalName.replace('.', '/')}.class" + val url = classLoader.getResource(clp) + url?.toURI()?.schemeSpecificPart?.let { listOf(File(it.removePrefix("file:").split("!")[0])) } + }?: emptyList() + }.let(this::updateClasspath) +} \ No newline at end of file diff --git a/src/main/kotlin/cf/wayzer/SuperItem/scripts/ImportClass.kt b/src/main/kotlin/cf/wayzer/SuperItem/scripts/ImportClass.kt new file mode 100644 index 0000000..bd2eb01 --- /dev/null +++ b/src/main/kotlin/cf/wayzer/SuperItem/scripts/ImportClass.kt @@ -0,0 +1,6 @@ +package cf.wayzer.SuperItem.scripts + +@Target(AnnotationTarget.FILE) +annotation class ImportClass( + val value:String +) \ No newline at end of file diff --git a/src/main/kotlin/cf/wayzer/SuperItem/scripts/SuperItemScript.kt b/src/main/kotlin/cf/wayzer/SuperItem/scripts/SuperItemScript.kt index fa40e14..139340e 100644 --- a/src/main/kotlin/cf/wayzer/SuperItem/scripts/SuperItemScript.kt +++ b/src/main/kotlin/cf/wayzer/SuperItem/scripts/SuperItemScript.kt @@ -1,12 +1,11 @@ package cf.wayzer.SuperItem.scripts import cf.wayzer.SuperItem.Item -import cf.wayzer.SuperItem.ScriptSupporter import kotlin.script.experimental.annotations.KotlinScript @KotlinScript( displayName = "SuperItem Kotlin Script", fileExtension = "superitem.kts", - compilationConfiguration = ScriptSupporter.Configuration::class + compilationConfiguration = CompilationConfiguration::class ) -abstract class SuperItemScript(name:String): Item.Builder("scripts",name) \ No newline at end of file +open class SuperItemScript(name:String): Item.Builder("scripts",name) \ No newline at end of file diff --git a/src/main/resources/Mythicmobs_Support.superitem.kts b/src/main/resources/Mythicmobs_Support.superitem.kts index d6839bc..d5bc57c 100644 --- a/src/main/resources/Mythicmobs_Support.superitem.kts +++ b/src/main/resources/Mythicmobs_Support.superitem.kts @@ -1,4 +1,4 @@ -@file:DependsOn("io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent") +@file:JvmName("io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent") import cf.wayzer.SuperItem.ItemManager import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitItemStack