diff --git a/packages/bukkit/src/index.ts b/packages/bukkit/src/index.ts index fad3357a..a49a76c9 100644 --- a/packages/bukkit/src/index.ts +++ b/packages/bukkit/src/index.ts @@ -1,7 +1,7 @@ /// -import { server, plugin, command, event, task } from '@ms/api' -import { DefaultContainer as container } from '@ms/container' +import { server, command, event, task } from '@ms/api' +import { Container } from '@ms/container' import { BukkitConsole } from './console'; import { BukkitEvent } from './event'; @@ -9,13 +9,10 @@ import { BukkitServer } from './server'; import { BukkitCommand } from './command'; import { BukkitTaskManager } from './task'; -let BukkitServerType = 'bukkit'; -let Bukkit = Java.type("org.bukkit.Bukkit"); - -container.bind(server.Console).toConstantValue(BukkitConsole); -container.bind(server.ServerType).toConstantValue(BukkitServerType); - -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(); +export default function BukkitImpl(container: Container) { + container.bind(server.Console).toConstantValue(BukkitConsole); + 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(); +} diff --git a/packages/bungee/src/index.ts b/packages/bungee/src/index.ts index c81c4ea5..79123d5a 100644 --- a/packages/bungee/src/index.ts +++ b/packages/bungee/src/index.ts @@ -1,7 +1,7 @@ /// -import { server, plugin, command, event, task } from '@ms/api' -import { DefaultContainer as container } from '@ms/container' +import { server, command, event, task } from '@ms/api' +import { Container } from '@ms/container' import { BungeeConsole } from './console'; import { BungeeEvent } from './event'; @@ -9,12 +9,10 @@ import { BungeeServer } from './server'; import { BungeeCommand } from './command'; import { BungeeTaskManager } from './task'; -let BungeeServerType = 'bungee'; - -container.bind(server.Console).toConstantValue(BungeeConsole); -container.bind(server.ServerType).toConstantValue(BungeeServerType); - -container.bind(event.Event).to(BungeeEvent).inSingletonScope(); -container.bind(server.Server).to(BungeeServer).inSingletonScope(); -container.bind(command.Command).to(BungeeCommand).inSingletonScope(); -container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope(); +export default function BungeeImpl(container: Container) { + container.bind(server.Console).toConstantValue(BungeeConsole); + container.bind(event.Event).to(BungeeEvent).inSingletonScope(); + container.bind(server.Server).to(BungeeServer).inSingletonScope(); + container.bind(command.Command).to(BungeeCommand).inSingletonScope(); + container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope(); +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 69444bc5..e1f21cf7 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,11 +1,10 @@ -import '@ms/nashorn' - -import { plugin, server, task, MiaoScriptConsole } from '@ms/api' +import '@ms/ployfill' +let containerStartTime = new Date().getTime() +console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`) +import { plugin, server, task } from '@ms/api' import { PluginManagerImpl } from '@ms/plugin' -import { XMLHttpRequest as xhr } from '@ms/ployfill' import { DefaultContainer as container, injectable, inject, ContainerInstance } from '@ms/container' - -let startTime = new Date().getTime(); +console.log('MiaoScript IOC Container @ms/container loading completed(' + (new Date().getTime() - containerStartTime) / 1000 + 's)!'); @injectable() class MiaoScriptCore { @@ -19,15 +18,14 @@ class MiaoScriptCore { enable() { this.loadServerConsole(); this.loadTaskFunction(); + global.level = "TRACE" this.loadPlugins(); - console.log('MiaoScript engine loading completed... Done (' + (new Date().getTime() - startTime) / 1000 + 's)!'); return () => this.disable(); } loadServerConsole() { // @ts-ignore console = new this.Console(); - XMLHttpRequest = xhr; } loadTaskFunction() { @@ -38,10 +36,13 @@ class MiaoScriptCore { } loadPlugins() { + let loadPluginStartTime = new Date().getTime() + console.log(`Initialization MiaoScript Plugin System. Please wait...`) this.pluginManager.scan('plugins'); this.pluginManager.build(); this.pluginManager.load(); this.pluginManager.enable(); + console.log('MiaoScript Plugin System loading completed(' + (new Date().getTime() - loadPluginStartTime) / 1000 + 's)!'); } disable() { @@ -74,16 +75,19 @@ function detectServer() { } function init() { - console.info('Initialization MiaoScript Core Package @ms/core. Please wait...') + let corePackageStartTime = new Date().getTime() container.bind(ContainerInstance).toConstantValue(container); container.bind(plugin.PluginInstance).toConstantValue(base.getInstance()); 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(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).enable() + console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!'); + return disable; } -init(); - -export default container.get(MiaoScriptCore).enable(); +export default init(); diff --git a/packages/sponge/src/index.ts b/packages/sponge/src/index.ts index 3a85da42..62ecc7a8 100644 --- a/packages/sponge/src/index.ts +++ b/packages/sponge/src/index.ts @@ -1,7 +1,7 @@ /// -import { server, plugin, command, event, task } from '@ms/api' -import { DefaultContainer as container } from '@ms/container' +import { server, command, event, task } from '@ms/api' +import { Container } from '@ms/container' import { SpongeConsole } from './console'; import { SpongeEvent } from './event'; @@ -9,13 +9,10 @@ import { SpongeServer } from './server'; import { SpongeCommand } from './command'; import { SpongeTaskManager } from './task'; -let SpongeServerType = 'sponge'; -let Sponge = Java.type("org.spongepowered.api.Sponge"); - -container.bind(server.Console).toConstantValue(SpongeConsole); -container.bind(server.ServerType).toConstantValue(SpongeServerType); - -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(); +export default function SpongeImpl(container: Container) { + container.bind(server.Console).toConstantValue(SpongeConsole); + 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(); +}