-
Notifications
You must be signed in to change notification settings - Fork 21
Getting Started with Annotations
Java Annotations are a very useful tool for making development much more efficient and painless. It is one of many implementations by Oracle that make Java feel much less verbose. Today we will learn how to use Atlas's class scanner to automagically register all usages of annotations on load.
Please ensure that any class you would like to register has the @Init
annotation on top the class instance.
IMPORTANT: Ensure that your class does not include a constructor with parameters, or includes multiple constructors with one including no parameters. This will cause the scanner to error.
package me.you.project;
import cc.funkemunky.api.utils.Init;
@Init
public class MyClass {
}
This is how the scanner knows that your class contains information it needs to read. Without this tag, it will be skipped during the scanning process.
IMPORTANT: When running the scanner, ensure that you run it any objects with the @Init
tag are not being accessed before the scanning, as it may result in unwanted contents while the programs is running. This may cause erroring or bad memory leaks.
package cc.funkemunky.event;
import cc.funkemunky.api.Atlas;
import org.bukkit.plugin.java.JavaPlugin;
public class Victoria extends JavaPlugin {
@Override
public void onEnable() {
INSTANCE = this;
//Scanning for utils, command, listeners, etc.
Atlas.getInstance().initializeScanner(getClass(), this, true, true);
}
}