feat: 添加补丁扩展 添加异步执行
This commit is contained in:
parent
52d665c6e6
commit
21cca40534
@ -31,6 +31,8 @@ function loadCore() {
|
|||||||
// 加载基础模块
|
// 加载基础模块
|
||||||
load(core_dir + '/ext.js');
|
load(core_dir + '/ext.js');
|
||||||
load(core_dir + '/console.js');
|
load(core_dir + '/console.js');
|
||||||
|
// 加载补丁和扩展
|
||||||
|
load(core_dir + '/patch.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,14 +46,14 @@ function loadRequire() {
|
|||||||
function loadLib4Bukkit() {
|
function loadLib4Bukkit() {
|
||||||
require('modules/event');
|
require('modules/event');
|
||||||
var task = require('modules/task');
|
var task = require('modules/task');
|
||||||
global.setTimeout = function (func, time) {
|
global.setTimeout = function (func, time, async) {
|
||||||
return task.later(func, time)
|
return async ? task.laterAsync(func, time) : task.later(func, time);
|
||||||
};
|
};
|
||||||
global.clearTimeout = function (task) {
|
global.clearTimeout = function (task) {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
};
|
};
|
||||||
global.setInterval = function (func, time) {
|
global.setInterval = function (func, time, async) {
|
||||||
return task.timer(func, time)
|
return async ? task.timerAsync(func, time) : task.timer(func, time);
|
||||||
};
|
};
|
||||||
global.clearInterval = function (task) {
|
global.clearInterval = function (task) {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
|
9
src/main/resources/core/patch.js
Normal file
9
src/main/resources/core/patch.js
Normal file
@ -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); }
|
Loading…
Reference in New Issue
Block a user