From e71993ff22fedad3057a6f1545b6dc529bb8b21e Mon Sep 17 00:00:00 2001 From: Syrent <56670179+Syrent@users.noreply.github.com> Date: Sun, 22 Jan 2023 07:11:04 +0330 Subject: [PATCH] Spigot | Fixed NPE when player change vanish state on 1.8 --- .../spigot/VelocityVanishSpigot.kt | 2 +- .../spigot/core/VanishManager.kt | 20 ++++++++----------- .../spigot/listener/PostUnVanishListener.kt | 3 +-- .../spigot/listener/PostVanishListener.kt | 3 +-- .../velocityvanish/spigot/utils/Utils.kt | 2 +- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/VelocityVanishSpigot.kt b/src/main/java/ir/syrent/velocityvanish/spigot/VelocityVanishSpigot.kt index 7e6dede5..c5e4e130 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/VelocityVanishSpigot.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/VelocityVanishSpigot.kt @@ -102,7 +102,7 @@ class VelocityVanishSpigot : RUoMPlugin() { try { for (player in Ruom.getOnlinePlayers()) { if (startup) { - Utils.sendReportsActionbar(player) + Utils.sendVanishActionbar(player) } vanishManager.unVanish(player) } diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt b/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt index 3f4f1221..8f51035f 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/core/VanishManager.kt @@ -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() - val wasInvulnerable = mutableMapOf() - private val potions = mutableSetOf( PotionEffect(PotionEffectType.NIGHT_VISION, Int.MAX_VALUE, 255, false, false), PotionEffect(PotionEffectType.FIRE_RESISTANCE, Int.MAX_VALUE, 255, false, false), @@ -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 @@ -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") diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostUnVanishListener.kt b/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostUnVanishListener.kt index 96e5366e..437a4f58 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostUnVanishListener.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostUnVanishListener.kt @@ -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 @@ -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) diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostVanishListener.kt b/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostVanishListener.kt index d053a66e..340c9629 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostVanishListener.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/listener/PostVanishListener.kt @@ -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 @@ -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) diff --git a/src/main/java/ir/syrent/velocityvanish/spigot/utils/Utils.kt b/src/main/java/ir/syrent/velocityvanish/spigot/utils/Utils.kt index bb7528d9..d389d1eb 100644 --- a/src/main/java/ir/syrent/velocityvanish/spigot/utils/Utils.kt +++ b/src/main/java/ir/syrent/velocityvanish/spigot/utils/Utils.kt @@ -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")) {