fix: Dependency cycles

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-03-01 19:37:34 +08:00
parent b95b4f6928
commit 12b3973b38
8 changed files with 23 additions and 14 deletions

View File

@ -1,3 +1,5 @@
import { NativePluginManager } from './native_plugin'
export namespace server {
/**
* Runtime ServerType

View File

@ -1,4 +1,4 @@
interface NativePluginManager {
export interface NativePluginManager {
load(name: string): boolean;
unload(name: string): boolean;
reload(name: string): boolean;

View File

@ -41,7 +41,7 @@ export class BukkitServer implements server.Server {
return this.pluginsFolder;
}
getNativePluginManager() {
throw new Error("Method not implemented.");
return Bukkit.getPluginManager() as any;
}
sendJson(sender: string | any, json: object | string): void {
if (typeof sender === "string") {

View File

@ -39,7 +39,7 @@ export class BungeeServer implements server.Server {
return this.pluginsFolder;
}
getNativePluginManager() {
throw new Error("Method not implemented.");
return Bungee.getPluginManager() as any
}
sendJson(sender: string | any, json: string): void {
throw new Error("Method not implemented.");

View File

@ -28,9 +28,6 @@
"typescript": "^3.8.3"
},
"dependencies": {
"@ms/common": "^0.3.0",
"@ms/container": "^0.3.0",
"@ms/ployfill": "^0.3.0",
"js-yaml": "^3.13.1"
},
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"

View File

@ -1,7 +1,9 @@
import '@ms/ployfill'
/// <reference types="@ms/types/dist/typings/nashorn" />
/// <reference types="@ms/ployfill" />
import * as yaml from 'js-yaml'
import * as fs from '@ms/common/dist/fs'
const File = Java.type("java.io.File");
const separatorChar = File.separatorChar;
let langMap = {};
let fallbackMap = {};
@ -18,16 +20,24 @@ function translate(name: string, param?: TranslateParam) {
}
function initialize(lang: string = 'zh_cn', fallback: string = 'zh_cn') {
langMap = readYamlFile(root, lang) || readYamlFile(fs.concat(__dirname, '..'), lang)
fallbackMap = readYamlFile(root, fallback) || readYamlFile(fs.concat(__dirname, '..'), fallback)
langMap = readYamlFile(root, lang) || readYamlFile(concat(__dirname, '..'), lang)
fallbackMap = readYamlFile(root, fallback) || readYamlFile(concat(__dirname, '..'), fallback)
console.i18n = function i18n(name: string, param?: TranslateParam) {
console.log(translate(name, param))
}
}
function readYamlFile(dir: string, name: string) {
let langFile = fs.concat(dir, 'languages', name + '.yml');
return fs.exists(langFile) && yaml.safeLoad(base.read(langFile))
let langFile = concat(dir, 'languages', name + '.yml');
return exists(langFile) && yaml.safeLoad(base.read(langFile))
}
function concat(...args: string[]) {
return args.join(separatorChar)
}
function exists(path: string) {
return new File(path).exists()
}
declare global {

View File

@ -40,7 +40,7 @@ export class NukkitServer implements server.Server {
return this.pluginsFolder;
}
getNativePluginManager() {
throw new Error("Method not implemented.");
return Nukkit.getPluginManager() as any;
}
sendJson(sender: string | any, json: object | string): void {
throw new Error("Method not implemented.");

View File

@ -44,7 +44,7 @@ export class SpongeServer implements server.Server {
return this.pluginsFolder;
}
getNativePluginManager() {
throw new Error("Method not implemented.");
return Sponge.getPluginManager() as any;
}
sendJson(sender: string | any, json: string): void {
if (typeof sender === "string") {