修复检查可更新插件功能导致全局更新失效问题...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-03-02 16:12:25 +08:00
parent 557a15e246
commit 4480b0fb3d
4 changed files with 39 additions and 21 deletions

11
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId>
<artifactId>Yum</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<name>Yum</name>
<description>Minecraft 服务器插件管理系统</description>
<build>
@ -57,10 +57,9 @@
<jenkins.url>http://hs.yumc.pw:8080</jenkins.url>
<update.description>&amp;a全新 2.0 版本 震撼发布...</update.description>
<update.changes>
&amp;b2.0.1 &amp;6- &amp;c插件在upgrade时自动重命名为原有名称...
&amp;b2.0 &amp;6- &amp;a精简大量代码...
&amp;a 服务器启动后自动检查可更新插件...
&amp;a 优化检测流程...
&amp;b2.0.2 &amp;6- &amp;c修复检查可更新插件功能导致全局更新失效问题...;
&amp;b &amp;6- &amp;d新增全局更新限制 无法同时进行 防止错误...;
&amp;b2.0.1 &amp;6- &amp;c插件在upgrade时自动重命名为原有名称...;
</update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -80,7 +79,7 @@
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>

View File

@ -6,6 +6,7 @@ package cn.citycraft.Yum;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.CommonData.UpdatePlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker;
import cn.citycraft.Yum.api.YumAPI;
@ -34,5 +35,7 @@ public class Yum extends JavaPlugin {
@Override
public void onLoad() {
config = new FileConfig(this);
// 初始化更新列
UpdatePlugin.getUpdateList();
}
}

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
@ -28,6 +27,7 @@ public class YumAPI {
private static Plugin main;
private static PluginsManager plugman;
private static RepositoryManager repo;
private static boolean runlock = false;
/**
* 初始化Yum管理中心
@ -85,16 +85,9 @@ public class YumAPI {
for (final Entry<String, Plugin> updateplugin : UpdatePlugin.getUpdateList().entrySet()) {
ulist.add(updateplugin.getValue());
}
UpdatePlugin.clearList();
} catch (final Exception | Error e) {
try {
final Map<Plugin, String> updatelist = UpdatePlugin.getList();
ulist.addAll(updatelist.keySet());
UpdatePlugin.getList().clear();
} catch (final Exception | Error e2) {
sender.sendMessage("§4错误: §c无法检索全体更新列表!");
sender.sendMessage("§4异常: §c" + e2.getMessage());
}
sender.sendMessage("§4异常: §c" + e.getMessage());
}
return ulist;
}
@ -246,17 +239,30 @@ public class YumAPI {
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
if (runlock) {
sender.sendMessage("§d一键更新: §c一键更新运行中 请稍候重试...");
return;
}
runlock = true;
int failed = 0;
final List<Plugin> ulist = getUpdateList(sender);
if (ulist.size() > 0) {
sender.sendMessage("§d开始更新服务器可更新插件");
for (final Plugin updateplugin : ulist) {
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
updatefromyum(sender, updateplugin, null, true);
if (!updatefromyum(sender, updateplugin, null, true))
failed++;
}
if (failed != 0) {
sender.sendMessage("§d一键更新: §c升级过程中 §4" + failed + " §c个插件更新失败!");
}
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
updatecheck(sender);
} else {
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
}
runlock = false;
}
});
}
@ -329,6 +335,7 @@ public class YumAPI {
sender.sendMessage("§6更新: §e已下载 " + plugin.getName() + " 插件到服务器更新文件夹");
sender.sendMessage("§6更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
}
UpdatePlugin.getUpdateList().remove(plugin.getName());
return true;
}
} else {

View File

@ -8,6 +8,9 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
@ -30,7 +33,7 @@ import cn.citycraft.Yum.manager.RepositoryManager;
* @since 2016年1月9日 上午10:02:24
* @author
*/
public class YumCommand implements HandlerCommands {
public class YumCommand implements HandlerCommands, Listener {
Yum main;
RepositoryManager repo;
PluginsManager plugman;
@ -39,6 +42,7 @@ public class YumCommand implements HandlerCommands {
main = yum;
repo = YumAPI.getRepo();
plugman = YumAPI.getPlugman();
Bukkit.getPluginManager().registerEvents(this, yum);
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "yum");
cmdhandler.setAllCommandOnlyConsole(yum.config.getBoolean("onlyCommandConsole", false));
cmdhandler.registerCommands(this);
@ -174,6 +178,13 @@ public class YumCommand implements HandlerCommands {
}
}
@EventHandler
public void onAdminJoin(final PlayerJoinEvent e) {
if (e.getPlayer().isOp()) {
YumAPI.updatecheck(e.getPlayer());
}
}
@HandlerCommand(name = "reload", aliases = { "re" }, minimumArguments = 1, description = "重载插件", possibleArguments = "<插件名称|all|*>")
public void reload(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
@ -297,12 +308,10 @@ public class YumCommand implements HandlerCommands {
@HandlerCommand(name = "updateall", aliases = { "ua" }, description = "更新所有可更新插件")
public void updateall(final InvokeCommandEvent e) {
final CommandSender sender = e.getSender();
sender.sendMessage("§d开始更新服务器可更新插件");
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
@Override
public void run() {
YumAPI.updateall(sender);
YumAPI.updateall(e.getSender());
}
});
}