content: /*
   * BedWars1058 - A bed wars mini-game.
   * Copyright (C) 2021 Andrei Dascălu
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   *
   * Contact e-mail: andrew.dascalu@gmail.com
   */
  
  package com.andrei1058.bedwars.commands.bedwars.subcmds.sensitive;
  
  import com.andrei1058.bedwars.BedWars;
  import com.andrei1058.bedwars.api.command.ParentCommand;
  import com.andrei1058.bedwars.api.command.SubCommand;
  import com.andrei1058.bedwars.arena.Arena;
  import com.andrei1058.bedwars.arena.Misc;
  import com.andrei1058.bedwars.arena.SetupSession;
  import com.andrei1058.bedwars.commands.bedwars.MainCommand;
  import com.andrei1058.bedwars.configuration.Permissions;
  import net.md_5.bungee.api.chat.ClickEvent;
  import org.bukkit.command.CommandSender;
  import org.bukkit.command.ConsoleCommandSender;
  import org.bukkit.entity.Player;
  
  import java.util.List;
  
  import static com.andrei1058.bedwars.BedWars.config;
  
  public class SetLobby extends SubCommand {
  
      public SetLobby(ParentCommand parent, String name) {
          super(parent, name);
          setPriority(1);
          showInList(true);
          setPermission(Permissions.PERMISSION_SETUP_ARENA);
          setDisplayInfo(Misc.msgHoverClick("§6 ▪ §7/"+MainCommand.getInstance().getName()+" "+getSubCommandName()+ (config.getLobbyWorldName().isEmpty() ? " §c(not set)" : " §a(set)"),
                  "§aSet the main lobby. §fThis is required but\n§fif you are going to use the server in §eBUNGEE §fmode\n§fthe lobby location will §enot §fbe used.\n§eType again to replace the old spawn location.",
                  "/"+getParent().getName()+" "+getSubCommandName(), ClickEvent.Action.RUN_COMMAND));
      }
  
      @Override
      public boolean execute(String[] args, CommandSender s) {
          if (s instanceof ConsoleCommandSender) return false;
          Player p = (Player) s;
          if (SetupSession.isInSetupSession(p.getUniqueId())){
              p.sendMessage("§6 ▪ §4This command can't be used in arenas. It is meant for the main lobby!");
              return true;
          }
          config.saveConfigLoc("lobbyLoc", p.getLocation());
          p.sendMessage("§6 ▪ §7Lobby location set!");
          config.reload();
          BedWars.setLobbyWorld(p.getLocation().getWorld().getName());
          return true;
      }
  
      @Override
      public List<String> getTabComplete() {
          return null;
      }
  
      @Override
      public boolean canSee(CommandSender s, com.andrei1058.bedwars.api.BedWars api) {
          if (s instanceof ConsoleCommandSender) return false;
  
          Player p = (Player) s;
          if (Arena.isInArena(p)) return false;
  
          if (SetupSession.isInSetupSession(p.getUniqueId())) return false;
  
          if (!BedWars.getLobbyWorld().isEmpty()) return false;
  
          return hasPermission(s);
      }
  }
  