diff --git a/packages/bukkit/src/plugin.ts b/packages/bukkit/src/plugin.ts index 8220c3db..ae9be698 100644 --- a/packages/bukkit/src/plugin.ts +++ b/packages/bukkit/src/plugin.ts @@ -14,10 +14,10 @@ export class BukkitNativePluginManager extends server.NativePluginManager { return Java.from(this.bukkitPluginManager.getPlugins()).map(plugin => this.convert(plugin)) } has(name: string): boolean { - return !!Bukkit.getPluginManager().getPlugin(name) + return !!this.bukkitPluginManager.getPlugin(name) } get(name: string): server.NativePlugin { - return this.convert(Bukkit.getPluginManager().getPlugin(name)) + return this.convert(this.bukkitPluginManager.getPlugin(name)) } private convert(plugin: org.bukkit.plugin.Plugin): server.NativePlugin { diff --git a/packages/bungee/src/plugin.ts b/packages/bungee/src/plugin.ts index 19fda2d5..724db815 100644 --- a/packages/bungee/src/plugin.ts +++ b/packages/bungee/src/plugin.ts @@ -3,10 +3,34 @@ import { server } from '@ccms/api' let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy() export class BungeeNativePluginManager extends server.NativePluginManager { - has(name: string) { - return !!this.get(name) + private bungeePluginManager: net.md_5.bungee.api.plugin.PluginManager + + constructor() { + super() + this.bungeePluginManager = Bungee.getPluginManager() } - get(name: string) { - return Bungee.getPluginManager().getPlugin(name) + + list(): server.NativePlugin[] { + return Java.from(this.bungeePluginManager.getPlugins()).map(plugin => this.convert(plugin)) + } + has(name: string): boolean { + return !!this.bungeePluginManager.getPlugin(name) + } + get(name: string): server.NativePlugin { + return this.convert(this.bungeePluginManager.getPlugin(name)) + } + + private convert(plugin: net.md_5.bungee.api.plugin.Plugin): server.NativePlugin { + if (!plugin) return plugin as any + let desc = plugin.getDescription() + return { + name: desc.getName(), + version: desc.getVersion(), + authors: [desc.getAuthor()], + depends: Java.from(desc.getDepends()) as any, + softDepends: Java.from(desc.getSoftDepends()) as any, + enable: true, + origin: plugin + } } } diff --git a/packages/nukkit/src/plugin.ts b/packages/nukkit/src/plugin.ts index b13c58cc..3bc4959c 100644 --- a/packages/nukkit/src/plugin.ts +++ b/packages/nukkit/src/plugin.ts @@ -3,10 +3,34 @@ import { server } from '@ccms/api' let Nukkit: cn.nukkit.Server = base.getInstance().getServer() export class NukkitNativePluginManager extends server.NativePluginManager { + 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)) + } has(name: string) { - return !!this.get(name) + return !!this.nukkitPluginManager.getPlugin(name) } get(name: string) { - return Nukkit.getPluginManager().getPlugin(name) + 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 + } } } diff --git a/packages/sponge/src/plugin.ts b/packages/sponge/src/plugin.ts index 7dff50e0..9a53ce30 100644 --- a/packages/sponge/src/plugin.ts +++ b/packages/sponge/src/plugin.ts @@ -1,12 +1,35 @@ import { server } from '@ccms/api' -const Sponge = org.spongepowered.api.Sponge +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.get(name) + return !!this.spongePluginManager.getPlugin(name).orElse(null) } get(name: string) { - return Sponge.getPluginManager().getPlugin(name).orElse(null) + 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 + } } }