Skip to content

Commit

Permalink
refactor: revert the revert of Geary Cooldown change
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 13, 2024
1 parent 2102937 commit 87e35e2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 48 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=1.10
idofrontVersion=0.24.0-dev.8
idofrontVersion=0.24.0-dev.10
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
gearyPaper = "0.30.1-dev.10"
blocky = "0.9.13-dev.6"
gearyPaper = "0.30.1-dev.12"
blocky = "0.9.13-dev.13"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/com/mineinabyss/bonfire/BonfireCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.serialization.setPersisting
import com.mineinabyss.idofront.commands.arguments.intArg
import com.mineinabyss.idofront.commands.arguments.offlinePlayerArg
import com.mineinabyss.idofront.commands.arguments.playerArg
import com.mineinabyss.idofront.commands.arguments.stringArg
import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor
import com.mineinabyss.idofront.commands.extensions.actions.playerAction
import com.mineinabyss.idofront.messaging.error
import com.mineinabyss.idofront.messaging.info
import com.mineinabyss.idofront.messaging.observeLogger
import com.mineinabyss.idofront.messaging.success
import com.mineinabyss.idofront.nms.nbt.editOfflinePDC
import com.mineinabyss.idofront.nms.nbt.getOfflinePDC
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/com/mineinabyss/bonfire/BonfirePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ class BonfirePlugin : JavaPlugin() {
override val logger: ComponentLogger by plugin.observeLogger()
})
}
}

override fun onDisable() {
// Plugin shutdown logic
// ProtocolLibrary.getProtocolManager().removePacketListener(ChatPacketAdapter);

}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mineinabyss.bonfire.listeners

import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent
import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.blocky.api.BlockyFurnitures
import com.mineinabyss.blocky.api.events.furniture.BlockyFurnitureBreakEvent
import com.mineinabyss.blocky.api.events.furniture.BlockyFurnitureInteractEvent
Expand All @@ -17,6 +16,7 @@ import com.mineinabyss.geary.papermc.datastore.decode
import com.mineinabyss.geary.papermc.datastore.encode
import com.mineinabyss.geary.papermc.datastore.encodeComponentsTo
import com.mineinabyss.geary.papermc.datastore.remove
import com.mineinabyss.geary.papermc.features.general.cooldown.Cooldown
import com.mineinabyss.geary.papermc.tracking.entities.toGeary
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.serialization.setPersisting
Expand All @@ -26,7 +26,6 @@ import com.mineinabyss.idofront.messaging.success
import com.mineinabyss.idofront.nms.nbt.editOfflinePDC
import com.mineinabyss.idofront.nms.nbt.getOfflinePDC
import org.bukkit.Bukkit
import kotlinx.coroutines.delay
import org.bukkit.entity.ItemDisplay
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
Expand All @@ -39,6 +38,7 @@ import kotlin.math.abs
import kotlin.time.Duration.Companion.seconds

