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 {
|
2021-08-03 09:56:11 +00:00
|
|
|
return !!this.bukkitPluginManager.getPlugin(name)
|
2021-08-03 09:30:53 +00:00
|
|
|
}
|
|
|
|
get(name: string): server.NativePlugin {
|
2021-08-03 09:56:11 +00:00
|
|
|
return this.convert(this.bukkitPluginManager.getPlugin(name))
|
2021-08-03 09:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|