Effects.kt

Branches > main > bedd093 > files / src / main / kotlin / net / bowmap / stormbow / effect / Effects.kt

package net.bowmap.stormbow.effect

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor.*
import net.kyori.adventure.audience.Audience
import net.bowmap.stormbow.effect.*
import org.bukkit.inventory.ItemStack
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.entity.Entity
import net.bowmap.server.item.*

// TODO you can send a message to more than one audience
// I'd like audiences to just be able to be collections :/
data class SendMessage(val audience: Collection<Audience>, val message: Component) : DefaultEffect {
  override fun execute() {
    audience.forEach { a ->
      a.sendMessage(message)
    }
  }
}

data class Broadcast(val message: Component) : DefaultEffect {
  override fun execute() {
    Bukkit.broadcast(message)
  }
}

data class Debug(val id: String, val x: Any?) : DefaultEffect {
  override fun execute() {
    Bukkit.broadcast(Component.text("Debug ($id): $x", GRAY))
  }
}

// Also make Player, mutable players are yucky
data class Give(val player: Player, val items: List<Item>) : DefaultEffect {
  constructor(player: Player, item: Item) : this(player, listOf(item))
  override fun execute() {
    player.give(items.map(::toItemStack))
  }
}

/// Cancels the current action.
/// Events will generally call .setCancelled(true), but this is a logical action, and they could do something else.
class Cancel() : Effect
data class SetFishTime(val ticks: Int) : Effect
data class Teleport(val entity: Entity, val location: Location) : DefaultEffect {
  override fun execute() {
    entity.teleport(location)
  }
}