feat: print stack on game

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-03-09 10:29:06 +08:00
parent 8d5902600f
commit 2dff086a01

View File

@ -41,7 +41,7 @@ var help = [
]; ];
function load() { function load() {
task.async(function () { task.async(function() {
pluginCache = Object.keys(manager.plugins); pluginCache = Object.keys(manager.plugins);
JSON.parse(http.get(self.config.center)).data.forEach(function cachePackageName(pkg) { JSON.parse(http.get(self.config.center)).data.forEach(function cachePackageName(pkg) {
packageCache[pkg.name] = pkg; packageCache[pkg.name] = pkg;
@ -52,12 +52,12 @@ function load() {
function enable() { function enable() {
command.on(this, 'mpm', { command.on(this, 'mpm', {
cmd: function (sender, command, args) { cmd: function(sender, command, args) {
task.async(function asyncCommand() { task.async(function asyncCommand() {
main(sender, command, args); main(sender, command, args);
}); });
}, },
tab: function (sender, command, args) { tab: function(sender, command, args) {
if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create']; if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create'];
if (args.length > 1) { if (args.length > 1) {
switch (args[0]) { switch (args[0]) {
@ -73,7 +73,7 @@ function enable() {
}) })
} }
function main(sender, command, args){ function main(sender, command, args) {
if (!args[0] || args[1] === 'help') { if (!args[0] || args[1] === 'help') {
sendHelp(sender); sendHelp(sender);
return; return;
@ -82,7 +82,7 @@ function main(sender, command, args){
case "list": case "list":
if (args[1]) { if (args[1]) {
console.sender(sender, '§6当前 §bMiaoScript §6已安装下列插件:'); console.sender(sender, '§6当前 §bMiaoScript §6已安装下列插件:');
pluginCache.forEach(function listInfo(pluginName){ pluginCache.forEach(function listInfo(pluginName) {
var desc = manager.plugins[pluginName].description; var desc = manager.plugins[pluginName].description;
console.sender(sender, '§6插件名称: §b%s §6版本: §a%s §6作者: §3%s'.format(desc.name, desc.version || '1.0', desc.author || '未知')) console.sender(sender, '§6插件名称: §b%s §6版本: §a%s §6作者: §3%s'.format(desc.name, desc.version || '1.0', desc.author || '未知'))
}) })
@ -123,8 +123,9 @@ function main(sender, command, args){
var pname = args[1]; var pname = args[1];
if (pluginCache.indexOf(pname) !== -1) { if (pluginCache.indexOf(pname) !== -1) {
manager.reload(pname) manager.reload(pname)
console.sender(sender, '§6插件 §b%s §a重载完成!'.format(pname))
} else { } else {
console.sender(sender, '§c插件 %s 不存在!'.format(pname)) console.sender(sender, '§c插件 §b%s §c不存在!'.format(pname))
} }
} else { } else {
self.reloadConfig(); self.reloadConfig();
@ -133,17 +134,24 @@ function main(sender, command, args){
break; break;
case "restart": case "restart":
try { try {
console.sender(sender, '§6Reloading §3MiaoScript Engine...');
ScriptEngineContextHolder.disableEngine(); ScriptEngineContextHolder.disableEngine();
ScriptEngineContextHolder.enableEngine(); ScriptEngineContextHolder.enableEngine();
console.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...'); console.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...');
} catch (ex) { } catch (ex) {
console.sender(sender, "§3MiaoScript Engine §6Reload §cError! ERR: " + ex); console.sender(sender, "§3MiaoScript Engine §6Reload §cError! ERR: " + ex);
console.ex(ex); console.sender(sender, console.stack(ex));
} }
break; break;
case "run": case "run":
args.shift(1); args.shift(1);
console.sender(sender, eval(args.join(' ')) || '§4没有返回结果!'); try {
var script = args.join(' ')
console.sender(sender, '§b运行脚本:§r', script)
console.sender(sender, '§a返回结果:§r', eval(script) || '§4没有返回结果!');
} catch (ex) {
console.sender(sender, console.stack(ex))
}
break; break;
case "create": case "create":
var name = args[1]; var name = args[1];
@ -158,7 +166,7 @@ function main(sender, command, args){
command: args[4] || name.toLowerCase(), command: args[4] || name.toLowerCase(),
}); });
fs.save(fs.file(__dirname, name + '.js'), result); fs.save(fs.file(__dirname, name + '.js'), result);
console.sender(sender, '§6插件 §a' + name + ' §6已生成到插件目录...'); console.sender(sender, '§6插件 §a' + name + ' §6已生成到插件目录...');
break; break;
default: default:
sendHelp(sender); sendHelp(sender);
@ -167,7 +175,7 @@ function main(sender, command, args){
} }
function sendHelp(sender) { function sendHelp(sender) {
help.forEach(function (msg) { help.forEach(function(msg) {
console.sender(sender, msg); console.sender(sender, msg);
}) })
} }