commit 4f56a2dcc4fd41984a99f41464a851e661921694 Author: 502647092 Date: Fri Aug 21 18:53:28 2015 +0800 init Project... Signed-off-by: 502647092 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3ec578f --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..043fc2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Eclipse stuff +/.settings + +# netbeans +/nbproject + +# we use maven! +/build.xml + +# maven +/target +/repo + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf + +/world + +# Mac filesystem dust +*.DS_Store + +# intellij +*.iml +*.ipr +*.iws +.idea/ + +# Project Stuff +/src/main/resources/Soulbound + +# Atlassian Stuff +/atlassian-ide-plugin.xml \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..422f681 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + Yum + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7019e54 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + cn.CityCraft + Yum + 0.0.1-SNAPSHOT + Yum + + ${project.name} + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + org.spigotmc + spigot-api + jar + 1.8.3-R0.1-SNAPSHOT + + + + UTF-8 + + \ No newline at end of file diff --git a/src/main/java/cn/citycraft/Yum/Yum.java b/src/main/java/cn/citycraft/Yum/Yum.java new file mode 100644 index 0000000..bff6d73 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/Yum.java @@ -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; + } + +} diff --git a/src/main/java/cn/citycraft/Yum/utils/DownloadUtils.java b/src/main/java/cn/citycraft/Yum/utils/DownloadUtils.java new file mode 100644 index 0000000..d8d2a42 --- /dev/null +++ b/src/main/java/cn/citycraft/Yum/utils/DownloadUtils.java @@ -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); + } + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..bb0c914 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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查看帮助! \ No newline at end of file