feat: optimize framework

Signed-off-by: MiaoWoo <admin@yumc.pw>
merge/3/MERGE
MiaoWoo 2019-04-28 18:06:42 +08:00
parent 03129b8797
commit a78e6482e8
7 changed files with 2288 additions and 35 deletions

View File

@ -17,4 +17,4 @@
}
});
}
})();
})();

View File

@ -1,15 +1,14 @@
/**
* 补丁和方法扩展
*/
(function () {
(function() {
/**
* 日期格式化
* : new Date().format('yyyy-MM-dd hh:mm:ss.s') => "2017-08-24 16:15:40.693"
* @param fmt 格式化字符串
* @returns {*}
*/
Date.prototype.format = function (fmt) {
Date.prototype.format = function(fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日

View File

@ -2,14 +2,12 @@
* 补丁和方法扩展
*/
(function () {
(function() {
// Object.assign Polyfill
if (!Object.assign) {
Object.defineProperty(Object, "assign", {
enumerable: false,
configurable: true,
writable: true,
value: function (target) {
value: function(target) {
"use strict";
if (target === undefined || target === null)
throw new TypeError("Cannot convert first argument to object");
@ -28,13 +26,11 @@
}
});
}
// Object.values Polyfill
if (!Object.values) {
Object.defineProperty(Object, "values", {
enumerable: false,
configurable: true,
writable: true,
value: function (target) {
value: function(target) {
"use strict";
var values = [];
for (var key in target) {
@ -50,22 +46,9 @@
if (!Object.toJson) {
Object.defineProperty(Object.prototype, "toJson", {
enumerable: false,
configurable: true,
writable: true,
value: function () {
value: function() {
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);
// };
})();

View File

@ -31,7 +31,7 @@
var File = Java.type("java.io.File");
var separatorChar = File.separatorChar;
var cacheDir = parent + separatorChar + "runtime";
var paths = [parent, parent + separatorChar + 'node_modules'];
var paths = [parent + separatorChar + 'node_modules', parent];
try {
base.delete(cacheDir);

View File

@ -3,13 +3,8 @@
/*global Java, base, module, exports, require, __FILE__*/
var File = Java.type("java.io.File");
var Files = Java.type("java.nio.file.Files");
// noinspection JSUnresolvedVariable
var separatorChar = File.separatorChar;
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()) {
return;
}
// noinspection JSValidateTypes
if (file.isDirectory()) {
// noinspection JSUnresolvedVariable
Files.list(file.toPath()).collect(java.util.stream.Collector.toList()).forEach(function(f) {
del(f);
})
@ -155,7 +148,6 @@ function del(file) {
Files.delete(file.toPath());
}
// noinspection JSUnusedLocalSymbols
function exists(file) {
return fs.file(file).exists()
}
@ -173,6 +165,7 @@ Object.assign(fs, {
concat: concat,
create: create,
mkdirs: mkdirs,
exists: exists,
file: file,
copy: copy,
read: read

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,8 @@ var Bukkit = MServer;
var item = {};
var ItemStack = Java.type("org.bukkit.inventory.ItemStack");
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)
switch (argType) {
case "[object Number]":
if (Material['LEGACY_PREFIX']) {
idOrType = Material[Material['LEGACY_PREFIX'] + ItemIDMaterial[idOrType]];
}
break;
case "[object String]":
if (ItemIDRegex.test(idOrType)) {
idOrType = ItemIDMaterial[idOrType];
}
// 尝试获取老版本枚举
idOrType = Material[idOrType] || Material[Material['LEGACY_PREFIX'] + idOrType];
break;