Entity.kt

Branches > main > bfb8108 > files / src / main / kotlin / net / bowmap / stormbow / game / Entity.kt

package net.bowmap.stormbow.game

import java.util.UUID
import net.kyori.adventure.text.Component

// An immutable reference to a mutable entity
// Can only call pure functions on this entity to get things from it
// And execute effects on it to do things to it

// Players also go under this category

/// An immutable game entity
interface Entity {
  val uuid: UUID
  val entityType: EntityType
}

enum class EntityType {
  ZOMBIE, PLAYER, UNKNOWN
}

data class UnknownEntity(override val uuid: UUID) : Entity {
  override val entityType = EntityType.UNKNOWN
}

/// An immutable player
data class Player(override val uuid: UUID, val name: Component) : Entity {
  override val entityType = EntityType.PLAYER
}

// TODO rename
fun fromBukkitPlayer(p: org.bukkit.entity.Player): Player =
  Player(uuid = p.uniqueId, name = p.displayName())

fun toGameEntity(e: org.bukkit.entity.Entity): Entity =
  UnknownEntity(uuid = e.uniqueId)