From 7afea75454e48179cd0c8201011808b4426f7807 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Tue, 3 Aug 2021 17:56:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MiaoWoo --- packages/bukkit/src/plugin.ts | 4 ++-- packages/bungee/src/plugin.ts | 32 ++++++++++++++++++++++++++++---- packages/nukkit/src/plugin.ts | 28 ++++++++++++++++++++++++++-- packages/sponge/src/plugin.ts | 29 ++++++++++++++++++++++++++--- 4 files changed, 82 insertions(+), 11 deletions(-) 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 + } } }