package net.wayward_realms.waywardmoderation.vanish;

import net.wayward_realms.waywardmoderation.WaywardModeration;
import org.bukkit.entity.Player;

import java.util.HashSet;
import java.util.Set;

public class VanishManager {

    private WaywardModeration plugin;
    private Set<String> vanished = new HashSet<>();

    public VanishManager(WaywardModeration plugin) {
        this.plugin = plugin;
    }

    public boolean isVanished(Player player) {
        return vanished.contains(player.getName());
    }

    public void setVanished(Player player, boolean vanished) {
        if (vanished) {
            this.vanished.add(player.getName());
            for (Player player1 : plugin.getServer().getOnlinePlayers()) {
                if (!canSee(player1, player)) player1.hidePlayer(player);
            }
        } else {
            this.vanished.remove(player.getName());
            for (Player player1 : plugin.getServer().getOnlinePlayers()) {
                player1.showPlayer(player);
            }
        }
    }

    public Set<Player> getVanishedPlayers() {
        Set<Player> vanishedPlayers = new HashSet<>();
        for (String playerName : vanished) {
            if (plugin.getServer().getOfflinePlayer(playerName).isOnline()) {
                vanishedPlayers.add(plugin.getServer().getPlayer(playerName));
            }
        }
        return vanishedPlayers;
    }

    public boolean canSee(Player player, Player target) {
        if (!vanished.contains(target.getName())) return true;
        int playerTier = 4, targetTier = 4;
        if (player.hasPermission("wayward.moderation.vanish.see.tier3")) {
            playerTier = 3;
        }
        if (target.hasPermission("wayward.moderation.vanish.see.tier3")) {
            targetTier = 3;
        }
        if (player.hasPermission("wayward.moderation.vanish.see.tier2")) {
            playerTier = 2;
        }
        if (target.hasPermission("wayward.moderation.vanish.see.tier2")) {
            targetTier = 2;
        }
        if (player.hasPermission("wayward.moderation.vanish.see.tier1")) {
            playerTier = 1;
        }
        if (target.hasPermission("wayward.moderation.vanish.see.tier1")) {
            targetTier = 1;
        }
        return playerTier <= targetTier;
    }

}

@@ -191,16 +191,39 @@
 til.Set;
+%0Aimport java.util.UUID;
 %0A%0Apublic
@@ -300,22 +300,20 @@
 ate Set%3C
-String
+UUID
 %3E vanish
@@ -507,36 +507,40 @@
 tains(player.get
-Name
+UniqueId
 ());%0A    %7D%0A%0A    
@@ -654,36 +654,40 @@
 d.add(player.get
-Name
+UniqueId
 ());%0A           
@@ -898,20 +898,24 @@
 ayer.get
-Name
+UniqueId
 ());%0A   
@@ -1179,25 +1179,17 @@
 or (
-String playerName
+UUID uuid
  : v
@@ -1251,26 +1251,20 @@
 ePlayer(
-playerName
+uuid
 ).isOnli
@@ -1340,18 +1340,12 @@
 yer(
-playerName
+uuid
 ));%0A
@@ -1510,12 +1510,16 @@
 .get
-Name
+UniqueId
 ()))

Convert vanished to UUIDs, #94