fix dir error...

This commit is contained in:
502647092 2015-08-21 20:47:42 +08:00
parent 0669722000
commit 0661c52fb2
2 changed files with 8 additions and 7 deletions

View File

@ -38,7 +38,7 @@ public class Yum extends JavaPlugin {
Plugin plugin = this.getServer().getPluginManager().getPlugin(args[1]);
switch (args[0]) {
case "install":
if (DownloadUtils.download(sender, args[1]))
if (DownloadUtils.download(sender, getDataFolder().getParent(), args[1]))
sender.sendMessage(PluginUtil.load(args[1]));
break;
case "remove":
@ -50,7 +50,7 @@ public class Yum extends JavaPlugin {
break;
case "update":
if (plugin != null) {
if (DownloadUtils.download(sender, args[1]))
if (DownloadUtils.download(sender, getDataFolder().getParent(), args[1]))
sender.sendMessage(PluginUtil.load(args[1]));
} else {
sender.sendMessage("插件不存在或已卸载!");

View File

@ -17,23 +17,24 @@ import org.bukkit.command.CommandSender;
* TODO
*/
public class DownloadUtils {
public static boolean download(CommandSender sender, String pluginname) {
public static boolean download(CommandSender sender, String dir, String pluginname) {
String url = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
BufferedInputStream in = null;
FileOutputStream fout = null;
if (sender == null)
sender = Bukkit.getConsoleSender();
try {
String filename = pluginname + ".jar";
sender.sendMessage("开始下载: " + pluginname);
URL fileUrl = new URL(String.format(url, pluginname));
sender.sendMessage("下载地址: http://********/" + fileUrl.getFile());
sender.sendMessage("下载地址: http://********/" + filename);
int fileLength = fileUrl.openConnection().getContentLength();
sender.sendMessage("文件长度: " + fileLength);
in = new BufferedInputStream(fileUrl.openStream());
File file = new File("/plugins/", fileUrl.getFile());
File file = new File(dir, filename);
if (!file.exists()) {
file.createNewFile();
sender.sendMessage("创建新文件: " + fileUrl.getFile());
sender.sendMessage("创建新文件: " + filename);
}
fout = new FileOutputStream(file);
byte[] data = new byte[1024];
@ -52,6 +53,7 @@ public class DownloadUtils {
return true;
} catch (Exception ex) {
sender.sendMessage("插件下载失败!");
ex.printStackTrace();
return false;
} finally {
try {
@ -60,7 +62,6 @@ public class DownloadUtils {
fout.close();
}
} catch (Exception ex) {
sender.sendMessage("关闭数据流时发生错误!");
}
}
}