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 aee0457d9f
commit 2042b49e0d
4 changed files with 69 additions and 9 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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;
} }
} }

View File

@ -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;
} }
/** /**