Package redempt.redlib.enchants
Class CustomEnchant
java.lang.Object
redempt.redlib.enchants.CustomEnchant
Represents a custom enchantment created by another plugin
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends org.bukkit.event.Event>
voidaddTrigger
(EnchantTrigger<T> trigger, BiConsumer<T, Integer> activate) Registers an EnchantTrigger with a listenerprotected <T extends org.bukkit.event.Event>
voidaddTrigger
(EnchantTrigger<T> trigger, BiConsumer<T, Integer> activate, BiConsumer<T, Integer> deactivate) Registers an EnchantTrigger with a listenerprotected boolean
appliesTo
(org.bukkit.Material type) Checks whether this CustomEnchant applies to a certain item typeorg.bukkit.inventory.ItemStack
apply
(org.bukkit.inventory.ItemStack item, int level) Applies this CustomEnchant to an item, replacing it if it was already present.final boolean
canApply
(org.bukkit.inventory.ItemStack item) Checks if this CustomEnchant can be applied to the given itemfinal boolean
canApply
(org.bukkit.Material type) Checks whether this CustomEnchant applies to the given typestatic int
fromRomanNumerals
(String romanNumerals) Converts roman numeral string, between 1 and 10, back to a numberfinal String
getId()
int
getLevel
(org.bukkit.inventory.ItemStack item) Gets the level of this CustomEnchant on an itemgetLore
(int level) Gets the lore that will be added to an item if this CustomEnchant is applied at the given levelfinal int
final String
getName()
final EnchantRegistry
final Map<EnchantTrigger<?>,
redempt.redlib.enchants.EnchantListener<?>> 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 levelboolean
isCompatible
(CustomEnchant ench) Checks if this CustomEnchant is compatible with another CustomEnchantfinal boolean
protected void
register
(EnchantRegistry registry) org.bukkit.inventory.ItemStack
remove
(org.bukkit.inventory.ItemStack item) Removes this CustomEnchant from the given itemstatic String
toRomanNumerals
(int num) Converts a number to roman numerals, between 1 and 10
-
Constructor Details
-
CustomEnchant
Constructs a new CustomEnchant- Parameters:
name
- The name of this CustomEnchantmaxLevel
- The max level of this CustomEnchant
-
-
Method Details
-
toRomanNumerals
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
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
-
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 registeractivate
- The callback for when this trigger is activateddeactivate
- 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 registeractivate
- The callback for when this trigger is activated
-
getIncompatible
- Returns:
- An array of all other CustomEnchants that are incompatible with this one
-
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
- Returns:
- The name of this CustomEnchant
-
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
- 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
- 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 tolevel
- 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
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
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.
-