更新命令处理...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-11-25 09:37:09 +08:00
parent 281e09b496
commit 857cda6fe5
12 changed files with 64 additions and 13 deletions

View File

@ -17,6 +17,7 @@ import cn.citycraft.Yum.commands.CommandReload;
import cn.citycraft.Yum.commands.CommandRepo; import cn.citycraft.Yum.commands.CommandRepo;
import cn.citycraft.Yum.commands.CommandUnload; import cn.citycraft.Yum.commands.CommandUnload;
import cn.citycraft.Yum.commands.CommandUpdate; import cn.citycraft.Yum.commands.CommandUpdate;
import cn.citycraft.Yum.commands.CommandUpdateAll;
import cn.citycraft.Yum.commands.CommandUpgrade; import cn.citycraft.Yum.commands.CommandUpgrade;
import cn.citycraft.Yum.manager.YumManager; import cn.citycraft.Yum.manager.YumManager;
@ -30,10 +31,11 @@ public class Yum extends JavaPlugin {
public YumManager yumgr; public YumManager yumgr;
public void initCommands() { public void initCommands() {
final HandlerSubCommand cmdhandler = new HandlerSubCommand(this); final HandlerSubCommand cmdhandler = new HandlerSubCommand(this, "yum");
cmdhandler.registerCommand(new CommandList(this)); cmdhandler.registerCommand(new CommandList(this));
cmdhandler.registerCommand(new CommandInstall(this)); cmdhandler.registerCommand(new CommandInstall(this));
cmdhandler.registerCommand(new CommandUpdate(this)); cmdhandler.registerCommand(new CommandUpdate(this));
cmdhandler.registerCommand(new CommandUpdateAll(this));
cmdhandler.registerCommand(new CommandDelete(this)); cmdhandler.registerCommand(new CommandDelete(this));
cmdhandler.registerCommand(new CommandInfo(this)); cmdhandler.registerCommand(new CommandInfo(this));
cmdhandler.registerCommand(new CommandRepo(this)); cmdhandler.registerCommand(new CommandRepo(this));
@ -41,8 +43,6 @@ public class Yum extends JavaPlugin {
cmdhandler.registerCommand(new CommandLoad(this)); cmdhandler.registerCommand(new CommandLoad(this));
cmdhandler.registerCommand(new CommandUnload(this)); cmdhandler.registerCommand(new CommandUnload(this));
cmdhandler.registerCommand(new CommandUpgrade(this)); cmdhandler.registerCommand(new CommandUpgrade(this));
this.getCommand("yum").setExecutor(cmdhandler);
this.getCommand("yum").setTabCompleter(cmdhandler);
} }
@Override @Override

View File

@ -25,7 +25,7 @@ public class CommandDelete extends BaseCommand {
* @param name * @param name
*/ */
public CommandDelete(final Yum main) { public CommandDelete(final Yum main) {
super("delete", "remove"); super("remove");
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("删除插件"); setDescription("删除插件");

View File

@ -30,7 +30,7 @@ public class CommandInfo extends BaseCommand {
* @param name * @param name
*/ */
public CommandInfo(final Yum main) { public CommandInfo(final Yum main) {
super("info"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("查看插件详情"); setDescription("查看插件详情");

View File

@ -29,7 +29,7 @@ public class CommandInstall extends BaseCommand {
* @param name * @param name
*/ */
public CommandInstall(final Yum main) { public CommandInstall(final Yum main) {
super("install"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("安装插件"); setDescription("安装插件");

View File

@ -25,7 +25,7 @@ public class CommandList extends BaseCommand {
* @param name * @param name
*/ */
public CommandList(final Yum main) { public CommandList(final Yum main) {
super("list"); super();
this.main = main; this.main = main;
setDescription("列出已安装插件列表"); setDescription("列出已安装插件列表");
} }

View File

@ -25,7 +25,7 @@ public class CommandLoad extends BaseCommand {
* @param name * @param name
*/ */
public CommandLoad(final Yum main) { public CommandLoad(final Yum main) {
super("load"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("载入插件"); setDescription("载入插件");

View File

@ -25,7 +25,7 @@ public class CommandReload extends BaseCommand {
* @param name * @param name
*/ */
public CommandReload(final Yum main) { public CommandReload(final Yum main) {
super("reload"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("重载插件"); setDescription("重载插件");

View File

@ -28,7 +28,7 @@ public class CommandRepo extends BaseCommand {
* @param name * @param name
*/ */
public CommandRepo(final Yum main) { public CommandRepo(final Yum main) {
super("repo"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("插件源命令"); setDescription("插件源命令");

View File

@ -25,7 +25,7 @@ public class CommandUnload extends BaseCommand {
* @param name * @param name
*/ */
public CommandUnload(final Yum main) { public CommandUnload(final Yum main) {
super("unload"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("卸载插件"); setDescription("卸载插件");

View File

@ -23,7 +23,7 @@ public class CommandUpdate extends BaseCommand {
* @param name * @param name
*/ */
public CommandUpdate(final Yum main) { public CommandUpdate(final Yum main) {
super("update"); super();
this.main = main; this.main = main;
setMinimumArguments(1); setMinimumArguments(1);
setDescription("更新插件"); setDescription("更新插件");

View File

@ -0,0 +1,51 @@
/**
*
*/
package cn.citycraft.Yum.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.commands.BaseCommand;
import cn.citycraft.Yum.Yum;
import cn.citycraft.Yum.manager.YumManager;
/**
* @author 蒋天蓓 2015年8月12日下午2:04:05
*/
public class CommandUpdateAll extends BaseCommand {
Yum main;
/**
* @param name
*/
public CommandUpdateAll(final Yum main) {
super();
this.main = main;
setDescription("更新所有可更新插件");
}
@Override
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
final String pluginname = args[0];
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
sender.sendMessage("§a开始更新服务器可更新插件");
if (plugin != null) {
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (args.length < 2) {
YumManager.update(sender, plugin);
} else {
YumManager.update(sender, plugin, args[1]);
}
}
});
} else {
sender.sendMessage("§c插件" + pluginname + "未安装或已卸载 需要安装请使用/yum install " + pluginname + "!");
}
};
}

View File

@ -23,7 +23,7 @@ public class CommandUpgrade extends BaseCommand {
* @param name * @param name
*/ */
public CommandUpgrade(final Yum main) { public CommandUpgrade(final Yum main) {
super("upgrade"); super();
this.main = main; this.main = main;
setDescription("升级插件"); setDescription("升级插件");
setPossibleArguments("[插件名称]"); setPossibleArguments("[插件名称]");