diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..a92a607
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index e6df42b..043fc2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,39 +1,38 @@
-# Eclipse stuff
-/.classpath
-/.settings
-
-# netbeans
-/nbproject
-
-# we use maven!
-/build.xml
-
-# maven
-/target
-/repo
-
-# vim
-.*.sw[a-p]
-
-# various other potential build files
-/build
-/bin
-/dist
-/manifest.mf
-
-/world
-
-# Mac filesystem dust
-*.DS_Store
-
-# intellij
-*.iml
-*.ipr
-*.iws
-.idea/
-
-# Project Stuff
-/src/main/resources/Soulbound
-
-# Atlassian Stuff
+# Eclipse stuff
+/.settings
+
+# netbeans
+/nbproject
+
+# we use maven!
+/build.xml
+
+# maven
+/target
+/repo
+
+# vim
+.*.sw[a-p]
+
+# various other potential build files
+/build
+/bin
+/dist
+/manifest.mf
+
+/world
+
+# Mac filesystem dust
+*.DS_Store
+
+# intellij
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# Project Stuff
+/src/main/resources/Soulbound
+
+# Atlassian Stuff
/atlassian-ide-plugin.xml
\ No newline at end of file
diff --git a/src/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/cn/citycraft/SimpleEssential/SimpleEssential.java
index 5a39984..654f3dc 100644
--- a/src/cn/citycraft/SimpleEssential/SimpleEssential.java
+++ b/src/cn/citycraft/SimpleEssential/SimpleEssential.java
@@ -25,12 +25,20 @@ import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand;
import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
+import cn.citycraft.SimpleEssential.utils.VersionChecker;
/**
* @author 蒋天蓓 2015年8月11日下午3:29:32 TODO
*/
public class SimpleEssential extends JavaPlugin {
+
+ /**
+ * 传送控制
+ */
public TeleportControl tpcontrol;
+ /**
+ * 命令监听列表
+ */
private List commandlist;
@Override
@@ -49,27 +57,25 @@ public class SimpleEssential extends JavaPlugin {
sender.sendMessage(e.getMessage());
}
}
- return false;
}
}
- return true;
+ return false;
}
@Override
public void onDisable() {
- this.getLogger().info("");
}
@Override
public void onEnable() {
+ tpcontrol = new TeleportControl(this);
this.registerCommands();
this.registerEvents();
- tpcontrol = new TeleportControl(this);
-
+ new VersionChecker(this);
}
/**
- * 注册监听
+ * 注册事件
*/
private void registerEvents() {
registerEvent(new PlayerLocationListen(this));
diff --git a/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java b/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java
index 99dde29..b6111ff 100644
--- a/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java
+++ b/src/cn/citycraft/SimpleEssential/command/SimpleEssentialCommand.java
@@ -74,9 +74,9 @@ public abstract class SimpleEssentialCommand {
public abstract String getPossibleArguments();
/**
- * 获得最小参数组
+ * 获得最小参数个数
*
- * @return 最小参数组
+ * @return 最小参数个数
*/
public abstract int getMinimumArguments();
@@ -92,8 +92,7 @@ public abstract class SimpleEssentialCommand {
* @throws CommandException
* - 命令异常
*/
- public abstract void execute(CommandSender sender, String label, String[] args)
- throws CommandException;
+ public abstract void execute(CommandSender sender, String label, String[] args) throws CommandException;
/**
* 命令匹配检测
diff --git a/src/cn/citycraft/SimpleEssential/config/ConfigLoader.java b/src/cn/citycraft/SimpleEssential/config/ConfigLoader.java
index d85fce3..e853cfb 100644
--- a/src/cn/citycraft/SimpleEssential/config/ConfigLoader.java
+++ b/src/cn/citycraft/SimpleEssential/config/ConfigLoader.java
@@ -32,8 +32,7 @@ public class ConfigLoader extends FileConfig {
public ConfigLoader(Plugin p, String filename) {
ConfigLoader.plugin = p;
- config = loadConfig(p, new File(p.getDataFolder(), filename), null,
- true);
+ config = loadConfig(p, new File(p.getDataFolder(), filename), null, true);
}
public ConfigLoader(Plugin p, String filename, boolean res) {
@@ -56,7 +55,7 @@ public class ConfigLoader extends FileConfig {
}
public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) {
- tip = res ;
+ tip = res;
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "...");
@@ -68,16 +67,23 @@ public class ConfigLoader extends FileConfig {
FileConfig configcheck = init(file);
String version = configcheck.getString("version");
if (version == null || !version.equals(ver)) {
+ p.getLogger().warning("配置文件: " + file.getName() + " 版本过低 正在升级...");
+ try {
+ configcheck.save(new File(file.getParent(), file.getName() + ".backup"));
+ p.getLogger()
+ .warning(
+ "配置文件: " + file.getName() + " 已备份为 " + file.getName()
+ + ".backup !");
+ } catch (IOException e) {
+ p.getLogger().warning("配置文件: " + file.getName() + "备份失败!");
+ }
p.saveResource(file.getName(), true);
- p.getLogger().warning(
- "配置文件: " + file.getName() + " 版本过低 正在升级...");
+ p.getLogger().info("配置文件: " + file.getName() + "升级成功!");
}
}
}
if (tip)
- p.getLogger().info(
- "载入配置文件: " + file.getName()
- + (ver != null ? " 版本: " + ver : ""));
+ p.getLogger().info("载入配置文件: " + file.getName() + (ver != null ? " 版本: " + ver : ""));
return init(file);
}
diff --git a/src/cn/citycraft/SimpleEssential/listen/PlayerLocationListen.java b/src/cn/citycraft/SimpleEssential/listen/PlayerLocationListen.java
index 4ce398d..1dfbb77 100644
--- a/src/cn/citycraft/SimpleEssential/listen/PlayerLocationListen.java
+++ b/src/cn/citycraft/SimpleEssential/listen/PlayerLocationListen.java
@@ -6,6 +6,7 @@ package cn.citycraft.SimpleEssential.listen;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
@@ -23,7 +24,7 @@ public class PlayerLocationListen implements Listener {
this.plugin = main;
}
- @EventHandler
+ @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent e) {
Player player = e.getEntity();
Location loc = player.getLocation();
diff --git a/src/cn/citycraft/SimpleEssential/utils/VersionChecker.java b/src/cn/citycraft/SimpleEssential/utils/VersionChecker.java
new file mode 100644
index 0000000..eeb2187
--- /dev/null
+++ b/src/cn/citycraft/SimpleEssential/utils/VersionChecker.java
@@ -0,0 +1,82 @@
+package cn.citycraft.SimpleEssential.utils;
+
+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.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.plugin.Plugin;
+
+import com.google.common.base.Charsets;
+
+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(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 = 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));
+ 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 {
+ plugin.getServer().getConsoleSender().sendMessage(msg);
+ }
+ }
+ } catch (IOException e) {
+ plugin.getLogger().warning("版本更新检查失败!");
+ }
+ }
+ });
+ }
+
+}