Making a new annotation question

I would like an easy way to implement commands, with each command being in its own class (I think I’ll make a separate package for these). So I derived an idea from SpongeAPI- you have to use the @Plugin annotation to get your plugin even viewed by Sponge. Can I make my own @spongeCommand annotation; create classes using the annotation then create something to look for all the @spongeCommand annotations, to then run the classes with the annotation?

Actually, this question might help better. Can someone explain to me (in a basic, probably short) how Sponge deals with the annotation? Or, link me to something, on how it works?

Thank you very much!

if your only goal is to have commands in separate classes you don’t need to go through so much trouble, this is possible within the sponge api itself.

Command Class

public class TestCommand implements CommandExecutor { public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { //do stuff } }
Registering command in main class

@Listener public void onInit(GameInitializationEvent event) { CommandSpec testCmd = CommandSpec.builder .executor(new TestCommand()) .build(); game.getCommandManager().register(this, testCmd, "test"); }

Before rolling out your own solution it is probably worth to look at existing libraries. I would recommend sk89q’s Intake.

Integration with Sponge should be easy using the low level API.

In reply to RysingDragon, That won’t work for me. I would still have to have a list of commands in a designated file, or put it all in the same area of onInit(), because of the “TestCommand()” part. I would need to hard-code/know the method, wouldn’t I?