From f94e87960fdefaf2c9c34186de734e86f2ec9805 Mon Sep 17 00:00:00 2001 From: Esophose Date: Thu, 25 Feb 2021 19:05:02 -0700 Subject: [PATCH] Don't display particles if the player is invisible --- .../playerparticles/manager/ParticleManager.java | 9 ++++----- .../dev/esophose/playerparticles/util/ParticleUtils.java | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/esophose/playerparticles/manager/ParticleManager.java b/src/main/java/dev/esophose/playerparticles/manager/ParticleManager.java index 16b5f94..af74129 100644 --- a/src/main/java/dev/esophose/playerparticles/manager/ParticleManager.java +++ b/src/main/java/dev/esophose/playerparticles/manager/ParticleManager.java @@ -12,7 +12,7 @@ import dev.esophose.playerparticles.particles.ParticlePair; import dev.esophose.playerparticles.particles.data.NoteColor; import dev.esophose.playerparticles.particles.data.OrdinaryColor; import dev.esophose.playerparticles.styles.DefaultStyles; -import dev.esophose.playerparticles.util.NMSUtil; +import dev.esophose.playerparticles.util.ParticleUtils; import java.awt.Color; import java.util.Collection; import java.util.Iterator; @@ -22,7 +22,6 @@ import java.util.Random; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -190,9 +189,9 @@ public class ParticleManager extends Manager implements Listener, Runnable { for (PPlayer pplayer : this.particlePlayers.values()) { Player player = pplayer.getPlayer(); - // Don't show their particles if they are in spectator mode + // Don't show their particles if they are invisible // Don't spawn particles if the world doesn't allow it - if (player != null && (NMSUtil.getVersionNumber() < 8 || player.getGameMode() != GameMode.SPECTATOR) && permissionManager.isWorldEnabled(player.getWorld().getName())) + if (player != null && ParticleUtils.isPlayerVisible(player) && permissionManager.isWorldEnabled(player.getWorld().getName())) for (ParticlePair particles : pplayer.getActiveParticles()) this.displayParticles(pplayer, particles, player.getLocation().clone().add(0, 1, 0)); @@ -285,7 +284,7 @@ public class ParticleManager extends Manager implements Listener, Runnable { player = pplayer.getPlayer(); } - if ((player != null && (NMSUtil.getVersionNumber() < 8 || player.getGameMode() == GameMode.SPECTATOR)) || !permissionManager.isWorldEnabled(world.getName())) + if ((player != null && !ParticleUtils.isPlayerVisible(player)) || !permissionManager.isWorldEnabled(world.getName())) return; for (PParticle pparticle : particles) diff --git a/src/main/java/dev/esophose/playerparticles/util/ParticleUtils.java b/src/main/java/dev/esophose/playerparticles/util/ParticleUtils.java index 9059702..6f815c2 100644 --- a/src/main/java/dev/esophose/playerparticles/util/ParticleUtils.java +++ b/src/main/java/dev/esophose/playerparticles/util/ParticleUtils.java @@ -6,9 +6,12 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffectType; public final class ParticleUtils { @@ -128,4 +131,9 @@ public final class ParticleUtils { return false; } + public static boolean isPlayerVisible(Player player) { + return (NMSUtil.getVersionNumber() <= 8 || player.getGameMode() != GameMode.SPECTATOR) + && !player.hasPotionEffect(PotionEffectType.INVISIBILITY); + } + }