All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.hologram.api.ItemLine.kt Maven / Gradle / Ivy

package walkmc.hologram.api

import net.minecraft.server.*
import org.bukkit.entity.*
import org.bukkit.entity.Item
import org.bukkit.inventory.ItemStack
import walkmc.collections.*
import walkmc.extensions.*
import walkmc.hologram.entity.*

/**
 * Represents an item line of a hologram.
 */
interface ItemLine : Line {
	
	/**
	 * The NMS entity holding this line.
	 */
	override val holder: EntityHologramItem
	
	/**
	 * The bukkit entity holding this line.
	 */
	override val holderEntity: Item
	
	/**
	 * All item options that this line can display.
	 */
	var options: IndexList
	
	/**
	 * Returns if the item of this item line is not AIR.
	 */
	override val hasOptions: Boolean
		get() = options.isNotEmpty()
	
	/**
	 * Returns if a player can pick up the current item displaying of this item line.
	 *
	 * Automatically when pickuping and this is true, the line will be deleted.
	 */
	var allowPickup: Boolean
	
	/**
	 * Changes the current item display of this item line by the specified [item].
	 */
	fun changeDisplay(item: ItemStack) {
		holder.itemStack = item.handlerCopy() ?: ItemStack(Blocks.BARRIER)
	}
	
	/**
	 * Gets an option from this item line by the specified [index].
	 */
	fun getOption(index: Int): ItemStack = options[index]
	
	/**
	 * Adds a [option] in the last position of this item line.
	 */
	fun addOption(option: ItemStack) = options.addLast(option)
	
	/**
	 * Adds a [option] in the first position of this item line.
	 */
	fun addOptionFirst(option: ItemStack) = options.addFirst(option)
	
	/**
	 * Removes an option from this item line in the specified [index].
	 */
	fun removeOption(index: Int) {
		try {
			options.removeAt(index)
		} catch (ex: Exception) {
		
		}
	}
	
	/**
	 * Sets a [option] in the specified [index] in this item line.
	 */
	fun setOption(index: Int, option: ItemStack) {
		try {
			options[index] = option
		} catch (ex: Exception) {
		
		}
	}
	
	/**
	 * Gets the current displaying option.
	 */
	fun currentOption() = options.current()
	
	/**
	 * An event handler for when a player pickups the item of this item line
	 */
	fun onPickup(player: Player)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy