feat: add api doc

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-03-24 17:59:18 +08:00
parent c6575ed481
commit 100ccbcde3
4 changed files with 69 additions and 9 deletions

View File

@ -10,7 +10,12 @@ export namespace channel {
@injectable()
export abstract class Channel {
private listenerMap = [];
/**
*
* @param plugin
* @param channel
* @param exec
*/
listen(plugin: any, channel: string, exec: ChannelListener) {
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
let name = plugin.description.name;
@ -29,6 +34,10 @@ export namespace channel {
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
return off;
}
/**
*
* @param plugin
*/
disable(plugin: any) {
var channelCache = this.listenerMap[plugin.description.name];
if (channelCache) {
@ -36,7 +45,6 @@ export namespace channel {
delete this.listenerMap[plugin.description.name];
}
}
/**
* Send Channel Message
* @param player recover target

View File

@ -4,6 +4,12 @@ import { injectable } from "@ms/container";
export namespace command {
@injectable()
export abstract class Command {
/**
*
* @param plugin
* @param name
* @param exec
*/
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, name);
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);
}
}
/**
*
* @param plugin
* @param name
*/
off(plugin: any, name: string) {
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
this.remove(plugin, name);
}
/**
* Create Server Command Object
*/
protected abstract create(plugin: any, command: string);
protected abstract remove(plugin: any, command: string);
protected abstract onCommand(plugin: any, command: any, executor: Function);
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
protected setExecutor(plugin: any, command: any, executor: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
@ -40,7 +48,6 @@ export namespace command {
}
}
}
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
@ -55,10 +62,9 @@ export namespace command {
}
}
}
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
if (!token) { return complete }
complete.forEach(function(e) {
complete.forEach(function (e) {
if (typeof e === "string" && e.toLowerCase().startsWith(token.toLowerCase())) {
array.push(e)
}

View File

@ -7,6 +7,9 @@ import { injectable, unmanaged } from '@ms/container'
const Thread = Java.type('java.lang.Thread');
export namespace event {
/**
*
*/
export enum EventPriority {
LOWEST = "LOWEST",
LOW = "LOW",
@ -144,6 +147,10 @@ export namespace event {
return off;
}
/**
*
* @param plugin
*/
disable(plugin: any) {
var eventCache = this.listenerMap[plugin.description.name];
if (eventCache) {
@ -152,8 +159,24 @@ export namespace event {
}
}
/**
*
* @param clazz
*/
abstract isValidEvent(clazz: any): boolean;
/**
*
* @param eventCls
* @param exec
* @param priority
* @param ignoreCancel
*/
abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
/**
*
* @param event
* @param listener
*/
abstract unregister(event: any, listener: any): void;
}
}

View File

@ -1,7 +1,15 @@
export namespace task {
export const TaskManager = Symbol('TaskManager')
export interface TaskManager {
/**
*
* @param func
*/
create(func: Function): task.Task;
/**
* 线
* @param func
*/
callSyncMethod(func: Function): any;
}
/**
@ -19,16 +27,28 @@ export namespace task {
this.func = func;
}
/**
*
* @param isAsync
*/
async(isAsync: boolean = true): task.Task {
this.isAsync = isAsync;
return this;
}
/**
*
* @param tick Tick
*/
later(tick: number): task.Task {
this.laterTime = tick;
return this;
}
/**
*
* @param tick Tick
*/
timer(tick: number): task.Task {
this.interval = tick;
return this;
@ -43,6 +63,9 @@ export namespace task {
}
}
/**
*
*/
abstract submit(): Cancelable;
}
/**