feat: add download and getPluginsFolder
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
ce431aded4
commit
488eecba07
@ -4,7 +4,7 @@ export namespace plugin {
|
||||
*/
|
||||
export const Plugin = Symbol("Plugin");
|
||||
/**
|
||||
* MiaoScript Plugin
|
||||
* MiaoScript Plugin Folder
|
||||
*/
|
||||
export const PluginFolder = Symbol("PluginFolder");
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@ export namespace server {
|
||||
getService(service: string): any;
|
||||
dispatchCommand(sender: string | any, command: string): boolean;
|
||||
dispatchConsoleCommand(command: string): boolean;
|
||||
getPluginsFolder(): string;
|
||||
sendJson(sender: string | any, json: object | string): void;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ export class BukkitServer implements server.Server {
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
||||
}
|
||||
sendJson(sender: string | any, json: object | string): void {
|
||||
if (typeof sender === "string") {
|
||||
sender = this.getPlayer(sender)
|
||||
|
@ -29,6 +29,9 @@ export class BungeeServer implements server.Server {
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return Bungee.getPluginsFolder().getCanonicalPath();
|
||||
}
|
||||
sendJson(sender: string | any, json: string): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
import '@ms/api'
|
||||
|
||||
const URL = Java.type('java.net.URL')
|
||||
const Paths = Java.type('java.nio.file.Paths');
|
||||
const Files = Java.type('java.nio.file.Files');
|
||||
const StandardCopyOption = Java.type('java.nio.file.StandardCopyOption');
|
||||
|
||||
export type Method =
|
||||
| 'get' | 'GET'
|
||||
| 'delete' | 'DELETE'
|
||||
@ -31,6 +36,10 @@ function request(config: RequestConfig) {
|
||||
return xhr.get();
|
||||
}
|
||||
|
||||
function download(url: string, target: string) {
|
||||
Files.copy(new URL(url).openStream(), Paths.get(target), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
function _proxy(method: Method) {
|
||||
return function (url: string, data?: any, config?: RequestConfig) {
|
||||
return request({ url, method, data, ...config });
|
||||
@ -40,5 +49,6 @@ function _proxy(method: Method) {
|
||||
export default {
|
||||
get: _proxy('GET'),
|
||||
post: _proxy('POST'),
|
||||
request
|
||||
request,
|
||||
download
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { server } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
let Sponge = org.spongepowered.api.Sponge;
|
||||
let TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import * as fs from '@ms/common/dist/fs'
|
||||
|
||||
const Sponge = org.spongepowered.api.Sponge;
|
||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
const URL = Java.type("java.net.URL");
|
||||
const File = Java.type("java.io.File");
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class SpongeServer implements server.Server {
|
||||
@ -30,6 +34,10 @@ export class SpongeServer implements server.Server {
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
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()
|
||||
}
|
||||
sendJson(sender: string | any, json: string): void {
|
||||
if (typeof sender === "string") {
|
||||
sender = this.getPlayer(sender)
|
||||
|
Loading…
Reference in New Issue
Block a user