3 minutes estimated read time

Metadata

Vital is designed in a way to keep your project code as readable and as short as possible.
This means less writing to separate configuration files, more writing to your actual classes in code.

Because some implementations need additional metadata, like commands need a name, permissions, args, etc. Vital uses a system called metaprogramming to directly configure your classes in code.
Each class that must be fitted with additional metadata will fail to initialize or work if you don't provide them.

Metadata is always provided in the form of annotations.
For example, when you create a command, you must specify its name and permissions.
To do this, you must add an info annotation to your command class, e.g.:

MyCommand.java
@VitalCommand.Info(name = "mycommand", permission = "mycommand.permission.node", playerOnly = true)
public class MyCommand extends VitalCommand.Spigot {
  
}

This metadata info annotation is read when the command is constructed and will determine how your command behaves.

These annotations are not only limited to classes, you may also sometimes need to provide annotations to specific functions.
E.g., when you define arguments in a command.

MyCommand.java
@VitalCommand.Info(name = "mycommand", permission = "mycommand.permission.node", playerOnly = true)
public class MyCommand extends VitalCommand.Spigot {
  @ArgHandler(arg = @Arg(name = "somearg", permission = "mycommand.somearg.permission.node", playerOnly = true))
  public ReturnState onSomearg(Player player) {
    // ...
  }
}

Every class that supports these metadata info annotations implements the VitalHasInfo interface.
You can also define your own classes that support these info annotations.

MyCustomInfoClass.java
public class MyCustomInfoClass implements VitalHasInfo {
  private final Map<Class<? extends Annotation>, ? extends Annotation> info;
 
  @Override
  public Map<Class<? extends Annotation>, ? extends Annotation> getInfo() {
    return info;
  }
}

To retrieve an info annotation from any of these classes that support them, use getInfo(Class<? extends Annotation>).
Because classes may support multiple info annotations, VitalHasInfo will always be a Map<Class<? extends Annotation>, ? extends Annotation>.

MyCustomInfoClass.java
final VitalCommand.Info myCommandInfo = getInfo(VitalCommand.Info);

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann