2020-12-07 03:12:49 +00:00
|
|
|
import { server } from '@ccms/api'
|
|
|
|
|
2021-08-03 09:56:11 +00:00
|
|
|
const Sponge: typeof org.spongepowered.api.Sponge = Java.type('org.spongepowered.api.Sponge')
|
2020-12-07 03:12:49 +00:00
|
|
|
|
|
|
|
export class SpongeNativePluginManager extends server.NativePluginManager {
|
2021-08-03 09:56:11 +00:00
|
|
|
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))
|
|
|
|
}
|
2020-12-07 03:12:49 +00:00
|
|
|
has(name: string) {
|
2021-08-03 09:56:11 +00:00
|
|
|
return !!this.spongePluginManager.getPlugin(name).orElse(null)
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
|
|
|
get(name: string) {
|
2021-08-03 09:56:11 +00:00
|
|
|
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
|
|
|
|
}
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
|
|
|
}
|