feat: use inversify autoProvide inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import { channel, plugin, event } from '@ms/api'
|
||||
import { inject, injectable } from '@ms/container'
|
||||
import { channel } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container'
|
||||
|
||||
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(channel.Channel)
|
||||
export class BungeeChannel extends channel.Channel {
|
||||
send(player: any, channel: string, data: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { command, plugin } from "@ms/api";
|
||||
import { inject, injectable } from "@ms/container";
|
||||
import * as ref from '@ms/common/dist/reflect'
|
||||
import { inject, provideSingleton } from "@ms/container";
|
||||
|
||||
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'));
|
||||
@ -13,26 +12,7 @@ const createCommand = eval(`
|
||||
}
|
||||
`)
|
||||
|
||||
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})`
|
||||
}
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(command.Command)
|
||||
export class BungeeCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
@ -64,3 +44,22 @@ export class BungeeCommand extends command.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 { injectable, inject, postConstruct } from '@ms/container'
|
||||
import { event } from '@ms/api'
|
||||
import { provideSingleton, postConstruct } from '@ms/container'
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
|
||||
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
|
||||
*/
|
||||
@injectable()
|
||||
@provideSingleton(event.Event)
|
||||
export class BungeeEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
private pluginManager = Bungee.getPluginManager()
|
||||
|
||||
// EventBus
|
||||
|
@ -4,17 +4,12 @@ import { server, command, event, channel, task } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
import { BungeeConsole } from './console';
|
||||
import { BungeeEvent } from './event';
|
||||
import { BungeeServer } from './server';
|
||||
import { BungeeCommand } from './command';
|
||||
import { BungeeChannel } from './channel';
|
||||
import { BungeeTaskManager } from './task';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './channel';
|
||||
import './task';
|
||||
|
||||
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(channel.Channel).to(BungeeChannel).inSingletonScope();
|
||||
container.bind(task.TaskManager).to(BungeeTaskManager).inSingletonScope();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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();
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(server.Server)
|
||||
export class BungeeServer implements server.Server {
|
||||
getPlayer(name: string) {
|
||||
return Bungee.getPlayer(name);
|
||||
|
@ -1,10 +1,10 @@
|
||||
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')
|
||||
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class BungeeTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
Reference in New Issue
Block a user