Updata AutoUpdata ...

Signed-off-by: j502647092 <jtb1@163.com>
pull/1/HEAD
j502647092 2015-08-14 10:17:19 +08:00
parent a8b92a19a0
commit 95c26f5fbd
7 changed files with 170 additions and 57 deletions

20
.classpath Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

75
.gitignore vendored
View File

@ -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

View File

@ -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 20158113:29:32 TODO
*/
public class SimpleEssential extends JavaPlugin {
/**
*
*/
public TeleportControl tpcontrol;
/**
*
*/
private List<SimpleEssentialCommand> 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));

View File

@ -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;
/**
*

View File

@ -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);
}

View File

@ -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();

View File

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