1
0
mirror of https://e.coding.net/circlecloud/RealBackpacks.git synced 2024-12-04 03:49:07 +00:00

add VersionCheck...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-06-12 19:47:25 +08:00
parent e3f38801ac
commit 4411a726ff
2 changed files with 68 additions and 2 deletions

View File

@ -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("版本更新检查失败!");
}
}
});
}
}

View File

@ -1,18 +1,22 @@
name: RealBackpacks name: RealBackpacks
main: cn.citycraft.RealBackpacks.RealBackpacks main: cn.citycraft.RealBackpacks.RealBackpacks
version: 0.1.4 version: 0.1.5
author: Slayr288,喵♂呜 author: Slayr288,喵♂呜
softdepend: [Vault] softdepend: [Vault]
commands: commands:
rb: rb:
description: Main commands. description: 主命令.
aliases: [realbackpacks, realb, rbs] aliases: [realbackpacks, realb, rbs]
permissions: permissions:
rb.reload: rb.reload:
description: 重新载入插件!
default: op default: op
rb.list: rb.list:
description: 列出可购买背包!
default: op default: op
rb.filetomysql: rb.filetomysql:
description: 转换数据到MySql!
default: op default: op
rb.fullview: rb.fullview:
description: 完整查看别的玩家背包!
default: op default: op