UNPKG

yoni-mcscripts-lib

Version:

为 Minecraft Script API 中的部分接口创建了 wrapper,并提供简单的事件管理器和任务管理器,另附有一些便于代码编写的一些小工具。

21 lines 851 B
export function MethodAbuseWarning(message?: string): MethodDecorator { return function make(target: Object, propKey: string | symbol, propDesc: PropertyDescriptor){ let warning = true; const className = target.constructor.name; const propKeyStr = String(propKey); const msg = message ?? `警告:方法 ${className}[${propKeyStr}]() 被滥用`; const originMethod = propDesc.value; const resultFuncName = originMethod.name ?? "a"; const result = { [resultFuncName]: function(){ if (warning){ console.warn(msg); warning = false; } return Reflect.apply(originMethod, this, arguments); } }; propDesc.value = result[resultFuncName]; return propDesc; } }