2019-09-07 04:23:15 +00:00
|
|
|
import '@ms/nashorn'
|
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
import { plugin, server, task } from '@ms/api'
|
2019-09-07 04:23:15 +00:00
|
|
|
import { PluginManagerImpl } from '@ms/plugin'
|
2019-11-04 12:26:22 +00:00
|
|
|
import { XMLHttpRequest as xhr } from '@ms/ployfill'
|
2019-09-22 10:01:35 +00:00
|
|
|
import { DefaultContainer as container, injectable, inject, postConstruct } from '@ms/container'
|
|
|
|
|
|
|
|
let startTime = new Date().getTime();
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
@injectable()
|
|
|
|
class MiaoScriptCore {
|
|
|
|
@inject(server.Console)
|
|
|
|
private Console: Console;
|
|
|
|
@inject(task.TaskManager)
|
|
|
|
private taskManager: task.TaskManager;
|
|
|
|
@inject(plugin.PluginManager)
|
|
|
|
private pluginManager: plugin.PluginManager;
|
|
|
|
|
|
|
|
enable() {
|
|
|
|
try {
|
|
|
|
this.loadServerConsole();
|
|
|
|
this.loadTaskFunction();
|
|
|
|
this.loadPlugins();
|
|
|
|
} catch (error) {
|
|
|
|
console.console(`§cMiaoScript start error please contact plugin author!`);
|
|
|
|
console.ex(error);
|
|
|
|
}
|
2019-09-22 10:01:35 +00:00
|
|
|
console.log('MiaoScript engine loading completed... Done (' + (new Date().getTime() - startTime) / 1000 + 's)!');
|
2019-09-21 07:06:17 +00:00
|
|
|
return () => this.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadServerConsole() {
|
2019-11-04 12:26:22 +00:00
|
|
|
// @ts-ignore
|
|
|
|
console = new this.Console();
|
|
|
|
XMLHttpRequest = xhr;
|
2019-09-21 07:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loadTaskFunction() {
|
|
|
|
//@ts-ignore
|
2019-11-05 09:02:58 +00:00
|
|
|
global.setTimeout = (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).later(tick).async(async).submit()
|
2019-09-21 07:06:17 +00:00
|
|
|
//@ts-ignore
|
2019-11-05 09:02:58 +00:00
|
|
|
global.setInterval = (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).timer(tick).async(async).submit()
|
2019-09-21 07:06:17 +00:00
|
|
|
}
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
loadPlugins() {
|
|
|
|
this.pluginManager.scan('plugins');
|
|
|
|
this.pluginManager.build(container);
|
|
|
|
this.pluginManager.load();
|
|
|
|
this.pluginManager.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
|
|
|
this.pluginManager.disable();
|
|
|
|
}
|
2019-09-10 09:22:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
function init() {
|
|
|
|
try {
|
|
|
|
Java.type("org.bukkit.Bukkit");
|
|
|
|
require('@ms/bukkit');
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Java.type("org.spongepowered.api.Sponge");
|
|
|
|
require('@ms/sponge');
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
|
|
|
container.bind(MiaoScriptCore).to(MiaoScriptCore).inSingletonScope();
|
|
|
|
}
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
init();
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2019-09-21 07:06:17 +00:00
|
|
|
export default container.get<MiaoScriptCore>(MiaoScriptCore).enable();
|