diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index ea56c94..cbd3ad5 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -31,6 +31,8 @@ function loadCore() { // 加载基础模块 load(core_dir + '/ext.js'); load(core_dir + '/console.js'); + // 加载补丁和扩展 + load(core_dir + '/patch.js'); } /** @@ -44,14 +46,14 @@ function loadRequire() { function loadLib4Bukkit() { require('modules/event'); var task = require('modules/task'); - global.setTimeout = function (func, time) { - return task.later(func, time) + global.setTimeout = function (func, time, async) { + return async ? task.laterAsync(func, time) : task.later(func, time); }; global.clearTimeout = function (task) { task.cancel(); }; - global.setInterval = function (func, time) { - return task.timer(func, time) + global.setInterval = function (func, time, async) { + return async ? task.timerAsync(func, time) : task.timer(func, time); }; global.clearInterval = function (task) { task.cancel(); diff --git a/src/main/resources/core/patch.js b/src/main/resources/core/patch.js new file mode 100644 index 0000000..f05898f --- /dev/null +++ b/src/main/resources/core/patch.js @@ -0,0 +1,9 @@ +/** + * 补丁和方法扩展 + */ + +// JSON快捷方法 +Object.prototype.toJson = function(){ return JSON.stringify(this); } + +// YAML快速生成 +Object.prototype.toYaml = function(){ return require('modules/yaml').safeDump(plugin.config); } \ No newline at end of file