feat: MSPM异步处理命令

This commit is contained in:
coding 2018-05-30 14:09:20 +00:00
parent 324fbee2e5
commit ee496c5bda

View File

@ -53,7 +53,31 @@ function load() {
function enable() { function enable() {
command.on(this, 'mpm', { command.on(this, 'mpm', {
cmd: function (sender, command, args) { cmd: function (sender, command, args) {
if (args.length > 0) { task.async(function asyncCommand() {
main(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) {
switch (args[0]) {
case "install":
return packageNameCache;
case "update":
case "upgrade":
case "reload":
return pluginCache;
}
}
}
})
}
function main(sender, command, args){
if (!args[0] || args[1] === 'help') {
sendHelp(sender);
return;
}
switch (args[0]) { switch (args[0]) {
case "list": case "list":
console.sender(sender, '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:'); console.sender(sender, '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:');
@ -111,7 +135,7 @@ function enable() {
break; break;
case "run": case "run":
args.shift(1); args.shift(1);
console.sender(sender, eval(args.join(' '))); console.sender(sender, eval(args.join(' ')) || '§4没有返回结果!');
break; break;
case "create": case "create":
var name = args[1]; var name = args[1];
@ -128,28 +152,10 @@ function enable() {
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;
case "help": default:
sendHelp(sender); sendHelp(sender);
break; break;
} }
} else {
sendHelp(sender);
}
},
tab: function (sender, command, args) {
if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help'];
if (args.length > 1) {
switch (args[0]) {
case "install":
return packageNameCache;
case "update":
case "upgrade":
case "reload":
return pluginCache;
}
}
}
})
} }
function sendHelp(sender) { function sendHelp(sender) {