Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
拓展脚本机制
Browse files Browse the repository at this point in the history
  • Loading branch information
EikoocS committed Jun 21, 2022
1 parent 4d84729 commit aa26462
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object ScriptCommands {
val reload = subCommand {
execute<ProxyCommandSender> { sender, _, _ ->
sender.sendLang("script-reloading")
ScriptManager.reloadAllScripts()
ScriptManager.reloadAll()
sender.sendLang("script-reloaded")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tech.cookiepower.jythonengine.script

import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.function.info
import tech.cookiepower.jythonengine.event.ScriptLoadEvent
import tech.cookiepower.jythonengine.event.ScriptUnloadEvent
import java.io.File
Expand Down Expand Up @@ -32,26 +31,26 @@ object ScriptManager {
scripts.remove(script)
}

private fun unRemoveUnload(script: Script){
ScriptUnloadEvent(script).call()
namespacedKeys.remove(script.namespacedKey)
}

fun loadScripts(){
rootDir.walk().filter {
fun loadByDir(dir: File = rootDir){
dir.walk().filter {
it.isFile && it.extension == "jy"
}.forEach {
load(Script(it))
}
}

fun unloadScripts(){
scripts
fun unloadAll(){
scripts.forEach {
namespacedKeys.remove(it.namespacedKey)
ScriptUnloadEvent(it).call()
unload(it)
}
scripts.clear()
}

@Awake(LifeCycle.ENABLE)
fun reloadAllScripts(){
unloadScripts()
loadScripts()
fun reloadAll(){
unloadAll()
loadByDir()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ object SchedulerTrigger : Trigger<List<SchedulerTriggerTask>>(){

@SubscribeEvent(ignoreCancelled = true)
fun onScriptUnload(event: ScriptUnloadEvent){
info("####################################################################################")
info("event subscriber: ScriptUnloadEvent")
info("####################################################################################")
if(event.script.isSchedulerScript){
onUnsubscribe(event.script)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.cookiepower.jythonengine.script.trigger

import taboolib.common.platform.event.EventPriority
import taboolib.common.platform.event.SubscribeEvent
import tech.cookiepower.jythonengine.event.ScriptExecuteEvent
import tech.cookiepower.jythonengine.event.ScriptLoadEvent
Expand Down

0 comments on commit aa26462

Please sign in to comment.