Class AutoRegister

java.lang.Object
com.miketheshadow.autoregister.AutoRegister

public final class AutoRegister extends Object
The core class of this tool. Automatically reads the jar file and attempts to register any listener and command available. Commands need to be annotated with CommandLoader Listeners need to extend Spigots Listener class.
  • Constructor Details

    • AutoRegister

      public AutoRegister(org.bukkit.plugin.Plugin plugin, String packageName)
      Parameters:
      plugin - Your plugin. Do not pass in another plugin but your own into this method, or you will end up with nothing working
      packageName - A package path using . as the separator. Example: com.miketheshadow.autoregister Where autoregister is the base package directory. Do not pass in something like com. or com.name as this could have the unintended effect of registering any library's listeners as well.
  • Method Details

    • enableDebugMessages

      public AutoRegister enableDebugMessages()
      Enable debug messages. Currently, the names of everything registered and the sizes/amounts of classes loaded are all that is logged.
      Returns:
      The instance of AutoRegister.
    • forceLoadAllClasses

      public AutoRegister forceLoadAllClasses()
      Enables the force loading of all classes. In some circumstances it's possible for things to not work as intended. force loading all classes will create a more significant delay on the speed of loading and should only be used if listeners are not registering properly.
      Returns:
      The instance of AutoRegister.
    • defaultSetup

      public void defaultSetup()
      This is what should be used by default. Unless you have your own custom auto-registry this method will handle the registering of commands and listeners for you.
    • registerListeners

      public void registerListeners() throws Exception
      Registers all listener classes
      Throws:
      Exception - This should probably never throw, but if it does contact me.
    • registerCommands

      public void registerCommands() throws Exception
      Throws:
      Exception - Like above this will probably never throw (if you're annotating the right things), but if it does send me a screenshot because that would be pretty breaking.
    • getClassesAnnotatedWith

      public <A extends Annotation> Set<Class<?>> getClassesAnnotatedWith(Class<A> annotation)
      Gets any class in the package annotated with annotation
      Type Parameters:
      A - Specifies the class is an annotation.
      Parameters:
      annotation - The annotation to filter the classes by.
      Returns:
      All classes annotated with the parameter.
    • getListeners

      public Set<Class<?>> getListeners()
      Returns:
      returns a Set of classes that implement Spigot's Listener class
    • getClasses

      public Set<Class<?>> getClasses()
      Returns:
      a set of every class in your project.