Skip to content

Commit

Permalink
Merge pull request #82
Browse files Browse the repository at this point in the history
Spigot | Fixed NPE when player change vanish state on 1.8
  • Loading branch information
Syrent authored Jan 22, 2023
2 parents 37ddea7 + e71993f commit 426d4f1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class VelocityVanishSpigot : RUoMPlugin() {
try {
for (player in Ruom.getOnlinePlayers()) {
if (startup) {
Utils.sendReportsActionbar(player)
Utils.sendVanishActionbar(player)
}
vanishManager.unVanish(player)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ class VanishManager(
private val plugin: VelocityVanishSpigot
) {

// It's better to move this to a data object like VanishPlayer
// TODO: Move this to VanishPlayer
// Requirement: Create VanishPlayer object
val wasFlying = mutableMapOf<UUID, Boolean>()
val wasInvulnerable = mutableMapOf<UUID, Boolean>()

private val potions = mutableSetOf(
PotionEffect(PotionEffectType.NIGHT_VISION, Int.MAX_VALUE, 255, false, false),
PotionEffect(PotionEffectType.FIRE_RESISTANCE, Int.MAX_VALUE, 255, false, false),
Expand Down Expand Up @@ -149,13 +143,13 @@ class VanishManager(
updateTabState(player, GameMode.SPECTATOR)
hidePlayer(player)

wasFlying[player.uniqueId] = player.allowFlight
player.allowFlight = true
player.isFlying = true

wasInvulnerable[player.uniqueId] = player.isInvulnerable
if (Settings.invincible) {
player.isInvulnerable = true
if (ServerVersion.supports(9)) {
if (Settings.invincible) {
player.isInvulnerable = true
}
}

player.isSleepingIgnored = true
Expand Down Expand Up @@ -233,12 +227,14 @@ class VanishManager(

updateTabState(player, GameMode.SURVIVAL)

if (wasFlying[player.uniqueId] == false) {
if (!player.isOp) {
player.allowFlight = false
player.isFlying = false
}

player.isInvulnerable = wasInvulnerable[player.uniqueId] ?: player.isInvulnerable
if (ServerVersion.supports(9)) {
player.isInvulnerable = false
}

for (onlinePlayer in Ruom.getOnlinePlayers()) {
@Suppress("DEPRECATION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ir.syrent.velocityvanish.spigot.listener

import ir.syrent.velocityvanish.spigot.VelocityVanishSpigot
import ir.syrent.velocityvanish.spigot.event.PostUnVanishEvent
import ir.syrent.velocityvanish.spigot.hook.DependencyManager
import ir.syrent.velocityvanish.spigot.ruom.Ruom
import ir.syrent.velocityvanish.spigot.storage.Message
import ir.syrent.velocityvanish.spigot.storage.Settings
Expand All @@ -23,7 +22,7 @@ class PostUnVanishListener(
@EventHandler
private fun onPostUnVanish(event: PostUnVanishEvent) {
val player = event.player
Utils.sendReportsActionbar(player)
Utils.sendVanishActionbar(player)
plugin.vanishedNames.remove(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ir.syrent.velocityvanish.spigot.listener

import ir.syrent.velocityvanish.spigot.VelocityVanishSpigot
import ir.syrent.velocityvanish.spigot.event.PostVanishEvent
import ir.syrent.velocityvanish.spigot.hook.DependencyManager
import ir.syrent.velocityvanish.spigot.ruom.Ruom
import ir.syrent.velocityvanish.spigot.storage.Message
import ir.syrent.velocityvanish.spigot.storage.Settings
Expand All @@ -23,7 +22,7 @@ class PostVanishListener(
@EventHandler
private fun onPostVanish(event: PostVanishEvent) {
val player = event.player
Utils.sendReportsActionbar(player)
Utils.sendVanishActionbar(player)
plugin.vanishedNames.add(player.name)
plugin.bridgeManager?.updateVanishedPlayersRequest(player, true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Utils {
}, 0, 30)
}

fun sendReportsActionbar(player: Player) {
fun sendVanishActionbar(player: Player) {
if (actionbarPlayers.contains(player)) return

if (Settings.actionbar && player.hasPermission("velocityvanish.admin.actionbar")) {
Expand Down

0 comments on commit 426d4f1

Please sign in to comment.