- import org.bukkit.Location
- import org.bukkit.util.Vector
- import taboolib.module.effect.Line
- val aimeds = mutableMapOf<ArmorStand, Pair<Entity, Double>>()
- val damage = 3.0
- val interval = 25L
- val distance = 1560
- fun main() {
- println("激光器 开始运行")
- // 检测目标
- submit(period = 5) {
- Bukkit.getWorlds().flatMap { it.entities }.forEach { entity ->
- if (entity.type != EntityType.ARMOR_STAND) {
- return@forEach
- }
- val armorStand = entity as ArmorStand
- if (armorStand.equipment?.helmet?.type != Material.END_ROD) {
- return@forEach
- }
- val muzzleLocation = armorStand.eyeLocation
- val target = sel(entity, arrayOf(EntityType.PHANTOM, EntityType.ZOMBIE)) ?: return@forEach run {
- if (!aimeds.contains(armorStand))
- armorStand.headPose = armorStand.headPose
- .setX(0.0)
- .setY(0.0)
- .setZ(0.0)
- }
- if (aimeds.contains(armorStand)) {
- return@forEach
- }
- aimeds.computeIfAbsent(armorStand) {
- target to damage
- }
- // 转头
- submit(period = 2L) {
- if (target.isDead()
- || !aimeds.contains(armorStand)
- || armorStand.location.distanceSquared(target.location) > distance
- || armorStand.isDead()
- ) {
- cancel()
- submit(async = true, delay = interval) {
- aimeds.remove(armorStand)
- }
- return@submit
- }
- val loc = armorStand.location.clone()
- // 屎山
- val bodyYaw = loc.yaw
- loc.direction = target.location.toVector().subtract(armorStand.location.toVector())
-
- armorStand.headPose = armorStand.headPose
- .setX(Math.toRadians(loc.pitch + 30.0))
- .setY(Math.toRadians((loc.yaw - bodyYaw).toDouble()))
- // info(vec.getYaw())
- // info(vec.getPitch())
- // info(Math.PI / (360 / armorStand.bodyPose.y))
- }
- // 发射
- submit(async = true, period = interval) {
- if (target.isDead()
- || !aimeds.contains(armorStand)
- || armorStand.location.distanceSquared(target.location) > distance
- || armorStand.isDead()
- ) {
- cancel()
- return@submit
- }
- armorStand.world.playSound(armorStand.location, Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.5f, 2.0f)
- Line.buildLine(
- muzzleLocation.toProxyLocation(),
- target.eyeLocation.toProxyLocation(),
- 0.2,
- object : ParticleSpawner {
- override fun spawn(location: taboolib.common.util.Location) {
- val location = location.toBukkitLocation()
- location.world!!.spawnParticle(
- Particle.REDSTONE,
- location.x,
- location.y,
- location.z,
- 1,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- Particle.DustOptions(
- Color.AQUA,
- max(
- 0.75f,
- min(5.0f, (aimeds[armorStand]!!.second / 25).toFloat())
- )
- )
- )
- }
- }
- )
- if (target is LivingEntity) {
- submit {
- target.damage(aimeds[armorStand]!!.second, armorStand)
- aimeds[armorStand] = aimeds[armorStand]!!.copy(second = aimeds[armorStand]!!.second * 1.25)
- }
- target.world.playSound(target.location, Sound.BLOCK_HONEY_BLOCK_BREAK, 2.0f, 1.0f)
- }
-
- target.location.world!!.spawnParticle(
- Particle.GLOW,
- target.location.x,
- target.location.y,
- target.location.z,
- 5,
- 0.0,
- 0.0,
- 0.0
- )
- }
-
- }
- }
- }
- val Entity.eyeLocation: Location
- get() {
- if (this is LivingEntity) {
- return eyeLocation
- }
- return location
- }
- fun sel(originEntity: Entity, includes: Array<EntityType>): Entity? {
- if (originEntity.location.world == null) {
- return null
- }
- var goalEntity: Entity? = null
- var excluded: Entity? = null
- for (entity in originEntity.location.world!!.entities) {
- if (!includes.contains(entity.type)) {
- continue
- }
- if (entity is Player) {
- if (entity.gameMode === GameMode.CREATIVE) {
- continue
- }
- if (entity.gameMode === GameMode.SPECTATOR) {
- continue
- }
- }
- if (originEntity.location.distanceSquared(entity.location) > distance) {
- continue
- }
- // var isWithinRange: Boolean
- // run {
- // val goal = entity.location
- // val vecLoc = goal.subtract(originEntity.location).toVector().normalize()
- // val rayTraceResult =
- // entity.world.rayTrace(originEntity.location, vecLoc, 36.0, FluidCollisionMode.NEVER, true, 1.0, null)
- // isWithinRange = rayTraceResult!!.hitBlock == null && rayTraceResult.hitEntity != null
- // }
- // if (!isWithinRange) {
- // continue
- // }
- if (aimeds.values.any { it.first == entity }) {
- excluded = entity
- continue
- }
- if (goalEntity == null) {
- goalEntity = entity
- }
- if (originEntity.location.distanceSquared(entity.location) < originEntity.location.distanceSquared(goalEntity!!.location)) {
- goalEntity = entity
- }
- }
- if (goalEntity == null && excluded != null) {
- return excluded
- }
- return goalEntity
- }
- fun sels(origin: Location, includes: List<EntityType?>): List<Entity> {
- val goalEntities = mutableListOf<Entity>()
- for (entity in origin.world!!.entities) {
- if (!includes.contains(entity.type)) {
- continue
- }
- if (entity is Player) {
- if (entity.gameMode === GameMode.CREATIVE) {
- continue
- }
- if (entity.gameMode === GameMode.SPECTATOR) {
- continue
- }
- }
- if (origin.distanceSquared(entity.location) > distance) {
- continue
- }
- var isWithinRange: Boolean
- run {
- val goal = entity.location
- val vecLoc = goal.subtract(origin).toVector().normalize()
- val rayTraceResult =
- entity.world.rayTrace(origin, vecLoc, 36.0, FluidCollisionMode.NEVER, true, 1.0, null)
- isWithinRange = rayTraceResult!!.hitBlock == null && rayTraceResult.hitEntity != null
- }
- if (!isWithinRange) {
- continue
- }
- goalEntities.add(entity)
- }
- return goalEntities.sortedBy { origin.distanceSquared(it.location) }
- }
- fun release() {
- // Main.task.cancel()
- println("激光器 卸载")
- }
- // Main.main()
- main()
复制代码 |