feat: use inversify autoProvide inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
68380ddbba
commit
a9996ba297
@ -90,20 +90,24 @@ export class MiaoScriptConsole implements Console {
|
|||||||
try {
|
try {
|
||||||
if (fileName.endsWith('js')) {
|
if (fileName.endsWith('js')) {
|
||||||
var file = Paths.get(fileName + '.map');
|
var file = Paths.get(fileName + '.map');
|
||||||
if (!this.sourceMaps[fileName]) {
|
if (this.sourceMaps[fileName] === undefined) {
|
||||||
if (file.toFile().exists()) {
|
if (file.toFile().exists()) {
|
||||||
var sourceMapObj = JSON.parse(new JavaString(Files.readAllBytes(file), "UTF-8"))
|
var sourceMapObj = JSON.parse(new JavaString(Files.readAllBytes(file), "UTF-8"))
|
||||||
this.sourceMaps[fileName] = new SourceMapBuilder(sourceMapObj)
|
this.sourceMaps[fileName] = new SourceMapBuilder(sourceMapObj)
|
||||||
|
} else {
|
||||||
|
this.sourceMaps[fileName] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sourceMaps[fileName]) {
|
if (this.sourceMaps[fileName]) {
|
||||||
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, lineNumber);
|
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 0);
|
||||||
if (sourceMapping) {
|
if (sourceMapping) {
|
||||||
|
if(lineNumber != sourceMapping.mapping.sourceLine){
|
||||||
fileName = fileName.replace(".js", ".ts");
|
fileName = fileName.replace(".js", ".ts");
|
||||||
lineNumber = sourceMapping.mapping.sourceLine;
|
lineNumber = sourceMapping.mapping.sourceLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.debug('search source map', fileName, 'line', lineNumber, 'error:', error)
|
console.debug('search source map', fileName, 'line', lineNumber, 'error:', error)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { channel, plugin } from '@ms/api'
|
import { channel, plugin } from '@ms/api'
|
||||||
import { inject, injectable } from '@ms/container'
|
import { inject, provideSingleton } from '@ms/container'
|
||||||
|
|
||||||
const Bukkit = org.bukkit.Bukkit
|
const Bukkit = org.bukkit.Bukkit
|
||||||
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
||||||
const Messenger = Bukkit.getMessenger()
|
const Messenger = Bukkit.getMessenger()
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(channel.Channel)
|
||||||
export class BukkitChannel extends channel.Channel {
|
export class BukkitChannel extends channel.Channel {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -2,14 +2,14 @@ import '@ms/nashorn'
|
|||||||
|
|
||||||
import { command, plugin } from '@ms/api'
|
import { command, plugin } from '@ms/api'
|
||||||
import * as reflect from '@ms/common/dist/reflect'
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
import { injectable, postConstruct, inject } from '@ms/container'
|
import { provideSingleton, postConstruct, inject } from '@ms/container'
|
||||||
|
|
||||||
let Bukkit = org.bukkit.Bukkit;
|
let Bukkit = org.bukkit.Bukkit;
|
||||||
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
||||||
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||||
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(command.Command)
|
||||||
export class BukkitCommand extends command.Command {
|
export class BukkitCommand extends command.Command {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { event, server, plugin } from '@ms/api'
|
import { event, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
import * as reflect from '@ms/common/dist/reflect'
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
const Bukkit = Java.type("org.bukkit.Bukkit");
|
const Bukkit = Java.type("org.bukkit.Bukkit");
|
||||||
@ -9,7 +9,7 @@ const Listener = Java.type("org.bukkit.event.Listener");
|
|||||||
const EventPriority = Java.type("org.bukkit.event.EventPriority");
|
const EventPriority = Java.type("org.bukkit.event.EventPriority");
|
||||||
const EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
const EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(event.Event)
|
||||||
export class BukkitEvent extends event.Event {
|
export class BukkitEvent extends event.Event {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
|
@ -4,17 +4,12 @@ import { server, command, event, channel, task } from '@ms/api'
|
|||||||
import { Container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { BukkitConsole } from './console';
|
import { BukkitConsole } from './console';
|
||||||
import { BukkitEvent } from './event';
|
import './event';
|
||||||
import { BukkitServer } from './server';
|
import './server';
|
||||||
import { BukkitCommand } from './command';
|
import './command';
|
||||||
import { BukkitChannel } from './channel';
|
import './channel';
|
||||||
import { BukkitTaskManager } from './task';
|
import './task';
|
||||||
|
|
||||||
export default function BukkitImpl(container: Container) {
|
export default function BukkitImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(BukkitConsole);
|
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(channel.Channel).to(BukkitChannel).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(BukkitTaskManager).inSingletonScope();
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { injectable } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
import chat from './enhance/chat'
|
import chat from './enhance/chat'
|
||||||
|
|
||||||
let Bukkit = org.bukkit.Bukkit;
|
let Bukkit = org.bukkit.Bukkit;
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(server.Server)
|
||||||
export class BukkitServer implements server.Server {
|
export class BukkitServer implements server.Server {
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bukkit.getPlayer(name)
|
return Bukkit.getPlayer(name)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { task, plugin } from '@ms/api'
|
import { task, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
const Bukkit = Java.type('org.bukkit.Bukkit');
|
const Bukkit = Java.type('org.bukkit.Bukkit');
|
||||||
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
|
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
|
||||||
const Callable = Java.type('java.util.concurrent.Callable')
|
const Callable = Java.type('java.util.concurrent.Callable')
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(task.TaskManager)
|
||||||
export class BukkitTaskManager implements task.TaskManager {
|
export class BukkitTaskManager implements task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { channel, plugin, event } from '@ms/api'
|
import { channel } from '@ms/api'
|
||||||
import { inject, injectable } from '@ms/container'
|
import { provideSingleton } from '@ms/container'
|
||||||
|
|
||||||
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(channel.Channel)
|
||||||
export class BungeeChannel extends channel.Channel {
|
export class BungeeChannel extends channel.Channel {
|
||||||
send(player: any, channel: string, data: any) {
|
send(player: any, channel: string, data: any) {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { command, plugin } from "@ms/api";
|
import { command, plugin } from "@ms/api";
|
||||||
import { inject, injectable } from "@ms/container";
|
import { inject, provideSingleton } from "@ms/container";
|
||||||
import * as ref from '@ms/common/dist/reflect'
|
|
||||||
|
|
||||||
const Arrays = Java.type('java.util.Arrays')
|
const Arrays = Java.type('java.util.Arrays')
|
||||||
const Command = Java.extend(Java.type('net.md_5.bungee.api.plugin.Command'), Java.type('net.md_5.bungee.api.plugin.TabExecutor'));
|
const Command = Java.extend(Java.type('net.md_5.bungee.api.plugin.Command'), Java.type('net.md_5.bungee.api.plugin.TabExecutor'));
|
||||||
@ -13,26 +12,7 @@ const createCommand = eval(`
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
class SimpleCommand {
|
@provideSingleton(command.Command)
|
||||||
public callable: any;
|
|
||||||
private name: string;
|
|
||||||
private executor: Function;
|
|
||||||
private tabComplete: Function = () => [];
|
|
||||||
|
|
||||||
constructor(command: string) {
|
|
||||||
this.name = command;
|
|
||||||
this.callable = createCommand(Command, command,
|
|
||||||
(sender, args) => this.executor(sender, '', command, args),
|
|
||||||
(sender, args) => Arrays.asList(this.tabComplete(sender, '', command, args))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
setExecutor = (executor: Function) => this.executor = executor;
|
|
||||||
setTabComplete = (tabComplete: Function) => this.tabComplete = tabComplete;
|
|
||||||
toString = () => `Bungee SimpleCommand(${this.name})`
|
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class BungeeCommand extends command.Command {
|
export class BungeeCommand extends command.Command {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
@ -64,3 +44,22 @@ export class BungeeCommand extends command.Command {
|
|||||||
return plugin.description.name.toLowerCase() + ":" + command;
|
return plugin.description.name.toLowerCase() + ":" + command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SimpleCommand {
|
||||||
|
public callable: any;
|
||||||
|
private name: string;
|
||||||
|
private executor: Function;
|
||||||
|
private tabComplete: Function = () => [];
|
||||||
|
|
||||||
|
constructor(command: string) {
|
||||||
|
this.name = command;
|
||||||
|
this.callable = createCommand(Command, command,
|
||||||
|
(sender, args) => this.executor(sender, '', command, args),
|
||||||
|
(sender, args) => Arrays.asList(this.tabComplete(sender, '', command, args))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setExecutor = (executor: Function) => this.executor = executor;
|
||||||
|
setTabComplete = (tabComplete: Function) => this.tabComplete = tabComplete;
|
||||||
|
toString = () => `Bungee SimpleCommand(${this.name})`
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { event, plugin } from '@ms/api'
|
import { event } from '@ms/api'
|
||||||
import { injectable, inject, postConstruct } from '@ms/container'
|
import { provideSingleton, postConstruct } from '@ms/container'
|
||||||
import * as reflect from '@ms/common/dist/reflect'
|
import * as reflect from '@ms/common/dist/reflect'
|
||||||
|
|
||||||
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||||
@ -21,10 +21,8 @@ EventPriority[event.EventPriority.HIGHEST] = Byte.valueOf(64);
|
|||||||
/**
|
/**
|
||||||
* Bungee Event Impl
|
* Bungee Event Impl
|
||||||
*/
|
*/
|
||||||
@injectable()
|
@provideSingleton(event.Event)
|
||||||
export class BungeeEvent extends event.Event {
|
export class BungeeEvent extends event.Event {
|
||||||
@inject(plugin.PluginInstance)
|
|
||||||
private pluginInstance: any;
|
|
||||||
private pluginManager = Bungee.getPluginManager()
|
private pluginManager = Bungee.getPluginManager()
|
||||||
|
|
||||||
// EventBus
|
// EventBus
|
||||||
|
@ -4,17 +4,12 @@ import { server, command, event, channel, task } from '@ms/api'
|
|||||||
import { Container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { BungeeConsole } from './console';
|
import { BungeeConsole } from './console';
|
||||||
import { BungeeEvent } from './event';
|
import './event';
|
||||||
import { BungeeServer } from './server';
|
import './server';
|
||||||
import { BungeeCommand } from './command';
|
import './command';
|
||||||
import { BungeeChannel } from './channel';
|
import './channel';
|
||||||
import { BungeeTaskManager } from './task';
|
import './task';
|
||||||
|
|
||||||
export default function BungeeImpl(container: Container) {
|
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.Server).to(BungeeServer).inSingletonScope();
|
|
||||||
container.bind(command.Command).to(BungeeCommand).inSingletonScope();
|
|
||||||
container.bind(channel.Channel).to(BungeeChannel).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope();
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { injectable } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(server.Server)
|
||||||
export class BungeeServer implements server.Server {
|
export class BungeeServer implements server.Server {
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Bungee.getPlayer(name);
|
return Bungee.getPlayer(name);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { task, plugin } from '@ms/api'
|
import { task, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
var Runnable = Java.type('java.lang.Runnable')
|
var Runnable = Java.type('java.lang.Runnable')
|
||||||
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(task.TaskManager)
|
||||||
export class BungeeTaskManager implements task.TaskManager {
|
export class BungeeTaskManager implements task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -2,11 +2,10 @@ import '@ms/ployfill'
|
|||||||
let containerStartTime = new Date().getTime()
|
let containerStartTime = new Date().getTime()
|
||||||
console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`)
|
console.log(`Initialization MiaoScript IOC Container @ms/container. Please wait...`)
|
||||||
import { plugin, server, task } from '@ms/api'
|
import { plugin, server, task } from '@ms/api'
|
||||||
import { PluginManagerImpl } from '@ms/plugin'
|
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } 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)!');
|
console.log('MiaoScript IOC Container @ms/container loading completed(' + (new Date().getTime() - containerStartTime) / 1000 + 's)!');
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(MiaoScriptCore)
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@inject(server.Console)
|
@inject(server.Console)
|
||||||
private Console: Console;
|
private Console: Console;
|
||||||
@ -85,11 +84,11 @@ function initialize() {
|
|||||||
let type = detectServer();
|
let type = detectServer();
|
||||||
console.info(`Detect Compatible Server set ServerType to ${type} ...`)
|
console.info(`Detect Compatible Server set ServerType to ${type} ...`)
|
||||||
container.bind(server.ServerType).toConstantValue(type);
|
container.bind(server.ServerType).toConstantValue(type);
|
||||||
console.log(`Initialization MiaoScript Package @ms/core @ms/${type}. Please wait...`)
|
console.log(`Initialization MiaoScript Package @ms/core @ms/${type} @ms/plugin. Please wait...`)
|
||||||
require(`@ms/${type}`).default(container);
|
require(`@ms/${type}`).default(container);
|
||||||
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
require('@ms/plugin')
|
||||||
container.bind(MiaoScriptCore).to(MiaoScriptCore).inSingletonScope();
|
container.load(buildProviderModule());
|
||||||
console.log(`MiaoScript Package @ms/core @ms/${type} loading completed(` + (new Date().getTime() - corePackageStartTime) / 1000 + 's)!');
|
console.log(`MiaoScript Package @ms/core @ms/${type} @ms/plugin loading completed(` + (new Date().getTime() - corePackageStartTime) / 1000 + 's)!');
|
||||||
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||||
console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!');
|
console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!');
|
||||||
return disable;
|
return disable;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import '@ms/nashorn'
|
import '@ms/nashorn'
|
||||||
|
|
||||||
import { command, plugin } from '@ms/api'
|
import { command, plugin } from '@ms/api'
|
||||||
import { injectable, postConstruct, inject } from '@ms/container'
|
import { inject, provideSingleton, postConstruct } from '@ms/container'
|
||||||
|
|
||||||
let PluginCommand = Java.type('cn.nukkit.command.PluginCommand');
|
let PluginCommand = Java.type('cn.nukkit.command.PluginCommand');
|
||||||
let CommandExecutor = Java.type('cn.nukkit.command.CommandExecutor');
|
let CommandExecutor = Java.type('cn.nukkit.command.CommandExecutor');
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(command.Command)
|
||||||
export class NukkitCommand extends command.Command {
|
export class NukkitCommand extends command.Command {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
@ -30,7 +30,6 @@ export class NukkitCommand extends command.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onCommand(plugin: any, command: any, executor: Function) {
|
onCommand(plugin: any, command: any, executor: Function) {
|
||||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
|
||||||
command.setExecutor(new CommandExecutor({
|
command.setExecutor(new CommandExecutor({
|
||||||
onCommand: super.setExecutor(plugin, command, executor)
|
onCommand: super.setExecutor(plugin, command, executor)
|
||||||
}));
|
}));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { event, server, plugin } from '@ms/api'
|
import { event, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container'
|
import { inject, provideSingleton } from '@ms/container'
|
||||||
|
|
||||||
const Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
const Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||||
const Event = Java.type("cn.nukkit.event.Event");
|
const Event = Java.type("cn.nukkit.event.Event");
|
||||||
@ -8,7 +8,7 @@ const Listener = Java.type("cn.nukkit.event.Listener");
|
|||||||
const EventPriority = Java.type("cn.nukkit.event.EventPriority");
|
const EventPriority = Java.type("cn.nukkit.event.EventPriority");
|
||||||
const EventExecutor = Java.type("cn.nukkit.plugin.EventExecutor");
|
const EventExecutor = Java.type("cn.nukkit.plugin.EventExecutor");
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(event.Event)
|
||||||
export class NukkitEvent extends event.Event {
|
export class NukkitEvent extends event.Event {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
/// <reference types="@ms/types/dist/typings/nukkit" />
|
/// <reference types="@ms/types/dist/typings/nukkit" />
|
||||||
|
|
||||||
import { server, command, event, task } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { Container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { NukkitConsole } from './console';
|
import { NukkitConsole } from './console';
|
||||||
import { NukkitEvent } from './event';
|
import './event';
|
||||||
import { NukkitServer } from './server';
|
import './server';
|
||||||
import { NukkitCommand } from './command';
|
import './command';
|
||||||
import { NukkitTaskManager } from './task';
|
import './task';
|
||||||
|
|
||||||
export default function NukkitImpl(container: Container) {
|
export default function NukkitImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(NukkitConsole);
|
container.bind(server.Console).toConstantValue(NukkitConsole);
|
||||||
container.bind(event.Event).to(NukkitEvent).inSingletonScope();
|
|
||||||
container.bind(server.Server).to(NukkitServer).inSingletonScope();
|
|
||||||
container.bind(command.Command).to(NukkitCommand).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(NukkitTaskManager).inSingletonScope();
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { injectable } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(server.Server)
|
||||||
export class NukkitServer implements server.Server {
|
export class NukkitServer implements server.Server {
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Nukkit.getPlayer(name)
|
return Nukkit.getPlayer(name)
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import { task, plugin } from '@ms/api'
|
import { task, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
const Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
|
||||||
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable');
|
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable');
|
||||||
const Callable = Java.type('java.util.concurrent.Callable')
|
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(task.TaskManager)
|
||||||
export class NukkitTaskManager implements task.TaskManager {
|
export class NukkitTaskManager implements task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { plugin, server, command, event } from '@ms/api'
|
import { plugin, server, command, event } from '@ms/api'
|
||||||
import { injectable, inject, postConstruct, Container, ContainerInstance } from '@ms/container'
|
import { inject, provideSingleton, postConstruct, Container, ContainerInstance } from '@ms/container'
|
||||||
import * as fs from '@ms/common/dist/fs'
|
import * as fs from '@ms/common/dist/fs'
|
||||||
|
|
||||||
import { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata, getPlugin, getPluginTabCompleterMetadata, getPluginConfigMetadata } from './utils'
|
import { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata, getPlugin, getPluginTabCompleterMetadata, getPluginConfigMetadata } from './utils'
|
||||||
import { interfaces } from './interfaces'
|
import { interfaces } from './interfaces'
|
||||||
import { getConfigLoader } from './config'
|
import { getConfigLoader } from './config'
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(plugin.PluginManager)
|
||||||
export class PluginManagerImpl implements plugin.PluginManager {
|
export class PluginManagerImpl implements plugin.PluginManager {
|
||||||
@inject(ContainerInstance)
|
@inject(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { channel, plugin } from '@ms/api'
|
import { channel, plugin } from '@ms/api'
|
||||||
import { inject, injectable } from '@ms/container'
|
import { inject, provideSingleton } from '@ms/container'
|
||||||
|
|
||||||
const Sponge = org.spongepowered.api.Sponge
|
const Sponge = org.spongepowered.api.Sponge
|
||||||
const RawDataListener = Java.type("org.spongepowered.api.network.RawDataListener")
|
const RawDataListener = Java.type("org.spongepowered.api.network.RawDataListener")
|
||||||
const ChannelRegistrar = Sponge.getChannelRegistrar()
|
const ChannelRegistrar = Sponge.getChannelRegistrar()
|
||||||
const Consumer = Java.type("java.util.function.Consumer");
|
const Consumer = Java.type("java.util.function.Consumer");
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(channel.Channel)
|
||||||
export class SpongeChannel extends channel.Channel {
|
export class SpongeChannel extends channel.Channel {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -1,15 +1,43 @@
|
|||||||
import { command, plugin } from "@ms/api";
|
import { command, plugin } from "@ms/api";
|
||||||
import { inject, injectable } from "@ms/container";
|
import { inject, provideSingleton } from "@ms/container";
|
||||||
|
|
||||||
let Sponge = Java.type('org.spongepowered.api.Sponge');
|
let Sponge = Java.type('org.spongepowered.api.Sponge');
|
||||||
|
let Text = Java.type('org.spongepowered.api.text.Text');
|
||||||
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
||||||
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult');
|
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult');
|
||||||
|
|
||||||
let Text = Java.type('org.spongepowered.api.text.Text');
|
|
||||||
|
|
||||||
var Optional = Java.type('java.util.Optional');
|
var Optional = Java.type('java.util.Optional');
|
||||||
|
|
||||||
|
@provideSingleton(command.Command)
|
||||||
|
export class SpongeCommand extends command.Command {
|
||||||
|
@inject(plugin.PluginInstance)
|
||||||
|
private pluginInstance: any
|
||||||
|
private commandMapping: any[] = [];
|
||||||
|
|
||||||
|
create(plugin: any, command: string) {
|
||||||
|
let commandKey = this.getCommandKey(plugin, command);
|
||||||
|
let commandCallable = new SimpleCommandCallable(command);
|
||||||
|
this.commandMapping[commandKey] = Sponge.getCommandManager().register(this.pluginInstance, commandCallable.callable, command, commandKey).orElse(null);
|
||||||
|
return commandCallable;
|
||||||
|
}
|
||||||
|
remove(plugin: any, command: string) {
|
||||||
|
var commandKey = this.getCommandKey(plugin, command);
|
||||||
|
if (this.commandMapping[commandKey]) {
|
||||||
|
Sponge.getCommandManager().removeMapping(this.commandMapping[commandKey]);
|
||||||
|
delete this.commandMapping[commandKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onCommand(plugin: any, command: any, executor: Function) {
|
||||||
|
command.setExecutor(super.setExecutor(plugin, command, executor));
|
||||||
|
}
|
||||||
|
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||||
|
command.setTabCompleter(super.setTabCompleter(plugin, command, tabCompleter));
|
||||||
|
}
|
||||||
|
|
||||||
|
private getCommandKey(plugin: any, command: string) {
|
||||||
|
return plugin.description.name.toLowerCase() + ":" + command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SimpleCommandCallable {
|
class SimpleCommandCallable {
|
||||||
public callable: any;
|
public callable: any;
|
||||||
private name: string;
|
private name: string;
|
||||||
@ -50,34 +78,3 @@ class SimpleCommandCallable {
|
|||||||
setTabCompleter = (tabCompleter: Function) => this.tabCompleter = tabCompleter;
|
setTabCompleter = (tabCompleter: Function) => this.tabCompleter = tabCompleter;
|
||||||
toString = () => `Sponge SimpleCommandCallable(${this.name})`
|
toString = () => `Sponge SimpleCommandCallable(${this.name})`
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class SpongeCommand extends command.Command {
|
|
||||||
@inject(plugin.PluginInstance)
|
|
||||||
private pluginInstance: any
|
|
||||||
private commandMapping: any[] = [];
|
|
||||||
|
|
||||||
create(plugin: any, command: string) {
|
|
||||||
let commandKey = this.getCommandKey(plugin, command);
|
|
||||||
let commandCallable = new SimpleCommandCallable(command);
|
|
||||||
this.commandMapping[commandKey] = Sponge.getCommandManager().register(this.pluginInstance, commandCallable.callable, command, commandKey).orElse(null);
|
|
||||||
return commandCallable;
|
|
||||||
}
|
|
||||||
remove(plugin: any, command: string) {
|
|
||||||
var commandKey = this.getCommandKey(plugin, command);
|
|
||||||
if (this.commandMapping[commandKey]) {
|
|
||||||
Sponge.getCommandManager().removeMapping(this.commandMapping[commandKey]);
|
|
||||||
delete this.commandMapping[commandKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onCommand(plugin: any, command: any, executor: Function) {
|
|
||||||
command.setExecutor(super.setExecutor(plugin, command, executor));
|
|
||||||
}
|
|
||||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
|
||||||
command.setTabCompleter(super.setTabCompleter(plugin, command, tabCompleter));
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCommandKey(plugin: any, command: string) {
|
|
||||||
return plugin.description.name.toLowerCase() + ":" + command;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { event, plugin } from '@ms/api'
|
import { event, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
let Modifier = Java.type("java.lang.reflect.Modifier");
|
let Modifier = Java.type("java.lang.reflect.Modifier");
|
||||||
let Order = Java.type("org.spongepowered.api.event.Order");
|
let Order = Java.type("org.spongepowered.api.event.Order");
|
||||||
@ -19,7 +19,7 @@ let priorityMap = {
|
|||||||
/**
|
/**
|
||||||
* Sponge Event Impl
|
* Sponge Event Impl
|
||||||
*/
|
*/
|
||||||
@injectable()
|
@provideSingleton(event.Event)
|
||||||
export class SpongeEvent extends event.Event {
|
export class SpongeEvent extends event.Event {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
@ -1,20 +1,15 @@
|
|||||||
/// <reference types="@ms/types/dist/typings/sponge" />
|
/// <reference types="@ms/types/dist/typings/sponge" />
|
||||||
|
|
||||||
import { server, command, event, channel, task } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { Container } from '@ms/container'
|
import { Container } from '@ms/container'
|
||||||
|
|
||||||
import { SpongeConsole } from './console';
|
import { SpongeConsole } from './console';
|
||||||
import { SpongeEvent } from './event';
|
import './event';
|
||||||
import { SpongeServer } from './server';
|
import './server';
|
||||||
import { SpongeCommand } from './command';
|
import './command';
|
||||||
import { SpongeChannel } from './channel';
|
import './channel';
|
||||||
import { SpongeTaskManager } from './task';
|
import './task';
|
||||||
|
|
||||||
export default function SpongeImpl(container: Container) {
|
export default function SpongeImpl(container: Container) {
|
||||||
container.bind(server.Console).toConstantValue(SpongeConsole);
|
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(channel.Channel).to(SpongeChannel).inSingletonScope();
|
|
||||||
container.bind(task.TaskManager).to(SpongeTaskManager).inSingletonScope();
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { server } from '@ms/api'
|
import { server } from '@ms/api'
|
||||||
import { injectable } from '@ms/container';
|
import { provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
let Sponge = org.spongepowered.api.Sponge;
|
let Sponge = org.spongepowered.api.Sponge;
|
||||||
let TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
let TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(server.Server)
|
||||||
export class SpongeServer implements server.Server {
|
export class SpongeServer implements server.Server {
|
||||||
getPlayer(name: string) {
|
getPlayer(name: string) {
|
||||||
return Sponge.getServer().getPlayer(name).orElse(null)
|
return Sponge.getServer().getPlayer(name).orElse(null)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { task, plugin } from '@ms/api'
|
import { task, plugin } from '@ms/api'
|
||||||
import { injectable, inject } from '@ms/container';
|
import { inject, provideSingleton } from '@ms/container';
|
||||||
|
|
||||||
const Sponge = Java.type("org.spongepowered.api.Sponge");
|
const Sponge = Java.type("org.spongepowered.api.Sponge");
|
||||||
const Task = Java.type("org.spongepowered.api.scheduler.Task");
|
const Task = Java.type("org.spongepowered.api.scheduler.Task");
|
||||||
@ -7,7 +7,7 @@ const Consumer = Java.type('java.util.function.Consumer');
|
|||||||
const Callable = Java.type('java.util.concurrent.Callable');
|
const Callable = Java.type('java.util.concurrent.Callable');
|
||||||
const TimeUnit = Java.type('java.util.concurrent.TimeUnit');
|
const TimeUnit = Java.type('java.util.concurrent.TimeUnit');
|
||||||
|
|
||||||
@injectable()
|
@provideSingleton(task.TaskManager)
|
||||||
export class SpongeTaskManager implements task.TaskManager {
|
export class SpongeTaskManager implements task.TaskManager {
|
||||||
@inject(plugin.PluginInstance)
|
@inject(plugin.PluginInstance)
|
||||||
private pluginInstance: any;
|
private pluginInstance: any;
|
||||||
|
Loading…
Reference in New Issue
Block a user