generated from emmaboecker/kspigot-gradle-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ object ChallengeManager { | |
LevelBorder, | ||
IceWalker, | ||
Medusa, | ||
DamageSwap, | ||
) | ||
} | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/de/stckoverflw/stckutils/minecraft/challenge/impl/DamageSwap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters