From f821998801b11a7d3bd811e07d53951826eafd36 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sun, 1 Mar 2020 15:19:43 +0800 Subject: [PATCH] feat: add NativePluginManager Signed-off-by: MiaoWoo --- .../src/interfaces/{server.ts => server/index.ts} | 1 + packages/api/src/interfaces/server/native_plugin.ts | 6 ++++++ packages/bukkit/src/server.ts | 11 ++++++++++- packages/bungee/src/server.ts | 11 ++++++++++- packages/nukkit/src/server.ts | 13 +++++++++++++ packages/sponge/src/server.ts | 12 ++++++++++-- 6 files changed, 50 insertions(+), 4 deletions(-) rename packages/api/src/interfaces/{server.ts => server/index.ts} (94%) create mode 100644 packages/api/src/interfaces/server/native_plugin.ts diff --git a/packages/api/src/interfaces/server.ts b/packages/api/src/interfaces/server/index.ts similarity index 94% rename from packages/api/src/interfaces/server.ts rename to packages/api/src/interfaces/server/index.ts index f94744db..47f4c3ce 100644 --- a/packages/api/src/interfaces/server.ts +++ b/packages/api/src/interfaces/server/index.ts @@ -27,6 +27,7 @@ export namespace server { dispatchCommand(sender: string | any, command: string): boolean; dispatchConsoleCommand(command: string): boolean; getPluginsFolder(): string; + getNativePluginManager(): NativePluginManager; sendJson(sender: string | any, json: object | string): void; } } diff --git a/packages/api/src/interfaces/server/native_plugin.ts b/packages/api/src/interfaces/server/native_plugin.ts new file mode 100644 index 00000000..2f826e35 --- /dev/null +++ b/packages/api/src/interfaces/server/native_plugin.ts @@ -0,0 +1,6 @@ +interface NativePluginManager { + load(name: string): boolean; + unload(name: string): boolean; + reload(name: string): boolean; + delete(name: string): boolean; +} \ No newline at end of file diff --git a/packages/bukkit/src/server.ts b/packages/bukkit/src/server.ts index a6e17a24..814a0b93 100644 --- a/packages/bukkit/src/server.ts +++ b/packages/bukkit/src/server.ts @@ -7,6 +7,12 @@ let Bukkit = org.bukkit.Bukkit; @provideSingleton(server.Server) export class BukkitServer implements server.Server { + private pluginsFolder: string; + + constructor() { + this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath(); + } + getPlayer(name: string) { return Bukkit.getPlayer(name) } @@ -32,7 +38,10 @@ export class BukkitServer implements server.Server { return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command) } getPluginsFolder(): string { - return Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath(); + return this.pluginsFolder; + } + getNativePluginManager() { + throw new Error("Method not implemented."); } sendJson(sender: string | any, json: object | string): void { if (typeof sender === "string") { diff --git a/packages/bungee/src/server.ts b/packages/bungee/src/server.ts index c43b2401..6eddbc20 100644 --- a/packages/bungee/src/server.ts +++ b/packages/bungee/src/server.ts @@ -5,6 +5,12 @@ let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy(); @provideSingleton(server.Server) export class BungeeServer implements server.Server { + private pluginsFolder: string; + + constructor() { + this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath(); + } + getPlayer(name: string) { return Bungee.getPlayer(name); } @@ -30,7 +36,10 @@ export class BungeeServer implements server.Server { return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command) } getPluginsFolder(): string { - return Bungee.getPluginsFolder().getCanonicalPath(); + return this.pluginsFolder; + } + getNativePluginManager() { + throw new Error("Method not implemented."); } sendJson(sender: string | any, json: string): void { throw new Error("Method not implemented."); diff --git a/packages/nukkit/src/server.ts b/packages/nukkit/src/server.ts index e20a6987..ce2c9ad1 100644 --- a/packages/nukkit/src/server.ts +++ b/packages/nukkit/src/server.ts @@ -2,9 +2,16 @@ import { server } from '@ms/api' import { provideSingleton } from '@ms/container'; let Nukkit: cn.nukkit.Server = base.getInstance().getServer(); +const File = Java.type("java.io.File"); @provideSingleton(server.Server) export class NukkitServer implements server.Server { + private pluginsFolder: string; + + constructor() { + this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath() + } + getPlayer(name: string) { return Nukkit.getPlayer(name) } @@ -29,6 +36,12 @@ export class NukkitServer implements server.Server { dispatchConsoleCommand(command: string): boolean { return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command) } + getPluginsFolder(): string { + return this.pluginsFolder; + } + getNativePluginManager() { + throw new Error("Method not implemented."); + } sendJson(sender: string | any, json: object | string): void { throw new Error("Method not implemented."); } diff --git a/packages/sponge/src/server.ts b/packages/sponge/src/server.ts index 1790dd5f..4b509a2d 100644 --- a/packages/sponge/src/server.ts +++ b/packages/sponge/src/server.ts @@ -10,6 +10,12 @@ const File = Java.type("java.io.File"); @provideSingleton(server.Server) export class SpongeServer implements server.Server { + private pluginsFolder: string; + + constructor() { + this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath() + } + getPlayer(name: string) { return Sponge.getServer().getPlayer(name).orElse(null) } @@ -35,8 +41,10 @@ export class SpongeServer implements server.Server { return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult() } getPluginsFolder(): string { - let pluginFile = new URL(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0]).path - return new File(pluginFile).getParentFile().getCanonicalPath() + return this.pluginsFolder; + } + getNativePluginManager() { + throw new Error("Method not implemented."); } sendJson(sender: string | any, json: string): void { if (typeof sender === "string") {