diff --git a/pom.xml b/pom.xml index d1c16f4..0c4f88d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.citycraft SimpleEssential - 1.4 + 1.4.1 SimpleEssential 轻量级基础插件 diff --git a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java index 7a420e0..086a760 100644 --- a/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java +++ b/src/main/java/cn/citycraft/SimpleEssential/SimpleEssential.java @@ -3,17 +3,12 @@ */ package cn.citycraft.SimpleEssential; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.command.Command; -import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import cn.citycraft.PluginHelper.commands.BaseCommand; +import cn.citycraft.PluginHelper.commands.HandlerMainCommand; import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.SimpleEssential.command.CommandBack; @@ -47,42 +42,30 @@ public class SimpleEssential extends JavaPlugin { * 传送控制 */ public TeleportControl tpcontrol; + /** * 命令监听列表 */ - private List commandlist; FileConfig config; + /** + * 命令处理 + */ + HandlerMainCommand hmc; + @Override public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { - for (final BaseCommand command : commandlist) { - if (command.isValidTrigger(label)) { - if (!command.hasPermission(sender)) { - sender.sendMessage(I18n.p("Base.no-permission")); - return true; - } - if (command.isOnlyPlayerExecutable() && !(sender instanceof Player)) { - sender.sendMessage(I18n.p("Base.playercommand")); - return true; - } - if (args.length >= command.getMinimumArguments()) { - try { - command.execute(sender, cmd, label, args); - return true; - } catch (final CommandException e) { - sender.sendMessage(e.getMessage()); - } - } - } + if (!hmc.onCommand(sender, cmd, label, args)) { + hmc.sendHelp(sender); } - return false; + return true; } @Override public void onEnable() { this.initTeleportControl(); - this.registerCommands(); this.registerEvents(); + this.registerCommands(); new VersionChecker(this); } @@ -93,37 +76,27 @@ public class SimpleEssential extends JavaPlugin { } /** - * 注册命令 - * - * @param command - * - 被注册的命令类 - */ - public void registerCommand(final BaseCommand command) { - commandlist.add(command); - } - - /** - * 注册命令 + * 注册插件主要命令 */ public void registerCommands() { - commandlist = new ArrayList(); - registerCommand(new CommandTpa(this)); - registerCommand(new CommandTop(this)); - registerCommand(new CommandTpaccept(this)); - registerCommand(new CommandTpdeny(this)); - registerCommand(new CommandTphere(this)); - registerCommand(new CommandBack(this)); - registerCommand(new CommandSetHome(this)); - registerCommand(new CommandHome(this)); - registerCommand(new CommandHat(this)); - registerCommand(new CommandSuicide(this)); - registerCommand(new CommandEnchantBench(this)); - registerCommand(new CommandWorkBench(this)); - registerCommand(new CommandSetSpawn(this)); - registerCommand(new CommandSpawn(this)); - registerCommand(new CommandGc(this)); - registerCommand(new CommandWorld(this)); - registerCommand(new CommandPing(this)); + hmc = new HandlerMainCommand(this); + hmc.registerCommand(new CommandTpa(this)); + hmc.registerCommand(new CommandTop(this)); + hmc.registerCommand(new CommandTpaccept(this)); + hmc.registerCommand(new CommandTpdeny(this)); + hmc.registerCommand(new CommandTphere(this)); + hmc.registerCommand(new CommandBack(this)); + hmc.registerCommand(new CommandSetHome(this)); + hmc.registerCommand(new CommandHome(this)); + hmc.registerCommand(new CommandHat(this)); + hmc.registerCommand(new CommandSuicide(this)); + hmc.registerCommand(new CommandEnchantBench(this)); + hmc.registerCommand(new CommandWorkBench(this)); + hmc.registerCommand(new CommandSetSpawn(this)); + hmc.registerCommand(new CommandSpawn(this)); + hmc.registerCommand(new CommandGc(this)); + hmc.registerCommand(new CommandWorld(this)); + hmc.registerCommand(new CommandPing(this)); } /**