diff --git a/packages/api/src/console.ts b/packages/api/src/console.ts index 5f33ffe3..2fa2e833 100644 --- a/packages/api/src/console.ts +++ b/packages/api/src/console.ts @@ -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; + } } } } diff --git a/packages/bukkit/src/channel.ts b/packages/bukkit/src/channel.ts index 58c516a0..e92c679c 100644 --- a/packages/bukkit/src/channel.ts +++ b/packages/bukkit/src/channel.ts @@ -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; diff --git a/packages/bukkit/src/command.ts b/packages/bukkit/src/command.ts index 75afbf4a..2b363383 100644 --- a/packages/bukkit/src/command.ts +++ b/packages/bukkit/src/command.ts @@ -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 diff --git a/packages/bukkit/src/event.ts b/packages/bukkit/src/event.ts index 98a911f9..2ed585fb 100644 --- a/packages/bukkit/src/event.ts +++ b/packages/bukkit/src/event.ts @@ -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 diff --git a/packages/bukkit/src/index.ts b/packages/bukkit/src/index.ts index b7d99770..5fdf063f 100644 --- a/packages/bukkit/src/index.ts +++ b/packages/bukkit/src/index.ts @@ -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(); } diff --git a/packages/bukkit/src/server.ts b/packages/bukkit/src/server.ts index f63abea4..23669b4b 100644 --- a/packages/bukkit/src/server.ts +++ b/packages/bukkit/src/server.ts @@ -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) diff --git a/packages/bukkit/src/task.ts b/packages/bukkit/src/task.ts index 69ed492c..0f329fdb 100644 --- a/packages/bukkit/src/task.ts +++ b/packages/bukkit/src/task.ts @@ -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; diff --git a/packages/bungee/src/channel.ts b/packages/bungee/src/channel.ts index 3038e1d1..04685079 100644 --- a/packages/bungee/src/channel.ts +++ b/packages/bungee/src/channel.ts @@ -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."); diff --git a/packages/bungee/src/command.ts b/packages/bungee/src/command.ts index 2434a39c..48b4a972 100644 --- a/packages/bungee/src/command.ts +++ b/packages/bungee/src/command.ts @@ -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})` +} \ No newline at end of file diff --git a/packages/bungee/src/event.ts b/packages/bungee/src/event.ts index c6df5cfe..b0f960bd 100644 --- a/packages/bungee/src/event.ts +++ b/packages/bungee/src/event.ts @@ -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 diff --git a/packages/bungee/src/index.ts b/packages/bungee/src/index.ts index a3a59a16..f79c9420 100644 --- a/packages/bungee/src/index.ts +++ b/packages/bungee/src/index.ts @@ -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(); } diff --git a/packages/bungee/src/server.ts b/packages/bungee/src/server.ts index 83ce23c5..e397f1a9 100644 --- a/packages/bungee/src/server.ts +++ b/packages/bungee/src/server.ts @@ -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); diff --git a/packages/bungee/src/task.ts b/packages/bungee/src/task.ts index 9d537cca..3deb1abe 100644 --- a/packages/bungee/src/task.ts +++ b/packages/bungee/src/task.ts @@ -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; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8794c3de..af3f93ee 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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).enable() console.log('MiaoScript ScriptEngine loading completed... Done (' + (new Date().getTime() - global.NashornEngineStartTime) / 1000 + 's)!'); return disable; diff --git a/packages/nukkit/src/command.ts b/packages/nukkit/src/command.ts index 2d3b4372..b1e90d38 100644 --- a/packages/nukkit/src/command.ts +++ b/packages/nukkit/src/command.ts @@ -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) })); diff --git a/packages/nukkit/src/event.ts b/packages/nukkit/src/event.ts index 5da47eef..3132fbba 100644 --- a/packages/nukkit/src/event.ts +++ b/packages/nukkit/src/event.ts @@ -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 diff --git a/packages/nukkit/src/index.ts b/packages/nukkit/src/index.ts index 6f855aa3..46b0e750 100644 --- a/packages/nukkit/src/index.ts +++ b/packages/nukkit/src/index.ts @@ -1,18 +1,14 @@ /// -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(); } diff --git a/packages/nukkit/src/server.ts b/packages/nukkit/src/server.ts index 09759c2b..e20a6987 100644 --- a/packages/nukkit/src/server.ts +++ b/packages/nukkit/src/server.ts @@ -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) diff --git a/packages/nukkit/src/task.ts b/packages/nukkit/src/task.ts index 26cae6af..3de76d80 100644 --- a/packages/nukkit/src/task.ts +++ b/packages/nukkit/src/task.ts @@ -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; diff --git a/packages/plugin/src/manager.ts b/packages/plugin/src/manager.ts index e8532f8b..607d98e7 100644 --- a/packages/plugin/src/manager.ts +++ b/packages/plugin/src/manager.ts @@ -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 diff --git a/packages/sponge/src/channel.ts b/packages/sponge/src/channel.ts index 33688079..87fc5063 100644 --- a/packages/sponge/src/channel.ts +++ b/packages/sponge/src/channel.ts @@ -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; diff --git a/packages/sponge/src/command.ts b/packages/sponge/src/command.ts index 398ead04..b3fc4fad 100644 --- a/packages/sponge/src/command.ts +++ b/packages/sponge/src/command.ts @@ -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; - } -} +} \ No newline at end of file diff --git a/packages/sponge/src/event.ts b/packages/sponge/src/event.ts index 53797cdc..bb26a8a7 100644 --- a/packages/sponge/src/event.ts +++ b/packages/sponge/src/event.ts @@ -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; diff --git a/packages/sponge/src/index.ts b/packages/sponge/src/index.ts index bd26aa0b..0b536975 100644 --- a/packages/sponge/src/index.ts +++ b/packages/sponge/src/index.ts @@ -1,20 +1,15 @@ /// -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(); } diff --git a/packages/sponge/src/server.ts b/packages/sponge/src/server.ts index b448bd61..ce27ad27 100644 --- a/packages/sponge/src/server.ts +++ b/packages/sponge/src/server.ts @@ -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) diff --git a/packages/sponge/src/task.ts b/packages/sponge/src/task.ts index ae3a7adc..d0cba0f5 100644 --- a/packages/sponge/src/task.ts +++ b/packages/sponge/src/task.ts @@ -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;