mirror of
https://e.coding.net/circlecloud/SimpleEssential.git
synced 2025-01-02 10:50:21 +00:00
Updata AutoUpdata ...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
a8b92a19a0
commit
95c26f5fbd
20
.classpath
Normal file
20
.classpath
Normal 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
75
.gitignore
vendored
@ -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
|
@ -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<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));
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 命令匹配检测
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
82
src/cn/citycraft/SimpleEssential/utils/VersionChecker.java
Normal file
82
src/cn/citycraft/SimpleEssential/utils/VersionChecker.java
Normal 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("版本更新检查失败!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user