2020-12-07 03:12:49 +00:00
|
|
|
import { server } from '@ccms/api'
|
|
|
|
|
2021-08-03 09:30:53 +00:00
|
|
|
const Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit')
|
2020-12-07 03:12:49 +00:00
|
|
|
|
|
|
|
export class BukkitNativePluginManager extends server.NativePluginManager {
|
2021-08-03 09:30:53 +00:00
|
|
|
private bukkitPluginManager: org.bukkit.plugin.PluginManager
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
this.bukkitPluginManager = Bukkit.getPluginManager()
|
|
|
|
}
|
|
|
|
|
|
|
|
list(): server.NativePlugin[] {
|
|
|
|
return Java.from(this.bukkitPluginManager.getPlugins()).map(plugin => this.convert(plugin))
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
2021-08-03 09:30:53 +00:00
|
|
|
has(name: string): boolean {
|
|
|
|
return !!Bukkit.getPluginManager().getPlugin(name)
|
|
|
|
}
|
|
|
|
get(name: string): server.NativePlugin {
|
|
|
|
return this.convert(Bukkit.getPluginManager().getPlugin(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
private convert(plugin: org.bukkit.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()),
|
|
|
|
depends: Java.from(desc.getDepend()),
|
|
|
|
softDepends: Java.from(desc.getSoftDepend()),
|
|
|
|
enable: plugin.isEnabled(),
|
|
|
|
origin: plugin
|
|
|
|
}
|
2020-12-07 03:12:49 +00:00
|
|
|
}
|
|
|
|
}
|