mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
add update repo...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
04e6faa6be
commit
cf7368da66
@ -22,22 +22,26 @@ public class Yum extends JavaPlugin {
|
|||||||
public RepositoryManager repo;
|
public RepositoryManager repo;
|
||||||
public FileConfig config;
|
public FileConfig config;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
config = new FileConfig(this, "config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
CommandHandler cmdhandler = new CommandHandler(this);
|
CommandHandler cmdhandler = new CommandHandler(this);
|
||||||
this.getCommand("yum").setExecutor(cmdhandler);
|
this.getCommand("yum").setExecutor(cmdhandler);
|
||||||
this.getCommand("yum").setTabCompleter(cmdhandler);
|
this.getCommand("yum").setTabCompleter(cmdhandler);
|
||||||
|
|
||||||
plugman = new PluginsManager(this);
|
plugman = new PluginsManager(this);
|
||||||
download = new DownloadManager(this);
|
download = new DownloadManager(this);
|
||||||
repo = new RepositoryManager(this);
|
repo = new RepositoryManager(this);
|
||||||
config = new FileConfig(this, "config.yml");
|
repo.jsonToCache(config);
|
||||||
repo.jsonToCache(config.getString("cache"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (config != null)
|
repo.cacheToJson(config);
|
||||||
config.set("cache", repo.cacheToJson());
|
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,8 @@ public class CommandHandler implements CommandExecutor, TabCompleter {
|
|||||||
plugins = Arrays.asList(new String[] {
|
plugins = Arrays.asList(new String[] {
|
||||||
"add",
|
"add",
|
||||||
"list",
|
"list",
|
||||||
"clean"
|
"clean",
|
||||||
|
"update"
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
plugins = main.plugman.getPluginNames(false);
|
plugins = main.plugman.getPluginNames(false);
|
||||||
|
@ -48,6 +48,9 @@ public class CommandRepo extends BaseCommand {
|
|||||||
main.repo.clean();
|
main.repo.clean();
|
||||||
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
sender.sendMessage("§6仓库: §a缓存的插件信息已清理!");
|
||||||
break;
|
break;
|
||||||
|
case "update":
|
||||||
|
main.repo.updateRepositories(sender);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ 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.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import cn.citycraft.Yum.Yum;
|
import cn.citycraft.Yum.Yum;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
@ -26,6 +29,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
*/
|
*/
|
||||||
public class RepositoryManager {
|
public class RepositoryManager {
|
||||||
Gson gson;
|
Gson gson;
|
||||||
|
List<String> repos;
|
||||||
HashMap<String, PluginInfo> plugins;
|
HashMap<String, PluginInfo> plugins;
|
||||||
|
|
||||||
Yum main;
|
Yum main;
|
||||||
@ -34,6 +38,7 @@ public class RepositoryManager {
|
|||||||
this.main = yum;
|
this.main = yum;
|
||||||
gson = new Gson();
|
gson = new Gson();
|
||||||
plugins = new HashMap<String, PluginInfo>();
|
plugins = new HashMap<String, PluginInfo>();
|
||||||
|
repos = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clean() {
|
public void clean() {
|
||||||
@ -50,17 +55,20 @@ public class RepositoryManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cacheToJson() {
|
public void cacheToJson(FileConfiguration config) {
|
||||||
return gson.toJson(plugins);
|
config.set("repocache", gson.toJson(repos));
|
||||||
|
config.set("plugincache", gson.toJson(plugins));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean jsonToCache(String json) {
|
public boolean jsonToCache(FileConfiguration config) {
|
||||||
if (json == null || json == "") {
|
String repocache = config.getString("repocache");
|
||||||
plugins = new HashMap<String, PluginInfo>();
|
String plugincache = config.getString("plugincache");
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
plugins = gson.fromJson(json, new TypeToken<HashMap<String, PluginInfo>>() {
|
if (repocache != null && repocache != "")
|
||||||
|
repos = gson.fromJson(repocache, new TypeToken<List<String>>() {
|
||||||
|
}.getType());
|
||||||
|
if (plugincache != null && plugincache != "")
|
||||||
|
plugins = gson.fromJson(plugincache, new TypeToken<HashMap<String, PluginInfo>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
return true;
|
return true;
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
@ -68,6 +76,19 @@ public class RepositoryManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean updateRepositories(CommandSender sender) {
|
||||||
|
plugins.clear();
|
||||||
|
for (String string : repos) {
|
||||||
|
if (addRepositories(string)) {
|
||||||
|
sender.sendMessage("§6源: §e" + string + " §a更新成功!");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("§6源: §e" + string + " §c更新失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage("§6源: §a所有的源已更新完成!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addRepositories(String urlstring) {
|
public boolean addRepositories(String urlstring) {
|
||||||
String json = getHtml(urlstring);
|
String json = getHtml(urlstring);
|
||||||
if (json == "") {
|
if (json == "") {
|
||||||
@ -80,6 +101,7 @@ public class RepositoryManager {
|
|||||||
for (Repository repository : lrepo) {
|
for (Repository repository : lrepo) {
|
||||||
addPackage(repository.url);
|
addPackage(repository.url);
|
||||||
}
|
}
|
||||||
|
repos.add(urlstring);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user