Package me.efekos.simpler.items
Class ItemManager
java.lang.Object
me.efekos.simpler.items.ItemManager
Static manager for
CustomItem
s. You can register your CustomItem
s using this class.-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.bukkit.NamespacedKey
Key that is used to save item ids ofCustomItem
s onItemStack
s. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.inventory.ItemStack
createStack
(CustomItem item) Creates an item stack using the custom item instance given.static CustomItem
getItem
(org.bukkit.inventory.ItemStack stack) Finds theCustomItem
instance of theItemStack
given.static void
giveItem
(@NotNull org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item) Adds anItemStack
to someone's inventory.static void
giveItem
(@NotNull org.bukkit.entity.Player player, org.bukkit.Material type) Gives someone anItemStack
of theMaterial
given.static void
giveItem
(org.bukkit.entity.Player player, CustomItem item) Creates anItemStack
for the item given, and gives it to the player.static void
giveSkull
(@NotNull org.bukkit.entity.Player player, org.bukkit.entity.Player skullOwner) Gives someone the skull of thePlayer
given.static void
giveSkull
(@NotNull org.bukkit.entity.Player player, org.bukkit.OfflinePlayer skullOwner) Gives someone the skull of theOfflinePlayer
given.static boolean
isCustom
(org.bukkit.inventory.ItemStack stack) Checks the stack to validate that it is a custom item instance.static void
Loads the custom item data from the plugin given before usingsetPlugin(JavaPlugin)
static void
registerItem
(org.bukkit.NamespacedKey key, Class<? extends CustomItem> item) Registers a custom item.static void
Saves the custom item data to the plugin given before usingsetPlugin(JavaPlugin)
static void
setPlugin
(org.bukkit.plugin.java.JavaPlugin plugin) Registers the event listeners using the plugin given.
-
Field Details
-
ITEM_UUID_KEY
public static final org.bukkit.NamespacedKey ITEM_UUID_KEYKey that is used to save item ids ofCustomItem
s onItemStack
s.
-
-
Constructor Details
-
ItemManager
public ItemManager()Creates a new instance if you somehow need one.
-
-
Method Details
-
saveCustomItems
public static void saveCustomItems()Saves the custom item data to the plugin given before usingsetPlugin(JavaPlugin)
-
loadCustomItems
public static void loadCustomItems()Loads the custom item data from the plugin given before usingsetPlugin(JavaPlugin)
-
setPlugin
public static void setPlugin(org.bukkit.plugin.java.JavaPlugin plugin) Registers the event listeners using the plugin given.- Parameters:
plugin
- An instance of the plugin that will use this manager.
-
registerItem
Registers a custom item.- Parameters:
key
- Identifier of this custom item type.item
- Class of the custom item.
-
createStack
Creates an item stack using the custom item instance given.- Parameters:
item
- An instance of a custom item.- Returns:
- The stack created.
- Throws:
IllegalStateException
- If a plugin isn't set
-
isCustom
public static boolean isCustom(org.bukkit.inventory.ItemStack stack) Checks the stack to validate that it is a custom item instance.- Parameters:
stack
- An item stack.- Returns:
- Whether the stack given is a custom item instance.
-
getItem
Finds theCustomItem
instance of theItemStack
given.- Parameters:
stack
- A stack.- Returns:
- A
CustomItem
instance if found,null
otherwise.
-
giveItem
Creates anItemStack
for the item given, and gives it to the player.- Parameters:
player
- A player that will receive this custom item.item
- ACustomItem
instance.
-
giveItem
public static void giveItem(@NotNull @NotNull org.bukkit.entity.Player player, org.bukkit.Material type) Gives someone anItemStack
of theMaterial
given.- Parameters:
player
- Someone to give an item.type
- Type of the item you want to give.
-
giveItem
public static void giveItem(@NotNull @NotNull org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack item) Adds anItemStack
to someone's inventory.- Parameters:
player
- Someone to give the stack.item
-ItemStack
you want to give.
-
giveSkull
public static void giveSkull(@NotNull @NotNull org.bukkit.entity.Player player, org.bukkit.OfflinePlayer skullOwner) Gives someone the skull of theOfflinePlayer
given.- Parameters:
player
-Player
who you want to give a skull.skullOwner
-OfflinePlayer
who will be the owner of this skull.
-
giveSkull
public static void giveSkull(@NotNull @NotNull org.bukkit.entity.Player player, org.bukkit.entity.Player skullOwner) Gives someone the skull of thePlayer
given.- Parameters:
player
-Player
who you want to give a skull.skullOwner
-Player
who will be the owner of this skull.
-