diff options
author | md_5 <md_5@bigpond.com> | 2012-10-07 21:30:06 +1100 |
---|---|---|
committer | md_5 <md_5@bigpond.com> | 2012-10-07 21:30:06 +1100 |
commit | 41946a2da9199e5fafadeea4716daf389752fd9c (patch) | |
tree | 6b33377f1796e32f794bb653bb62a4243e157af9 | |
parent | 7be9114d1aa90ac2fcae3352e08fc0a9c13b803d (diff) | |
download | Essentials-41946a2da9199e5fafadeea4716daf389752fd9c.tar Essentials-41946a2da9199e5fafadeea4716daf389752fd9c.tar.gz Essentials-41946a2da9199e5fafadeea4716daf389752fd9c.tar.lz Essentials-41946a2da9199e5fafadeea4716daf389752fd9c.tar.xz Essentials-41946a2da9199e5fafadeea4716daf389752fd9c.zip |
Don't name each command Commandxxx
-rw-r--r-- | EssentialsExtra/src/net/ess3/extra/EssentialsExtra.java | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/EssentialsExtra/src/net/ess3/extra/EssentialsExtra.java b/EssentialsExtra/src/net/ess3/extra/EssentialsExtra.java index 53339bde2..9c2af2f55 100644 --- a/EssentialsExtra/src/net/ess3/extra/EssentialsExtra.java +++ b/EssentialsExtra/src/net/ess3/extra/EssentialsExtra.java @@ -86,39 +86,34 @@ public class EssentialsExtra extends JavaPlugin for (File file : commandDir.listFiles()) { - String name = file.getName(); - if (name.startsWith("Command") && name.endsWith(".class")) + String fileName = file.getName(); + if (fileName.startsWith("Command") && fileName.endsWith(".class")) { + String commandName = fileName.substring(7, fileName.length() - 7); try { - registerCommand(name); - getLogger().info("Loaded command " + name.substring(0, name.length() - 7)); + AnnotatedCommand anot = Class.forName(fileName).getAnnotation(AnnotatedCommand.class); + if (anot == null) + { + throw new IllegalArgumentException("Command class is not annotated with AnnotatedCommand.class"); + } + commandMap.register("Essentials", new Command(commandName, anot.description(), anot.usage(), Arrays.asList(anot.aliases())) + { + @Override + public boolean execute(CommandSender cs, String label, String[] args) + { + return handler.handleCommand(cs, this, label, args); + } + }); + getLogger().info("Loaded command " + commandName); } catch (Exception ex) { - getLogger().log(Level.SEVERE, "Could not register " + name, ex); + getLogger().log(Level.SEVERE, "Could not register " + fileName, ex); } } } handler = new EssentialsCommandHandler(loader, "Command", "essentials.", ess); } - - private void registerCommand(String name) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, NoSuchFieldException, SecurityException - { - - AnnotatedCommand anot = Class.forName(name).getAnnotation(AnnotatedCommand.class); - if (anot == null) - { - throw new IllegalArgumentException("Command class is not annotated with AnnotatedCommand.class"); - } - commandMap.register("Essentials", new Command(name.substring(0, name.length() - 7), anot.description(), anot.usage(), Arrays.asList(anot.aliases())) - { - @Override - public boolean execute(CommandSender cs, String label, String[] args) - { - return handler.handleCommand(cs, this, label, args); - } - }); - } } |