feat: use inversify autoProvide inject
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
0ade2b2855
commit
6a5b1598d4
@ -90,17 +90,21 @@ export class MiaoScriptConsole implements Console {
|
||||
try {
|
||||
if (fileName.endsWith('js')) {
|
||||
var file = Paths.get(fileName + '.map');
|
||||
if (!this.sourceMaps[fileName]) {
|
||||
if (this.sourceMaps[fileName] === undefined) {
|
||||
if (file.toFile().exists()) {
|
||||
var sourceMapObj = JSON.parse(new JavaString(Files.readAllBytes(file), "UTF-8"))
|
||||
this.sourceMaps[fileName] = new SourceMapBuilder(sourceMapObj)
|
||||
} else {
|
||||
this.sourceMaps[fileName] = null;
|
||||
}
|
||||
}
|
||||
if (this.sourceMaps[fileName]) {
|
||||
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, lineNumber);
|
||||
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 0);
|
||||
if (sourceMapping) {
|
||||
if(lineNumber != sourceMapping.mapping.sourceLine){
|
||||
fileName = fileName.replace(".js", ".ts");
|
||||
lineNumber = sourceMapping.mapping.sourceLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { channel, plugin } from '@ms/api'
|
||||
import { inject, injectable } from '@ms/container'
|
||||
import { inject, provideSingleton } from '@ms/container'
|
||||
|
||||
const Bukkit = org.bukkit.Bukkit
|
||||
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
||||
const Messenger = Bukkit.getMessenger()
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(channel.Channel)
|
||||
export class BukkitChannel extends channel.Channel {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
@ -2,14 +2,14 @@ import '@ms/nashorn'
|
||||
|
||||
import { command, plugin } from '@ms/api'
|
||||
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 TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
||||
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(command.Command)
|
||||
export class BukkitCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { event, server, plugin } from '@ms/api'
|
||||
import { injectable, inject } from '@ms/container';
|
||||
import { event, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
|
||||
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 EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(event.Event)
|
||||
export class BukkitEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
|
@ -4,17 +4,12 @@ import { server, command, event, channel, task } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
import { BukkitConsole } from './console';
|
||||
import { BukkitEvent } from './event';
|
||||
import { BukkitServer } from './server';
|
||||
import { BukkitCommand } from './command';
|
||||
import { BukkitChannel } from './channel';
|
||||
import { BukkitTaskManager } from './task';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './channel';
|
||||
import './task';
|
||||
|
||||
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(channel.Channel).to(BukkitChannel).inSingletonScope();
|
||||
container.bind(task.TaskManager).to(BukkitTaskManager).inSingletonScope();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { server } from '@ms/api'
|
||||
import { injectable } from '@ms/container';
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
import chat from './enhance/chat'
|
||||
|
||||
let Bukkit = org.bukkit.Bukkit;
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(server.Server)
|
||||
export class BukkitServer implements server.Server {
|
||||
getPlayer(name: string) {
|
||||
return Bukkit.getPlayer(name)
|
||||
|
@ -1,11 +1,11 @@
|
||||
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 BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
|
||||
const Callable = Java.type('java.util.concurrent.Callable')
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class BukkitTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
@ -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;
|
||||
|
@ -2,11 +2,10 @@ 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 { DefaultContainer as container, injectable, inject, ContainerInstance } from '@ms/container'
|
||||
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ms/container'
|
||||
console.log('MiaoScript IOC Container @ms/container loading completed(' + (new Date().getTime() - containerStartTime) / 1000 + 's)!');
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(MiaoScriptCore)
|
||||
class MiaoScriptCore {
|
||||
@inject(server.Console)
|
||||
private Console: Console;
|
||||
@ -85,11 +84,11 @@ function initialize() {
|
||||
let type = detectServer();
|
||||
console.info(`Detect Compatible Server set ServerType to ${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);
|
||||
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
||||
container.bind(MiaoScriptCore).to(MiaoScriptCore).inSingletonScope();
|
||||
console.log(`MiaoScript Package @ms/core @ms/${type} loading completed(` + (new Date().getTime() - corePackageStartTime) / 1000 + 's)!');
|
||||
require('@ms/plugin')
|
||||
container.load(buildProviderModule());
|
||||
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()
|
||||
console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!');
|
||||
return disable;
|
||||
|
@ -1,12 +1,12 @@
|
||||
import '@ms/nashorn'
|
||||
|
||||
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 CommandExecutor = Java.type('cn.nukkit.command.CommandExecutor');
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(command.Command)
|
||||
export class NukkitCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
@ -30,7 +30,6 @@ export class NukkitCommand extends command.Command {
|
||||
}
|
||||
}
|
||||
onCommand(plugin: any, command: any, executor: Function) {
|
||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||
command.setExecutor(new CommandExecutor({
|
||||
onCommand: super.setExecutor(plugin, command, executor)
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { event, server, plugin } from '@ms/api'
|
||||
import { injectable, inject } from '@ms/container'
|
||||
import { event, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container'
|
||||
|
||||
const Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||
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 EventExecutor = Java.type("cn.nukkit.plugin.EventExecutor");
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(event.Event)
|
||||
export class NukkitEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
|
@ -1,18 +1,14 @@
|
||||
/// <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 { NukkitConsole } from './console';
|
||||
import { NukkitEvent } from './event';
|
||||
import { NukkitServer } from './server';
|
||||
import { NukkitCommand } from './command';
|
||||
import { NukkitTaskManager } from './task';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './task';
|
||||
|
||||
export default function NukkitImpl(container: Container) {
|
||||
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 { injectable } from '@ms/container';
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(server.Server)
|
||||
export class NukkitServer implements server.Server {
|
||||
getPlayer(name: string) {
|
||||
return Nukkit.getPlayer(name)
|
||||
|
@ -1,11 +1,9 @@
|
||||
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 Callable = Java.type('java.util.concurrent.Callable')
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class NukkitTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
@ -1,12 +1,12 @@
|
||||
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 { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata, getPlugin, getPluginTabCompleterMetadata, getPluginConfigMetadata } from './utils'
|
||||
import { interfaces } from './interfaces'
|
||||
import { getConfigLoader } from './config'
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(plugin.PluginManager)
|
||||
export class PluginManagerImpl implements plugin.PluginManager {
|
||||
@inject(ContainerInstance)
|
||||
private container: Container
|
||||
|
@ -1,12 +1,12 @@
|
||||
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 RawDataListener = Java.type("org.spongepowered.api.network.RawDataListener")
|
||||
const ChannelRegistrar = Sponge.getChannelRegistrar()
|
||||
const Consumer = Java.type("java.util.function.Consumer");
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(channel.Channel)
|
||||
export class SpongeChannel extends channel.Channel {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
@ -1,15 +1,43 @@
|
||||
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 Text = Java.type('org.spongepowered.api.text.Text');
|
||||
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
||||
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');
|
||||
|
||||
@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 {
|
||||
public callable: any;
|
||||
private name: string;
|
||||
@ -49,35 +77,4 @@ class SimpleCommandCallable {
|
||||
setExecutor = (executor: Function) => this.executor = executor;
|
||||
setTabCompleter = (tabCompleter: Function) => this.tabCompleter = tabCompleter;
|
||||
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 { injectable, inject } from '@ms/container';
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
|
||||
let Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
let Order = Java.type("org.spongepowered.api.event.Order");
|
||||
@ -19,7 +19,7 @@ let priorityMap = {
|
||||
/**
|
||||
* Sponge Event Impl
|
||||
*/
|
||||
@injectable()
|
||||
@provideSingleton(event.Event)
|
||||
export class SpongeEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
@ -1,20 +1,15 @@
|
||||
/// <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 { SpongeConsole } from './console';
|
||||
import { SpongeEvent } from './event';
|
||||
import { SpongeServer } from './server';
|
||||
import { SpongeCommand } from './command';
|
||||
import { SpongeChannel } from './channel';
|
||||
import { SpongeTaskManager } from './task';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './channel';
|
||||
import './task';
|
||||
|
||||
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(channel.Channel).to(SpongeChannel).inSingletonScope();
|
||||
container.bind(task.TaskManager).to(SpongeTaskManager).inSingletonScope();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { server } from '@ms/api'
|
||||
import { injectable } from '@ms/container';
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
let Sponge = org.spongepowered.api.Sponge;
|
||||
let TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(server.Server)
|
||||
export class SpongeServer implements server.Server {
|
||||
getPlayer(name: string) {
|
||||
return Sponge.getServer().getPlayer(name).orElse(null)
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 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 TimeUnit = Java.type('java.util.concurrent.TimeUnit');
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class SpongeTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
Loading…
Reference in New Issue
Block a user