diff --git a/pom.xml b/pom.xml index 86a7a44..3dd3f08 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft SimpleProtect - 1.2 + 1.3 SimpleProtect Minecraft 服务器保护插件 @@ -33,14 +33,9 @@ cn.citycraft:PluginHelper - org.mcstats.*:* - - org.mcstats - ${project.groupId}.${project.artifactId}.mcstats - cn.citycraft.PluginHelper ${project.groupId}.${project.artifactId} @@ -67,17 +62,13 @@ citycraft-repo ${jenkins.url}/plugin/repository/everything/ - - Plugin Metrics - http://repo.mcstats.org/content/repositories/public - org.spigotmc spigot-api jar - 1.8.3-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT cn.citycraft @@ -85,12 +76,6 @@ jar 1.0 - - org.mcstats.bukkit - metrics - R8-SNAPSHOT - compile - UTF-8 diff --git a/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java b/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java index 914cbb1..21ede01 100644 --- a/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java +++ b/src/main/java/cn/citycraft/SimpleProtect/SimpleProtect.java @@ -1,11 +1,8 @@ package cn.citycraft.SimpleProtect; -import java.io.IOException; - import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.mcstats.Metrics; import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; @@ -20,23 +17,23 @@ import cn.citycraft.SimpleProtect.listen.Tip; public class SimpleProtect extends JavaPlugin { - public String servername; - public String pluginname; - public Spam spam = new Spam(this); public FileConfig config; + public String pluginname; + public String servername; + public Spam spam = new Spam(this); - public String getfullmsg(String path) { + public String getfullmsg(final String path) { return servername + pluginname + " " + getmessage(path); } - public String getmessage(String path) { + public String getmessage(final String path) { return config.getMessage(path); } @Override public void onEnable() { getServer().getConsoleSender().sendMessage("==========" + servername + pluginname + "=========="); - PluginManager pm = Bukkit.getPluginManager(); + final PluginManager pm = Bukkit.getPluginManager(); if (config.getBoolean("Tip.Enable", true)) { pm.registerEvents(new Tip(this), this); @@ -59,26 +56,20 @@ public class SimpleProtect extends JavaPlugin { getLogger().info("防止无限夜视作弊已加载!"); } if (config.getBoolean("HighRedstone.Enable", true)) { - HighRedstone redstone = new HighRedstone(this); + final HighRedstone redstone = new HighRedstone(this); pm.registerEvents(redstone, this); Bukkit.getScheduler().runTaskTimer(this, redstone, 20, 20); getLogger().info("防止玩家高频红石已加载!"); } - if (config.getBoolean("Spam.Enable", true)) { Bukkit.getPluginManager().registerEvents(spam, this); - int resettime = config.getInt("Spam.MuteReset") * 20; + final 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 + "=========="); new VersionChecker(this); - try { - Metrics metrics = new Metrics(this); - metrics.start(); - } catch (IOException e) { - } } @Override diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdd.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdd.java new file mode 100644 index 0000000..1a14825 --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdd.java @@ -0,0 +1,35 @@ +package cn.citycraft.SimpleProtect.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandAdd extends BaseCommand { + SimpleProtect plugin; + + public CommandAdd(final SimpleProtect main) { + super("add"); + this.plugin = main; + setMinimumArguments(1); + setDescription("禁言某个玩家"); + setPossibleArguments("<玩家名称>"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final String pname = args[0]; + final Player p = Bukkit.getPlayer(pname); + if (p != null) { + plugin.spam.getCc().add(pname); + sender.sendMessage(plugin.getfullmsg("Spam.MuteOn").replace("%player%", p.getDisplayName())); + } else { + sender.sendMessage(plugin.getfullmsg("Spam.OffLine")); + } + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdmin.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdmin.java new file mode 100644 index 0000000..cfa055c --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandAdmin.java @@ -0,0 +1,36 @@ +package cn.citycraft.SimpleProtect.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandAdmin extends BaseCommand { + SimpleProtect plugin; + + public CommandAdmin(final SimpleProtect main) { + super("admin"); + this.plugin = main; + setMinimumArguments(1); + setPossibleArguments("[on|off]"); + setDescription("开启管理员聊天模式"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final String toggle = args[0].toLowerCase(); + switch (toggle) { + case "on": + plugin.spam.setAdminchat(true); + sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOn")); + return; + case "off": + plugin.spam.setAdminchat(false); + sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOff")); + return; + } + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandDel.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandDel.java new file mode 100644 index 0000000..24a2ddd --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandDel.java @@ -0,0 +1,35 @@ +package cn.citycraft.SimpleProtect.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandDel extends BaseCommand { + SimpleProtect plugin; + + public CommandDel(final SimpleProtect main) { + super("delete", "del"); + this.plugin = main; + setMinimumArguments(1); + setDescription("解禁某个玩家"); + setPossibleArguments("<玩家名称>"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final String pname = args[0]; + final Player p = Bukkit.getPlayer(pname); + 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.NotMute")); + } + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandList.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandList.java new file mode 100644 index 0000000..8d72827 --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandList.java @@ -0,0 +1,48 @@ +package cn.citycraft.SimpleProtect.command; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.PluginHelper.utils.StringUtil; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandList extends BaseCommand { + SimpleProtect plugin; + + public CommandList(final SimpleProtect main) { + super("list"); + this.plugin = main; + setDescription("查看被禁言的玩家"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + sender.sendMessage(plugin.getfullmsg("Spam.MutePlayer")); + StringUtil.sendStringArray(sender, plugin.spam.getCc(), "§6 - "); + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { + if (args.length < 1) { + return null; + } + final String subcmd = args[0].toLowerCase(); + switch (subcmd) { + case "add": + case "del": + return plugin.spam.getCc(); + case "admin": + final List tg = new ArrayList(); + tg.add("on"); + tg.add("off"); + return tg; + } + return null; + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandReload.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandReload.java new file mode 100644 index 0000000..88a874a --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandReload.java @@ -0,0 +1,25 @@ +package cn.citycraft.SimpleProtect.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandReload extends BaseCommand { + SimpleProtect plugin; + + public CommandReload(final SimpleProtect main) { + super("reload"); + this.plugin = main; + setDescription("重载配置文件"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + plugin.onLoad(); + sender.sendMessage(plugin.pluginname + "§a配置文件已重载!"); + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/CommandSetSpawn.java b/src/main/java/cn/citycraft/SimpleProtect/command/CommandSetSpawn.java new file mode 100644 index 0000000..d56eabb --- /dev/null +++ b/src/main/java/cn/citycraft/SimpleProtect/command/CommandSetSpawn.java @@ -0,0 +1,32 @@ +package cn.citycraft.SimpleProtect.command; + +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.SimpleProtect.SimpleProtect; + +public class CommandSetSpawn extends BaseCommand { + SimpleProtect plugin; + + public CommandSetSpawn(final SimpleProtect main) { + super("setspawn"); + this.plugin = main; + setOnlyPlayerExecutable(); + setDescription("配置保护插件出生点"); + } + + @Override + public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final Location l = ((Player) sender).getLocation(); + 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")); + } + +} diff --git a/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java b/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java index 6a5e3dc..03b1ed8 100644 --- a/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java +++ b/src/main/java/cn/citycraft/SimpleProtect/command/SimpleProtectCommand.java @@ -3,92 +3,45 @@ */ package cn.citycraft.SimpleProtect.command; -import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.command.Command; +import org.bukkit.command.CommandException; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import cn.citycraft.PluginHelper.commands.DefaultCommand; +import cn.citycraft.PluginHelper.commands.HandlerSubCommand; import cn.citycraft.SimpleProtect.SimpleProtect; /** * @author Administrator * */ -public class SimpleProtectCommand implements CommandExecutor { +public class SimpleProtectCommand implements CommandExecutor, DefaultCommand { + + HandlerSubCommand hsc; SimpleProtect plugin; - /** - * @param simpleProtect - */ public SimpleProtectCommand(final SimpleProtect simpleProtect) { plugin = simpleProtect; + hsc = new HandlerSubCommand(plugin); + hsc.setDefaultCommand(this); + hsc.registerCommand(new CommandAdd(plugin)); + hsc.registerCommand(new CommandAdmin(plugin)); + hsc.registerCommand(new CommandDel(plugin)); + hsc.registerCommand(new CommandList(plugin)); + hsc.registerCommand(new CommandReload(plugin)); + hsc.registerCommand(new CommandSetSpawn(plugin)); + } + + @Override + public void defaultExecute(final CommandSender sender, final Command command, final String label) throws CommandException { + hsc.sendHelp(sender, label); } @Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { - switch (args.length) { - case 1: - switch (args[0]) { - case "setspawn": - if (sender instanceof Player) { - final Location l = ((Player) sender).getLocation(); - 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": - plugin.onLoad(); - sender.sendMessage(plugin.pluginname + "§a配置文件已重载!"); - return true; - case "list": - sender.sendMessage(plugin.getfullmsg("Spam.MutePlayer")); - for (final String player : plugin.spam.getCc()) { - sender.sendMessage("§6 - " + player); - } - return true; - } - break; - case 2: - final Player p = Bukkit.getPlayer(args[1]); - switch (args[0]) { - 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.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.NotMute")); - } - return true; - case "admin": - if (args[1].equalsIgnoreCase("on")) { - plugin.spam.setAdminchat(true); - sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOn")); - return true; - } - if (args[1].equalsIgnoreCase("off")) { - plugin.spam.setAdminchat(false); - sender.sendMessage(plugin.getfullmsg("Spam.AdminChatOff")); - return true; - } - break; - } - break; - } - return false; + return hsc.onCommand(sender, command, label, args); } }