Files
src
build.gradle.kts
Code
5 823
src/main/kotlin/com/animatedcube/AnimatedCube.kt
package com.animatedcube
import org.bukkit.*
import org.bukkit.attribute.Attribute
import org.bukkit.boss.BarColor
import org.bukkit.boss.BarStyle
import org.bukkit.boss.BossBar
import org.bukkit.entity.ArmorStand
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitRunnable
import org.bukkit.util.Vector
import java.util.concurrent.ThreadLocalRandom
import kotlin.math.cos
import kotlin.math.sin
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.Sound
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent
class BossDamageListener : Listener {
@EventHandler
fun onDamage(e: EntityDamageByEntityEvent) {
val entity = e.entity
if (entity is ArmorStand) {
val cube = AnimatedCube.findByEntity(entity)
if (cube != null) {
cube.handleDamage(entity, e.damage)
e.isCancelled = true
}
}
}
}
class AnimatedCube(private val plugin: JavaPlugin, private val spawnLoc: Location) : BukkitRunnable() {
companion object {
private val activeCubes = mutableListOf<AnimatedCube>()
fun stopAll() {
activeCubes.forEach { it.destroy() }
activeCubes.clear()
}
fun findByEntity(entity: org.bukkit.entity.Entity): AnimatedCube? =
activeCubes.find { it.matchesEntity(entity) }
}
private val size = 2.5
private val cornerLength = 0.8
private val random = ThreadLocalRandom.current()
private val arenaRadius = 100.0
private var centerLoc = spawnLoc.clone()
private var targetLoc = spawnLoc.clone()
private var rotX = 0.0; private var rotY = 0.0; private var rotZ = 0.0
private var vX = 0.0; private var vY = 0.0; private var vZ = 0.0
private val corePoints = Array(51) { DoubleArray(3) }
private val edgePoints = mutableListOf<DoubleArray>()
private val fractalSteps = mutableListOf<List<DoubleArray>>()
private val fractalEnds = mutableListOf<Pair<Int, DoubleArray>>()
private val neonOrangeDust = Particle.DustOptions(Color.fromRGB(255, 80, 0), 0.8f)
private val purpleDust = Particle.DustOptions(Color.fromRGB(138, 43, 226), 1.0f)
private val redDust = Particle.DustOptions(Color.fromRGB(255, 0, 0), 1.2f)
private val yellowDust = Particle.DustOptions(Color.fromRGB(255, 255, 0), 1.0f)
private val whiteDust = Particle.DustOptions(Color.fromRGB(255, 255, 255), 0.6f)
private var tickCount = 0
private var revealProgress = 0.0
private var coreReveal = 0.0
private var fractalReveal = 0.0
private var cornerReveal = 0.0
private var health = 1000.0
private val maxHealth = 1000.0
private val bossBar: BossBar = Bukkit.createBossBar("§5§l⚡ Рефракция ⚡", BarColor.PURPLE, BarStyle.SEGMENTED_10)
private val hitbox: ArmorStand = (spawnLoc.world.spawnEntity(centerLoc, EntityType.ARMOR_STAND) as ArmorStand).apply {
isInvisible = true
isInvulnerable = false
setGravity(false)
isMarker = false
setAI(false)
isSilent = true
setSmall(true)
customName = "§5§lРефракция"
isCustomNameVisible = false
val attr = getAttribute(org.bukkit.attribute.Attribute.valueOf("GENERIC_MAX_HEALTH"))
if (attr != null) {
attr.baseValue = 1000.0
health = 1000.0
}
}
private var shieldStand: ArmorStand? = null
private var shieldHealth = 200.0
private val shieldMaxHealth = 200.0
private var shieldCooldown = 0
private var shellVisible = true
private data class GroundColumn(val x: Double, val z: Double, val baseY: Double, val createdTick: Int, val lifeTicks: Int, val height: Double)
private val groundColumns = mutableListOf<GroundColumn>()
private fun matchesEntity(entity: org.bukkit.entity.Entity): Boolean =
entity === hitbox || entity === shieldStand
private fun setEntityScale(entity: org.bukkit.entity.Entity, scale: Double) {
try {
val method = entity.javaClass.getMethod("setScale", java.lang.Double.TYPE)
method.invoke(entity, scale)
} catch (_: Exception) {
}
}
fun handleDamage(entity: org.bukkit.entity.Entity, damage: Double) {
if (entity === shieldStand) {
shieldHealth = (shieldHealth - damage).coerceAtLeast(0.0)
shieldStand?.health = shieldHealth
entity.world.playSound(entity.location, Sound.ITEM_SHIELD_BREAK, 1.0f, 1.0f)
entity.world.spawnParticle(Particle.CRIT, entity.location, 8, 0.4, 0.4, 0.4, 0.05)
if (shieldHealth <= 0.0) {
breakShield(600)
}
return
}
if (entity === hitbox) {
if (shieldStand != null) {
entity.world.playSound(entity.location, Sound.ITEM_SHIELD_BLOCK, 1.2f, 1.0f)
entity.world.spawnParticle(Particle.CRIT, entity.location, 6, 0.3, 0.3, 0.3, 0.05)
return
}
val newHealth = (hitbox.health - damage).coerceAtLeast(0.0)
hitbox.health = newHealth
if (newHealth <= 0) {
hitbox.remove()
}
}
}
private fun spawnShield() {
if (shieldStand != null) return
shieldHealth = shieldMaxHealth
shellVisible = true
shieldStand = (spawnLoc.world.spawnEntity(centerLoc.clone().add(0.0, -3.0, 0.0), EntityType.ARMOR_STAND) as ArmorStand).apply {
isInvisible = true
isInvulnerable = false
setGravity(false)
isMarker = false
setAI(false)
isSilent = true
setSmall(false)
customName = "§5§lРефракцияЩит"
isCustomNameVisible = false
val attr = getAttribute(org.bukkit.attribute.Attribute.valueOf("GENERIC_MAX_HEALTH"))
if (attr != null) {
attr.baseValue = shieldMaxHealth
health = shieldHealth
}
}
val scaleAttr = shieldStand!!.getAttribute(Attribute.SCALE)
scaleAttr?.baseValue = 5.0
hitbox.isMarker = true
}
private fun removeShield() {
shieldStand?.remove()
shieldStand = null
hitbox.isMarker = false
}
private fun breakShield(durationTicks: Int) {
shieldHealth = 0.0
removeShield()
shellVisible = false
shieldCooldown = durationTicks
centerLoc.world.playSound(centerLoc, Sound.ITEM_SHIELD_BREAK, 1.8f, 0.9f)
centerLoc.world.spawnParticle(Particle.EXPLOSION_EMITTER, centerLoc, 12, 1.0, 1.0, 1.0, 0.0)
}
private fun teleportHitboxes() {
hitbox.teleport(centerLoc)
shieldStand?.teleport(centerLoc.clone().add(0.0, -3.0, 0.0))
}
private var currentAttack: AttackType? = null
private var attackCooldown = 0
private var attackTick = 0
private var laserRotation = 0.0
private enum class AttackType {
GROUND_SLAM,