Class CustomEnchant

java.lang.Object
redempt.redlib.enchants.CustomEnchant

public abstract class CustomEnchant extends Object
Represents a custom enchantment created by another plugin
  • Constructor Details

    • CustomEnchant

      public CustomEnchant(String name, int maxLevel)
      Constructs a new CustomEnchant
      Parameters:
      name - The name of this CustomEnchant
      maxLevel - The max level of this CustomEnchant
  • Method Details

    • toRomanNumerals

      public static String toRomanNumerals(int num)
      Converts a number to roman numerals, between 1 and 10
      Parameters:
      num - The number to convert
      Returns:
      The roman numerals representation of the number
    • fromRomanNumerals

      public static int fromRomanNumerals(String romanNumerals)
      Converts roman numeral string, between 1 and 10, back to a number
      Parameters:
      romanNumerals - The roman numerals string
      Returns:
      The number represented by the roman numerals
    • register

      protected void register(EnchantRegistry registry)
    • addTrigger

      protected <T extends org.bukkit.event.Event> void addTrigger(EnchantTrigger<T> trigger, BiConsumer<T,Integer> activate, BiConsumer<T,Integer> deactivate)
      Registers an EnchantTrigger with a listener
      Type Parameters:
      T - The event type
      Parameters:
      trigger - The EnchantTrigger to register
      activate - The callback for when this trigger is activated
      deactivate - The callback for when this trigger is deactivated
    • addTrigger

      protected <T extends org.bukkit.event.Event> void addTrigger(EnchantTrigger<T> trigger, BiConsumer<T,Integer> activate)
      Registers an EnchantTrigger with a listener
      Type Parameters:
      T - The event type
      Parameters:
      trigger - The EnchantTrigger to register
      activate - The callback for when this trigger is activated
    • getIncompatible

      public CustomEnchant[] getIncompatible()
      Returns:
      An array of all other CustomEnchants that are incompatible with this one
    • getTriggers

      public final Map<EnchantTrigger<?>,redempt.redlib.enchants.EnchantListener<?>> getTriggers()
      Returns:
      The EventTrigger for this CustomEnchant
    • appliesTo

      protected boolean appliesTo(org.bukkit.Material type)
      Checks whether this CustomEnchant applies to a certain item type
      Parameters:
      type - The type to check
      Returns:
      Whether this CustomEnchant applies to the given type
    • getName

      public final String getName()
      Returns:
      The name of this CustomEnchant
    • getId

      public final String getId()
      Returns:
      The ID of this CustomEnchant, the same as a lowercase version of the name that has spaces replaced with underscores
    • getMaxLevel

      public final int getMaxLevel()
      Returns:
      The max level of this CustomEnchant
    • getRegistry

      public final EnchantRegistry getRegistry()
      Returns:
      The EnchantRegistry this CustomEnchant is registered to, or null if it has not yet been registered
    • isRegistered

      public final boolean isRegistered()
      Returns:
      Whether this CustomEnchant has been registered yet
    • getDisplayName

      public String getDisplayName()
      Returns:
      The display name of this CustomEnchant, generated using the namer function of its EnchantRegistry
    • apply

      public org.bukkit.inventory.ItemStack apply(org.bukkit.inventory.ItemStack item, int level)
      Applies this CustomEnchant to an item, replacing it if it was already present. Removes if level is 0.
      Parameters:
      item - The item to apply this CustomEnchant to
      level - The level to apply
      Returns:
      The enchanted item
    • remove

      public org.bukkit.inventory.ItemStack remove(org.bukkit.inventory.ItemStack item)
      Removes this CustomEnchant from the given item
      Parameters:
      item - The item to remove this CustomEnchant from
      Returns:
      The item with the enchant removed
    • getLevel

      public int getLevel(org.bukkit.inventory.ItemStack item)
      Gets the level of this CustomEnchant on an item
      Parameters:
      item - The item to check the level on
      Returns:
      The level on the item, 0 if it is absent or if the item is null
    • canApply

      public final boolean canApply(org.bukkit.inventory.ItemStack item)
      Checks if this CustomEnchant can be applied to the given item
      Parameters:
      item - The item to check
      Returns:
      False if this CustomEnchantment cannot be applied to the item's type, or one of the CustomEnchants already on the item is incompatible with this one, true otherwise
    • canApply

      public final boolean canApply(org.bukkit.Material type)
      Checks whether this CustomEnchant applies to the given type
      Parameters:
      type - The type
      Returns:
      Whether this CustomEnchant applies to the type
    • isCompatible

      public boolean isCompatible(CustomEnchant ench)
      Checks if this CustomEnchant is compatible with another CustomEnchant
      Parameters:
      ench - The CustomEnchant to check compatibility with
      Returns:
      Whether this CustomEnchant is compatible with the given enchant
    • getLore

      public String getLore(int level)
      Gets the lore that will be added to an item if this CustomEnchant is applied at the given level
      Parameters:
      level - The level to be specified in the lore
      Returns:
      The line of lore
    • increaseLevel

      public org.bukkit.inventory.ItemStack increaseLevel(org.bukkit.inventory.ItemStack itemStack, CustomEnchant customEnchant, int amount)
      Increase the level of this enchantment on an item, ensuring it does not exceed the maximum level
      Parameters:
      itemStack - The targeted item stack of which contains the CustomEnchant to be increased.
      customEnchant - The CustomEnchant to be increased on the ItemStack.
      amount - The amount to increase the enchant level by.
      Returns:
      The item stack with the increased enchant level.