package support.plugin.hcf.factions.commands.arguments;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import support.plugin.hcf.command.CommandResult;
import support.plugin.hcf.factions.Faction;
import support.plugin.hcf.player.ChatMode;
import support.plugin.hcf.player.HCFPlayer;
import support.plugin.hcf.utils.Messages;

public class FactionChatArg implements support.plugin.hcf.command.HCFCommand
{
  public FactionChatArg() {}
  
  public String getName()
  {
    return "chat";
  }
  
  public String getDescription()
  {
    return "Toggle your chat mode.";
  }
  
  public String[] getAliases()
  {
    return new String[] { "c" };
  }
  
  public String[] getUsage()
  {
    return new String[] { "/f chat [mode]" };
  }
  


  public String getPermission()
  {
    return null;
  }
  
  public CommandResult execute(CommandSender sender, String[] args)
  {
    Player player = (Player)sender;
    HCFPlayer hcfplayer = support.plugin.hcf.player.PlayerManager.getPlayer(player);
    Faction faction = hcfplayer.getFaction();
    if (faction != null) {
      ChatMode newMode = ChatMode.PUBLIC;
      if (hcfplayer.getChatMode() == ChatMode.PUBLIC) {
        newMode = ChatMode.FACTION;
      } else if (hcfplayer.getChatMode() == ChatMode.FACTION) {
        newMode = ChatMode.ALLY;
      }
      if (args.length > 0) {
        if (args[0].toLowerCase().startsWith("p")) {
          newMode = ChatMode.PUBLIC;
        } else if (args[0].toLowerCase().startsWith("f")) {
          newMode = ChatMode.FACTION;
        } else if (args[0].toLowerCase().startsWith("a")) {
          newMode = ChatMode.ALLY;
        }
      }
      
      hcfplayer.setChatMode(newMode);
      Messages.sendMessage(player, new String[] { "&eYour chat mode is now &c" + support.plugin.hcf.utils.utils.Utils.capitalizeString(newMode.toString()) + "&e." });
    } else {
      Messages.sendMessage(player, new String[] { "&cYou are not in a faction." });
    }
    return CommandResult.SUCCESS;
  }
}
