Skip to content

Commit

Permalink
add DamageSwap Challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
l4zs committed Dec 18, 2021
1 parent 92865ed commit 0ac4697
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object ChallengeManager {
LevelBorder,
IceWalker,
Medusa,
DamageSwap,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.stckoverflw.stckutils.minecraft.challenge.impl

import de.stckoverflw.stckutils.extension.isPlaying
import de.stckoverflw.stckutils.minecraft.challenge.Challenge
import net.axay.kspigot.extensions.onlinePlayers
import net.axay.kspigot.gui.ForInventoryFiveByNine
import net.axay.kspigot.gui.GUI
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.entity.EntityDamageEvent

object DamageSwap : Challenge() {

override val id: String = "damage-swap"
override val name: String = "§4DamageSwap"
override val material: Material = Material.SHIELD
override val description: List<String> = listOf(
" ",
"§7When you take damage, someone else",
"§7takes the damage instead of you"
)
override val usesEvents: Boolean = true

override fun configurationGUI(): GUI<ForInventoryFiveByNine>? = null

@EventHandler
fun onDamage(event: EntityDamageEvent) {
if (event.entity !is Player ||
!(event.entity as Player).isPlaying() ||
event.cause == EntityDamageEvent.DamageCause.CUSTOM
) {
return
}
val otherPlayers = onlinePlayers.filter { it != event.entity && it.isPlaying() }
if (otherPlayers.isEmpty()) {
return
}
otherPlayers
.random()
.damage(event.damage)
event.isCancelled = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object IceWalker : Challenge() {
override val description: List<String> = listOf(
" ",
"§7When you walk, a 3x3 ice platform",
"will be formed below you.",
"§7will be formed below you.",
"§7You can toggle this ability by sneaking."
)
override val usesEvents: Boolean = true
Expand Down

0 comments on commit 0ac4697

Please sign in to comment.