Skip to content

Commit

Permalink
Merge pull request #31 from Astra-Interactive/debuf-newbee
Browse files Browse the repository at this point in the history
Remove newbee effects when engage in pvp
  • Loading branch information
makeevrserg authored May 12, 2024
2 parents 63f7467 + 4770135 commit dab32b5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ makeevrserg.java.ktarget=17
# Project
makeevrserg.project.name=AspeKt
makeevrserg.project.group=ru.astrainteractive.aspekt
makeevrserg.project.version.string=2.19.6
makeevrserg.project.version.string=2.19.7
makeevrserg.project.description=Essentials plugin for EmpireProjekt
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://empireprojekt.ru
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ class PluginTranslation(
"&7[&#DBB72BЗАЩИТА&7] &#1D72F2Вы новичок! &6Поэтому в первые 50 минут вам будет играть легче! Наслаждайтесь игрой!"
),
val newBeeTitle: StringDesc.Raw = StringDesc.Raw("&#DBB72BЗащита новичка"),
val newBeeSubtitle: StringDesc.Raw = StringDesc.Raw("&#db2c18Включена")
val newBeeSubtitle: StringDesc.Raw = StringDesc.Raw("&#db2c18Включена"),
val newBeeShieldForceDisabled: StringDesc.Raw = StringDesc.Raw(
"&7[&#DBB72BЗАЩИТА&7] &#DBB72BВы вступили в бой с игроком. Защита новичка была удалена"
)
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.withContext
import net.kyori.adventure.title.Title
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerRespawnEvent
Expand Down Expand Up @@ -71,17 +72,22 @@ internal class NewBeeEventListener(
addPotionEffects(effects)
val message = kyoriComponentSerializer.toComponent(translation.newBee.youAreNewBee)
sendMessage(message)
showTitle(
Title.title(
kyoriComponentSerializer.toComponent(translation.newBee.newBeeTitle),
kyoriComponentSerializer.toComponent(translation.newBee.newBeeSubtitle),
Title.Times.times(
1.seconds.toJavaDuration(),
3.seconds.toJavaDuration(),
1.seconds.toJavaDuration()
)
Title.title(
kyoriComponentSerializer.toComponent(translation.newBee.newBeeTitle),
kyoriComponentSerializer.toComponent(translation.newBee.newBeeSubtitle),
Title.Times.times(
1.seconds.toJavaDuration(),
3.seconds.toJavaDuration(),
1.seconds.toJavaDuration()
)
)
).run(::showTitle)
}

private fun Player.takeNewBeeEffects() = scope.launch(dispatcher.Main) {
val effects = getNewBeeEffects(this@takeNewBeeEffects)
addPotionEffects(effects)
val message = kyoriComponentSerializer.toComponent(translation.newBee.newBeeShieldForceDisabled)
sendMessage(message)
}

private fun Player.clearNewBeeEffects() {
Expand All @@ -95,6 +101,22 @@ internal class NewBeeEventListener(
e.damage *= NewBeeConstants.NEW_BEE_DAMAGED_PERCENT
}

@EventHandler
fun onNewBeeAttackPlayer(e: EntityDamageByEntityEvent) {
if (e.entity !is Player) return
val newBeeAttacker = e.damager as? Player ?: return
if (!newBeeAttacker.isNewBee) return
newBeeAttacker.takeNewBeeEffects()
}

@EventHandler
fun onPlayerAttackNewBee(e: EntityDamageByEntityEvent) {
if (e.damager !is Player) return
val newBee = e.entity as? Player ?: return
if (!newBee.isNewBee) return
newBee.takeNewBeeEffects()
}

@EventHandler
fun onNewBeeSpawn(e: PlayerRespawnEvent) {
val player = e.player
Expand Down

0 comments on commit dab32b5

Please sign in to comment.