Slightly better vanish plugin support

This commit is contained in:
Esophose 2019-05-02 20:15:41 -06:00
parent 2a474faa88
commit 79c8f8ab2c
2 changed files with 25 additions and 6 deletions

View file

@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -40,8 +39,8 @@ public class DataManager {
* @return The PPlayer from cache * @return The PPlayer from cache
*/ */
public static PPlayer getPPlayer(UUID playerUUID) { public static PPlayer getPPlayer(UUID playerUUID) {
List<PPlayer> pplayers = ParticleManager.getPPlayers(); List<PPlayer> pplayers;
synchronized (pplayers) { // Under rare circumstances, the PPlayers list can be changed while it's looping synchronized (pplayers = ParticleManager.getPPlayers()) { // Under rare circumstances, the PPlayers list can be changed while it's looping
for (PPlayer pp : pplayers) for (PPlayer pp : pplayers)
if (pp.getUniqueId().equals(playerUUID)) if (pp.getUniqueId().equals(playerUUID))
return pp; return pp;
@ -64,8 +63,8 @@ public class DataManager {
} }
async(() -> { async(() -> {
List<ParticleGroup> groups = new ArrayList<ParticleGroup>(); List<ParticleGroup> groups = new ArrayList<>();
List<FixedParticleEffect> fixedParticles = new ArrayList<FixedParticleEffect>(); List<FixedParticleEffect> fixedParticles = new ArrayList<>();
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> { PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
// Load settings // Load settings

View file

@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.esophose.playerparticles.util.NMSUtil; import com.esophose.playerparticles.util.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -21,6 +22,7 @@ import org.bukkit.material.MaterialData;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.SettingManager.PSetting; import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import org.bukkit.metadata.MetadataValue;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public enum ParticleEffect { public enum ParticleEffect {
@ -329,7 +331,7 @@ public enum ParticleEffect {
for (PPlayer pplayer : ParticleManager.getPPlayers()) { for (PPlayer pplayer : ParticleManager.getPPlayers()) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
if (!isFixedEffect && !p.canSee(owner)) if (!isFixedEffect && !this.canSee(p, owner))
continue; continue;
if (p != null && pplayer.canSeeParticles() && p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= range * range) { 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; 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 * Represents the property of a particle effect
* <p> * <p>