feat: optimize framework
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
03129b8797
commit
a78e6482e8
@ -1,7 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* 补丁和方法扩展
|
* 补丁和方法扩展
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
/**
|
/**
|
||||||
* 日期格式化
|
* 日期格式化
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
if (!Object.assign) {
|
if (!Object.assign) {
|
||||||
Object.defineProperty(Object, "assign", {
|
Object.defineProperty(Object, "assign", {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true,
|
|
||||||
writable: true,
|
|
||||||
value: function(target) {
|
value: function(target) {
|
||||||
"use strict";
|
"use strict";
|
||||||
if (target === undefined || target === null)
|
if (target === undefined || target === null)
|
||||||
@ -28,12 +26,10 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Object.values Polyfill
|
||||||
if (!Object.values) {
|
if (!Object.values) {
|
||||||
Object.defineProperty(Object, "values", {
|
Object.defineProperty(Object, "values", {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true,
|
|
||||||
writable: true,
|
|
||||||
value: function(target) {
|
value: function(target) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var values = [];
|
var values = [];
|
||||||
@ -50,22 +46,9 @@
|
|||||||
if (!Object.toJson) {
|
if (!Object.toJson) {
|
||||||
Object.defineProperty(Object.prototype, "toJson", {
|
Object.defineProperty(Object.prototype, "toJson", {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true,
|
|
||||||
writable: true,
|
|
||||||
value: function() {
|
value: function() {
|
||||||
return JSON.stringify(this);
|
return JSON.stringify(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Object.prototype.toJson = function () {
|
|
||||||
// return JSON.stringify(this);
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // YAML快速生成
|
|
||||||
// var yaml = require('modules/yaml');
|
|
||||||
// Object.prototype.toYaml = function () {
|
|
||||||
// return yaml.safeDump(this);
|
|
||||||
// };
|
|
||||||
})();
|
})();
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
var File = Java.type("java.io.File");
|
var File = Java.type("java.io.File");
|
||||||
var separatorChar = File.separatorChar;
|
var separatorChar = File.separatorChar;
|
||||||
var cacheDir = parent + separatorChar + "runtime";
|
var cacheDir = parent + separatorChar + "runtime";
|
||||||
var paths = [parent, parent + separatorChar + 'node_modules'];
|
var paths = [parent + separatorChar + 'node_modules', parent];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
base.delete(cacheDir);
|
base.delete(cacheDir);
|
||||||
|
9
src/main/resources/node_modules/fs.js
generated
vendored
9
src/main/resources/node_modules/fs.js
generated
vendored
@ -3,13 +3,8 @@
|
|||||||
/*global Java, base, module, exports, require, __FILE__*/
|
/*global Java, base, module, exports, require, __FILE__*/
|
||||||
var File = Java.type("java.io.File");
|
var File = Java.type("java.io.File");
|
||||||
var Files = Java.type("java.nio.file.Files");
|
var Files = Java.type("java.nio.file.Files");
|
||||||
// noinspection JSUnresolvedVariable
|
|
||||||
var separatorChar = File.separatorChar;
|
var separatorChar = File.separatorChar;
|
||||||
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||||
// noinspection JSUnusedLocalSymbols
|
|
||||||
var _toString = function(obj) {
|
|
||||||
return Object.prototype.toString.call(obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用文件分割符合并路径
|
* 用文件分割符合并路径
|
||||||
@ -145,9 +140,7 @@ function del(file) {
|
|||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// noinspection JSValidateTypes
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
// noinspection JSUnresolvedVariable
|
|
||||||
Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function(f) {
|
Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function(f) {
|
||||||
del(f);
|
del(f);
|
||||||
})
|
})
|
||||||
@ -155,7 +148,6 @@ function del(file) {
|
|||||||
Files.delete(file.toPath());
|
Files.delete(file.toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// noinspection JSUnusedLocalSymbols
|
|
||||||
function exists(file) {
|
function exists(file) {
|
||||||
return fs.file(file).exists()
|
return fs.file(file).exists()
|
||||||
}
|
}
|
||||||
@ -173,6 +165,7 @@ Object.assign(fs, {
|
|||||||
concat: concat,
|
concat: concat,
|
||||||
create: create,
|
create: create,
|
||||||
mkdirs: mkdirs,
|
mkdirs: mkdirs,
|
||||||
|
exists: exists,
|
||||||
file: file,
|
file: file,
|
||||||
copy: copy,
|
copy: copy,
|
||||||
read: read
|
read: read
|
||||||
|
2270
src/main/resources/node_modules/internal/bukkit/item-id-material.json
generated
vendored
Normal file
2270
src/main/resources/node_modules/internal/bukkit/item-id-material.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
src/main/resources/node_modules/internal/bukkit/item.js
generated
vendored
8
src/main/resources/node_modules/internal/bukkit/item.js
generated
vendored
@ -8,6 +8,8 @@ var Bukkit = MServer;
|
|||||||
var item = {};
|
var item = {};
|
||||||
var ItemStack = Java.type("org.bukkit.inventory.ItemStack");
|
var ItemStack = Java.type("org.bukkit.inventory.ItemStack");
|
||||||
var Material = Java.type('org.bukkit.Material');
|
var Material = Java.type('org.bukkit.Material');
|
||||||
|
var ItemIDMaterial = require('./item-id-material.json')
|
||||||
|
var ItemIDRegex = /^[0-9]*$/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个物品
|
* 创建一个物品
|
||||||
@ -20,8 +22,14 @@ item.create = function() {
|
|||||||
var argType = toString.call(idOrType)
|
var argType = toString.call(idOrType)
|
||||||
switch (argType) {
|
switch (argType) {
|
||||||
case "[object Number]":
|
case "[object Number]":
|
||||||
|
if (Material['LEGACY_PREFIX']) {
|
||||||
|
idOrType = Material[Material['LEGACY_PREFIX'] + ItemIDMaterial[idOrType]];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "[object String]":
|
case "[object String]":
|
||||||
|
if (ItemIDRegex.test(idOrType)) {
|
||||||
|
idOrType = ItemIDMaterial[idOrType];
|
||||||
|
}
|
||||||
// 尝试获取老版本枚举
|
// 尝试获取老版本枚举
|
||||||
idOrType = Material[idOrType] || Material[Material['LEGACY_PREFIX'] + idOrType];
|
idOrType = Material[idOrType] || Material[Material['LEGACY_PREFIX'] + idOrType];
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user