From 79c8f8ab2c45f1d5950a3270fbd6fc812e09a1f9 Mon Sep 17 00:00:00 2001 From: Esophose Date: Thu, 2 May 2019 20:15:41 -0600 Subject: [PATCH] Slightly better vanish plugin support --- .../playerparticles/manager/DataManager.java | 9 ++++---- .../particles/ParticleEffect.java | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/com/esophose/playerparticles/manager/DataManager.java b/src/com/esophose/playerparticles/manager/DataManager.java index 105d7bb..2d0bcd5 100644 --- a/src/com/esophose/playerparticles/manager/DataManager.java +++ b/src/com/esophose/playerparticles/manager/DataManager.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.scheduler.BukkitRunnable; @@ -40,8 +39,8 @@ public class DataManager { * @return The PPlayer from cache */ public static PPlayer getPPlayer(UUID playerUUID) { - List pplayers = ParticleManager.getPPlayers(); - synchronized (pplayers) { // Under rare circumstances, the PPlayers list can be changed while it's looping + List pplayers; + synchronized (pplayers = ParticleManager.getPPlayers()) { // Under rare circumstances, the PPlayers list can be changed while it's looping for (PPlayer pp : pplayers) if (pp.getUniqueId().equals(playerUUID)) return pp; @@ -64,8 +63,8 @@ public class DataManager { } async(() -> { - List groups = new ArrayList(); - List fixedParticles = new ArrayList(); + List groups = new ArrayList<>(); + List fixedParticles = new ArrayList<>(); PlayerParticles.getPlugin().getDBConnector().connect((connection) -> { // Load settings diff --git a/src/com/esophose/playerparticles/particles/ParticleEffect.java b/src/com/esophose/playerparticles/particles/ParticleEffect.java index 4ba7fda..7b334d6 100644 --- a/src/com/esophose/playerparticles/particles/ParticleEffect.java +++ b/src/com/esophose/playerparticles/particles/ParticleEffect.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Map.Entry; import com.esophose.playerparticles.util.NMSUtil; +import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; @@ -21,6 +22,7 @@ import org.bukkit.material.MaterialData; import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.SettingManager.PSetting; import com.esophose.playerparticles.styles.api.PParticle; +import org.bukkit.metadata.MetadataValue; @SuppressWarnings("deprecation") public enum ParticleEffect { @@ -329,7 +331,7 @@ public enum ParticleEffect { for (PPlayer pplayer : ParticleManager.getPPlayers()) { Player p = pplayer.getPlayer(); - if (!isFixedEffect && !p.canSee(owner)) + if (!isFixedEffect && !this.canSee(p, owner)) continue; if (p != null && pplayer.canSeeParticles() && p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= range * range) { @@ -340,6 +342,24 @@ public enum ParticleEffect { return players; } + /** + * Checks if a player can see another player + * + * @param player The player + * @param target The target + * @return True if player can see target, otherwise false + */ + private boolean canSee(Player player, Player target) { + if (player == null || target == null) + return true; + + for (MetadataValue meta : target.getMetadata("vanished")) + if (meta.asBoolean()) + return false; + + return player.canSee(target); + } + /** * Represents the property of a particle effect *