Skip to content

Commit

Permalink
refactor: code cleanup, imports, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbker committed Dec 13, 2023
1 parent 6cbbe30 commit 0e1440a
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/gg/flyte/event/debug/DebugCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object DebugCommand {
sendMessage("Teleported to ${world.name}")
}
}

data class WorldName(val value: String)

@Subcommand("limit")
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/gg/flyte/event/game/lobby/LobbyGameEngine.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gg.flyte.event.game.lobby

import gg.flyte.event.ChristmasEvent
import gg.flyte.event.game.GameCategory
import gg.flyte.event.game.GameType
import gg.flyte.twilight.event.TwilightListener
import gg.flyte.twilight.extension.applyForEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PresentHuntGame(override val player: Player) : LobbyGame() {
private var metadataSet = false

private val PRESENT_LOCATIONS = listOf(
MapLocation(1,1,1)
MapLocation(1, 1, 1)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package gg.flyte.event.game.main.type

import gg.flyte.event.game.main.MainGame
import gg.flyte.event.game.main.MainGameEngine
import gg.flyte.event.util.NBSSongType
import com.xxmicloxx.NoteBlockAPI.model.RepeatMode
import com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer
import gg.flyte.event.game.GameType
import gg.flyte.event.game.main.MainGame
import gg.flyte.event.game.main.MainGameEngine
import gg.flyte.event.util.NBSSongType
import gg.flyte.twilight.event.event
import gg.flyte.twilight.extension.applyForEach
import gg.flyte.twilight.scheduler.repeat
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
Expand All @@ -18,7 +17,6 @@ import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.potion.PotionEffectType

class BlockPartyGame : MainGame(GameType.MUSICAL_MINECARTS) {// CHnage to block party

Expand Down
56 changes: 35 additions & 21 deletions src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package gg.flyte.event.game.main.type
import gg.flyte.event.game.GameType
import gg.flyte.event.game.main.MainGame
import gg.flyte.event.game.main.MainGameEngine
import gg.flyte.event.game.main.MainGameEngine.points
import gg.flyte.twilight.event.event
import gg.flyte.twilight.extension.*
import gg.flyte.twilight.extension.applyForEach
import gg.flyte.twilight.extension.clearActionBar
import gg.flyte.twilight.extension.contains
import gg.flyte.twilight.extension.playSound
import gg.flyte.twilight.scheduler.repeat
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.Component.text
Expand Down Expand Up @@ -76,20 +78,27 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {

onHill[0].apply {
val newPoints = points[uniqueId]!! + 50
sendActionBar(text().append(
text("${df.format(newPoints / 1000.0)}s held").color(NamedTextColor.GREEN).decorate(TextDecoration.BOLD),
text(" | ").color(NamedTextColor.GRAY),
text("$GAME_SECONDS second" + (if (GAME_SECONDS == 1) "" else "s") + " left").color(NamedTextColor.DARK_AQUA).decorate(TextDecoration.BOLD)
).build())
sendActionBar(
text().append(
text("${df.format(newPoints / 1000.0)}s held").color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD),
text(" | ").color(NamedTextColor.GRAY),
text("$GAME_SECONDS second" + (if (GAME_SECONDS == 1) "" else "s") + " left").color(
NamedTextColor.DARK_AQUA
).decorate(TextDecoration.BOLD)
).build()
)
points[uniqueId] = newPoints
}
} else if (onHill.size > 1) {
Bukkit.getOnlinePlayers().applyForEach {
showTitle(Title.title(
text("CONTESTED!").color(NamedTextColor.RED),
Component.empty(),
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ZERO)
))
showTitle(
Title.title(
text("CONTESTED!").color(NamedTextColor.RED),
Component.empty(),
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ZERO)
)
)
}
}
}
Expand All @@ -104,7 +113,7 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {
}

