From 4411a726ffb702270a9d875646ca0e72efe90735 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Fri, 12 Jun 2015 19:47:25 +0800 Subject: [PATCH] add VersionCheck... Signed-off-by: j502647092 --- .../RealBackpacks/util/VersionChecker.java | 62 +++++++++++++++++++ src/plugin.yml | 8 ++- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/cn/citycraft/RealBackpacks/util/VersionChecker.java diff --git a/src/cn/citycraft/RealBackpacks/util/VersionChecker.java b/src/cn/citycraft/RealBackpacks/util/VersionChecker.java new file mode 100644 index 0000000..aa78ffc --- /dev/null +++ b/src/cn/citycraft/RealBackpacks/util/VersionChecker.java @@ -0,0 +1,62 @@ +package cn.citycraft.RealBackpacks.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import com.google.common.base.Charsets; + +public class VersionChecker { + Plugin plugin; + + public VersionChecker(Plugin plugin) { + this.plugin = plugin; + } + + public void VersionCheck(final Player player) { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + String website = plugin.getDescription().getWebsite(); + String readURL = website + + (website.substring(website.length() - 1).equals("/") ? "" : "/") + + "/lastSuccessfulBuild/artifact/src/plugin.yml"; + FileConfiguration config; + String currentVersion = plugin.getDescription().getVersion(); + try { + URL url = new URL(readURL); + 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 + plugin.getName() + "插件最新版本 v" + newVersion, + ChatColor.RED + "服务器运行版本: v" + currentVersion, + ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + + plugin.getDescription().getWebsite() }; + if (player != null) { + player.sendMessage(msg); + } else { + for (String s : msg) { + plugin.getLogger().info(s); + } + } + } + } catch (IOException e) { + plugin.getLogger().warning("版本更新检查失败!"); + } + } + }); + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index b4e1682..1339494 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,18 +1,22 @@ name: RealBackpacks main: cn.citycraft.RealBackpacks.RealBackpacks -version: 0.1.4 +version: 0.1.5 author: Slayr288,喵♂呜 softdepend: [Vault] commands: rb: - description: Main commands. + description: 主命令. aliases: [realbackpacks, realb, rbs] permissions: rb.reload: + description: 重新载入插件! default: op rb.list: + description: 列出可购买背包! default: op rb.filetomysql: + description: 转换数据到MySql! default: op rb.fullview: + description: 完整查看别的玩家背包! default: op \ No newline at end of file