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