mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 22:38:46 +00:00
fix dir error...
This commit is contained in:
parent
0669722000
commit
0661c52fb2
@ -38,7 +38,7 @@ public class Yum extends JavaPlugin {
|
|||||||
Plugin plugin = this.getServer().getPluginManager().getPlugin(args[1]);
|
Plugin plugin = this.getServer().getPluginManager().getPlugin(args[1]);
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "install":
|
case "install":
|
||||||
if (DownloadUtils.download(sender, args[1]))
|
if (DownloadUtils.download(sender, getDataFolder().getParent(), args[1]))
|
||||||
sender.sendMessage(PluginUtil.load(args[1]));
|
sender.sendMessage(PluginUtil.load(args[1]));
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
@ -50,7 +50,7 @@ public class Yum extends JavaPlugin {
|
|||||||
break;
|
break;
|
||||||
case "update":
|
case "update":
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
if (DownloadUtils.download(sender, args[1]))
|
if (DownloadUtils.download(sender, getDataFolder().getParent(), args[1]))
|
||||||
sender.sendMessage(PluginUtil.load(args[1]));
|
sender.sendMessage(PluginUtil.load(args[1]));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("插件不存在或已卸载!");
|
sender.sendMessage("插件不存在或已卸载!");
|
||||||
|
@ -17,23 +17,24 @@ import org.bukkit.command.CommandSender;
|
|||||||
* TODO
|
* TODO
|
||||||
*/
|
*/
|
||||||
public class DownloadUtils {
|
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";
|
String url = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
|
||||||
BufferedInputStream in = null;
|
BufferedInputStream in = null;
|
||||||
FileOutputStream fout = null;
|
FileOutputStream fout = null;
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
sender = Bukkit.getConsoleSender();
|
sender = Bukkit.getConsoleSender();
|
||||||
try {
|
try {
|
||||||
|
String filename = pluginname + ".jar";
|
||||||
sender.sendMessage("开始下载: " + pluginname);
|
sender.sendMessage("开始下载: " + pluginname);
|
||||||
URL fileUrl = new URL(String.format(url, pluginname));
|
URL fileUrl = new URL(String.format(url, pluginname));
|
||||||
sender.sendMessage("下载地址: http://********/" + fileUrl.getFile());
|
sender.sendMessage("下载地址: http://********/" + filename);
|
||||||
int fileLength = fileUrl.openConnection().getContentLength();
|
int fileLength = fileUrl.openConnection().getContentLength();
|
||||||
sender.sendMessage("文件长度: " + fileLength);
|
sender.sendMessage("文件长度: " + fileLength);
|
||||||
in = new BufferedInputStream(fileUrl.openStream());
|
in = new BufferedInputStream(fileUrl.openStream());
|
||||||
File file = new File("/plugins/", fileUrl.getFile());
|
File file = new File(dir, filename);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
sender.sendMessage("创建新文件: " + fileUrl.getFile());
|
sender.sendMessage("创建新文件: " + filename);
|
||||||
}
|
}
|
||||||
fout = new FileOutputStream(file);
|
fout = new FileOutputStream(file);
|
||||||
byte[] data = new byte[1024];
|
byte[] data = new byte[1024];
|
||||||
@ -52,6 +53,7 @@ public class DownloadUtils {
|
|||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
sender.sendMessage("插件下载失败!");
|
sender.sendMessage("插件下载失败!");
|
||||||
|
ex.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
@ -60,7 +62,6 @@ public class DownloadUtils {
|
|||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
sender.sendMessage("关闭数据流时发生错误!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user