
walkmc.hologram.common.Holograms.kt Maven / Gradle / Ivy
package walkmc.hologram.common
import net.minecraft.server.*
import org.bukkit.*
import org.bukkit.entity.*
import org.bukkit.entity.Entity
import walkmc.extensions.*
import walkmc.hologram.*
import walkmc.hologram.api.*
import walkmc.hologram.entity.*
/**
* Returns if this entity is a base of a hologram or a hologram line.
*/
val Entity.isHologram: Boolean
get() = handler is Hologram
/**
* Returns if this entity is a hologram text line or item line.
*/
val Entity.isHologramLine: Boolean
get() = handler is TextLine || handler is ItemLine
/**
* Returns if this entity is a hologram text line.
*/
val Entity.isHologramTextLine: Boolean
get() = handler is TextLine
/**
* Returns if this entity is a hologram item line.
*/
val Entity.isHologramItemLine: Boolean
get() = handler is ItemLine
/**
* Creates a new hologram with specified [text] as line.
*/
fun newHologram(text: String): Hologram {
val hologram = SimpleHologram()
hologram.addTextLine(text)
return hologram
}
/**
* Creates a new hologram with specified [text] as line.
*/
fun newHologram(text: String, location: Location): Hologram {
val hologram = SimpleHologram()
hologram.addTextLine(text)
hologram.display(location)
return hologram
}
/**
* Builds a newly created hologram and returns them.
*
* This doesn't display the hologram.
*/
inline fun buildHologram(text: String, crossinline block: Hologram.() -> Unit): Hologram =
newHologram(text).apply(block)
/**
* Builds a newly created hologram and returns them.
*
* The hologram will be displayed in the specified [location]
*/
inline fun buildHologram(
location: Location,
text: String,
crossinline block: Hologram.() -> Unit
): Hologram {
val hologram = buildHologram(text, block)
hologram.display(location)
return hologram
}
/**
* Builds a newly created moveable hologram and returns them.
*
* This doesn't display the hologram.
*/
inline fun buildMoveableHologram(
text: String,
crossinline block: MoveableHologram.() -> Unit
): MoveableHologram {
return MoveableHologram().apply {
addTextLine(text)
block(this)
}
}
/**
* Builds a newly created moveable hologram and returns them.
*
* The hologram will be displayed in the specified [location]
*/
inline fun buildMoveableHologram(
location: Location,
text: String,
crossinline block: MoveableHologram.() -> Unit
): Hologram {
val hologram = buildMoveableHologram(text, block)
hologram.display(location)
return hologram
}
/**
* Register a new hologram in the server.
*/
inline fun registerHologram() {
val java = T::class.java
val name = T::class.simpleName ?: return
EntityTypes.c[name] = java
EntityTypes.d[java] = name
EntityTypes.f[java] = EntityType.ARMOR_STAND.typeId.toInt()
}
fun registerSimpleHologramEntity() {
registerHologram()
registerHologram()
registerHologram()
registerHologram()
registerHologram()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy