Add new game states

This commit is contained in:
Laurin
2025-12-04 15:01:10 +01:00
parent ac185e35ce
commit 2c10e3e7fd
10 changed files with 724 additions and 26 deletions

View File

@@ -0,0 +1,50 @@
package club.mcscrims.speedhg.util
import club.mcscrims.speedhg.SpeedHG
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player
import org.bukkit.util.Vector
import kotlin.math.atan2
object DirectionUtil {
private val plugin = SpeedHG.instance
private val directions = arrayOf("north", "northEast", "east", "southEast", "south", "southWest", "west", "northWest")
fun getDirectionToPlayer(
player: Player,
nearestPlayer: Player
): Component
{
val yaw = getDirection( player, nearestPlayer )
var normalizedYaw = yaw % 360
if ( normalizedYaw < 0 )
normalizedYaw += 360
val index = (( normalizedYaw + 22.5 ) / 45 ).toInt() % 8
return plugin.chatFormatter.format( "compass.directions.${directions[ index ]}" )
}
private fun getDirection(
fromPlayer: Player,
toPlayer: Player
): Double
{
val fromLocation = fromPlayer.location
val toLocation = toPlayer.location
val directionVector = Vector( toLocation.x - fromLocation.x, 0.0, toLocation.z - fromLocation.z ).normalize()
val angle = atan2( directionVector.x, directionVector.z )
val yaw = Math.toDegrees( angle )
var adjustedYaw = yaw + 180
if ( adjustedYaw < 0)
adjustedYaw += 360
return adjustedYaw
}
}