class BonfireListener : Listener {
val cooldown = Cooldown(length = bonfire.config.bonfireInteractCooldown)

private fun currentTime() = LocalDateTime.now().toInstant(ZoneOffset.UTC).epochSecond

Expand All @@ -52,7 +52,8 @@ class BonfireListener : Listener {
@EventHandler
fun BlockyFurniturePlaceEvent.onBonfirePlace() {
baseEntity.toGearyOrNull()?.with { bonfire: Bonfire ->
baseEntity.toGeary().setPersisting(bonfire.copy(bonfireOwner = player.uniqueId, bonfirePlayers = mutableListOf()))
baseEntity.toGeary()
.setPersisting(bonfire.copy(bonfireOwner = player.uniqueId, bonfirePlayers = mutableListOf()))
baseEntity.toGeary().setPersisting(BonfireExpirationTime(0.seconds, currentTime()))
baseEntity.updateBonfireState()
}
Expand All @@ -69,13 +70,24 @@ class BonfireListener : Listener {
// Bonfire is lit, player is only registered player, player is unsetting
// Since it is being unlit, set lastUnlitTimeStamp to currentTime
bonfireData.bonfirePlayers.isNotEmpty() && bonfireData.bonfirePlayers.all { it == player.uniqueId } -> {
gearyEntity.setPersisting(expiration.copy(totalUnlitTime = expiration.totalUnlitTime, lastUnlitTimeStamp = currentTime))
gearyEntity.setPersisting(
expiration.copy(
totalUnlitTime = expiration.totalUnlitTime,
lastUnlitTimeStamp = currentTime
)
)
}
// Bonfire was empty and player is attempting to set spawn
// Check if Bonfires new totalUnlittime is greater than expiration time
else -> {
val totalUnlitTime = expiration.totalUnlitTime + (currentTime - expiration.lastUnlitTimeStamp).seconds
gearyEntity.setPersisting(expiration.copy(totalUnlitTime = totalUnlitTime, lastUnlitTimeStamp = currentTime))
val totalUnlitTime =
expiration.totalUnlitTime + (currentTime - expiration.lastUnlitTimeStamp).seconds
gearyEntity.setPersisting(
expiration.copy(
totalUnlitTime = totalUnlitTime,
lastUnlitTimeStamp = currentTime
)
)
if (totalUnlitTime >= bonfireData.bonfireExpirationTime) {
player.error(bonfire.messages.BONFIRE_EXPIRED)
BlockyFurnitures.removeFurniture(baseEntity)
Expand All @@ -88,11 +100,18 @@ class BonfireListener : Listener {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun BlockyFurnitureInteractEvent.onBonfireInteract() {
if (!player.isSneaking || player.toGeary().has<BonfireCooldown>()) return
if (!player.isSneaking) return
if (hand != EquipmentSlot.HAND || abs(0 - player.velocity.y) < 0.001) return

val gearyEntity = baseEntity.toGearyOrNull()
gearyEntity?.with { bonfireData: Bonfire ->
val gearyPlayer = player.toGeary()
val gearyBonfire = baseEntity.toGearyOrNull() ?: return
if (!Cooldown.isComplete(gearyPlayer, gearyBonfire)) {
isCancelled = true
return
}
Cooldown.start(gearyPlayer, gearyBonfire, cooldown)

gearyBonfire.with { bonfireData: Bonfire ->
when (player.uniqueId) {
!in bonfireData.bonfirePlayers -> {
if (bonfireData.bonfirePlayers.size >= bonfireData.maxPlayerCount &&
Expand Down Expand Up @@ -125,13 +144,7 @@ class BonfireListener : Listener {
}

baseEntity.updateBonfireState()
gearyEntity.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC

player.toGeary().set(BonfireCooldown(baseEntity.uniqueId))
bonfire.plugin.launch {
delay(bonfire.config.bonfireInteractCooldown)
if (player.isOnline) player.toGeary().remove<BonfireCooldown>()
}
gearyBonfire.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC
}
}

Expand All @@ -146,17 +159,6 @@ class BonfireListener : Listener {
}
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
fun BlockyFurnitureInteractEvent.onBonfireCooldown() {
if (hand != EquipmentSlot.HAND || abs(0 - player.velocity.y) < 0.001) return
if (player.fallDistance > bonfire.config.minFallDist) return

player.toGeary().with { cooldown: BonfireCooldown ->
if (cooldown.bonfire == baseEntity.uniqueId) isCancelled = true
else player.toGeary().remove<BonfireCooldown>()
}
}

private fun ItemDisplay.ensureSavedPlayersAreValid(bonfireData: Bonfire): Boolean {
val validPlayers = bonfireData.bonfirePlayers.filter {
val offlinePlayer = Bukkit.getOfflinePlayer(it)
Expand Down Expand Up @@ -188,12 +190,10 @@ class BonfireListener : Listener {
if (onlinePlayer != null) {
onlinePlayer.toGeary().remove<BonfireEffectArea>()
onlinePlayer.toGeary().remove<BonfireRespawn>()
onlinePlayer.toGeary().remove<BonfireCooldown>()
} else {
p.editOfflinePDC {
encode(BonfireRemoved())
remove<BonfireRespawn>()
remove<BonfireCooldown>()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.blocky.helpers.GenericHelpers.toEntity
import com.mineinabyss.bonfire.bonfire
import com.mineinabyss.bonfire.components.Bonfire
import com.mineinabyss.bonfire.components.BonfireCooldown
import com.mineinabyss.bonfire.components.BonfireRemoved
import com.mineinabyss.bonfire.components.BonfireRespawn
import com.mineinabyss.bonfire.extensions.isBonfire
Expand Down Expand Up @@ -90,7 +89,6 @@ class PlayerListener : Listener {

@EventHandler
fun PlayerJoinEvent.onPlayerJoin() {
player.toGearyOrNull()?.remove<BonfireCooldown>()
val bonfire = player.toGeary().get<BonfireRespawn>() ?: return
val bonfireEntity = bonfire.bonfireUuid.toEntity() as? ItemDisplay ?: return
com.mineinabyss.bonfire.bonfire.plugin.launch {
Expand All @@ -100,7 +98,6 @@ class PlayerListener : Listener {
}
@EventHandler
fun PlayerQuitEvent.onPlayerQuit() {
player.toGearyOrNull()?.remove<BonfireCooldown>()
player.persistentDataContainer.remove<BonfireRemoved>()
}
}

0 comments on commit 87e35e2

Please sign in to comment.