1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-10 08:34:17 +02:00

Don't name each command Commandxxx

This commit is contained in:
md_5
2012-10-07 21:30:06 +11:00
parent 7be9114d1a
commit 41946a2da9

View File

@@ -86,33 +86,18 @@ public class EssentialsExtra extends JavaPlugin
for (File file : commandDir.listFiles()) for (File file : commandDir.listFiles())
{ {
String name = file.getName(); String fileName = file.getName();
if (name.startsWith("Command") && name.endsWith(".class")) if (fileName.startsWith("Command") && fileName.endsWith(".class"))
{ {
String commandName = fileName.substring(7, fileName.length() - 7);
try try
{ {
registerCommand(name); AnnotatedCommand anot = Class.forName(fileName).getAnnotation(AnnotatedCommand.class);
getLogger().info("Loaded command " + name.substring(0, name.length() - 7));
}
catch (Exception ex)
{
getLogger().log(Level.SEVERE, "Could not register " + name, 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) if (anot == null)
{ {
throw new IllegalArgumentException("Command class is not annotated with AnnotatedCommand.class"); 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())) commandMap.register("Essentials", new Command(commandName, anot.description(), anot.usage(), Arrays.asList(anot.aliases()))
{ {
@Override @Override
public boolean execute(CommandSender cs, String label, String[] args) public boolean execute(CommandSender cs, String label, String[] args)
@@ -120,5 +105,15 @@ public class EssentialsExtra extends JavaPlugin
return handler.handleCommand(cs, this, label, args); return handler.handleCommand(cs, this, label, args);
} }
}); });
getLogger().info("Loaded command " + commandName);
}
catch (Exception ex)
{
getLogger().log(Level.SEVERE, "Could not register " + fileName, ex);
}
}
}
handler = new EssentialsCommandHandler(loader, "Command", "essentials.", ess);
} }
} }