From 67e5d4bd3da3fcd5e75d52cee96aaf1081dd0977 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Tue, 21 Jul 2015 20:28:52 +0800 Subject: [PATCH] add VersionChecker and add reload command... Signed-off-by: j502647092 --- .../SimpleProtect/SimpleProtect.java | 37 +++++++++- .../SimpleProtect/listen/NetherDoor.java | 17 ++--- .../SimpleProtect/utils/VersionChecker.java | 73 +++++++++++++++++++ src/config.yml | 10 +-- src/plugin.yml | 19 ++++- 5 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 src/cn/citycraft/SimpleProtect/utils/VersionChecker.java diff --git a/src/cn/citycraft/SimpleProtect/SimpleProtect.java b/src/cn/citycraft/SimpleProtect/SimpleProtect.java index ebddf11..73dd269 100644 --- a/src/cn/citycraft/SimpleProtect/SimpleProtect.java +++ b/src/cn/citycraft/SimpleProtect/SimpleProtect.java @@ -1,6 +1,10 @@ package cn.citycraft.SimpleProtect; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -11,6 +15,7 @@ import cn.citycraft.SimpleProtect.listen.HighRedstone; import cn.citycraft.SimpleProtect.listen.NetherDoor; import cn.citycraft.SimpleProtect.listen.Nightvision; import cn.citycraft.SimpleProtect.listen.Tip; +import cn.citycraft.SimpleProtect.utils.VersionChecker; public class SimpleProtect extends JavaPlugin { @@ -27,7 +32,8 @@ public class SimpleProtect extends JavaPlugin { @Override public void onEnable() { - getLogger().info("==========" + servername + pluginname + "=========="); + getServer().getConsoleSender().sendMessage( + "==========" + servername + pluginname + "=========="); PluginManager pm = Bukkit.getPluginManager(); @@ -39,7 +45,6 @@ public class SimpleProtect extends JavaPlugin { pm.registerEvents(new NetherDoor(this), this); getLogger().info("防止登录卡地狱门已加载!"); } - if (Config.getInstance().getBoolean("BreakFarm.Enable", true)) { pm.registerEvents(new BreakFarm(this), this); getLogger().info("防止玩家踩坏耕地已加载!"); @@ -58,8 +63,9 @@ public class SimpleProtect extends JavaPlugin { Bukkit.getScheduler().runTaskTimer(this, redstone, 20, 20); getLogger().info("防止玩家高频红石已加载!"); } - - getLogger().info("==========" + servername + pluginname + "=========="); + getServer().getConsoleSender().sendMessage( + "==========" + servername + pluginname + "=========="); + new VersionChecker(this); } @Override @@ -69,4 +75,27 @@ public class SimpleProtect extends JavaPlugin { pluginname = getmessage("pluginname"); } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + switch (args.length) { + case 1: + switch (args[0]) { + case "setspawn": + if (sender instanceof Player) { + Location l = ((Player) sender).getLocation(); + Config.getInstance().set("SafeNetherDoor.World", l.getWorld().getName()); + Config.getInstance().set("SafeNetherDoor.X", l.getBlockX()); + Config.getInstance().set("SafeNetherDoor.Y", l.getBlockY()); + Config.getInstance().set("SafeNetherDoor.Z", l.getBlockZ()); + sender.sendMessage(pluginname + Config.getMessage("SafeNetherDoor.Set")); + } + return true; + case "reload": + onLoad(); + sender.sendMessage(pluginname + "§a配置文件已重载!"); + } + break; + } + return false; + } } diff --git a/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java b/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java index 3220872..ea6c9c7 100644 --- a/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java +++ b/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java @@ -17,7 +17,8 @@ import cn.citycraft.SimpleProtect.config.Config; public class NetherDoor implements Listener { public FileConfiguration getConfig; - public Location spawn; + protected Location spawn; + SimpleProtect plugin; public NetherDoor(SimpleProtect main) { @@ -52,15 +53,11 @@ public class NetherDoor implements Listener { || loc_zleft.getBlock().getType() == Material.PORTAL || loc_zright.getBlock().getType() == Material.PORTAL) { p.sendMessage(plugin.getfullmsg("SafeNetherDoor.Tip")); - World lworld = Bukkit - .getWorld((String) Config.getInstance().get( - "SafeNetherDoor.World", "world")); - double lx = Config.getInstance().getInt("SafeNetherDoor.X", - 0); - double ly = Config.getInstance().getInt("SafeNetherDoor.Y", - 0); - double lz = Config.getInstance().getInt("SafeNetherDoor.Z", - 0); + World lworld = Bukkit.getWorld((String) Config.getInstance().get( + "SafeNetherDoor.World", "world")); + double lx = Config.getInstance().getInt("SafeNetherDoor.X", 0); + double ly = Config.getInstance().getInt("SafeNetherDoor.Y", 0); + double lz = Config.getInstance().getInt("SafeNetherDoor.Z", 0); spawn = new Location(lworld, lx, ly, lz); p.teleport(spawn); } diff --git a/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java b/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java new file mode 100644 index 0000000..5f4e593 --- /dev/null +++ b/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java @@ -0,0 +1,73 @@ +package cn.citycraft.SimpleProtect.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; + + public VersionChecker(Plugin plugin) { + this.plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); + this.VersionCheck(null); + } + + @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 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 { + plugin.getServer().getConsoleSender().sendMessage(msg); + } + } + } catch (IOException e) { + plugin.getLogger().warning("版本更新检查失败!"); + } + } + }); + } + +} diff --git a/src/config.yml b/src/config.yml index b0faf48..3683943 100644 --- a/src/config.yml +++ b/src/config.yml @@ -11,7 +11,6 @@ Tip: Message: - '&a服务器已开启保护功能!' - '&c将会实时监控您的操作!' - - '&b城市世界请圈地后建筑!' - '&e挖矿请带上火把或药水!' #耕地保护配置 @@ -38,14 +37,15 @@ HighRedstone: Nightvision: #是否开启 Enable: true - Tip: '&c为防止无限夜视作弊,以阻止挖矿,请插火把或用夜视药水!' + Tip: '&c为防止无限夜视作弊,已阻止挖矿,请插火把或用夜视药水!' #安全地狱门 SafeNetherDoor: #是否开启 Enable: true Tip: '&5为防止您卡在地狱门,现在将您传送回主城!' + Set: '&a新的传送点已设置!' World: world - X: -51 - Y: 73 - Z: 38 \ No newline at end of file + X: 0 + Y: 70 + Z: 0 \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 63e10fc..37f2b09 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,24 @@ name: SimpleProtect main: cn.citycraft.SimpleProtect.SimpleProtect -version: 0.0.1 +website: http://ci.citycraft.cn:8800/jenkins/job/SimpleProtect/ +version: 0.0.2 +commands: + simpleprotect: + description: 简单保护插件 + aliaese: [sp] + usage: §b使用/sp help 查看帮助! + permission: sp.* + permission-message: §c你没有 的权限来执行此命令! permissions: + sp.*: + description: 插件所有权限! + default: op + children: + sp.setspawn: true + sp.ignore.*: true + sp.setspawn: + description: 允许配置插件出生点! + default: op sp.ignore.*: description: 允许忽略插件的检测! default: op