alive.applyForEach {
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 10.0;
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 10.0
health = 10.0
inventory.addItem(knockbackStick)
}
Expand All @@ -124,7 +133,7 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {
world.strikeLightning(player.location)
teleport(GameType.KING_OF_THE_HILL.spectatorSpawn!!)
playSound(Sound.ENTITY_PLAYER_DEATH)
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0;
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0
health = 20.0
resetTitle()
clearActionBar()
Expand All @@ -133,7 +142,7 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {
Bukkit.broadcastMessage("${player.name} was elmimnated")

if (alive.size == 1) {
Bukkit.broadcastMessage("game ended, ${alive[0]!!.name} last man standing")
Bukkit.broadcastMessage("game ended, ${alive[0].name} last man standing")
MainGameEngine.stop()
return@repeat
}
Expand All @@ -156,11 +165,16 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {
}

Bukkit.getOnlinePlayers().applyForEach {
sendActionBar(text().append(
text("${df.format(points[uniqueId]!! / 1000.0)}s held").color(NamedTextColor.GREEN).decorate(TextDecoration.BOLD),
text(" | ").color(NamedTextColor.GRAY),
text("$GAME_SECONDS second" + (if (GAME_SECONDS == 1) "" else "s") + " left").color(NamedTextColor.DARK_AQUA).decorate(TextDecoration.BOLD)
).build())
sendActionBar(
text().append(
text("${df.format(points[uniqueId]!! / 1000.0)}s held").color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD),
text(" | ").color(NamedTextColor.GRAY),
text("$GAME_SECONDS second" + (if (GAME_SECONDS == 1) "" else "s") + " left").color(
NamedTextColor.DARK_AQUA
).decorate(TextDecoration.BOLD)
).build()
)
}

GAME_SECONDS--
Expand All @@ -169,7 +183,7 @@ class KingOfTheHillGame : MainGame(GameType.KING_OF_THE_HILL) {

override fun stop() {
Bukkit.getOnlinePlayers().applyForEach {
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0;
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0
health = 20.0
inventory.storageContents = emptyArray()
resetTitle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SledRacingGame : MainGame(GameType.SLED_RACING) {
private val boats = mutableMapOf<Player, Boat>()

init {
STARTING_WALL.getBlocks(gg.flyte.event.ChristmasEvent.WORLD).applyForEach { type = Material.OAK_FENCE }
STARTING_WALL.getBlocks(ChristmasEvent.WORLD).applyForEach { type = Material.OAK_FENCE }

Bukkit.getOnlinePlayers().forEach { player ->
(player.world.spawnEntity(player.location, EntityType.BOAT) as Boat).apply {
Expand All @@ -62,7 +62,7 @@ class SledRacingGame : MainGame(GameType.SLED_RACING) {
override fun start() {
startTime = System.currentTimeMillis()

STARTING_WALL.getBlocks(gg.flyte.event.ChristmasEvent.WORLD).applyForEach { type = Material.AIR }
STARTING_WALL.getBlocks(ChristmasEvent.WORLD).applyForEach { type = Material.AIR }

var timer = 60.0
tasks += repeat(5) {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/gg/flyte/event/util/NBSSongType.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gg.flyte.event.util

import gg.flyte.event.ChristmasEvent
import com.xxmicloxx.NoteBlockAPI.model.Song
import com.xxmicloxx.NoteBlockAPI.utils.NBSDecoder
import java.io.File
Expand Down
18 changes: 13 additions & 5 deletions src/main/kotlin/gg/flyte/event/util/npc/NPC.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gg.flyte.event.util.npc

import gg.flyte.event.ChristmasEvent
import gg.flyte.event.util.Skin
import com.mojang.authlib.GameProfile
import com.mojang.authlib.properties.Property
import gg.flyte.event.util.Skin
import net.minecraft.network.protocol.game.*
import net.minecraft.network.syncher.EntityDataAccessor
import net.minecraft.network.syncher.EntityDataSerializers
Expand All @@ -27,7 +26,8 @@ class NPC(
location: Location,
skin: Skin,
followPlayer: Boolean,
vararg holograms: String) : BukkitRunnable() {
vararg holograms: String
) : BukkitRunnable() {

val serverPlayer: ServerPlayer
val stands = mutableListOf<ArmorStand>()
Expand Down Expand Up @@ -108,11 +108,19 @@ class NPC(
}

if (closest != null) {
val location = craftPlayer.location.setDirection(closest!!.location.subtract(craftPlayer.location).toVector())
val location =
craftPlayer.location.setDirection(closest!!.location.subtract(craftPlayer.location).toVector())
val yaw = location.yaw
val pitch = location.pitch
(closest as CraftPlayer).handle.connection.apply {
send(ClientboundMoveEntityPacket.Rot(serverPlayer.id, (yaw % 360.0 * 256 / 360).toInt().toByte(), (pitch % 360.0 * 256 / 360).toInt().toByte(), false))
send(
ClientboundMoveEntityPacket.Rot(
serverPlayer.id,
(yaw % 360.0 * 256 / 360).toInt().toByte(),
(pitch % 360.0 * 256 / 360).toInt().toByte(),
false
)
)
send(ClientboundRotateHeadPacket(serverPlayer, (yaw % 360.0 * 256 / 360).toInt().toByte()))
}
}
Expand Down
26 changes: 20 additions & 6 deletions src/main/kotlin/gg/flyte/event/visual/TablistManager.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gg.flyte.event.visual

import gg.flyte.event.ChristmasEvent
import gg.flyte.event.util.CHRISTMAS_RED
import com.mojang.authlib.GameProfile
import com.mojang.authlib.properties.Property
import gg.flyte.event.ChristmasEvent
import gg.flyte.event.util.CHRISTMAS_RED
import gg.flyte.twilight.string.smallText
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
Expand All @@ -30,7 +30,8 @@ object TablistMan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3vBKmzL/2k8JPs+GAUG/5tFARpZ0yhWDgk=")
"s/TIW86bb1jKqnGqgaGMakBqVCQRgpsqM8MKcfULp4BRcXrMNkax1jKA121cEG1SjoPWGjH1cqMdH9KKqnHFbhE1yFDhMFKuBKRRJyGyV+DRdtbz0fDV5mGABoDHcY2u4PcQJh6pova/+IaaDn66F8xKduMET6BHuvhjrGFbX9r+ZFVUQS1EuF51EWblKvOUkDCMH6pBzbdqeXRhQfbbm6KpRttVxnNKbsxiRdDEvJ8j67JrAy6p2BTXr/gFW/BF6ktvFqLL9OQzH/cW/TScZYglvTUb1GnztxPn/PbYJlCMKL4QTEAJs1Ti7l4Uj5do4/cK/AXxsuvEqTMArvdBrwv6+AgCvFnh7PPTIRHMzTHyLmSHr1ikKtjloQgnkQVLO5gFEPnuExzAbvTZYL+F2NJN3OTQZ0KBWriIgS2futweFehKuhMoksLo056yb7coJpeaX/BAAcloRiC3IilozepdIYVnCxAw4MgW5Uy7gSoE7xBDIg2e0+24kdjA0yEpfrm9SBa9xhcpzVtH+g7zlKil4gEQhptNL7kz9iSMEMuNNFI8dLZs1jnTiscti5D/gp3BqscCX8wv4Nx2uRaQgrclxbZ4A/s81jAlbPhw5TdTZwFojFLCDDoBtpNA9zj4/YjcfXnN/3vBKmzL/2k8JPs+GAUG/5tFARpZ0yhWDgk="
)

repeat(84) {
val gameProfile = GameProfile(UUID.randomUUID(), " ")
Expand Down Expand Up @@ -61,14 +62,27 @@ object TablistManager {

private fun updateHeaderFooter() {
Bukkit.getOnlinePlayers().forEach {
it.setPlayerListHeaderFooter(TAB_HEADER.replace("{players}", Bukkit.getOnlinePlayers().size.toString()), TAB_FOOTER)
it.setPlayerListHeaderFooter(
TAB_HEADER.replace("{players}", Bukkit.getOnlinePlayers().size.toString()),
TAB_FOOTER
)
}
}

private fun sendTablist(player: Player) {
fakePlayers.forEach {
(player as CraftPlayer).handle.connection.send(ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, it))
player.handle.connection.send(ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, it))
(player as CraftPlayer).handle.connection.send(
ClientboundPlayerInfoUpdatePacket(
ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER,
it
)
)
player.handle.connection.send(
ClientboundPlayerInfoUpdatePacket(
ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED,
it
)
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/gg/flyte/event/visual/camera/Camera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ object Camera {
@Command("camera")
@CommandPermission("admin")
fun camera(sender: CommandSender, location: Location, @Optional cameraPlayer: Player? = null) {
val player = cameraPlayer ?: Bukkit.getPlayer(UUID.fromString(CAMERA_ACCOUNT_UUID)) ?: commandError("Unable to find a camera.")
val player = cameraPlayer ?: Bukkit.getPlayer(UUID.fromString(CAMERA_ACCOUNT_UUID))
?: commandError("Unable to find a camera.")
sender.sendMessage("Starting camera sequence to ${location.name}.")
player.apply {
gameMode = GameMode.SPECTATOR
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/gg/flyte/event/visual/hud/Font.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Font {

text.miniMessage.plainText.toCharArray().forEach { character ->
width += if (!iconTranslations.any { iconTranslation -> iconTranslation.toTranslate == character.toString() }) {
FontInfo.entries.firstOrNull { it.character == character }?.width ?: 0
FontInfo.entries.firstOrNull { it.character == character }?.width ?: 0
} else {
iconTranslations.first { iconTranslation -> iconTranslation.toTranslate == character.toString() }.width
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gg.flyte.event.visual.hud.actionbar

import gg.flyte.event.visual.hud.Font
import gg.flyte.event.visual.hud.Alignment
import gg.flyte.event.visual.hud.Font

/**
* Represents an element in the action bar.
Expand All @@ -28,10 +28,12 @@ class ActionBarElement(val id: String, val offset: Int, var text: String, alignm
leftOffset = offset
rightOffset = -offset - width
}

Alignment.RIGHT -> {
leftOffset = offset - width
rightOffset = -offset
}

Alignment.CENTER -> {
leftOffset = offset - width / 2
rightOffset = -leftOffset - width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ class ActionBarHUD(private val player: Player) {
val spaces = offset - Font.getTextWidth(truncatedText) - truncatedText.length
println("${it.id}: $spaces")

if (offset != 0) actionBar = actionBar.append("<font:learnspigot:ui_space><lang:space.$spaces:></font>".miniMessage)
if (offset != 0) actionBar =
actionBar.append("<font:learnspigot:ui_space><lang:space.$spaces:></font>".miniMessage)
actionBar = actionBar.append("<font:learnspigot:hud_actionbar>$editedText</font>".miniMessage)
offset = it.rightOffset

removeWidth += Font.getTextWidth(truncatedText)
}

if (offset != 0) actionBar = actionBar.append("<font:learnspigot:ui_space><lang:space.$offset:></font>".miniMessage)
if (offset != 0) actionBar =
actionBar.append("<font:learnspigot:ui_space><lang:space.$offset:></font>".miniMessage)
changed = false

return actionBar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gg.flyte.event.visual.hud.impl

import gg.flyte.event.game.Game
import gg.flyte.event.game.main.MainGameEngine
import gg.flyte.event.visual.hud.Alignment
import gg.flyte.event.visual.hud.Font
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/gg/flyte/event/visual/hud/sidebar/Sidebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.scoreboard.DisplaySlot
import org.bukkit.scoreboard.Scoreboard
import java.util.UUID
import java.util.*

object Sidebar {

Expand All @@ -16,13 +16,15 @@ object Sidebar {
player.scoreboard = Bukkit.getScoreboardManager().newScoreboard.apply {
activeScoreboards[player.uniqueId] = this

registerNewObjective("sidebar", "dummy", Component
.text("\"Flyte Christmas Event 2023\"")
.color(CHRISTMAS_RED))
registerNewObjective(
"sidebar", "dummy", Component
.text("\"Flyte Christmas Event 2023\"")
.color(CHRISTMAS_RED)
)
.apply {
displaySlot = DisplaySlot.SIDEBAR

}
}
}
}

Expand Down

0 comments on commit 0e1440a

Please sign in to comment.