feat: add NativePluginManager

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-03-01 15:19:43 +08:00
parent 488eecba07
commit 6b7a729e65
6 changed files with 50 additions and 4 deletions

View File

@ -27,6 +27,7 @@ export namespace server {
dispatchCommand(sender: string | any, command: string): boolean; dispatchCommand(sender: string | any, command: string): boolean;
dispatchConsoleCommand(command: string): boolean; dispatchConsoleCommand(command: string): boolean;
getPluginsFolder(): string; getPluginsFolder(): string;
getNativePluginManager(): NativePluginManager;
sendJson(sender: string | any, json: object | string): void; sendJson(sender: string | any, json: object | string): void;
} }
} }

View File

@ -0,0 +1,6 @@
interface NativePluginManager {
load(name: string): boolean;
unload(name: string): boolean;
reload(name: string): boolean;
delete(name: string): boolean;
}

View File

@ -7,6 +7,12 @@ let Bukkit = org.bukkit.Bukkit;
@provideSingleton(server.Server) @provideSingleton(server.Server)
export class BukkitServer implements server.Server { export class BukkitServer implements server.Server {
private pluginsFolder: string;
constructor() {
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
}
getPlayer(name: string) { getPlayer(name: string) {
return Bukkit.getPlayer(name) return Bukkit.getPlayer(name)
} }
@ -32,7 +38,10 @@ export class BukkitServer implements server.Server {
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command) return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)
} }
getPluginsFolder(): string { 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 { sendJson(sender: string | any, json: object | string): void {
if (typeof sender === "string") { if (typeof sender === "string") {

View File

@ -5,6 +5,12 @@ let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
@provideSingleton(server.Server) @provideSingleton(server.Server)
export class BungeeServer implements server.Server { export class BungeeServer implements server.Server {
private pluginsFolder: string;
constructor() {
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
}
getPlayer(name: string) { getPlayer(name: string) {
return Bungee.getPlayer(name); return Bungee.getPlayer(name);
} }
@ -30,7 +36,10 @@ export class BungeeServer implements server.Server {
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command) return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
} }
getPluginsFolder(): string { getPluginsFolder(): string {
return Bungee.getPluginsFolder().getCanonicalPath(); return this.pluginsFolder;
}
getNativePluginManager() {
throw new Error("Method not implemented.");
} }
sendJson(sender: string | any, json: string): void { sendJson(sender: string | any, json: string): void {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");

View File

@ -2,9 +2,16 @@ import { server } from '@ms/api'
import { provideSingleton } from '@ms/container'; import { provideSingleton } from '@ms/container';
let Nukkit: cn.nukkit.Server = base.getInstance().getServer(); let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
const File = Java.type("java.io.File");
@provideSingleton(server.Server) @provideSingleton(server.Server)
export class NukkitServer implements 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) { getPlayer(name: string) {
return Nukkit.getPlayer(name) return Nukkit.getPlayer(name)
} }
@ -29,6 +36,12 @@ export class NukkitServer implements server.Server {
dispatchConsoleCommand(command: string): boolean { dispatchConsoleCommand(command: string): boolean {
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command) 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 { sendJson(sender: string | any, json: object | string): void {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }

View File

@ -10,6 +10,12 @@ const File = Java.type("java.io.File");
@provideSingleton(server.Server) @provideSingleton(server.Server)
export class SpongeServer implements 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) { getPlayer(name: string) {
return Sponge.getServer().getPlayer(name).orElse(null) 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() return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult()
} }
getPluginsFolder(): string { getPluginsFolder(): string {
let pluginFile = new URL(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0]).path return this.pluginsFolder;
return new File(pluginFile).getParentFile().getCanonicalPath() }
getNativePluginManager() {
throw new Error("Method not implemented.");
} }
sendJson(sender: string | any, json: string): void { sendJson(sender: string | any, json: string): void {
if (typeof sender === "string") { if (typeof sender === "string") {