mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 22:38:46 +00:00
fix update error...
This commit is contained in:
parent
91cbc7fc7e
commit
896357ad1b
@ -36,7 +36,6 @@ public class CommandUpdate extends BaseCommand {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (yum.download.update(sender, plugin)) {
|
if (yum.download.update(sender, plugin)) {
|
||||||
sender.sendMessage(PluginsManager.unload(plugin));
|
sender.sendMessage(PluginsManager.unload(plugin));
|
||||||
// PluginsManager.getPluginFile(plugin).delete();
|
|
||||||
sender.sendMessage(PluginsManager.load(plugin));
|
sender.sendMessage(PluginsManager.load(plugin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,17 @@ public class DownloadManager {
|
|||||||
this.plugin = main;
|
this.plugin = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPer(double per) {
|
private String getPer(int per) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 11; i++) {
|
||||||
if (per > i) {
|
if (per > i) {
|
||||||
sb.append(" ");
|
|
||||||
} else {
|
|
||||||
sb.append("==");
|
sb.append("==");
|
||||||
|
} else if (per == i) {
|
||||||
|
sb.append("> ");
|
||||||
|
} else {
|
||||||
|
sb.append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(">");
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,20 +40,22 @@ public class DownloadManager {
|
|||||||
return run(sender, pluginname, null);
|
return run(sender, pluginname, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean run(CommandSender sender, String pluginname, String filename) {
|
public boolean run(final CommandSender sender, final String pluginname, final String filename) {
|
||||||
String url = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
|
String url = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
|
||||||
// String url = "https://502647092.github.io/plugins/%1$s/%1$s.jar";
|
// String url = "https://502647092.github.io/plugins/%1$s/%1$s.jar";
|
||||||
|
|
||||||
BufferedInputStream in = null;
|
BufferedInputStream in = null;
|
||||||
FileOutputStream fout = null;
|
FileOutputStream fout = null;
|
||||||
|
CommandSender resultsender = sender;
|
||||||
if (sender == null) {
|
if (sender == null) {
|
||||||
sender = Bukkit.getConsoleSender();
|
resultsender = Bukkit.getConsoleSender();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
sender.sendMessage("§6开始下载: §3" + pluginname);
|
resultsender.sendMessage("§6开始下载: §3" + pluginname);
|
||||||
URL fileUrl = new URL(String.format(url, pluginname));
|
URL fileUrl = new URL(String.format(url, pluginname));
|
||||||
sender.sendMessage("§6下载地址: §3" + fileUrl.getPath());
|
resultsender.sendMessage("§6下载地址: §3" + fileUrl.getPath());
|
||||||
int fileLength = fileUrl.openConnection().getContentLength();
|
int fileLength = fileUrl.openConnection().getContentLength();
|
||||||
sender.sendMessage("§6文件长度: §3" + fileLength);
|
resultsender.sendMessage("§6文件长度: §3" + fileLength);
|
||||||
in = new BufferedInputStream(fileUrl.openStream());
|
in = new BufferedInputStream(fileUrl.openStream());
|
||||||
File file = null;
|
File file = null;
|
||||||
if (filename == null) {
|
if (filename == null) {
|
||||||
@ -62,12 +65,13 @@ public class DownloadManager {
|
|||||||
}
|
}
|
||||||
if (!file.getParentFile().exists()) {
|
if (!file.getParentFile().exists()) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
sender.sendMessage("§d创建新目录: " + file.getParentFile().getAbsolutePath());
|
resultsender.sendMessage("§d创建新目录: " + file.getParentFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
}
|
}
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
sender.sendMessage("§d创建新文件: " + file.getName());
|
resultsender.sendMessage("§6创建新文件: §d" + file.getAbsolutePath());
|
||||||
}
|
|
||||||
fout = new FileOutputStream(file);
|
fout = new FileOutputStream(file);
|
||||||
byte[] data = new byte[1024];
|
byte[] data = new byte[1024];
|
||||||
long downloaded = 0L;
|
long downloaded = 0L;
|
||||||
@ -75,14 +79,15 @@ public class DownloadManager {
|
|||||||
while ((count = in.read(data)) != -1) {
|
while ((count = in.read(data)) != -1) {
|
||||||
downloaded += count;
|
downloaded += count;
|
||||||
fout.write(data, 0, count);
|
fout.write(data, 0, count);
|
||||||
double percent = downloaded / fileLength * 10000;
|
int percent = (int) (downloaded * 100L / fileLength);
|
||||||
sender.sendMessage(String.format("§a已下载: §a" + getPer(percent) + " %.2f%%", percent));
|
if (percent % 10 == 0) {
|
||||||
|
resultsender.sendMessage(String.format("§6已下载: §a" + getPer(percent / 10) + " %s%%", percent));
|
||||||
}
|
}
|
||||||
sender.sendMessage("§6已下载: §a====================> 100%");
|
}
|
||||||
sender.sendMessage("§a插件: " + pluginname + " 下载完成!");
|
resultsender.sendMessage("§a插件: " + pluginname + " 下载完成!");
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
sender.sendMessage("§c插件" + pluginname + "下载失败!");
|
resultsender.sendMessage("§c插件" + pluginname + "下载失败!");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: Yum
|
name: Yum
|
||||||
main: cn.citycraft.Yum.Yum
|
main: cn.citycraft.Yum.Yum
|
||||||
website: http://ci.citycraft.cn:8800/jenkins/job/Yum/
|
website: http://ci.citycraft.cn:8800/jenkins/job/Yum/
|
||||||
version: 1.1
|
version: 1.2
|
||||||
commands:
|
commands:
|
||||||
yum:
|
yum:
|
||||||
description: MC插件仓库
|
description: MC插件仓库
|
||||||
|
Loading…
Reference in New Issue
Block a user