/*
 * This file is part of PV-Star for Bukkit, licensed under the MIT License (MIT).
 *
 * Copyright (c) JCThePants (www.jcwhatever.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


package com.jcwhatever.bukkit.pvs.commands.admin.arena;

import com.jcwhatever.nucleus.commands.CommandInfo;
import com.jcwhatever.nucleus.commands.arguments.CommandArguments;
import com.jcwhatever.nucleus.commands.exceptions.CommandException;
import com.jcwhatever.nucleus.commands.response.CommandRequests;
import com.jcwhatever.nucleus.commands.response.IResponseHandler;
import com.jcwhatever.nucleus.commands.response.ResponseType;
import com.jcwhatever.nucleus.utils.language.Localizable;
import com.jcwhatever.bukkit.pvs.Lang;
import com.jcwhatever.bukkit.pvs.api.PVStarAPI;
import com.jcwhatever.bukkit.pvs.api.arena.Arena;
import com.jcwhatever.bukkit.pvs.api.commands.AbstractPVCommand;

import org.bukkit.command.CommandSender;

@CommandInfo(
        parent="arena",
        command="del",
        staticParams={"arenaName"},
        description="Delete the specified arena.",

        paramDescriptions = {
                "arenaName= The name of the arena to delete."})

public class DelSubCommand extends AbstractPVCommand {

    @Localizable static final String _DISABLE_FIRST = "You must disable the arena before it can be deleted.";
    @Localizable static final String _CONFIRM = "{WHITE}Please type '{YELLOW}/confirm{WHITE}' to delete arena '{0}'.";
    @Localizable static final String _SUCCESS = "Arena '{0}' deleted.";

    @Override
    public void execute(final CommandSender sender, CommandArguments args) throws CommandException {

        String arenaName = args.getString("arenaName");

        final Arena arena = getArena(sender, arenaName);
        if (arena == null) {
            return; // finish
        }

        if (arena.getSettings().isEnabled()) {
            tellError(sender, Lang.get(_DISABLE_FIRST));
            return; // finish
        }

        tell(sender, Lang.get(_CONFIRM, arena.getName()));

        // get confirmation
        CommandRequests.request(PVStarAPI.getPlugin(), "delete_" + arena.getName(), sender, new IResponseHandler() {

            @Override
            public void onResponse(ResponseType response) {

                PVStarAPI.getArenaManager().removeArena(arena.getId());

                Arena selectedArena = PVStarAPI.getArenaManager().getSelectedArena(sender);

                if (selectedArena != null && selectedArena.equals(arena)) {
                    PVStarAPI.getArenaManager().setSelectedArena(sender, null);
                }

                tellSuccess(sender, Lang.get(_SUCCESS, arena.getName()));

            }
        }, ResponseType.CONFIRM);
    }

}



@@ -1521,74 +1521,8 @@
 ts;%0A
-import com.jcwhatever.nucleus.commands.response.IResponseHandler;%0A
 impo
@@ -1838,16 +1838,146 @@
 Command;
+%0Aimport com.jcwhatever.nucleus.utils.observer.result.FutureSubscriber;%0Aimport com.jcwhatever.nucleus.utils.observer.result.Result;
 %0A%0Aimport
@@ -3243,34 +3243,104 @@
 er, 
-new IResponseHandler() %7B%0A%0A
+ResponseType.CONFIRM)%0A                .onSuccess(new FutureSubscriber%3CResponseType%3E() %7B%0A        
     
@@ -3365,24 +3365,32 @@
             
+   
+     
 public void 
@@ -3395,17 +3395,16 @@
 d on
+(
 Res
-ponse(
+ult%3C
 Resp
@@ -3415,22 +3415,29 @@
 Type
+%3E
  res
-ponse) %7B%0A%0A
+ult) %7B%0A%0A        
     
@@ -3521,16 +3521,24 @@
         
+    
+    
 Arena se
@@ -3618,24 +3618,32 @@
             
+        
 if (selected
@@ -3702,32 +3702,40 @@
                 
+ 
+       
 PVStarAPI.getAre
@@ -3786,35 +3786,51 @@
                 
+     
-%7D%0A%0A
+   %7D%0A%0A        
                 
@@ -3879,33 +3879,40 @@
 na.getName()));%0A
-%0A
+        
             %7D%0A  
@@ -3921,31 +3921,17 @@
     
-%7D, ResponseType.CONFIRM
+        %7D
 );%0A 

update CommandRequests to return a future