package com.elmakers.mine.bukkit.action.builtin;

import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.action.BaseSpellAction;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class FeedAction extends BaseSpellAction
{
    static private int MAX_FOOD_LEVEL = 20;

    private int feedAmount;
    private float saturationAmount;
    private boolean clearExhaustion;

    @Override
    public void prepare(CastContext context, ConfigurationSection parameters)
    {
        super.prepare(context, parameters);
        feedAmount = parameters.getInt("feed", 20);
        saturationAmount = parameters.getInt("saturation", 20);
        clearExhaustion = parameters.getBoolean("exhaustion", true);
    }

	@Override
	public SpellResult perform(CastContext context)
	{
        Entity targetEntity = context.getTargetEntity();
		if (!(targetEntity instanceof Player))
		{
			return SpellResult.NO_TARGET;
		}

        Player player = (Player)targetEntity;
        if (feedAmount != 0 && player.getFoodLevel() >= MAX_FOOD_LEVEL)
        {
            return SpellResult.NO_TARGET;
        }
        if (clearExhaustion)
        {
            player.setExhaustion(0);
        }
        if (saturationAmount != 0)
        {
            player.setSaturation(saturationAmount);
        }
        if (feedAmount != 0)
        {
            player.setFoodLevel(Math.min(MAX_FOOD_LEVEL, Math.max(0, player.getFoodLevel() + feedAmount)));
        }

		return SpellResult.CAST;
	}

    @Override
    public boolean requiresTargetEntity()
    {
        return true;
    }
}

@@ -1134,18 +1134,17 @@
 dAmount 
-!=
+%3E
  0 && pl
@@ -1236,32 +1236,152 @@
 RGET;%0A        %7D%0A
+        if (feedAmount %3C 0 && player.getFoodLevel() == 0)%0A        %7B%0A            return SpellResult.NO_TARGET;%0A        %7D%0A
         if (clea

Fix using Feed action with a negative "feed" parameter