Class AbilityCreator

java.lang.Object
valorless.rarespawns.builders.AbilityCreator

public class AbilityCreator extends Object
AbilityCreator is responsible for loading, compiling, and managing custom abilities in the RareSpawns plugin. It handles the creation, retrieval, and management of ability classes, including reading ability source files and compiling them at runtime. Abilities are loaded from the plugin's 'abilities' folder and cached for efficient access.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static Boolean
    Indicates whether the abilities have been fully loaded and are ready for use.
    Set to true once all abilities are compiled and cached.
    This may take some time to complete, especially if there are many abilities to process.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addAbility(String id, Class<? extends Ability> abilityInstance)
    Adds a new ability to the collection with the provided ID.
    static HashMap<String,Class<? extends Ability>>
    Returns a clone of the abilities map containing all compiled ability classes.
    static Class<? extends Ability>
    Retrieves a compiled ability class by its unique ID.
    static Boolean
    Checks if the abilities are fully loaded and ready for use.
    Set to true once all abilities are compiled and cached.
    This may take some time to complete, especially if there are many abilities to process.
    static List<String>
    Retrieves the names of all files (excluding their extensions) in the 'abilities' folder of the plugin's data directory.
    static String
    readFile(String filename)
    Reads a file from the plugin's data folder.
    static void
    Reloads all abilities from the 'abilities' folder, compiling and caching them.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ready

      protected static Boolean ready
      Indicates whether the abilities have been fully loaded and are ready for use.
      Set to true once all abilities are compiled and cached.
      This may take some time to complete, especially if there are many abilities to process.
  • Constructor Details

    • AbilityCreator

      public AbilityCreator()
  • Method Details

    • isReady

      public static Boolean isReady()
      Checks if the abilities are fully loaded and ready for use.
      Set to true once all abilities are compiled and cached.
      This may take some time to complete, especially if there are many abilities to process.
      Returns:
      True if abilities are ready; false otherwise.
    • getAbilities

      public static HashMap<String,Class<? extends Ability>> getAbilities()
      Returns a clone of the abilities map containing all compiled ability classes.
      Returns:
      A cloned HashMap of ability IDs to compiled ability classes.
    • getAbility

      public static Class<? extends Ability> getAbility(String id)
      Retrieves a compiled ability class by its unique ID.
      Parameters:
      id - The unique ID of the ability.
      Returns:
      The compiled ability class, or null if not found.
    • addAbility

      public static boolean addAbility(String id, Class<? extends Ability> abilityInstance) throws Exception
      Adds a new ability to the collection with the provided ID. Validates the ID and ability before adding.
      Parameters:
      id - The unique ID of the ability to be added.
      abilityInstance - The compiled ability class to add.
      Returns:
      True if the ability was successfully added; false if the ID already exists or if an error occurs.
      Throws:
      Exception - If the ID is null or empty.
    • reload

      public static void reload()
      Reloads all abilities from the 'abilities' folder, compiling and caching them. It will either add new abilities or update existing ones. This method runs asynchronously to avoid blocking the main server thread.
    • readFile

      public static String readFile(String filename)
      Reads a file from the plugin's data folder.
      Parameters:
      filename - The name of the file to read from the "/abilities" folder.
      Returns:
      The contents of the file as a string.
      Throws:
      IOException - If an I/O error occurs while reading the file.
    • listAbilities

      public static List<String> listAbilities()
      Retrieves the names of all files (excluding their extensions) in the 'abilities' folder of the plugin's data directory.
      Returns:
      A List of file names without extensions.