-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(see MythicMobs_Support.superitem.kts in src/main/resources for example) (because DependsOn need other dependency)
- Loading branch information
Showing
6 changed files
with
59 additions
and
41 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
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/cf/wayzer/SuperItem/scripts/CompilationConfiguration.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,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<out Any>) { | ||
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) | ||
} |
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,6 @@ | ||
package cf.wayzer.SuperItem.scripts | ||
|
||
@Target(AnnotationTarget.FILE) | ||
annotation class ImportClass( | ||
val value:String | ||
) |
5 changes: 2 additions & 3 deletions
5
src/main/kotlin/cf/wayzer/SuperItem/scripts/SuperItemScript.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 |
---|---|---|
@@ -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) | ||
open class SuperItemScript(name:String): Item.Builder("scripts",name) |
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