Skip to content

Commit

Permalink
Add backwards compatibility for potion effects
Browse files Browse the repository at this point in the history
  • Loading branch information
quantiom committed Nov 14, 2022
1 parent c49ed86 commit 8fa1311
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.quantiom.advancedvanish.util

import com.google.common.collect.Lists
import com.google.common.collect.Maps
import me.quantiom.advancedvanish.AdvancedVanish
import me.quantiom.advancedvanish.config.Config
import me.quantiom.advancedvanish.event.PlayerUnVanishEvent
import me.quantiom.advancedvanish.event.PlayerVanishEvent
Expand Down Expand Up @@ -44,16 +45,22 @@ object AdvancedVanishAPI {
.map { it.split(":") }
.filter { it.size > 1 }
.forEach {
PotionEffectType.values().find { e -> e.name == it[0] }?.run {
val currentPotionEffect = player.getPotionEffect(this)
PotionEffectType.values().find { e -> e?.name == it[0] }?.run {
val currentPotionEffect = player.activePotionEffects.find { e -> e.type == this }

if (currentPotionEffect != null) {
previousEffects.add(currentPotionEffect)
} else {
previousEffects.add(this.createEffect(0, 0))
}

player.addPotionEffect(this.createEffect(Integer.MAX_VALUE, it[1].toInt() - 1))
if (onJoin) {
Bukkit.getScheduler().runTaskLater(AdvancedVanish.instance!!, Runnable {
player.addPotionEffect(this.createEffect(Integer.MAX_VALUE, it[1].toInt() - 1))
}, 10L)
} else {
player.addPotionEffect(this.createEffect(Integer.MAX_VALUE, it[1].toInt() - 1))
}
}
}

Expand Down

0 comments on commit 8fa1311

Please sign in to comment.