Release Version...

This commit is contained in:
502647092 2015-09-18 08:30:35 +08:00
parent 383448d8d6
commit 8b13710497
10 changed files with 92 additions and 97 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.citycraft</groupId> <groupId>cn.citycraft</groupId>
<artifactId>Yum</artifactId> <artifactId>Yum</artifactId>
<version>1.3.2</version> <version>1.4</version>
<name>Yum</name> <name>Yum</name>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
<build> <build>

View File

@ -32,7 +32,7 @@ public class CommandRepo extends BaseCommand {
switch (cmd) { switch (cmd) {
case "add": case "add":
if (args.length == 2) { if (args.length == 2) {
if (YumManager.repo.addRepositories(args[1])) if (YumManager.repo.addRepositories(sender, args[1]))
sender.sendMessage("§6仓库: §a插件信息已缓存!"); sender.sendMessage("§6仓库: §a插件信息已缓存!");
else else
sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!"); sender.sendMessage("§6仓库: §c源地址未找到仓库信息或无法访问!");

View File

@ -0,0 +1,32 @@
package cn.citycraft.Yum.manager;
import java.util.List;
import cn.citycraft.Yum.manager.Repositories.Plugin;
import cn.citycraft.Yum.manager.Repositories.TagInfo;
public class PluginInfo {
public Plugin plugin;
public String url;
public String repo;
public List<TagInfo> tags;
public String getFileName() {
return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version);
}
public String getMavenUrl() {
return getMavenUrl(null);
}
public String getMavenUrl(String version) {
String ver = version;
if (ver == null && tags != null)
for (TagInfo tagInfo : tags)
if (tagInfo.tag.equalsIgnoreCase("1.7.10")) {
ver = tagInfo.version;
break;
}
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"), plugin.artifactId, ver == null ? plugin.version : ver);
}
}

View File

@ -0,0 +1,40 @@
/**
*
*/
package cn.citycraft.Yum.manager;
import java.util.ArrayList;
import java.util.List;
/**
* 源仓库序列化类
*
* @author 蒋天蓓
* 2015年8月31日下午7:41:53
*/
public class Repositories {
public class PackageInfo {
public String name;
public String url;
public List<Plugin> plugins = new ArrayList<>();
}
public class Plugin {
public String groupId;
public String artifactId;
public String description;
public String version;
public List<TagInfo> tags;
}
public class Repository {
public String id;
public String url;
public String type;
}
public class TagInfo {
public String tag;
public String version;
}
}

View File

@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -20,10 +21,9 @@ import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import cn.citycraft.Yum.repository.Package; import cn.citycraft.Yum.manager.Repositories.PackageInfo;
import cn.citycraft.Yum.repository.Plugin; import cn.citycraft.Yum.manager.Repositories.Plugin;
import cn.citycraft.Yum.repository.PluginInfo; import cn.citycraft.Yum.manager.Repositories.Repository;;
import cn.citycraft.Yum.repository.Repository;
/** /**
* 仓库管理类 * 仓库管理类
@ -44,22 +44,22 @@ public class RepositoryManager {
repos = new ArrayList<String>(); repos = new ArrayList<String>();
} }
public boolean addPackage(String urlstring) { public boolean addPackage(CommandSender sender, String urlstring) {
String json = getHtml(urlstring); String json = getHtml(urlstring);
if (json == "") if (json == "")
return false; return false;
Package pkg = jsonToPackage(json); PackageInfo pkg = jsonToPackage(json);
if (pkg == null) if (pkg == null)
return false; return false;
updatePackage(pkg); updatePackage(sender, pkg);
return true; return true;
} }
public boolean addRepositories(String urlstring) { public boolean addRepositories(CommandSender sender, String urlstring) {
if (urlstring == null || urlstring.isEmpty()) if (urlstring == null || urlstring.isEmpty())
return false; return false;
repos.add(urlstring); repos.add(urlstring);
return updateRepositories(urlstring); return updateRepositories(sender, urlstring);
} }
public void cacheToJson(FileConfiguration config) { public void cacheToJson(FileConfiguration config) {
@ -143,9 +143,9 @@ public class RepositoryManager {
} }
} }
public Package jsonToPackage(String json) { public PackageInfo jsonToPackage(String json) {
try { try {
return gson.fromJson(json, Package.class); return gson.fromJson(json, PackageInfo.class);
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {
return null; return null;
} }
@ -160,7 +160,7 @@ public class RepositoryManager {
} }
} }
public void updatePackage(Package pkg) { public void updatePackage(CommandSender sender, PackageInfo pkg) {
for (Plugin plugin : pkg.plugins) { for (Plugin plugin : pkg.plugins) {
PluginInfo pi = new PluginInfo(); PluginInfo pi = new PluginInfo();
pi.plugin = plugin; pi.plugin = plugin;
@ -168,19 +168,22 @@ public class RepositoryManager {
pi.repo = pkg.name; pi.repo = pkg.name;
plugins.put(plugin.groupId + "." + plugin.artifactId, pi); plugins.put(plugin.groupId + "." + plugin.artifactId, pi);
} }
sender.sendMessage("仓库: §e" + pkg.name + " §a更新成功!");
} }
public boolean updateRepositories(CommandSender sender) { public boolean updateRepositories(CommandSender sender) {
plugins.clear(); plugins.clear();
for (String string : repos) for (String string : repos)
if (updateRepositories(string)) if (updateRepositories(sender, string))
sender.sendMessage("§6源: §e" + string + " §a更新成功!"); sender.sendMessage("§6源: §e" + string + " §a更新成功!");
else else
sender.sendMessage("§6源: §e" + string + " §c更新失败!"); sender.sendMessage("§6源: §e" + string + " §c更新失败!");
return true; return true;
} }
public boolean updateRepositories(String urlstring) { public boolean updateRepositories(CommandSender sender, String urlstring) {
if (sender == null)
sender = Bukkit.getConsoleSender();
if (!urlstring.endsWith("repo.info")) if (!urlstring.endsWith("repo.info"))
urlstring = urlstring + "/repo.info"; urlstring = urlstring + "/repo.info";
String json = getHtml(urlstring); String json = getHtml(urlstring);
@ -190,7 +193,7 @@ public class RepositoryManager {
if (lrepo == null) if (lrepo == null)
return false; return false;
for (Repository repository : lrepo) for (Repository repository : lrepo)
addPackage(repository.url); addPackage(sender, repository.url);
return true; return true;
} }
} }

View File

@ -6,8 +6,6 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.Yum.repository.PluginInfo;
/** /**
* 自动更新类 * 自动更新类
* *

View File

@ -1,19 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.repository;
import java.util.ArrayList;
import java.util.List;
/**
* TODO
*
* @author 蒋天蓓
* 2015年8月31日下午7:42:22
*/
public class Package {
public String name;
public String url;
public List<Plugin> plugins = new ArrayList<>();
}

View File

@ -1,17 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.repository;
/**
* TODO
*
* @author 蒋天蓓
* 2015年8月31日下午7:42:54
*/
public class Plugin {
public String groupId;
public String artifactId;
public String description;
public String version;
}

View File

@ -1,26 +0,0 @@
package cn.citycraft.Yum.repository;
/**
* TODO
*
* @author 蒋天蓓
* 2015年8月31日下午7:43:19
*/
public class PluginInfo {
public Plugin plugin;
public String url;
public String repo;
public String getMavenUrl() {
return getMavenUrl(null);
}
public String getMavenUrl(String version) {
return String.format(url + (url.endsWith("/") ? "" : "/") + "%1$s/%2$s/%3$s/%2$s-%3$s.jar", plugin.groupId.replace(".", "/"),
plugin.artifactId, version == null ? plugin.version : version);
}
public String getFileName() {
return String.format("%1$s-%2$s.jar", plugin.artifactId, plugin.version);
}
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package cn.citycraft.Yum.repository;
/**
* TODO
*
* @author 蒋天蓓
* 2015年8月31日下午7:41:53
*/
public class Repository {
public String id;
public String url;
public String type;
}