feat: add api doc
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
f5a7a269e4
commit
73b9c2f163
@ -10,7 +10,12 @@ export namespace channel {
|
|||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Channel {
|
export abstract class Channel {
|
||||||
private listenerMap = [];
|
private listenerMap = [];
|
||||||
|
/**
|
||||||
|
* 注册通道
|
||||||
|
* @param plugin 插件
|
||||||
|
* @param channel 通道
|
||||||
|
* @param exec 执行器
|
||||||
|
*/
|
||||||
listen(plugin: any, channel: string, exec: ChannelListener) {
|
listen(plugin: any, channel: string, exec: ChannelListener) {
|
||||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
|
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
|
||||||
let name = plugin.description.name;
|
let name = plugin.description.name;
|
||||||
@ -29,6 +34,10 @@ export namespace channel {
|
|||||||
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
|
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 关闭插件注册的通道
|
||||||
|
* @param plugin 插件
|
||||||
|
*/
|
||||||
disable(plugin: any) {
|
disable(plugin: any) {
|
||||||
var channelCache = this.listenerMap[plugin.description.name];
|
var channelCache = this.listenerMap[plugin.description.name];
|
||||||
if (channelCache) {
|
if (channelCache) {
|
||||||
@ -36,7 +45,6 @@ export namespace channel {
|
|||||||
delete this.listenerMap[plugin.description.name];
|
delete this.listenerMap[plugin.description.name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Channel Message
|
* Send Channel Message
|
||||||
* @param player recover target
|
* @param player recover target
|
||||||
|
@ -4,6 +4,12 @@ import { injectable } from "@ms/container";
|
|||||||
export namespace command {
|
export namespace command {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Command {
|
export abstract class Command {
|
||||||
|
/**
|
||||||
|
* 注册插件命令
|
||||||
|
* @param plugin 插件
|
||||||
|
* @param name 命令
|
||||||
|
* @param exec 执行器
|
||||||
|
*/
|
||||||
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
|
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
|
||||||
var cmd = this.create(plugin, name);
|
var cmd = this.create(plugin, name);
|
||||||
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
|
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
|
||||||
@ -16,18 +22,20 @@ export namespace command {
|
|||||||
this.onTabComplete(plugin, cmd, exec.tab);
|
this.onTabComplete(plugin, cmd, exec.tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 取消命令注册
|
||||||
|
* @param plugin 插件
|
||||||
|
* @param name 命令
|
||||||
|
*/
|
||||||
off(plugin: any, name: string) {
|
off(plugin: any, name: string) {
|
||||||
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
|
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
|
||||||
this.remove(plugin, name);
|
this.remove(plugin, name);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Create Server Command Object
|
|
||||||
*/
|
|
||||||
protected abstract create(plugin: any, command: string);
|
protected abstract create(plugin: any, command: string);
|
||||||
protected abstract remove(plugin: any, command: string);
|
protected abstract remove(plugin: any, command: string);
|
||||||
protected abstract onCommand(plugin: any, command: any, executor: Function);
|
protected abstract onCommand(plugin: any, command: any, executor: Function);
|
||||||
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
|
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
|
||||||
|
|
||||||
protected setExecutor(plugin: any, command: any, executor: Function) {
|
protected setExecutor(plugin: any, command: any, executor: Function) {
|
||||||
return (sender: any, _: any, command: string, args: string[]) => {
|
return (sender: any, _: any, command: string, args: string[]) => {
|
||||||
try {
|
try {
|
||||||
@ -40,7 +48,6 @@ export namespace command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
|
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
|
||||||
return (sender: any, _: any, command: string, args: string[]) => {
|
return (sender: any, _: any, command: string, args: string[]) => {
|
||||||
try {
|
try {
|
||||||
@ -55,7 +62,6 @@ export namespace command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
||||||
if (!token) { return complete }
|
if (!token) { return complete }
|
||||||
complete.forEach(function (e) {
|
complete.forEach(function (e) {
|
||||||
|
@ -7,6 +7,9 @@ import { injectable, unmanaged } from '@ms/container'
|
|||||||
const Thread = Java.type('java.lang.Thread');
|
const Thread = Java.type('java.lang.Thread');
|
||||||
|
|
||||||
export namespace event {
|
export namespace event {
|
||||||
|
/**
|
||||||
|
* 事件监听优先级
|
||||||
|
*/
|
||||||
export enum EventPriority {
|
export enum EventPriority {
|
||||||
LOWEST = "LOWEST",
|
LOWEST = "LOWEST",
|
||||||
LOW = "LOW",
|
LOW = "LOW",
|
||||||
@ -144,6 +147,10 @@ export namespace event {
|
|||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭插件监听任务
|
||||||
|
* @param plugin 插件
|
||||||
|
*/
|
||||||
disable(plugin: any) {
|
disable(plugin: any) {
|
||||||
var eventCache = this.listenerMap[plugin.description.name];
|
var eventCache = this.listenerMap[plugin.description.name];
|
||||||
if (eventCache) {
|
if (eventCache) {
|
||||||
@ -152,8 +159,24 @@ export namespace event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断
|
||||||
|
* @param clazz 事件类
|
||||||
|
*/
|
||||||
abstract isValidEvent(clazz: any): boolean;
|
abstract isValidEvent(clazz: any): boolean;
|
||||||
|
/**
|
||||||
|
* 注册事件
|
||||||
|
* @param eventCls 事件类
|
||||||
|
* @param exec 执行器
|
||||||
|
* @param priority 优先级
|
||||||
|
* @param ignoreCancel 是否忽略已取消的事件
|
||||||
|
*/
|
||||||
abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
|
abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
|
||||||
|
/**
|
||||||
|
* 取消监听事件
|
||||||
|
* @param event 事件
|
||||||
|
* @param listener 监听器
|
||||||
|
*/
|
||||||
abstract unregister(event: any, listener: any): void;
|
abstract unregister(event: any, listener: any): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
export namespace task {
|
export namespace task {
|
||||||
export const TaskManager = Symbol('TaskManager')
|
export const TaskManager = Symbol('TaskManager')
|
||||||
export interface TaskManager {
|
export interface TaskManager {
|
||||||
|
/**
|
||||||
|
* 创建任务
|
||||||
|
* @param func 任务内容
|
||||||
|
*/
|
||||||
create(func: Function): task.Task;
|
create(func: Function): task.Task;
|
||||||
|
/**
|
||||||
|
* 在主线程执行代码
|
||||||
|
* @param func 执行内容
|
||||||
|
*/
|
||||||
callSyncMethod(func: Function): any;
|
callSyncMethod(func: Function): any;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -19,16 +27,28 @@ export namespace task {
|
|||||||
this.func = func;
|
this.func = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置任务异步执行
|
||||||
|
* @param isAsync 是否异步
|
||||||
|
*/
|
||||||
async(isAsync: boolean = true): task.Task {
|
async(isAsync: boolean = true): task.Task {
|
||||||
this.isAsync = isAsync;
|
this.isAsync = isAsync;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置任务延时执行
|
||||||
|
* @param tick 延时 Tick
|
||||||
|
*/
|
||||||
later(tick: number): task.Task {
|
later(tick: number): task.Task {
|
||||||
this.laterTime = tick;
|
this.laterTime = tick;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置任务循环执行
|
||||||
|
* @param tick 循环时间 Tick
|
||||||
|
*/
|
||||||
timer(tick: number): task.Task {
|
timer(tick: number): task.Task {
|
||||||
this.interval = tick;
|
this.interval = tick;
|
||||||
return this;
|
return this;
|
||||||
@ -43,6 +63,9 @@ export namespace task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交任务
|
||||||
|
*/
|
||||||
abstract submit(): Cancelable;
|
abstract submit(): Cancelable;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user