ms/packages/sponge/src/plugin.ts
MiaoWoo 7afea75454 feat: 更新插件管理模块
Signed-off-by: MiaoWoo <admin@yumc.pw>
2021-08-03 17:56:11 +08:00

36 lines
1.2 KiB
TypeScript

import { server } from '@ccms/api'
const Sponge: typeof org.spongepowered.api.Sponge = Java.type('org.spongepowered.api.Sponge')
export class SpongeNativePluginManager extends server.NativePluginManager {
private spongePluginManager: org.spongepowered.api.plugin.PluginManager
constructor() {
super()
this.spongePluginManager = Sponge.getPluginManager()
}
list(): server.NativePlugin[] {
return Java.from(this.spongePluginManager.getPlugins()).map(plugin => this.convert(plugin))
}
has(name: string) {
return !!this.spongePluginManager.getPlugin(name).orElse(null)
}
get(name: string) {
return this.convert(this.spongePluginManager.getPlugin(name).orElse(null))
}
private convert(plugin: org.spongepowered.api.plugin.PluginContainer): server.NativePlugin {
if (!plugin) return plugin as any
return {
name: plugin.getName(),
version: plugin.getVersion().get() as string,
authors: Java.from(plugin.getAuthors() as string[]),
depends: Java.from(plugin.getDependencies()),
softDepends: [],
enable: true,
origin: plugin
}
}
}