2020-12-07 03:12:49 +00:00
|
|
|
import { server } from '@ccms/api'
|
|
|
|
|
|
|
|
let Nukkit: cn.nukkit.Server = base.getInstance().getServer()
|
|
|
|
|
|
|
|
export class NukkitNativePluginManager extends server.NativePluginManager {
|
2021-08-03 09:56:11 +00:00
|
|
|
private nukkitPluginManager: cn.nukkit.plugin.PluginManager
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
this.nukkitPluginManager = Nukkit.getPluginManager()
|
|
|
|
}
|
|
|
|
|
|
|
|
list(): server.NativePlugin[] {
|
|
|
|
return Java.from(this.nukkitPluginManager.getPlugins().values()).map(plugin => this.convert(plugin))
|
|
|
|
}
|
2020-12-07 03:12:49 +00:00
|
|
|
has(name: string) {
|
2021-08-03 09:56:11 +00:00
|
|
|
return !!this.nukkitPluginManager.getPlugin(name)
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
|
|
|
get(name: string) {
|
2021-08-03 09:56:11 +00:00
|
|
|
return this.convert(this.nukkitPluginManager.getPlugin(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
private convert(plugin: cn.nukkit.plugin.Plugin): server.NativePlugin {
|
|
|
|
if (!plugin) return plugin as any
|
|
|
|
let desc = plugin.getDescription()
|
|
|
|
return {
|
|
|
|
name: plugin.getName(),
|
|
|
|
version: desc.getVersion(),
|
|
|
|
authors: Java.from(desc.getAuthors() as string[]),
|
|
|
|
depends: Java.from(desc.getDepend() as string[]),
|
|
|
|
softDepends: Java.from(desc.getSoftDepend() as string[]),
|
|
|
|
enable: plugin.isEnabled(),
|
|
|
|
origin: plugin
|
|
|
|
}
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
|
|
|
}
|