package fr.noogotte.useful_commands.command;

import java.util.List;
import java.util.Map.Entry;

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

import fr.aumgn.bukkitutils.command.Command;
import fr.aumgn.bukkitutils.command.NestedCommands;
import fr.aumgn.bukkitutils.command.args.CommandArgs;
import fr.aumgn.bukkitutils.command.exception.CommandError;
import fr.noogotte.useful_commands.component.WarpsComponent;
import fr.noogotte.useful_commands.component.WarpsComponent.Warp;

@NestedCommands(name = "useful")
public class WarpsCommand extends UsefulCommands {

    private WarpsComponent warpscomponent;

    public WarpsCommand(WarpsComponent warpscomponent) {
        this.warpscomponent = warpscomponent;
    }

    @Command(name = "setwarp", min = 1, max = 1)
    public void createWarp(Player player, CommandArgs args) {
        if(warpscomponent.isWarp(args.get(0))) {
            throw new CommandError("Le warp " + args.get(0) + " existe déjà.");
        } else {
            Location location = player.getLocation();
            warpscomponent.addWarp(args.get(0), location);
            player.sendMessage(ChatColor.GREEN + "Vous avez créé un warp : "
                    + ChatColor.AQUA + args.get(0));
        }
    }

    @Command(name = "warp", min = 1, max = 2)
    public void teleportToWarp(CommandSender sender, CommandArgs args) {
        if(!warpscomponent.isWarp(args.get(0))) {
            throw new CommandError("Le warp " + args.get(0) + " n'existe pas.");
        } else {
            String warpName = args.get(0);
            List<Player> targets = args.getPlayers(1).match(sender);

            for (Player target : targets) {
                Warp warp = warpscomponent.getWarp(warpName);
                target.teleport(warp.toLocation());
                target.sendMessage(ChatColor.GREEN + "Poof !");

                if (!sender.equals(target)) {
                    sender.sendMessage( target.getName() + "a été téléporté au warp : " + warpName);
                }
            }
        }
    }

    @Command(name = "deletewarp", flags = "a", min = 0, max = 1)
    public void deleteWarp(CommandSender sender, CommandArgs args) {
    	
    	boolean all = args.hasFlag('a');
    	
    	if(all) {
    		warpscomponent.clearWarp();
    		sender.sendMessage(ChatColor.RED + "Vous avez enlevés tous les Warps !");
    		return;
    	}

        if(!warpscomponent.isWarp(args.get(0))) {
            String arg = args.get(0);
            throw new CommandError("Le warp " + arg + " n'existe pas.");
        } else {
            warpscomponent.deleteWarp(args.get(0));
            sender.sendMessage(ChatColor.RED + "Vous avez supprimé le warp : " + args.get(0));
        }
    }

    @Command(name = "warps", min = 0, max = 0)
    public void warps(CommandSender sender, CommandArgs args) {
    	
    	if(warpscomponent.isEmpty()) {
    		throw new CommandError("Il n'y a pas de warp !");
    	}
    	
    	sender.sendMessage(ChatColor.GOLD + "Warps : ");
        for (Entry<String, Warp> warpEntry : warpscomponent.warps()) {
            sender.sendMessage(ChatColor.AQUA + "  -" + warpEntry.getKey());
        }
    }
}

@@ -2307,31 +2307,24 @@
 gs args) %7B%0D%0A
-    %09%0D%0A
     %09boolean
@@ -2346,24 +2346,24 @@
 Flag('a');%0D%0A
+
     %09%0D%0A    %09
@@ -2498,36 +2498,24 @@
    %09
-%09return;%0D%0A    %09%7D%0D%0A
+%7D else %7B
 %0D%0A    
-    
+%09%09
 if(!
@@ -2553,32 +2553,27 @@
 0))) %7B%0D%0A    
-        
+%09%09%09
 String arg =
@@ -2587,32 +2587,27 @@
 et(0);%0D%0A    
-   
-     
+%09%09%09
 throw new Co
@@ -2652,36 +2652,34 @@
 te pas.%22);%0D%0A    
-    
+%09%09
 %7D else %7B%0D%0A      
@@ -2672,32 +2672,27 @@
 else %7B%0D%0A    
-        
+%09%09%09
 warpscompone
@@ -2720,32 +2720,27 @@
 t(0));%0D%0A    
-        
+%09%09%09
 sender.sendM
@@ -2807,36 +2807,42 @@
 s.get(0));%0D%0A    
+%09%09%7D%0D%0A
     
+%09
 %7D%0D%0A    %7D%0D%0A%0D%0A    

Remove an "return;".