feat: move type bind and export impl function
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
8c4f266356
commit
c7f66d8252
@ -1,7 +1,7 @@
|
|||||||
/// <reference types="@ms/types/dist/typings/bukkit" />
|
/// <reference types="@ms/types/dist/typings/bukkit" />
|
||||||
|
|
||||||
import { server, plugin, command, event, task } from '@ms/api'
|
import { server, command, event, task } from '@ms/api'
|
||||||
import { DefaultContainer as container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { BukkitConsole } from './console';
|
import { BukkitConsole } from './console';
|
||||||
import { BukkitEvent } from './event';
|
import { BukkitEvent } from './event';
|
||||||
@ -9,13 +9,10 @@ import { BukkitServer } from './server';
|
|||||||
import { BukkitCommand } from './command';
|
import { BukkitCommand } from './command';
|
||||||
import { BukkitTaskManager } from './task';
|
import { BukkitTaskManager } from './task';
|
||||||
|
|
||||||
let BukkitServerType = 'bukkit';
|
export default function BukkitImpl(container: Container) {
|
||||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
container.bind(server.Console).toConstantValue(BukkitConsole);
|
||||||
|
container.bind(event.Event).to(BukkitEvent).inSingletonScope();
|
||||||
container.bind(server.Console).toConstantValue(BukkitConsole);
|
container.bind(server.Server).to(BukkitServer).inSingletonScope();
|
||||||
container.bind(server.ServerType).toConstantValue(BukkitServerType);
|
container.bind(command.Command).to(BukkitCommand).inSingletonScope();
|
||||||
|
container.bind(task.TaskManager).to(BukkitTaskManager).inSingletonScope();
|
||||||
container.bind(event.Event).to(BukkitEvent).inSingletonScope();
|
}
|
||||||
container.bind(server.Server).to(BukkitServer).inSingletonScope();
|
|
||||||
container.bind(command.Command).to(BukkitCommand).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(BukkitTaskManager).inSingletonScope();
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/// <reference types="@ms/types/dist/typings/bungee" />
|
/// <reference types="@ms/types/dist/typings/bungee" />
|
||||||
|
|
||||||
import { server, plugin, command, event, task } from '@ms/api'
|
import { server, command, event, task } from '@ms/api'
|
||||||
import { DefaultContainer as container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { BungeeConsole } from './console';
|
import { BungeeConsole } from './console';
|
||||||
import { BungeeEvent } from './event';
|
import { BungeeEvent } from './event';
|
||||||
@ -9,12 +9,10 @@ import { BungeeServer } from './server';
|
|||||||
import { BungeeCommand } from './command';
|
import { BungeeCommand } from './command';
|
||||||
import { BungeeTaskManager } from './task';
|
import { BungeeTaskManager } from './task';
|
||||||
|
|
||||||
let BungeeServerType = 'bungee';
|
export default function BungeeImpl(container: Container) {
|
||||||
|
container.bind(server.Console).toConstantValue(BungeeConsole);
|
||||||
container.bind(server.Console).toConstantValue(BungeeConsole);
|
container.bind(event.Event).to(BungeeEvent).inSingletonScope();
|
||||||
container.bind(server.ServerType).toConstantValue(BungeeServerType);
|
container.bind(server.Server).to(BungeeServer).inSingletonScope();
|
||||||
|
container.bind(command.Command).to(BungeeCommand).inSingletonScope();
|
||||||
container.bind(event.Event).to(BungeeEvent).inSingletonScope();
|
container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope();
|
||||||
container.bind(server.Server).to(BungeeServer).inSingletonScope();
|
}
|
||||||
container.bind(command.Command).to(BungeeCommand).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope();
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import '@ms/nashorn'
|
import '@ms/ployfill'
|
||||||
|
let containerStartTime = new Date().getTime()
|
||||||
import { plugin, server, task, MiaoScriptConsole } from '@ms/api'
|
console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`)
|
||||||
|
import { plugin, server, task } from '@ms/api'
|
||||||
import { PluginManagerImpl } from '@ms/plugin'
|
import { PluginManagerImpl } from '@ms/plugin'
|
||||||
import { XMLHttpRequest as xhr } from '@ms/ployfill'
|
|
||||||
import { DefaultContainer as container, injectable, inject, ContainerInstance } from '@ms/container'
|
import { DefaultContainer as container, injectable, inject, ContainerInstance } from '@ms/container'
|
||||||
|
console.log('MiaoScript IOC Container @ms/container loading completed(' + (new Date().getTime() - containerStartTime) / 1000 + 's)!');
|
||||||
let startTime = new Date().getTime();
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@ -19,15 +18,14 @@ class MiaoScriptCore {
|
|||||||
enable() {
|
enable() {
|
||||||
this.loadServerConsole();
|
this.loadServerConsole();
|
||||||
this.loadTaskFunction();
|
this.loadTaskFunction();
|
||||||
|
global.level = "TRACE"
|
||||||
this.loadPlugins();
|
this.loadPlugins();
|
||||||
console.log('MiaoScript engine loading completed... Done (' + (new Date().getTime() - startTime) / 1000 + 's)!');
|
|
||||||
return () => this.disable();
|
return () => this.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadServerConsole() {
|
loadServerConsole() {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console = new this.Console();
|
console = new this.Console();
|
||||||
XMLHttpRequest = xhr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTaskFunction() {
|
loadTaskFunction() {
|
||||||
@ -38,10 +36,13 @@ class MiaoScriptCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPlugins() {
|
loadPlugins() {
|
||||||
|
let loadPluginStartTime = new Date().getTime()
|
||||||
|
console.log(`Initialization MiaoScript Plugin System. Please wait...`)
|
||||||
this.pluginManager.scan('plugins');
|
this.pluginManager.scan('plugins');
|
||||||
this.pluginManager.build();
|
this.pluginManager.build();
|
||||||
this.pluginManager.load();
|
this.pluginManager.load();
|
||||||
this.pluginManager.enable();
|
this.pluginManager.enable();
|
||||||
|
console.log('MiaoScript Plugin System loading completed(' + (new Date().getTime() - loadPluginStartTime) / 1000 + 's)!');
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
@ -74,16 +75,19 @@ function detectServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
console.info('Initialization MiaoScript Core Package @ms/core. Please wait...')
|
let corePackageStartTime = new Date().getTime()
|
||||||
container.bind(ContainerInstance).toConstantValue(container);
|
container.bind(ContainerInstance).toConstantValue(container);
|
||||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
||||||
let type = detectServer();
|
let type = detectServer();
|
||||||
require(`@ms/${type}`);
|
container.bind(server.ServerType).toConstantValue(type);
|
||||||
|
console.log(`Initialization MiaoScript Package @ms/core @ms/${type}. Please wait...`)
|
||||||
|
require(`@ms/${type}`).default(container);
|
||||||
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
||||||
container.bind(MiaoScriptCore).to(MiaoScriptCore).inSingletonScope();
|
container.bind(MiaoScriptCore).to(MiaoScriptCore).inSingletonScope();
|
||||||
console.log(`Initialization MiaoScript Sub Package @ms/${type} loading completed... cost (${(new Date().getTime() - startTime) / 1000}s)!`);
|
console.log(`MiaoScript Package @ms/core @ms/${type} loading completed(` + (new Date().getTime() - corePackageStartTime) / 1000 + 's)!');
|
||||||
|
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||||
|
console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!');
|
||||||
|
return disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
export default init();
|
||||||
|
|
||||||
export default container.get<MiaoScriptCore>(MiaoScriptCore).enable();
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/// <reference types="@ms/types/dist/typings/sponge" />
|
/// <reference types="@ms/types/dist/typings/sponge" />
|
||||||
|
|
||||||
import { server, plugin, command, event, task } from '@ms/api'
|
import { server, command, event, task } from '@ms/api'
|
||||||
import { DefaultContainer as container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { SpongeConsole } from './console';
|
import { SpongeConsole } from './console';
|
||||||
import { SpongeEvent } from './event';
|
import { SpongeEvent } from './event';
|
||||||
@ -9,13 +9,10 @@ import { SpongeServer } from './server';
|
|||||||
import { SpongeCommand } from './command';
|
import { SpongeCommand } from './command';
|
||||||
import { SpongeTaskManager } from './task';
|
import { SpongeTaskManager } from './task';
|
||||||
|
|
||||||
let SpongeServerType = 'sponge';
|
export default function SpongeImpl(container: Container) {
|
||||||
let Sponge = Java.type("org.spongepowered.api.Sponge");
|
container.bind(server.Console).toConstantValue(SpongeConsole);
|
||||||
|
container.bind(event.Event).to(SpongeEvent).inSingletonScope();
|
||||||
container.bind(server.Console).toConstantValue(SpongeConsole);
|
container.bind(server.Server).to(SpongeServer).inSingletonScope();
|
||||||
container.bind(server.ServerType).toConstantValue(SpongeServerType);
|
container.bind(command.Command).to(SpongeCommand).inSingletonScope();
|
||||||
|
container.bind(task.TaskManager).to(SpongeTaskManager).inSingletonScope();
|
||||||
container.bind(event.Event).to(SpongeEvent).inSingletonScope();
|
}
|
||||||
container.bind(server.Server).to(SpongeServer).inSingletonScope();
|
|
||||||
container.bind(command.Command).to(SpongeCommand).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(SpongeTaskManager).inSingletonScope();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user