mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 06:18:46 +00:00
fix upgrade command ...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
2ecb988e50
commit
5570d82bed
@ -71,6 +71,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
registerCommand(new CommandReload(yum));
|
||||
registerCommand(new CommandLoad(yum));
|
||||
registerCommand(new CommandUnload(yum));
|
||||
registerCommand(new CommandUpgrade(yum));
|
||||
|
||||
RegisterCommandList = getRegisterCommands();
|
||||
}
|
||||
@ -82,9 +83,8 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
*/
|
||||
public List<String> getRegisterCommands() {
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
for (BaseCommand command : commandlist) {
|
||||
for (BaseCommand command : commandlist)
|
||||
cmds.addAll(command.getCommandList());
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
return true;
|
||||
String subcmd = args[0];
|
||||
String[] subargs = moveStrings(args, 1);
|
||||
for (BaseCommand command : commandlist) {
|
||||
for (BaseCommand command : commandlist)
|
||||
if (command.isValidTrigger(subcmd)) {
|
||||
if (!command.hasPermission(sender)) {
|
||||
sender.sendMessage("你没有此命令的权限!");
|
||||
@ -104,18 +104,16 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
sender.sendMessage("控制台无法使用此命令!");
|
||||
return true;
|
||||
}
|
||||
if (subargs.length >= command.getMinimumArguments()) {
|
||||
if (subargs.length >= command.getMinimumArguments())
|
||||
try {
|
||||
command.execute(sender, subcmd, subargs);
|
||||
return true;
|
||||
} catch (CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
else
|
||||
sender.sendMessage("错误的参数 /yum " + command.getName() + command.getPossibleArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -134,12 +132,10 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
||||
if (args[0].equalsIgnoreCase("install"))
|
||||
plugins = YumManager.repo.getAllPluginName();
|
||||
else if (args[0].equalsIgnoreCase("repo"))
|
||||
plugins = Arrays.asList(new String[] {
|
||||
"add",
|
||||
"list",
|
||||
"clean",
|
||||
"update"
|
||||
});
|
||||
plugins = Arrays.asList(new String[] { "add",
|
||||
"list",
|
||||
"clean",
|
||||
"update" });
|
||||
else
|
||||
plugins = YumManager.plugman.getPluginNames(false);
|
||||
StringUtil.copyPartialMatches(partialPlugin, plugins, completions);
|
||||
|
@ -29,13 +29,13 @@ public class CommandUpgrade extends BaseCommand {
|
||||
public void execute(final CommandSender sender, String label, final String[] args) throws CommandException {
|
||||
final String pluginname = args[0];
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginname);
|
||||
sender.sendMessage("§a开始更新插件: " + pluginname);
|
||||
sender.sendMessage("§a开始升级插件: " + pluginname);
|
||||
if (plugin != null)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(main, () -> {
|
||||
if (args.length < 2)
|
||||
YumManager.upgrade(sender, plugin);
|
||||
if (args.length == 1)
|
||||
YumManager.plugman.upgrade(sender, plugin);
|
||||
else
|
||||
YumManager.upgrade(sender, plugin, args[1]);
|
||||
YumManager.plugman.upgrade(sender);
|
||||
});
|
||||
else
|
||||
sender.sendMessage("§c插件未安装或已卸载 需要安装请使用yum install " + pluginname + "!");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.citycraft.Yum.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@ -485,8 +486,9 @@ public class PluginsManager {
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean updateall(CommandSender sender) {
|
||||
return updateall(sender, Bukkit.getServer().getUpdateFolderFile());
|
||||
public boolean upgrade(CommandSender sender) {
|
||||
sender.sendMessage("§6升级: §a开始升级 服务器更新 目录下的所有插件!");
|
||||
return upgrade(sender, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -498,27 +500,36 @@ public class PluginsManager {
|
||||
* - 更新目录
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean updateall(CommandSender sender, File directory) {
|
||||
public boolean upgrade(CommandSender sender, File directory, Plugin plugin) {
|
||||
boolean result = false;
|
||||
PluginLoader loader = main.getPluginLoader();
|
||||
File updateDirectory;
|
||||
if (!directory.isDirectory())
|
||||
if (directory == null || !directory.isDirectory())
|
||||
updateDirectory = Bukkit.getServer().getUpdateFolderFile();
|
||||
else
|
||||
updateDirectory = directory;
|
||||
try {
|
||||
sender.sendMessage("§6升级: §b从 " + updateDirectory.getCanonicalPath() + " 文件夹检索插件插件!");
|
||||
} catch (SecurityException | IOException e1) {
|
||||
sender.sendMessage("§4异常: §c文件夹 " + updateDirectory.getName() + " 权限不足或IO错误!");
|
||||
}
|
||||
for (File file : updateDirectory.listFiles()) {
|
||||
PluginDescriptionFile description = null;
|
||||
try {
|
||||
description = loader.getPluginDescription(file);
|
||||
String name = description.getName();
|
||||
sender.sendMessage("§6升级: 开始升级 " + name + " 插件!");
|
||||
if (plugin != null && name != plugin.getName())
|
||||
continue;
|
||||
result = true;
|
||||
sender.sendMessage("§6升级: §a开始升级 " + name + " 插件!");
|
||||
reload(sender, name);
|
||||
} catch (InvalidDescriptionException e) {
|
||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||
sender.sendMessage("§c文件: " + file.getName() + " 的plugin.yml文件存在错误!");
|
||||
sender.sendMessage("§4文件: §c" + file.getName() + " 的plugin.yml文件存在错误!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -526,7 +537,18 @@ public class PluginsManager {
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean updateall(File directory) {
|
||||
return updateall(Bukkit.getConsoleSender(), directory);
|
||||
public boolean upgrade(CommandSender sender, Plugin plugin) {
|
||||
sender.sendMessage("§6升级: §a开始升级 " + plugin.getName() + " 插件!");
|
||||
return upgrade(sender, null, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载update文件夹的插件
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean upgrade(File directory) {
|
||||
Bukkit.getConsoleSender().sendMessage("§6升级: §a开始升级 " + directory.getName() + " 目录下的所有插件!");
|
||||
return upgrade(Bukkit.getConsoleSender(), directory, null);
|
||||
}
|
||||
}
|
||||
|
@ -55,24 +55,4 @@ public class YumManager {
|
||||
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean upgrade(CommandSender sender) {
|
||||
return plugman.updateall(sender);
|
||||
}
|
||||
|
||||
public static boolean upgrade(CommandSender sender, Plugin plugin) {
|
||||
return update(sender, plugin, null);
|
||||
}
|
||||
|
||||
public static boolean upgrade(CommandSender sender, Plugin plugin, String version) {
|
||||
PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||
if (pi != null) {
|
||||
if (download.run(sender, pi.getMavenUrl(version), plugman.getPluginFile(plugin)))
|
||||
return plugman.reload(sender, plugin);
|
||||
return false;
|
||||
} else {
|
||||
sender.sendMessage("§6更新: §c仓库缓存中未找到插件 " + plugin.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user