package com.probablycoding.bukkit.simplevanish;

import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class SimpleVanish extends JavaPlugin implements Listener {
    public List<String> invisible;

    public void enableVanish(Player player, boolean force) {
        if (invisible.add(player.getName()) || force) {
            for (Player other : getServer().getOnlinePlayers()) {
                if (other.hasPermission("simplevanish.showvanished")) {
                    continue;
                }
                other.hidePlayer(player);
            }

            player.sendMessage(ChatColor.RED + "Poof!");
        } else {
            player.sendMessage(ChatColor.RED + "You are already vanished!");
        }
    }

    public void disableVanish(Player player, boolean force) {
        if (invisible.remove(player.getName()) || force) {
            for (Player other : getServer().getOnlinePlayers()) {
                other.showPlayer(player);
            }

            player.sendMessage(ChatColor.RED + "You have reappeared!");
        } else {
            player.sendMessage(ChatColor.RED + "You are not vanished!");
        }
    }

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        invisible = getConfig().getStringList("vanished");
    }

    @Override
    public void onDisable() {
        getConfig().set("vanished", invisible);
        saveConfig();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String name, String[] args) {
        if (!(sender instanceof Player))
            return false;

        if (command.getName().equalsIgnoreCase("vanish"))
            enableVanish((Player) sender, false);
        else if (command.getName().equalsIgnoreCase("unvanish"))
            disableVanish((Player) sender, false);

        return true;
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        if (invisible.contains(event.getPlayer().getName()))
            enableVanish(event.getPlayer(), true);

        if (event.getPlayer().hasPermission("simplevanish.showvanished"))
            return;

        for (String hidden : invisible) {
            Player hiddenPlayer = getServer().getPlayerExact(hidden);
            if (hiddenPlayer != null) {
                event.getPlayer().hidePlayer(hiddenPlayer);
            }
        }
    }
}

@@ -534,32 +534,33 @@
 ) %7B%0A        if (
+!
 invisible.add(pl
@@ -557,11 +557,16 @@
 ble.
-add
+contains
 (pla
@@ -827,32 +827,77 @@
 %0A            %7D%0A%0A
+            invisible.add(player.getName());%0A
             play
@@ -1471,33 +1471,642 @@
 %0A    %7D%0A%0A    
-@Override
+public void showVanishList(Player player) %7B%0A        String result = %22%22;%0A        boolean first = true;%0A        for (String hidden : invisible) %7B%0A            if (getServer().getPlayerExact(hidden) == null)%0A                continue;%0A%0A            if (first) %7B%0A                result += hidden;%0A                first = false;%0A                continue;%0A            %7D%0A%0A            result += %22, %22 + hidden;%0A        %7D%0A%0A        if (result.length() == 0)%0A            player.sendMessage(ChatColor.RED + %22All players are visible!%22);%0A        else%0A            player.sendMessage(ChatColor.RED + %22Vanished players: %22 + result);%0A    %7D%0A
 %0A    public 
@@ -2252,38 +2252,24 @@
 d%22);%0A    %7D%0A%0A
-    @Override%0A
     public v
@@ -2367,22 +2367,8 @@
  %7D%0A%0A
-    @Override%0A
     
@@ -2578,33 +2578,175 @@
 eCase(%22vanish%22))
+ %7B
 %0A
+            if (args.length == 1 && args%5B0%5D.equalsIgnoreCase(%22list%22))%0A                showVanishList((Player) sender);%0A            else%0A    
             enab
@@ -2775,24 +2775,34 @@
 er, false);%0A
+        %7D%0A
         else
@@ -2853,16 +2853,18 @@
 anish%22))
+ %7B
 %0A       
@@ -2906,16 +2906,26 @@
  false);
+%0A        %7D
 %0A%0A      

add vanish list