Package redempt.redlib.enchants
Class EnchantRegistry
java.lang.Object
redempt.redlib.enchants.EnchantRegistry
A registry for custom enchantments owned by a single plugin
-
Constructor Summary
ConstructorDescriptionEnchantRegistry
(org.bukkit.plugin.Plugin plugin) Instantiates a new EnchantRegistry with a namer that prepends the gray chat colorEnchantRegistry
(org.bukkit.plugin.Plugin plugin, String prefix) Instantiates a new EnchantRegistryEnchantRegistry
(org.bukkit.plugin.Plugin plugin, Function<CustomEnchant, String> namer) Instantiates a new EnchantRegistry -
Method Summary
Modifier and TypeMethodDescriptionorg.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 itemvoid
clear()
Removes all CustomEnchants from this EnchantRegistrycombine
(Map<CustomEnchant, Integer> first, Map<CustomEnchant, Integer> second) Combines two maps of CustomEnchants to their levels, in the same way that normal enchantments would be combined at an anvilfromLoreLine
(String line) Gets a CustomEnchant and its level from a line of lorestatic EnchantRegistry
get
(org.bukkit.plugin.Plugin plugin) Gets the EnchantRegistry owned by the given pluginGets a CustomEnchant by its name or IDgetDisplayName
(CustomEnchant enchant) Gets the display name of a CustomEnchantredempt.redlib.commandmanager.ArgType<? extends CustomEnchant>
getEnchantArgType
(String name) Gets the ArgType for CustomEnchants in this registry, with tab completion using IDsgetEnchants
(org.bukkit.inventory.ItemStack item) Gets all the CustomEnchants on an itemorg.bukkit.plugin.Plugin
void
register
(CustomEnchant ench) Registers a CustomEnchant in this EnchantRegistryvoid
registerAll
(org.bukkit.plugin.Plugin plugin) Peeks inside a plugin's jar and registers all the classes which extend CustomEnchant inside it.
-
Constructor Details
-
EnchantRegistry
Instantiates a new EnchantRegistry- Parameters:
plugin
- The plugin that owns this EnchantRegistrynamer
- A function which will generate a display name for any given CustomEnchant
-
EnchantRegistry
Instantiates a new EnchantRegistry- Parameters:
plugin
- The plugin that owns this EnchantResgistryprefix
- 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
Gets the EnchantRegistry owned by the given plugin- Parameters:
plugin
- The plugin owning the requested EnchantRegistry- Returns:
- The EnchantRegistry owned by the plugin
-
getByName
Gets a CustomEnchant by its name or ID- Parameters:
name
- The name or ID of the enchantment- Returns:
- The CustomEnchant
-
getEnchants
- Returns:
- A collection of all the CustomEnchants in this EnchantRegistry
-
register
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
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
public Map<CustomEnchant,Integer> combine(Map<CustomEnchant, Integer> first, Map<CustomEnchant, Integer> second) 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 levelssecond
- 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 levelsitem
- The item to apply the enchants to- Returns:
- The enchanted item
-
fromLoreLine
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
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
-