yoni-mcscripts-lib
Version:
为 Minecraft Script API 中的部分接口创建了 wrapper,并提供简单的事件管理器和任务管理器,另附有一些便于代码编写的一些小工具。
60 lines (59 loc) • 1.82 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
class a {
on() {
}
}
__decorate([
MethodAbuseWarning()
], a.prototype, "on", null);
function test() {
console.log("start");
console.log("1");
let s = new a();
console.log("2");
s.on();
console.log("3");
s.on();
s.on();
s.on();
s.on();
s.on();
s = new a();
s.on();
s.on();
s.on();
s.on();
s.on();
s.on();
s.on();
s.on();
console.log("end");
}
function MethodAbuseWarning(message) {
return function make(target, propKey, propDesc) {
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.log("WARN: " + msg);
warning = false;
}
return Reflect.apply(originMethod, this, arguments);
}
};
propDesc.value = result[resultFuncName];
return propDesc;
};
}
test();