feat: optimize framework

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

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" * : new Date().format('yyyy-MM-dd hh:mm:ss.s') => "2017-08-24 16:15:40.693"
* @param fmt 格式化字符串 * @param fmt 格式化字符串
* @returns {*} * @returns {*}
*/ */
Date.prototype.format = function (fmt) { Date.prototype.format = function(fmt) {
var o = { var o = {
"M+": this.getMonth() + 1, //月份 "M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日 "d+": this.getDate(), //日

View File

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

View File

@ -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);

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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;