content: package com.alessiodp.parties.common.commands.sub;
  
  import com.alessiodp.core.common.ADPPlugin;
  import com.alessiodp.core.common.commands.utils.ADPMainCommand;
  import com.alessiodp.core.common.commands.utils.CommandData;
  import com.alessiodp.core.common.user.User;
  import com.alessiodp.parties.common.commands.list.CommonCommands;
  import com.alessiodp.parties.common.commands.utils.PartiesCommandData;
  import com.alessiodp.parties.common.commands.utils.PartiesSubCommand;
  import com.alessiodp.parties.common.configuration.PartiesConstants;
  import com.alessiodp.parties.common.configuration.data.ConfigMain;
  import com.alessiodp.parties.common.configuration.data.Messages;
  import com.alessiodp.parties.common.parties.objects.PartyImpl;
  import com.alessiodp.parties.common.players.objects.PartyPlayerImpl;
  import com.alessiodp.parties.common.utils.EconomyManager;
  import com.alessiodp.parties.common.utils.PartiesPermission;
  import com.alessiodp.parties.common.utils.RankPermission;
  import org.jetbrains.annotations.NotNull;
  
  import java.util.List;
  
  public class CommandProtection extends PartiesSubCommand {
  	
  	public CommandProtection(ADPPlugin plugin, ADPMainCommand mainCommand) {
  		super(
  				plugin,
  				mainCommand,
  				CommonCommands.PROTECTION,
  				PartiesPermission.USER_PROTECTION,
  				ConfigMain.COMMANDS_SUB_PROTECTION,
  				false
  		);
  		
  		syntax = String.format("%s [%s/%s]",
  				baseSyntax(),
  				ConfigMain.COMMANDS_MISC_ON,
  				ConfigMain.COMMANDS_MISC_OFF
  		);
  		
  		description = Messages.HELP_ADDITIONAL_DESCRIPTIONS_PROTECTION;
  		help = Messages.HELP_ADDITIONAL_COMMANDS_PROTECTION;
  	}
  	
  	@Override
  	public boolean preRequisites(@NotNull CommandData commandData) {
  		return handlePreRequisitesFullWithParty(commandData, true, 2, 2, RankPermission.EDIT_PROTECTION);
  	}
  	
  	@Override
  	public void onCommand(@NotNull CommandData commandData) {
  		User sender = commandData.getSender();
  		PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
  		PartyImpl party = ((PartiesCommandData) commandData).getParty();
  		
  		// Command handling
  		Boolean protection = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isChatParty(), commandData.getArgs());
  		if (protection == null) {
  			sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE
  					.replace("%syntax%", syntax));
  			return;
  		}
  		
  		if (protection && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.PROTECTION, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
  			return;
  		
  		// Command starts
  		party.setProtection(protection);
  		
  		sendMessage(sender, partyPlayer, protection ? Messages.ADDCMD_PROTECTION_ON : Messages.ADDCMD_PROTECTION_OFF);
  		
  		plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_PROTECTION,
  				partyPlayer.getName(), party.getName() != null ? party.getName() : "_", protection), true);
  	}
  	
  	@Override
  	public List<String> onTabComplete(@NotNull User sender, String[] args) {
  		return plugin.getCommandManager().getCommandUtils().tabCompleteOnOff(args);
  	}
  }