mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-24 21:46:16 +00:00
Updata VersionChecker and rewrite DataBackup...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
@@ -10,45 +10,66 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
public class VersionChecker {
|
||||
Residence plugin;
|
||||
public class VersionChecker implements Listener {
|
||||
Plugin plugin;
|
||||
String checkurl = "https://coding.net/u/502647092/p/{0}/git/raw/{1}/src/plugin.yml";
|
||||
String branch = "master";
|
||||
|
||||
public VersionChecker(Residence plugin) {
|
||||
public VersionChecker(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.VersionCheck(null);
|
||||
}
|
||||
|
||||
// https://coding.net/u/502647092/p/SimpleEssential/git/raw/master/src/plugin.yml
|
||||
public VersionChecker(Plugin plugin, String branch) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.checkurl = branch;
|
||||
this.VersionCheck(null);
|
||||
}
|
||||
|
||||
public String getCheckUrl(String pluginName, String branch) {
|
||||
return String.format(checkurl, pluginName, branch);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().isOp()) {
|
||||
this.VersionCheck(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
public void VersionCheck(final Player player) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String readURL = "http://ci.citycraft.cn:8800/jenkins/job/Residence-Fix/lastSuccessfulBuild/artifact/src/plugin.yml";
|
||||
String readURL = getCheckUrl(plugin.getName(), branch);
|
||||
FileConfiguration config;
|
||||
String currentVersion = plugin.getDescription().getVersion();
|
||||
try {
|
||||
URL url = new URL(readURL);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),
|
||||
Charsets.UTF_8));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||
config = YamlConfiguration.loadConfiguration(br);
|
||||
String newVersion = config.getString("version");
|
||||
br.close();
|
||||
if (!newVersion.equals(currentVersion)) {
|
||||
String[] msg = new String[] {
|
||||
ChatColor.GREEN + "领地插件最新版本 v" + newVersion,
|
||||
ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion,
|
||||
ChatColor.RED + "服务器运行版本: v" + currentVersion,
|
||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE
|
||||
+ plugin.getDescription().getWebsite(),
|
||||
ChatColor.YELLOW
|
||||
+ "查看最新修改: "
|
||||
+ ChatColor.BLUE
|
||||
+ "http://ci.citycraft.cn:8800/jenkins/job/Residence-Fix/changes" };
|
||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite()
|
||||
};
|
||||
if (player != null) {
|
||||
player.sendMessage(msg);
|
||||
} else {
|
||||
plugin.consoleMessage(msg);
|
||||
plugin.getServer().getConsoleSender().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user