Class AbstractCustomItem
java.lang.Object
net.mathias2246.buildmc.api.item.AbstractCustomItem
- All Implemented Interfaces:
org.bukkit.Keyed
- Direct Known Subclasses:
AbstractTool
An abstract-class that can be used to define custom-item types for your plugin.
Custom items are defined by some data that is stored inside the ItemStack PDC.
This doesn't actually define a new item type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NotNull org.bukkit.NamespacedKeyThe NamespacedKey used to store the id of the custom item inside the ItemStack PDC -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCustomItem(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.NamespacedKey key) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract @NotNull org.bukkit.inventory.ItemStackCreates the default ItemStack for this custom-item typeabstract booleancanUse(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Checks if the player can interact in any way with this custom item.static @Nullable org.bukkit.NamespacedKeygetCustomItemKey(@Nullable org.bukkit.inventory.ItemStack item) Tries to read the custom item type from an ItemStack.@NotNull org.bukkit.NamespacedKeygetKey()@NotNull org.bukkit.plugin.PluginvoidgiveToPlayer(@NotNull org.bukkit.entity.Player player) Gives a single item of this type to a player.voidgiveToPlayer(@NotNull org.bukkit.entity.Player player, int amount) Gives a certain amount of this custom item to a player.voidgiveToPlayer(@NotNull org.bukkit.entity.Player player, @NotNull ItemMetaModifier modifier) Gives a single item of this type to a player and modifies the ItemMeta with a custom modifier.booleanisThis(@Nullable org.bukkit.inventory.ItemStack item) Checks if the given ItemStack is of this custom item type.protected abstract voidonInteract(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player left- or right-clicks with this custom-item type in his hand.voidonInteractEvent(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Called when a PlayerInteractEvent from the CustomItemListener was done with this custom item typeprotected abstract voidonLeftClick(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player left-clicks with this custom-item type in his hand.protected abstract voidonRightClick(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player right-clicks with this custom-item type in his hand.
-
Field Details
-
CUSTOM_ITEM_PDC_KEY
@NotNull public static final @NotNull org.bukkit.NamespacedKey CUSTOM_ITEM_PDC_KEYThe NamespacedKey used to store the id of the custom item inside the ItemStack PDC
-
-
Constructor Details
-
AbstractCustomItem
public AbstractCustomItem(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.NamespacedKey key)
-
-
Method Details
-
getPlugin
@NotNull public @NotNull org.bukkit.plugin.Plugin getPlugin()- Returns:
- The plugin that owns this custom type
-
getKey
@NotNull public @NotNull org.bukkit.NamespacedKey getKey()- Specified by:
getKeyin interfaceorg.bukkit.Keyed
-
getCustomItemKey
@Nullable public static @Nullable org.bukkit.NamespacedKey getCustomItemKey(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Tries to read the custom item type from an ItemStack.- Returns:
- The NamespacedKey for the custom item type or null if not found or invalid
-
giveToPlayer
public void giveToPlayer(@NotNull @NotNull org.bukkit.entity.Player player, int amount) Gives a certain amount of this custom item to a player. -
giveToPlayer
public void giveToPlayer(@NotNull @NotNull org.bukkit.entity.Player player) Gives a single item of this type to a player. -
giveToPlayer
public void giveToPlayer(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull ItemMetaModifier modifier) Gives a single item of this type to a player and modifies the ItemMeta with a custom modifier.- Parameters:
modifier- An implementation of a ItemMetaModifier to apply e.g. platform dependent modifications to the ItemMeta.
-
isThis
public boolean isThis(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Checks if the given ItemStack is of this custom item type.- Returns:
- True if the given ItemStack is of this type.
-
canUse
public abstract boolean canUse(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Checks if the player can interact in any way with this custom item. -
onInteractEvent
@Internal public void onInteractEvent(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Called when a PlayerInteractEvent from the CustomItemListener was done with this custom item type -
onInteract
protected abstract void onInteract(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player left- or right-clicks with this custom-item type in his hand. -
onLeftClick
protected abstract void onLeftClick(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player left-clicks with this custom-item type in his hand. -
onRightClick
protected abstract void onRightClick(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event) Executed when a player right-clicks with this custom-item type in his hand. -
buildDefaultItemStack
@NotNull protected abstract @NotNull org.bukkit.inventory.ItemStack buildDefaultItemStack()Creates the default ItemStack for this custom-item type
-