mirror of
https://e.coding.net/circlecloud/SimpleProtect.git
synced 2024-11-22 01:49:03 +00:00
add VersionChecker and add reload command...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
05c55841e3
commit
67e5d4bd3d
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
73
src/cn/citycraft/SimpleProtect/utils/VersionChecker.java
Normal file
73
src/cn/citycraft/SimpleProtect/utils/VersionChecker.java
Normal file
@ -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("版本更新检查失败!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
X: 0
|
||||
Y: 70
|
||||
Z: 0
|
@ -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你没有 <permission> 的权限来执行此命令!
|
||||
permissions:
|
||||
sp.*:
|
||||
description: 插件所有权限!
|
||||
default: op
|
||||
children:
|
||||
sp.setspawn: true
|
||||
sp.ignore.*: true
|
||||
sp.setspawn:
|
||||
description: 允许配置插件出生点!
|
||||
default: op
|
||||
sp.ignore.*:
|
||||
description: 允许忽略插件的检测!
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user