package squeek.spiceoflife.foodtracker.commands;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import squeek.spiceoflife.foodtracker.FoodHistory;
import squeek.spiceoflife.foodtracker.FoodTracker;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

public class CommandResetHistory extends CommandBase
{
	@Override
	@Nonnull
	public String getName()
	{
		return "spiceoflife";
	}

	@Override
	@Nonnull
	public String getUsage(@Nonnull ICommandSender commandSender)
	{
		return "/spiceoflife reset [player]";
	}

	@Override
	public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender commandSender, @Nonnull String[] args) throws CommandException
	{
		if (args.length > 0)
		{
			if (args[0].equals("reset"))
			{
				EntityPlayerMP playerToReset;
				playerToReset = args.length > 1 ? getPlayer(server, commandSender, args[1]) : getCommandSenderAsPlayer(commandSender);
				FoodHistory foodHistoryToReset = FoodHistory.get(playerToReset);
				if (foodHistoryToReset != null)
				{
					foodHistoryToReset.reset();
					FoodTracker.syncFoodHistory(foodHistoryToReset);
					notifyCommandListener(commandSender, this, 0, "Reset all 'The Spice of Life' mod data for " + playerToReset.getDisplayName());
				}
				else
					notifyCommandListener(commandSender, this, 0, "Unexpected error (null food history) while resetting 'The Spice of Life' mod data for " + playerToReset.getDisplayName());
				return;
			}
		}
		throw new WrongUsageException(getName() + " reset [player]");
	}

	@Override
	@Nonnull
	public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] curArgs, @Nullable BlockPos pos)
	{
		if (curArgs.length == 1)
			return Collections.singletonList("reset");
		else if (curArgs.length == 2)
			return getListOfStringsMatchingLastWord(curArgs, server.getOnlinePlayerNames());
		else
			return Collections.emptyList();
	}
}

@@ -1472,19 +1472,16 @@
 r, this,
- 0,
  %22Reset 
@@ -1530,39 +1530,32 @@
 layerToReset.get
-Display
 Name());%0A%09%09%09%09%7D%0A%09
@@ -1613,11 +1613,8 @@
 his,
- 0,
  %22Un
@@ -1722,15 +1722,8 @@
 .get
-Display
 Name

Fix /spiceoflife reset command feedback