style: 格式化代码

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-11-15 21:00:07 +08:00
parent 612d4ee856
commit dc716dc87c
7 changed files with 43 additions and 38 deletions

View File

@ -33,7 +33,7 @@ var disable;
var pluginYml; var pluginYml;
function checkClassLoader(){ function checkClassLoader() {
var classLoader = java.lang.Thread.currentThread().getContextClassLoader(); var classLoader = java.lang.Thread.currentThread().getContextClassLoader();
pluginYml = classLoader.getResource("plugin.yml"); pluginYml = classLoader.getResource("plugin.yml");
if (pluginYml === null) { if (pluginYml === null) {

View File

@ -18,7 +18,7 @@
var yaml = require('modules/yaml'); var yaml = require('modules/yaml');
Object.prototype.toYaml = function () { Object.prototype.toYaml = function () {
return yaml.safeDump(this); return yaml.safeDump(this);
} };
/** /**
* 日期格式化 * 日期格式化
@ -36,10 +36,10 @@
"q+": Math.floor((this.getMonth() + 3) / 3), //季度 "q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒 "S": this.getMilliseconds() //毫秒
}; };
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "") .substr(4 - RegExp.$1.length)); if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) { for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) { if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? o[k] : (("00" + o[k]).substr(("" + o[k]).length))); fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? o[k] : (("00" + o[k]).substr(("" + o[k]).length)));
} }
} }
return fmt; return fmt;

View File

@ -6,10 +6,11 @@ var global = this;
// noinspection JSUnusedLocalSymbols // noinspection JSUnusedLocalSymbols
global.init = function init(root) { global.init = function init(root) {
global.root = root; global.root = root;
global.noop = function () {}; global.noop = function () {
};
loadCore(); loadCore();
loadRequire(); loadRequire();
try{ try {
loadExt(); loadExt();
loadServerLib(); loadServerLib();
loadPlugins(); loadPlugins();
@ -17,7 +18,7 @@ var global = this;
console.console("§4初始化插件基础系统库错误:§c", ex); console.console("§4初始化插件基础系统库错误:§c", ex);
console.ex(ex); console.ex(ex);
} }
} };
/** /**
* 初始化核心 * 初始化核心
@ -46,7 +47,7 @@ var global = this;
var fs = require('core/fs'); var fs = require('core/fs');
fs.list(fs.file(root, 'core/ext')).forEach(function (path) { fs.list(fs.file(root, 'core/ext')).forEach(function (path) {
console.log('加载扩展类库', path); console.log('加载扩展类库', path);
try{ try {
load(path.toFile()); load(path.toFile());
} catch (ex) { } catch (ex) {
console.ex(ex); console.ex(ex);

View File

@ -39,7 +39,7 @@ function disable(jsp) {
var commands = jsp.description.commands; var commands = jsp.description.commands;
if (commands) { if (commands) {
for (var name in commands) { for (var name in commands) {
} }
} }
} }
@ -73,28 +73,30 @@ function on(jsp, name, exec) {
// 必须指定需要实现的接口类型 否则MOD服会报错 // 必须指定需要实现的接口类型 否则MOD服会报错
c.setExecutor(new org.bukkit.command.CommandExecutor({ c.setExecutor(new org.bukkit.command.CommandExecutor({
onCommand: function (sender, cmd, command, args) { onCommand: function (sender, cmd, command, args) {
try { try {
return exec.cmd(sender, command, args); return exec.cmd(sender, command, args);
} catch (ex) { } catch (ex) {
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6命令时发生异常 §4%s'.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex)); console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6命令时发生异常 §4%s'.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex));
console.ex(ex); console.ex(ex);
}
} }
}})); }));
} }
if (exec.tab) { if (exec.tab) {
// 必须指定需要实现的接口类型 否则MOD服会报错 // 必须指定需要实现的接口类型 否则MOD服会报错
c.setTabCompleter(new org.bukkit.command.TabCompleter({ c.setTabCompleter(new org.bukkit.command.TabCompleter({
onTabComplete: function (sender, cmd, command, args) { onTabComplete: function (sender, cmd, command, args) {
try { try {
var completions = new ArrayList(); var completions = new ArrayList();
var token = args[args.length - 1]; var token = args[args.length - 1];
StringUtil.copyPartialMatches(token, Arrays.asList(exec.tab(sender, command, args)), completions); StringUtil.copyPartialMatches(token, Arrays.asList(exec.tab(sender, command, args)), completions);
return completions; return completions;
} catch (ex) { } catch (ex) {
console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex)); console.console('§6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6补全时发生异常 §4%s'.format(sender.name, jsp.description.name, command, Java.from(args).join(' '), ex));
console.ex(ex); console.ex(ex);
}
} }
}})); }));
} }
} }

View File

@ -17,8 +17,8 @@ var Material = Java.type('org.bukkit.Material');
*/ */
item.create = function () { item.create = function () {
var idOrType = arguments[0]; var idOrType = arguments[0];
if (isNaN(new Number(idOrType))) { if (isNaN(Number(idOrType))) {
idOrType = Material[idOrType]; idOrType = Material[idOrType];
} }
switch (arguments.length) { switch (arguments.length) {
case 1: case 1:
@ -87,7 +87,9 @@ item.setName = function (item, name) {
item.setLore = item.setLores = function (item, lores) { item.setLore = item.setLores = function (item, lores) {
if (item.getType().name() !== "AIR") { if (item.getType().name() !== "AIR") {
var meta = item.hasItemMeta() ? item.getItemMeta() : Bukkit.getItemFactory().getItemMeta(item.getType()); var meta = item.hasItemMeta() ? item.getItemMeta() : Bukkit.getItemFactory().getItemMeta(item.getType());
if (typeof(lores) === 'string') { lores = lores.split("\n") }; if (typeof(lores) === 'string') {
lores = lores.split("\n")
}
meta.setLore(lores); meta.setLore(lores);
item.setItemMeta(meta); item.setItemMeta(meta);
} }

View File

@ -20,22 +20,22 @@ var ArrayList = Java.type('java.util.ArrayList');
var Arrays = Java.type('java.util.Arrays'); var Arrays = Java.type('java.util.Arrays');
var SimpleCommandCallable = function () { var SimpleCommandCallable = function () {
this.process = function (source, arguments) { this.process = function (source, args) {
}, };
this.getSuggestions = function (source, arguments, targetPosition) { this.getSuggestions = function (source, args, targetPosition) {
return Arrays.asList(''); return Arrays.asList('');
}, };
this.testPermission = function (source) { this.testPermission = function (source) {
return true; return true;
}, };
this.getShortDescription = function (source) { this.getShortDescription = function (source) {
return Optional.ofNullable(''); return Optional.ofNullable('');
}, };
this.getHelp = function (source) { this.getHelp = function (source) {
} }
} };
function enable(jsp) { function enable(jsp) {
var commands = jsp.description.commands; var commands = jsp.description.commands;

View File

@ -123,8 +123,8 @@ function newItemFromConfig(config) {
function enable() { function enable() {
command.on(this, 'l', { command.on(this, 'l', {
cmd: function (sender, command, args) { cmd: function (sender, command, args) {
if(!sender.openInventory){ if (!sender.openInventory) {
console.sender(sender, "§4当前用户无法使用该命令!"); console.sender(sender, "§4当前用户无法使用该命令!");
} }
var inv = bukkit.$.createInventory(null, 54, config.title); var inv = bukkit.$.createInventory(null, 54, config.title);
inv.setContents(items); inv.setContents(items);