Package wtf.choco.arrows.registry
Class ArrowRegistry
java.lang.Object
wtf.choco.arrows.registry.ArrowRegistry
- All Implemented Interfaces:
Iterable<AlchemicalArrow>
public final class ArrowRegistry extends Object implements Iterable<AlchemicalArrow>
Handles the registration of
AlchemicalArrow
implementations.- Author:
- Parker Hawke - Choco
-
Field Summary
Fields Modifier and Type Field Description static Set<org.bukkit.Material>
BOW_MATERIALS
-
Constructor Summary
Constructors Constructor Description ArrowRegistry()
-
Method Summary
Modifier and Type Method Description void
clear()
Clear all registry data.<T extends AlchemicalArrow>
Tget(@NotNull Class<T> clazz)
Get the registered instance of the provided AlchemicalArrow class.@Nullable AlchemicalArrow
get(@NotNull String key)
Get the registered instance of anAlchemicalArrow
according to its registered id.@Nullable AlchemicalArrow
get(@NotNull org.bukkit.inventory.ItemStack item)
Get the registered instance of an AlchemicalArrow represented by the provided ItemStack.@Nullable AlchemicalArrow
get(@NotNull org.bukkit.NamespacedKey key)
Get the registered instance of an AlchemicalArrow according to its unique namespaced key.@NotNull Collection<AlchemicalArrow>
getRegisteredArrows()
Get the registry for all instances of AlchemicalArrows.Iterator<AlchemicalArrow>
iterator()
void
register(@NotNull AlchemicalArrow arrow)
Register a custom AlchemicalArrow implementation.void
unregister(@NotNull Class<? extends AlchemicalArrow> arrowClass)
Unregister anAlchemicalArrow
implementation from the arrow registry based upon its class.void
unregister(@NotNull AlchemicalArrow arrow)
Unregister anAlchemicalArrow
implementation from the arrow registry.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
BOW_MATERIALS
-
-
Constructor Details
-
ArrowRegistry
public ArrowRegistry()
-
-
Method Details
-
register
Register a custom AlchemicalArrow implementation. All arrows must be registered here in order to be recognised by AlchemicalArrows when shooting custom arrows. The provided instance must have a unique, non-null key (AlchemicalArrow.getKey()
), as well as a unique, non-null ItemStack of typeMaterial.ARROW
.- Parameters:
arrow
- the arrow implementation to register- Throws:
IllegalArgumentException
- if arrow, its key or its ItemStack is null, or if the ItemStack is not of typeMaterial.ARROW
IllegalStateException
- if an arrow with the ID has already been registered, or an arrow with the ItemStack has already been registered
-
unregister
Unregister anAlchemicalArrow
implementation from the arrow registry. Note that upon unregistration, the arrow will no longer be recognised when attempting to shoot one.- Parameters:
arrow
- the arrow to unregister
-
unregister
Unregister anAlchemicalArrow
implementation from the arrow registry based upon its class. Note that upon unregistration, the arrow will no longer be recognised when attempting to shoot one.- Parameters:
arrowClass
- the class of the arrow to unregister
-
get
Get the registered instance of the provided AlchemicalArrow class. The registration instance provides various informational methods such as its representing ItemStack as well as a method to construct a new instance of the AlchemicalArrowEntity such that an instance ofArrow
is provided.- Type Parameters:
T
- the alchemical arrow class type- Parameters:
clazz
- the class of the AlchemicalArrow whose registration to get- Returns:
- the registered AlchemicalArrow. null if none
-
get
@Nullable public @Nullable AlchemicalArrow get(@NotNull @NotNull org.bukkit.inventory.ItemStack item)Get the registered instance of an AlchemicalArrow represented by the provided ItemStack. The registration instance provides various informational methods such as its representing ItemStack as well as a method to construct a new instance of the AlchemicalArrowEntity such that an instance ofArrow
is provided.- Parameters:
item
- the item of the AlchemicalArrow instance to retrieve- Returns:
- the registered AlchemicalArrow represented by the provided ItemStack. null if none
-
get
Get the registered instance of an AlchemicalArrow according to its unique namespaced key. The registration instance provides various informational methods such as its representing ItemStack as well as a method to construct a new instance of the AlchemicalArrowEntity such that an instance ofArrow
is provided.- Parameters:
key
- the unique key of the AlchemicalArrow instance to retrieve- Returns:
- the registered AlchemicalArrow represented by the provided ItemStack. null if none
-
get
Get the registered instance of anAlchemicalArrow
according to its registered id. The registration instance provides various informational methods such as its representing ItemStack as well as a method to construct a new instance of the AlchemicalArrowEntity such that an instance ofArrow
is provided.- Parameters:
key
- the registered NamespacedKey of the AlchemicalArrow instance to retrieve- Returns:
- the registered AlchemicalArrow represented by the provided key. null if none
-
getRegisteredArrows
Get the registry for all instances of AlchemicalArrows.- Returns:
- the arrow registration data
-
clear
public void clear()Clear all registry data. This will remove all data previously registered by AlchemicalArrows and by plugins that have registered their own arrows. -
iterator
- Specified by:
iterator
in interfaceIterable<AlchemicalArrow>
-