add Java API

This commit is contained in:
jiahua.liu 2020-04-06 13:20:10 +08:00
parent 4d8753d8e2
commit e82281367e
3 changed files with 23 additions and 1 deletions

View File

@ -14,7 +14,7 @@ public class EventListener {
PluginBase base;
protected EventListener(
public EventListener(
PluginBase base
){
this.base = base;

View File

@ -15,6 +15,7 @@ import kotlinx.coroutines.*
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.command.Command
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.events.EventListener
import net.mamoe.mirai.console.scheduler.PluginScheduler
import net.mamoe.mirai.console.scheduler.SchedulerTaskManagerInstance
import net.mamoe.mirai.utils.MiraiLogger
@ -138,6 +139,14 @@ abstract class PluginBase
return scheduler!!
}
private var eventListener:EventListener? = null
fun getEventListener():EventListener{
if(eventListener == null){
eventListener = EventListener(this)
}
return eventListener!!
}
}
/**

View File

@ -100,9 +100,22 @@ class PluginScheduler(_coroutineContext: CoroutineContext) :CoroutineScope{
}
)
}
/**
* 异步执行一个任务, 没有返回
*/
fun async(runnable: Runnable){
this.launch {
withContext(Dispatchers.IO){
runnable.run()
}
}
}
}
/**
* 这个类作为java与kotlin的桥接
* 用java的interface进行了kotlin的实现