package vg.civcraft.mc.namelayer.command.commands;

import java.util.List;
import java.util.UUID;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
import vg.civcraft.mc.namelayer.NameAPI;
import vg.civcraft.mc.namelayer.command.PlayerCommand;
import vg.civcraft.mc.namelayer.command.TabCompleters.GroupTabCompleter;
import vg.civcraft.mc.namelayer.command.TabCompleters.MemberTypeCompleter;
import vg.civcraft.mc.namelayer.group.Group;
import vg.civcraft.mc.namelayer.permission.GroupPermission;
import vg.civcraft.mc.namelayer.permission.PermissionType;

public class ListPermissions extends PlayerCommand{

	public ListPermissions(String name) {
		super(name);
		setIdentifier("nllp");
		setDescription("This command is used to show permissions for a PlayerType in a specific group.");
		setUsage("/nllp <group> <PlayerType>");
		setArguments(2,2);
	}

	@Override
	public boolean execute(CommandSender sender, String[] args) {
		if (!(sender instanceof Player)){
			sender.sendMessage(ChatColor.RED + "No.");
			return true;
		}
		Player p = (Player) sender;
		Group g = gm.getGroup(args[0]);
		if (g == null){
			p.sendMessage(ChatColor.RED + "That group does not exist.");
			return true;
		}
		UUID uuid = NameAPI.getUUID(p.getName());
		PlayerType playerType = g.getPlayerType(uuid);
		if (playerType == null){
			p.sendMessage(ChatColor.RED + "You do not have access to this group.");
			return true;
		}
		
		GroupPermission gPerm = gm.getPermissionforGroup(g);
		if (!gPerm.isAccessible(playerType, PermissionType.LIST_PERMS)){
			p.sendMessage(ChatColor.RED + "You do not have permission in this group to run this command.");
			return true;
		}
		
		PlayerType check = PlayerType.getPlayerType(args[1]);
		if (check == null){
			PlayerType.displayPlayerTypes(p);
			return true;
		}
		String types = gPerm.listPermsforPlayerType(check);
		p.sendMessage(ChatColor.GREEN + types);
		return true;
	}

	@Override
	public List<String> tabComplete(CommandSender sender, String[] args) {
		if (!(sender instanceof Player))
			return null;

		if (args.length == 0)
			return GroupTabCompleter.complete(null, null, (Player) sender);
		else if (args.length == 1)
			return GroupTabCompleter.complete(args[0], null, (Player)sender);
		else if (args.length == 2)
			return MemberTypeCompleter.complete(args[1]);

		return  null;
	}

}

@@ -951,17 +951,17 @@
 guments(
-2
+1
 ,2);%0A%09%7D%0A
@@ -1581,16 +1581,17 @@
 );%0A%09%09if 
+(
 (!gPerm.
@@ -1642,16 +1642,39 @@
 _PERMS))
+ && (args.length != 1))
 %7B%0A%09%09%09p.s
@@ -1789,16 +1789,60 @@
 %0A%09%09%7D%0A%09%09%0A
+%09%09String types;%0A%09%09if(args.length == 2)%0A%09%09%7B%0A%09
 %09%09Player
@@ -1887,24 +1887,25 @@
 args%5B1%5D);%0A%09%09
+%09
 if (check ==
@@ -1912,16 +1912,17 @@
  null)%7B%0A
+%09
 %09%09%09Playe
@@ -1949,24 +1949,25 @@
 ypes(p);%0A%09%09%09
+%09
 return true;
@@ -1971,21 +1971,16 @@
 ue;%0A
+%09
 %09%09%7D%0A%09%09
-String 
+%09
 type
@@ -2020,16 +2020,88 @@
 check);%0A
+%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09types = gPerm.listPermsforPlayerType(playerType);%0A%09%09%7D%0A
 %09%09p.send

Allow for Player Permission viewing