From 21cca405340b081a09dd8e700b4dc1b81892ffb2 Mon Sep 17 00:00:00 2001 From: coding Date: Sat, 14 Oct 2017 06:32:50 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A1=A5=E4=B8=81?= =?UTF-8?q?=E6=89=A9=E5=B1=95=20=E6=B7=BB=E5=8A=A0=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/core/init.js | 10 ++++++---- src/main/resources/core/patch.js | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/core/patch.js 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