init Project...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-08-21 18:53:28 +08:00
commit 4f56a2dcc4
7 changed files with 254 additions and 0 deletions

View File

@ -0,0 +1,44 @@
/**
*
*/
package cn.citycraft.Yum;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.Yum.utils.DownloadUtils;
/**
* MC插件仓库
*
* @author 蒋天蓓
* 2015年8月21日下午5:14:39
*/
public class Yum extends JavaPlugin {
String url = "http://ci.citycraft.cn:8800/jenkins/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) {
case 0:
break;
case 2:
switch (args[0]) {
case "install":
if (DownloadUtils.download(String.format(url, args[1]), getDataFolder().getParent(), args[1])) {
sender.sendMessage("OK");
} else {
sender.sendMessage("Error");
}
break;
case "remove":
break;
}
break;
}
return true;
}
}

View File

@ -0,0 +1,67 @@
/**
*
*/
package cn.citycraft.Yum.utils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import org.bukkit.Bukkit;
/**
* @author 蒋天蓓
* 2015年8月21日下午6:08:09
* TODO
*/
public class DownloadUtils {
public static boolean download(String url, String dir, String filename) {
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
URL fileUrl = new URL(url);
System.out.println("下载地址: " + url);
int fileLength = fileUrl.openConnection().getContentLength();
System.out.println("文件长度: " + fileLength);
in = new BufferedInputStream(fileUrl.openStream());
File file = new File(dir, filename + ".jar");
if (!file.exists()) {
file.createNewFile();
}
fout = new FileOutputStream(file);
byte[] data = new byte[1024];
// long downloaded = 0L;
int count;
while ((count = in.read(data)) != -1) {
// downloaded += count;
fout.write(data, 0, count);
// int percent = (int) (downloaded / fileLength);
}
return true;
} catch (Exception ex) {
Bukkit.getLogger().log(Level.WARNING, "The auto-updater tried to download a new update, but was unsuccessful.", ex);
return false;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, null, ex);
}
try {
if (fout != null) {
fout.close();
}
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, null, ex);
}
}
}
}

View File

@ -0,0 +1,8 @@
name: Yum
main: cn.citycraft.Yum.Yum
website: http://ci.citycraft.cn:8800/jenkins/job/Yum/
version: 1.0
commands:
yum:
description: MC插件仓库
usage: §6使用§a/yum help§6查看帮助!