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

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Listener;

import com.elmakers.mine.bukkit.action.BaseSpellAction;
import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.spell.Spell;
import com.elmakers.mine.bukkit.api.spell.SpellResult;

public class ModifyMaxHealthAction extends BaseSpellAction implements Listener {
    /**
     * The max health to be applied with this action.
     */
    private double health = 0.0;

    @Override
    public void initialize(Spell spell, ConfigurationSection parameters) {
        super.initialize(spell, parameters);
        health = parameters.getDouble("health", 0.0);
    }

    @Override
    public SpellResult perform(CastContext context) {
        Entity target = context.getTargetEntity();

        if (target == null || !(target instanceof LivingEntity)) {
            return SpellResult.NO_TARGET;
        }
        if (health <= 0) {
            return SpellResult.FAIL;
        }

        LivingEntity li = (LivingEntity)target;
        if (li.getHealth() > health) {
            li.setHealth(health);
        }
        li.setMaxHealth(health);

        return SpellResult.CAST;
    }

    @Override
    public boolean isUndoable()
    {
        return false;
    }

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

@@ -43,16 +43,71 @@
 iltin;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Collection;%0A%0A
 import o
@@ -148,24 +148,24 @@
 ionSection;%0A
-
 import org.b
@@ -474,16 +474,65 @@
 lResult;
+%0Aimport com.elmakers.mine.bukkit.spell.BaseSpell;
 %0A%0Apublic
@@ -744,30 +744,35 @@
 oid 
-initialize(Spell spell
+prepare(CastContext context
 , Co
@@ -822,24 +822,23 @@
 per.
-initialize(spell
+prepare(context
 , pa
@@ -887,16 +887,20 @@
 Double(%22
+max_
 health%22,
@@ -1567,32 +1567,32 @@
 tEntity()%0A    %7B%0A
-
         return t
@@ -1602,10 +1602,549 @@
 ;%0A    %7D%0A
+%0A%0A    @Override%0A    public void getParameterNames(Spell spell, Collection%3CString%3E parameters)%0A    %7B%0A        super.getParameterNames(spell, parameters);%0A        parameters.add(%22max_health%22);%0A    %7D%0A%0A    @Override%0A    public void getParameterOptions(Spell spell, String parameterKey, Collection%3CString%3E examples)%0A    %7B%0A        if (parameterKey.equals(%22max_health%22)) %7B%0A            examples.addAll(Arrays.asList((BaseSpell.EXAMPLE_SIZES)));%0A        %7D else %7B%0A            super.getParameterOptions(spell, parameterKey, examples);%0A        %7D%0A    %7D%0A
 %7D%0A

Fix modify max health action, change parameter to max_health