diff --git a/pom.xml b/pom.xml index 39d2953..7f11e03 100644 --- a/pom.xml +++ b/pom.xml @@ -1,19 +1,17 @@ 4.0.0 - cn.CityCraft + cn.citycraft SimpleProtect - 0.0.1-SNAPSHOT + 1.1 SimpleProtect + Minecraft 服务器保护插件 ${project.name} - src - src - - **/*.java - + src/main/resources + true @@ -21,10 +19,43 @@ maven-compiler-plugin 3.1 - 1.7 - 1.7 + 1.8 + 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + cn.citycraft:PluginHelper + org.mcstats.*:* + + + + + org.mcstats + ${project.groupId}.${project.artifactId}.mcstats + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + @@ -32,6 +63,14 @@ spigot-repo https://hub.spigotmc.org/nexus/content/groups/public/ + + citycraft-repo + http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/ + + + Plugin Metrics + http://repo.mcstats.org/content/repositories/public + @@ -40,6 +79,18 @@ jar 1.8.3-R0.1-SNAPSHOT + + cn.citycraft + PluginHelper + jar + 1.0 + + + org.mcstats.bukkit + metrics + R8-SNAPSHOT + compile + UTF-8 diff --git a/src/cn/citycraft/SimpleProtect/config/Config.java b/src/cn/citycraft/SimpleProtect/config/Config.java deleted file mode 100644 index 6776585..0000000 --- a/src/cn/citycraft/SimpleProtect/config/Config.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.citycraft.SimpleProtect.config; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.plugin.Plugin; - -public class Config extends ConfigLoader { - private static String CONFIG_NAME = "config.yml"; - private static FileConfig instance; - private static File file; - - public Config(Plugin p) { - super(p, CONFIG_NAME); - file = new File(p.getDataFolder(), CONFIG_NAME); - instance = super.getInstance(); - } - - public Config(Plugin p, String ver) { - super(p, CONFIG_NAME, ver); - instance = super.getInstance(); - } - - public static void load(Plugin p) { - new Config(p); - } - - public static void load(Plugin p, String ver) { - new Config(p, ver); - } - - public static FileConfig getInstance() { - return instance; - } - - public static String getMessage(String path) { - String message = instance.getString(path); - if (message != null) - message = message.replaceAll("&", "§"); - return message; - } - - public static String[] getStringArray(String path) { - return instance.getStringList(path).toArray(new String[0]); - } - - public static void save(){ - try { - instance.save(file); - } catch (IOException e) { - saveError(file); - e.printStackTrace(); - } - } -} diff --git a/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java b/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java deleted file mode 100644 index 3da94f3..0000000 --- a/src/cn/citycraft/SimpleProtect/config/ConfigLoader.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.citycraft.SimpleProtect.config; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.plugin.Plugin; - -public class ConfigLoader extends FileConfig { - protected static FileConfig config; - protected static boolean tip = true; - protected static Plugin plugin; - - public ConfigLoader(Plugin p, File file) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, null, true); - } - - public ConfigLoader(Plugin p, File file, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, null, res); - } - - public ConfigLoader(Plugin p, File file, String ver) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, ver, true); - } - - public ConfigLoader(Plugin p, File file, String ver, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, file, ver, res); - } - - public ConfigLoader(Plugin p, String filename) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), null, - true); - } - - public ConfigLoader(Plugin p, String filename, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), null, res); - } - - public ConfigLoader(Plugin p, String filename, String ver) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); - } - - public ConfigLoader(Plugin p, String filename, String ver, boolean res) { - ConfigLoader.plugin = p; - config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true); - } - - public static FileConfig getInstance() { - return config; - } - - public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) { - tip = res ; - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "..."); - } - if (!file.exists()) { - fileCreate(p, file, res); - } else { - if (ver != null) { - FileConfig configcheck = init(file); - String version = configcheck.getString("version"); - if (version == null || !version.equals(ver)) { - p.saveResource(file.getName(), true); - p.getLogger().warning( - "配置文件: " + file.getName() + " 版本过低 正在升级..."); - } - } - } - if (tip) - p.getLogger().info( - "载入配置文件: " + file.getName() - + (ver != null ? " 版本: " + ver : "")); - return init(file); - } - - private void fileCreate(Plugin p, File file, boolean res) { - if (res) { - p.saveResource(file.getName(), false); - } else { - try { - p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "..."); - file.createNewFile(); - } catch (IOException e) { - p.getLogger().info("配置文件" + file.getName() + "创建失败..."); - e.printStackTrace(); - } - } - } - - public static void saveError(File file) { - plugin.getLogger().info("配置文件" + file.getName() + "保存错误..."); - } - -} diff --git a/src/cn/citycraft/SimpleProtect/config/FileConfig.java b/src/cn/citycraft/SimpleProtect/config/FileConfig.java deleted file mode 100644 index 24a6c30..0000000 --- a/src/cn/citycraft/SimpleProtect/config/FileConfig.java +++ /dev/null @@ -1,108 +0,0 @@ -package cn.citycraft.SimpleProtect.config; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.configuration.Configuration; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.file.YamlConstructor; -import org.bukkit.configuration.file.YamlRepresenter; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.representer.Representer; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; - -/** - * An implementation of {@link Configuration} which saves all files in Yaml. Note that this - * implementation is not synchronized. - */ -public class FileConfig extends YamlConfiguration { - - public static FileConfig init(File file) { - return FileConfig.loadConfiguration(file); - } - - public static FileConfig loadConfiguration(File file) { - Validate.notNull(file, "File cannot be null"); - FileConfig config = new FileConfig(); - try { - config.load(file); - } catch (FileNotFoundException ex) { - } catch (IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } catch (InvalidConfigurationException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } - return config; - } - - protected final DumperOptions yamlOptions = new DumperOptions(); - - protected final Representer yamlRepresenter = new YamlRepresenter(); - - protected final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); - - @Override - public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException { - Validate.notNull(file, "File cannot be null"); - final FileInputStream stream = new FileInputStream(file); - load(new InputStreamReader(stream, Charsets.UTF_8)); - } - - @Override - public void load(Reader reader) throws IOException, InvalidConfigurationException { - BufferedReader input = (reader instanceof BufferedReader) ? (BufferedReader) reader - : new BufferedReader(reader); - StringBuilder builder = new StringBuilder(); - try { - String line; - while ((line = input.readLine()) != null) { - builder.append(line); - builder.append('\n'); - } - } finally { - input.close(); - } - loadFromString(builder.toString()); - } - - @Override - public void save(File file) throws IOException { - Validate.notNull(file, "File cannot be null"); - Files.createParentDirs(file); - String data = saveToString(); - Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); - try { - writer.write(data); - } finally { - writer.close(); - } - } - - @Override - public String saveToString() { - yamlOptions.setIndent(options().indent()); - yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - String header = buildHeader(); - String dump = yaml.dump(getValues(false)); - if (dump.equals(BLANK_CONFIG)) { - dump = ""; - } - return header + dump; - } -} diff --git a/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java b/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java deleted file mode 100644 index e4524a1..0000000 --- a/src/cn/citycraft/SimpleProtect/utils/VersionChecker.java +++ /dev/null @@ -1,111 +0,0 @@ -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; - -/** - * @author 蒋天蓓 - * 2015年8月14日下午4:01:15 - * 自动更新类 - */ -public class VersionChecker implements Listener { - Plugin plugin; - public String checkurl = "https://coding.net/u/502647092/p/%s/git/raw/%s/src/plugin.yml"; - public String branch = "master"; - - /** - * @param plugin - * - 插件 - */ - public VersionChecker(Plugin plugin) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.versioncheck(null); - } - - /** - * @param plugin - * - 插件 - * @param branch - * - 分支名称 - */ - public VersionChecker(Plugin plugin, String branch) { - this.plugin = plugin; - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.checkurl = branch; - this.versioncheck(null); - } - - /** - * 获取插件更新链接 - * - * @param pluginName - * - 插件名称 - * @param branch - * - 插件分支 - * @return 更新链接 - */ - 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()); - } - } - - /** - * 开始更新 - * - * @param player - * - 获取更新的玩家(null则默认为控制台) - */ - 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("版本更新检查失败!"); - } - } - }); - } - -} diff --git a/src/cn/citycraft/SimpleProtect/SimpleProtect.java b/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java similarity index 68% rename from src/cn/citycraft/SimpleProtect/SimpleProtect.java rename to src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java index 794978c..8c6f8c8 100644 --- a/src/cn/citycraft/SimpleProtect/SimpleProtect.java +++ b/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java @@ -4,8 +4,9 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import cn.citycraft.PluginHelper.config.FileConfig; +import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.SimpleProtect.command.SimpleProtectCommand; -import cn.citycraft.SimpleProtect.config.Config; import cn.citycraft.SimpleProtect.listen.BreakFarm; import cn.citycraft.SimpleProtect.listen.Explosion; import cn.citycraft.SimpleProtect.listen.HighRedstone; @@ -13,71 +14,69 @@ import cn.citycraft.SimpleProtect.listen.NetherDoor; import cn.citycraft.SimpleProtect.listen.Nightvision; import cn.citycraft.SimpleProtect.listen.Spam; import cn.citycraft.SimpleProtect.listen.Tip; -import cn.citycraft.SimpleProtect.utils.VersionChecker; public class SimpleProtect extends JavaPlugin { public String servername; public String pluginname; public Spam spam = new Spam(this); + public FileConfig config; public String getfullmsg(String path) { return servername + pluginname + " " + getmessage(path); } public String getmessage(String path) { - return Config.getMessage(path); + return config.getMessage(path); } @Override public void onEnable() { - getServer().getConsoleSender().sendMessage( - "==========" + servername + pluginname + "=========="); + getServer().getConsoleSender().sendMessage("==========" + servername + pluginname + "=========="); PluginManager pm = Bukkit.getPluginManager(); - if (Config.getInstance().getBoolean("Tip.Enable", true)) { + if (config.getBoolean("Tip.Enable", true)) { pm.registerEvents(new Tip(this), this); getLogger().info("保护插件提醒功能已加载!"); } - if (Config.getInstance().getBoolean("SafeNetherDoor.Enable", true)) { + if (config.getBoolean("SafeNetherDoor.Enable", true)) { pm.registerEvents(new NetherDoor(this), this); getLogger().info("防止登录卡地狱门已加载!"); } - if (Config.getInstance().getBoolean("BreakFarm.Enable", true)) { + if (config.getBoolean("BreakFarm.Enable", true)) { pm.registerEvents(new BreakFarm(this), this); getLogger().info("防止玩家踩坏耕地已加载!"); } - if (Config.getInstance().getBoolean("Explosion.Enable", true)) { + if (config.getBoolean("Explosion.Enable", true)) { pm.registerEvents(new Explosion(), this); getLogger().info("防止爆炸破坏地形已加载!"); } - if (Config.getInstance().getBoolean("Nightvision.Enable", true)) { + if (config.getBoolean("Nightvision.Enable", true)) { pm.registerEvents(new Nightvision(this), this); getLogger().info("防止无限夜视作弊已加载!"); } - if (Config.getInstance().getBoolean("HighRedstone.Enable", true)) { + if (config.getBoolean("HighRedstone.Enable", true)) { HighRedstone redstone = new HighRedstone(this); pm.registerEvents(redstone, this); Bukkit.getScheduler().runTaskTimer(this, redstone, 20, 20); getLogger().info("防止玩家高频红石已加载!"); } - if (Config.getInstance().getBoolean("Spam.Enable", true)) { + if (config.getBoolean("Spam.Enable", true)) { Bukkit.getPluginManager().registerEvents(spam, this); - int resettime = Config.getInstance().getInt("Spam.MuteReset") * 20; + int resettime = config.getInt("Spam.MuteReset") * 20; Bukkit.getScheduler().runTaskTimer(this, spam, resettime, resettime); getLogger().info("防止玩家聊天刷屏已加载!"); } getCommand("simpleprotect").setExecutor(new SimpleProtectCommand(this)); - getServer().getConsoleSender().sendMessage( - "==========" + servername + pluginname + "=========="); + getServer().getConsoleSender().sendMessage("==========" + servername + pluginname + "=========="); new VersionChecker(this); } @Override public void onLoad() { - Config.load(this, "1.0"); + config = new FileConfig(this); servername = getmessage("servername"); pluginname = getmessage("pluginname"); } diff --git a/src/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java b/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java similarity index 78% rename from src/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java rename to src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java index 9f1838f..f0cebfc 100644 --- a/src/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java +++ b/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java @@ -11,7 +11,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import cn.citycraft.SimpleProtect.SimpleProtect; -import cn.citycraft.SimpleProtect.config.Config; /** * @author Administrator @@ -36,11 +35,11 @@ public class SimpleProtectCommand implements CommandExecutor { 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(plugin.pluginname + Config.getMessage("SafeNetherDoor.Set")); + plugin.config.set("SafeNetherDoor.World", l.getWorld().getName()); + plugin.config.set("SafeNetherDoor.X", l.getBlockX()); + plugin.config.set("SafeNetherDoor.Y", l.getBlockY()); + plugin.config.set("SafeNetherDoor.Z", l.getBlockZ()); + sender.sendMessage(plugin.pluginname + plugin.config.getMessage("SafeNetherDoor.Set")); } return true; case "reload": @@ -49,9 +48,8 @@ public class SimpleProtectCommand implements CommandExecutor { return true; case "list": sender.sendMessage("§c当前被禁言的玩家有: "); - for (String player : plugin.spam.getCc()) { + for (String player : plugin.spam.getCc()) sender.sendMessage("§6 - " + player); - } return true; } break; @@ -62,20 +60,16 @@ public class SimpleProtectCommand implements CommandExecutor { case "add": if (p != null) { plugin.spam.getCc().add(p.getName()); - sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%", - p.getDisplayName())); - } else { + sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%", p.getDisplayName())); + } else sender.sendMessage(plugin.getfullmsg("Spam.OffLine")); - } return true; case "del": if (p != null && plugin.spam.getCc().contains(p.getName())) { plugin.spam.getCc().remove(p); - sender.sendMessage(plugin.getfullmsg("Spam.MuteOff").replace("%player%", - p.getDisplayName())); - } else { + sender.sendMessage(plugin.getfullmsg("Spam.MuteOff").replace("%player%", p.getDisplayName())); + } else sender.sendMessage(plugin.getfullmsg("Spam.NotMute")); - } return true; case "admin": if (args[1].equalsIgnoreCase("on")) { diff --git a/src/cn/citycraft/SimpleProtect/listen/BreakFarm.java b/src/main/java/cn/citycraft/SimpleProtect/listen/BreakFarm.java similarity index 100% rename from src/cn/citycraft/SimpleProtect/listen/BreakFarm.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/BreakFarm.java diff --git a/src/cn/citycraft/SimpleProtect/listen/Explosion.java b/src/main/java/cn/citycraft/SimpleProtect/listen/Explosion.java similarity index 100% rename from src/cn/citycraft/SimpleProtect/listen/Explosion.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/Explosion.java diff --git a/src/cn/citycraft/SimpleProtect/listen/HighRedstone.java b/src/main/java/cn/citycraft/SimpleProtect/listen/HighRedstone.java similarity index 73% rename from src/cn/citycraft/SimpleProtect/listen/HighRedstone.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/HighRedstone.java index 2523810..f023b9d 100644 --- a/src/cn/citycraft/SimpleProtect/listen/HighRedstone.java +++ b/src/main/java/cn/citycraft/SimpleProtect/listen/HighRedstone.java @@ -16,7 +16,6 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockRedstoneEvent; import cn.citycraft.SimpleProtect.SimpleProtect; -import cn.citycraft.SimpleProtect.config.Config; public class HighRedstone implements Runnable, Listener { @@ -32,38 +31,24 @@ public class HighRedstone implements Runnable, Listener { @EventHandler public void onRedClock(BlockRedstoneEvent event) { Block rb = event.getBlock(); - if (rb.getType() == Material.REDSTONE_WIRE) { + if (rb.getType() == Material.REDSTONE_WIRE) put(event.getBlock()); - } - } - - private void put(Block block) { - if (map.containsKey(block)) { - int i = map.remove(block); - map.put(block, i + 1); - } else { - map.put(block, 1); - } } @EventHandler(ignoreCancelled = true) public void RedStonePlace(BlockPlaceEvent event) { Block rb = event.getBlock(); Player rp = event.getPlayer(); - if (rb.getType() == Material.REDSTONE_WIRE) { + if (rb.getType() == Material.REDSTONE_WIRE) pmap.put(rb, rp); - } } @Override public void run() { List blocks = new ArrayList(); - for (Entry entry : map.entrySet()) { - if (entry.getValue() > Config.getInstance().getLong( - "HighRedstone.Maxevents")) { + for (Entry entry : map.entrySet()) + if (entry.getValue() > plugin.config.getLong("HighRedstone.Maxevents")) blocks.add(entry.getKey()); - } - } Boolean tip = true; for (Block block : blocks) { World rw = block.getWorld(); @@ -71,7 +56,7 @@ public class HighRedstone implements Runnable, Listener { int ry = block.getY(); int rz = block.getZ(); Player rp = pmap.get(block); - if (rp != null) { + if (rp != null) if (rp.isOp() || rp.hasPermission("sp.ignore.highredstone")) { if (!tipop.contains(rp)) { rp.sendMessage(plugin.getfullmsg("HighRedstone.Admin")); @@ -79,16 +64,10 @@ public class HighRedstone implements Runnable, Listener { } continue; } - } if (tip) { - Bukkit.broadcastMessage(plugin.getfullmsg("HighRedstone.Find") - .replaceAll("%world%", rw.getName()) - .replaceAll("%x%", rx + "").replaceAll("%y%", ry + "") - .replaceAll("%z%", rz + "")); + Bukkit.broadcastMessage(plugin.getfullmsg("HighRedstone.Find").replaceAll("%world%", rw.getName()).replaceAll("%x%", rx + "").replaceAll("%y%", ry + "").replaceAll("%z%", rz + "")); if (rp != null) { - Bukkit.broadcastMessage(plugin.getfullmsg( - "HighRedstone.Check").replaceAll("%player%", - rp.getName())); + Bukkit.broadcastMessage(plugin.getfullmsg("HighRedstone.Check").replaceAll("%player%", rp.getName())); pmap.remove(block); } tip = !tip; @@ -97,4 +76,12 @@ public class HighRedstone implements Runnable, Listener { } map.clear(); } + + private void put(Block block) { + if (map.containsKey(block)) { + int i = map.remove(block); + map.put(block, i + 1); + } else + map.put(block, 1); + } } diff --git a/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java b/src/main/java/cn/citycraft/SimpleProtect/listen/NetherDoor.java similarity index 66% rename from src/cn/citycraft/SimpleProtect/listen/NetherDoor.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/NetherDoor.java index ea6c9c7..6f4645b 100644 --- a/src/cn/citycraft/SimpleProtect/listen/NetherDoor.java +++ b/src/main/java/cn/citycraft/SimpleProtect/listen/NetherDoor.java @@ -12,7 +12,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; import cn.citycraft.SimpleProtect.SimpleProtect; -import cn.citycraft.SimpleProtect.config.Config; public class NetherDoor implements Listener { @@ -46,18 +45,13 @@ public class NetherDoor implements Listener { Location loc_xright = new Location(world, x - 1.0D, y, z); Location loc_zleft = new Location(world, x, y, z + 1.0D); Location loc_zright = new Location(world, x, y, z - 1.0D); - if (loc_top.getBlock().getType() == Material.PORTAL - || loc_bottom.getBlock().getType() == Material.PORTAL - || loc_xleft.getBlock().getType() == Material.PORTAL - || loc_xright.getBlock().getType() == Material.PORTAL - || loc_zleft.getBlock().getType() == Material.PORTAL - || loc_zright.getBlock().getType() == Material.PORTAL) { + if (loc_top.getBlock().getType() == Material.PORTAL || loc_bottom.getBlock().getType() == Material.PORTAL || loc_xleft.getBlock().getType() == Material.PORTAL + || loc_xright.getBlock().getType() == Material.PORTAL || 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) plugin.config.get("SafeNetherDoor.World", "world")); + double lx = plugin.config.getInt("SafeNetherDoor.X", 0); + double ly = plugin.config.getInt("SafeNetherDoor.Y", 0); + double lz = plugin.config.getInt("SafeNetherDoor.Z", 0); spawn = new Location(lworld, lx, ly, lz); p.teleport(spawn); } diff --git a/src/cn/citycraft/SimpleProtect/listen/Nightvision.java b/src/main/java/cn/citycraft/SimpleProtect/listen/Nightvision.java similarity index 100% rename from src/cn/citycraft/SimpleProtect/listen/Nightvision.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/Nightvision.java diff --git a/src/cn/citycraft/SimpleProtect/listen/Spam.java b/src/main/java/cn/citycraft/SimpleProtect/listen/Spam.java similarity index 83% rename from src/cn/citycraft/SimpleProtect/listen/Spam.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/Spam.java index f442f27..7ea692e 100644 --- a/src/cn/citycraft/SimpleProtect/listen/Spam.java +++ b/src/main/java/cn/citycraft/SimpleProtect/listen/Spam.java @@ -14,7 +14,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import cn.citycraft.SimpleProtect.SimpleProtect; -import cn.citycraft.SimpleProtect.config.Config; /** * @@ -47,16 +46,15 @@ public class Spam implements Runnable, Listener { SaveMsg(n, s); return false; } - if (lt + Config.getInstance().getLong("Spam.ChatWait", 1) > nt) { + if (lt + plugin.config.getLong("Spam.ChatWait", 1) > nt) { AntiMsg = plugin.getmessage("Spam.TooMuchChat"); return true; } - if (lm.equals(s)) { - if (lt + Config.getInstance().getLong("Spam.SameChatWait", 5) > nt) { + if (lm.equals(s)) + if (lt + plugin.config.getLong("Spam.SameChatWait", 5) > nt) { AntiMsg = plugin.getmessage("Spam.TooMuchSameChat"); return true; } - } AntiMsg = ""; SaveMsg(n, s); return false; @@ -71,16 +69,15 @@ public class Spam implements Runnable, Listener { SaveMsg(n, s); return false; } - if (lt + Config.getInstance().getLong("Spam.CommandWait", 1) > nt) { + if (lt + plugin.config.getLong("Spam.CommandWait", 1) > nt) { AntiMsg = plugin.getmessage("Spam.TooMuchCommand"); return true; } - if (lm.equals(s)) { - if (lt + Config.getInstance().getLong("Spam.SameCommandWait", 3) > nt) { + if (lm.equals(s)) + if (lt + plugin.config.getLong("Spam.SameCommandWait", 3) > nt) { AntiMsg = plugin.getmessage("Spam.TooMuchSameCommand"); return true; } - } SaveMsg(n, s); return false; } @@ -129,15 +126,13 @@ public class Spam implements Runnable, Listener { public void put(Player p) { if (tc.containsKey(p.getName())) { int t = tc.get(p.getName()); - if (t > Config.getInstance().getLong("Spam.MuteCheck", 3)) { + if (t > plugin.config.getLong("Spam.MuteCheck", 3)) { p.sendMessage(plugin.getfullmsg("Spam.MuteMsg")); cc.add(p.getName()); - } else { + } else tc.put(p.getName(), t + 1); - } - } else { + } else tc.put(p.getName(), 1); - } } @Override diff --git a/src/cn/citycraft/SimpleProtect/listen/Tip.java b/src/main/java/cn/citycraft/SimpleProtect/listen/Tip.java similarity index 50% rename from src/cn/citycraft/SimpleProtect/listen/Tip.java rename to src/main/java/cn/citycraft/SimpleProtect/listen/Tip.java index e7805b3..9743105 100644 --- a/src/cn/citycraft/SimpleProtect/listen/Tip.java +++ b/src/main/java/cn/citycraft/SimpleProtect/listen/Tip.java @@ -6,7 +6,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import cn.citycraft.SimpleProtect.SimpleProtect; -import cn.citycraft.SimpleProtect.config.Config; public class Tip implements Listener { SimpleProtect plugin; @@ -17,19 +16,14 @@ public class Tip implements Listener { @EventHandler public void onJoin(final PlayerJoinEvent e) { - plugin.getServer().getScheduler() - .runTaskLaterAsynchronously(plugin, new Runnable() { - @Override - public void run() { - Player p = e.getPlayer(); - String[] msg = Config.getStringArray("Tip.Message"); - for (String s : msg) { - s = s.replaceAll("&", "§"); - p.sendMessage(plugin.servername + plugin.pluginname - + s); - } + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, () -> { + Player p = e.getPlayer(); + String[] msg = plugin.config.getStringArray("Tip.Message"); + for (String s : msg) { + s = s.replaceAll("&", "§"); + p.sendMessage(plugin.servername + plugin.pluginname + s); } - }, 15); + } , 15); } } diff --git a/src/config.yml b/src/main/resources/config.yml similarity index 100% rename from src/config.yml rename to src/main/resources/config.yml diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 75% rename from src/plugin.yml rename to src/main/resources/plugin.yml index 23cabb7..bbad8dd 100644 --- a/src/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,9 @@ -name: SimpleProtect -main: cn.citycraft.SimpleProtect.SimpleProtect -website: http://ci.citycraft.cn:8800/jenkins/job/SimpleProtect/ -version: 0.0.2 +name: ${project.artifactId} +description: ${project.description} +main: ${project.groupId}.${project.artifactId}.${project.artifactId} +version: ${project.version} +auther: 喵♂呜 +website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ commands: simpleprotect: description: 简单保护插件