/*
 * This file is part of SpongeSurvivalGamesPlugin, licensed under the MIT License (MIT).
 *
 * Copyright (c) Matthew Broomfield <m0pt0pmatt17@gmail.com>
 * Copyright (c) contributors
 *
 * 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 io.github.m0pt0pmatt.spongesurvivalgames.commands.game.ready;

import io.github.m0pt0pmatt.spongesurvivalgames.BukkitSurvivalGamesPlugin;
import io.github.m0pt0pmatt.spongesurvivalgames.commands.CommandKeywords;
import io.github.m0pt0pmatt.spongesurvivalgames.exceptions.NoPlayerLimitException;
import io.github.m0pt0pmatt.spongesurvivalgames.exceptions.PlayerLimitReachedException;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Map;

/**
 * Command to add a player to a game
 */
public class AddPlayerCommand extends ReadyCommand {

    @Override
    public boolean execute(CommandSender sender, Map<String, String> arguments) {

        if (!super.execute(sender, arguments)) {
            return false;
        }

        if (!arguments.containsKey(CommandKeywords.PLAYERNAME)) {
            Bukkit.getLogger().warning("Player name is not present.");
            return false;
        }
        String playerName = arguments.get(CommandKeywords.PLAYERNAME);

        Player player = Bukkit.getServer().getPlayer(playerName);
        if (player == null) {
            Bukkit.getLogger().warning("No such player \"" + playerName + "\".");
            return false;
        }

        try {
            BukkitSurvivalGamesPlugin.survivalGameMap.get(id).addPlayer(player.getUniqueId());
        } catch (NoPlayerLimitException e) {
            Bukkit.getLogger().warning("No player limit sey for game \"" + id + "\".");
            e.printStackTrace();
        } catch (PlayerLimitReachedException e) {
            Bukkit.getLogger().warning("Player limit reached for game \"" + id + "\".");
            return false;
        }

        Bukkit.getLogger().info("Player \"" + playerName + "\" added to survival game \"" + id + "\".");
        return true;
    }
}

@@ -1869,24 +1869,74 @@
 yCommand %7B%0A%0A
+%09private static final String allKeyword = %22@a%22;%0A%09%0A
     @Overrid
@@ -2350,16 +2350,24 @@
 RNAME);%0A
+        
 %0A       
@@ -2367,16 +2367,112 @@
         
+if (playerName.equals(allKeyword)) %7B%0A        %09return addAllPlayers();%0A        %7D else %7B%0A        %09
 Player p
@@ -2490,20 +2490,8 @@
 kit.
-getServer().
 getP
@@ -2509,16 +2509,17 @@
 rName);%0A
+%09
         
@@ -2536,24 +2536,25 @@
  == null) %7B%0A
+%09
             
@@ -2615,32 +2615,33 @@
 rName + %22%5C%22.%22);%0A
+%09
             retu
@@ -2642,32 +2642,33 @@
   return false;%0A
+%09
         %7D%0A%0A     
@@ -2652,32 +2652,154 @@
 alse;%0A%09        %7D
+%0A        %09return addPlayer(player);%0A        %7D%0A%0A        %0A        %0A    %7D%0A    %0A    private boolean addPlayer(Player player) %7B
 %0A%0A        try %7B%0A
@@ -3283,28 +3283,34 @@
 %5C%22%22 + player
+.get
 Name
+()
  + %22%5C%22 added
@@ -3338,32 +3338,41 @@
  + id + %22%5C%22.%22);%0A
+        %0A
         return t
@@ -3382,10 +3382,177 @@
 ;%0A    %7D%0A
+    %0A    private boolean addAllPlayers() %7B%0A    %09Bukkit.getOnlinePlayers().forEach(player -%3E %7B%0A    %09%09addPlayer(player);%0A    %09%7D);%0A    %09%0A    %09return true;%0A    %7D%0A    %0A   %0A
 %7D%0A

Allow for special all keyword when adding players