Class EnchantRegistry

java.lang.Object
redempt.redlib.enchants.EnchantRegistry

public class EnchantRegistry extends Object
A registry for custom enchantments owned by a single plugin
  • Constructor Details

    • EnchantRegistry

      public EnchantRegistry(org.bukkit.plugin.Plugin plugin, Function<CustomEnchant,String> namer)
      Instantiates a new EnchantRegistry
      Parameters:
      plugin - The plugin that owns this EnchantRegistry
      namer - A function which will generate a display name for any given CustomEnchant
    • EnchantRegistry

      public EnchantRegistry(org.bukkit.plugin.Plugin plugin, String prefix)
      Instantiates a new EnchantRegistry
      Parameters:
      plugin - The plugin that owns this EnchantResgistry
      prefix - The prefix to be prepended to the name of any given CustomEnchant to create the display name
    • EnchantRegistry

      public EnchantRegistry(org.bukkit.plugin.Plugin plugin)
      Instantiates a new EnchantRegistry with a namer that prepends the gray chat color
      Parameters:
      plugin - The plugin that owns this EnchantRegistry
  • Method Details

    • get

      public static EnchantRegistry get(org.bukkit.plugin.Plugin plugin)
      Gets the EnchantRegistry owned by the given plugin
      Parameters:
      plugin - The plugin owning the requested EnchantRegistry
      Returns:
      The EnchantRegistry owned by the plugin
    • getByName

      public CustomEnchant getByName(String name)
      Gets a CustomEnchant by its name or ID
      Parameters:
      name - The name or ID of the enchantment
      Returns:
      The CustomEnchant
    • getEnchants

      public Collection<CustomEnchant> getEnchants()
      Returns:
      A collection of all the CustomEnchants in this EnchantRegistry
    • register

      public void register(CustomEnchant ench)
      Registers a CustomEnchant in this EnchantRegistry
      Parameters:
      ench - The CustomEnchant to register
    • getPlugin

      public org.bukkit.plugin.Plugin getPlugin()
      Returns:
      The plugin that owns this EnchantRegistry
    • clear

      public void clear()
      Removes all CustomEnchants from this EnchantRegistry
    • registerAll

      public void registerAll(org.bukkit.plugin.Plugin plugin)
      Peeks inside a plugin's jar and registers all the classes which extend CustomEnchant inside it. Note: Custom enchantment classes MUST have a constructor with no arguments to be loaded by this method
      Parameters:
      plugin - The plugin to load all CustomEnchants from
    • getEnchants

      public Map<CustomEnchant,Integer> getEnchants(org.bukkit.inventory.ItemStack item)
      Gets all the CustomEnchants on an item
      Parameters:
      item - The item to get the CustomEnchants from
      Returns:
      A map of each CustomEnchant on this item to its level
    • combine

      Combines two maps of CustomEnchants to their levels, in the same way that normal enchantments would be combined at an anvil
      Parameters:
      first - The first map of CustomEnchants to levels
      second - The second map of CustomEnchants to levels - Incompatible enchants will be removed from this map
      Returns:
      A map of the combined CustomEnchants to their levels
    • applyAll

      public org.bukkit.inventory.ItemStack applyAll(Map<CustomEnchant,Integer> enchants, org.bukkit.inventory.ItemStack item)
      Applies all the enchantments in a map of CustomEnchants to their levels to an item
      Parameters:
      enchants - The map of CustomEnchants to their levels
      item - The item to apply the enchants to
      Returns:
      The enchanted item
    • fromLoreLine

      public EnchantInfo fromLoreLine(String line)
      Gets a CustomEnchant and its level from a line of lore
      Parameters:
      line - The line of lore
      Returns:
      The EnchantInfo containing the enchantment type and level, or null if there was no CustomEnchant on the given line of lore
    • getDisplayName

      public String getDisplayName(CustomEnchant enchant)
      Gets the display name of a CustomEnchant
      Parameters:
      enchant - The Enchant to get the display name of
      Returns:
      The display name
    • getEnchantArgType

      public redempt.redlib.commandmanager.ArgType<? extends CustomEnchant> getEnchantArgType(String name)
      Gets the ArgType for CustomEnchants in this registry, with tab completion using IDs
      Parameters:
      name - The name to use for the argument type
      Returns:
      A CommandArgumentType for CustomEnchants in this registry