
walkmc.hologram.api.Hologram.kt Maven / Gradle / Ivy
package walkmc.hologram.api
import org.bukkit.*
import org.bukkit.entity.*
import org.bukkit.inventory.*
import walkmc.block.*
import walkmc.collections.*
import walkmc.hologram.entity.*
import java.util.*
/**
* Represents a base interface for any hologram.
*/
interface Hologram {
/**
* The world that's this hologram resides.
*/
val world: World
/**
* The location that's this hologram resides.
*/
val location: Location
/**
* The NMS entity holding this hologram.
*/
val handler: EntityHologram
/**
* The bukkit entity holding this hologram.
*/
val entity: ArmorStand
/**
* The holding entity id of this hologram.
*/
val hologramId: UUID
get() = handler.uniqueID
/**
* All lines of this hologram.
*/
var lines: IndexList
/**
* The visibility of this hologram.
*/
var visibility: HologramVisibility
/**
* If this hologram will be deleted when the server disables.
*/
var deleteOnDisable: Boolean
/**
* Returns if this hologram is deleted.
*/
var isDeleted: Boolean
/**
* Returns if this hologram has any children lines.
*/
val hasLines: Boolean
get() = lines.isNotEmpty()
/**
* Returns the height of this hologram.
*/
val height: Double
get() = lines.sumOf { it.height }
/**
* Displays this hologram in the specified [location].
*/
fun display(location: Location)
/**
* Deletes this hologram.
*/
fun delete()
/**
* Move this hologram in the specified [location].
*
* @param broadcast if must send a teleport packet for all near players.
*/
fun move(location: Location, broadcast: Boolean = true)
/**
* Gets a hologram line in the specified [index]
*/
fun getLine(index: Int): Line = lines[index]
/**
* Adds a hologram [line] in the last position of this hologram.
*/
fun addLine(line: Line) = lines.add(line)
/**
* Adds a hologram [line] in the first position of this hologram.
*/
fun addLineFirst(line: Line) = lines.addFirst(line)
/**
* Removes a line from this hologram in the specified [index].
*/
fun removeLine(index: Int) {
try {
lines.removeAt(index)
} catch (ex: Exception) {
}
}
/**
* Removes a [line] from this hologram in the specified.
*/
fun removeLine(line: Line) {
try {
lines.remove(line)
} catch (ex: Exception) {
}
}
/**
* Sets a [line] in the specified [index] in this hologram.
*/
fun setLine(index: Int, line: Line) {
try {
lines[index] = line
} catch (ex: Exception) {
}
}
/**
* Creates a new text line that's this hologram supports.
*/
fun createTextLine(text: String): TextLine
/**
* Creates a new item line that's this hologram supports.
*/
fun createItemLine(item: ItemStack): ItemLine
/**
* Creates a new text line that's this hologram supports and adds them to the last position.
*/
fun addTextLine(text: String): TextLine {
val line = createTextLine(text)
addLine(line)
return line
}
/**
* Creates a new item line that's this hologram supports and adds them to the last position.
*/
fun addItemLine(item: ItemStack): ItemLine {
val line = createItemLine(item)
addLine(line)
return line
}
/**
* An event handler for when a player interacts with this hologram.
*
* This is called when a player interacts with any line of this hologram.
*/
fun onInteract(player: Player, click: Click, line: Line)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy