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

import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.spell.BaseSpell;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;

public class CommandSpell extends BaseSpell {
    @Override
    public SpellResult onCast(ConfigurationSection parameters)
    {
        String command = parameters.getString("command");
        if (command == null || command.length() == 0) {
            return SpellResult.FAIL;
        }

        CommandSender sender = mage.getCommandSender();
        if (sender == null) {
            return SpellResult.FAIL;
        }
        controller.getPlugin().getServer().dispatchCommand(sender, command);
        return SpellResult.CAST;
    }
}

@@ -146,16 +146,42 @@
 eSpell;%0A
+import org.bukkit.Bukkit;%0A
 import o
@@ -272,53 +272,203 @@
 n;%0A%0A
-public class CommandSpell extends BaseSpell %7B
+import java.util.Arrays;%0Aimport java.util.Collection;%0A%0Apublic class CommandSpell extends BaseSpell %7B%0A    public final static String%5B%5D PARAMETERS = %7B%0A            %22command%22, %22console%22, %22op%22%0A    %7D;%0A
 %0A   
@@ -721,242 +721,1313 @@
     
-CommandSender sender = mage.getCommandSender();%0A        if (sender == null) %7B%0A            return SpellResult.FAIL;%0A        %7D%0A        controller.getPlugin().getServer().dispatchCommand(sender, command);%0A        return SpellResult.CAST;
+boolean asConsole = parameters.getBoolean(%22console%22, false);%0A        CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();%0A        if (sender == null) %7B%0A            return SpellResult.FAIL;%0A        %7D%0A%0A        boolean opPlayer = parameters.getBoolean(%22op%22, false);%0A        boolean isOp = sender.isOp();%0A        if (opPlayer && !isOp) %7B%0A            sender.setOp(true);%0A        %7D%0A%0A        controller.getPlugin().getServer().dispatchCommand(sender, command);%0A%0A        if (opPlayer && !isOp) %7B%0A            sender.setOp(false);%0A        %7D%0A        return SpellResult.CAST;%0A    %7D%0A%0A    @Override%0A    public void getParameters(Collection%3CString%3E parameters)%0A    %7B%0A        super.getParameters(parameters);%0A        parameters.addAll(Arrays.asList(PARAMETERS));%0A    %7D%0A%0A    @Override%0A    public void getParameterOptions(Collection%3CString%3E examples, String parameterKey)%0A    %7B%0A        super.getParameterOptions(examples, parameterKey);%0A%0A        if (parameterKey.equals(%22command%22)) %7B%0A            examples.add(%22spawn%22);%0A            examples.add(%22clear%22);%0A        %7D else if (parameterKey.equals(%22console%22)) %7B%0A            examples.addAll(Arrays.asList(EXAMPLE_BOOLEANS));%0A        %7D else if (parameterKey.equals(%22op%22)) %7B%0A            examples.addAll(Arrays.asList(EXAMPLE_BOOLEANS));%0A        %7D
 %0A   

Add "op" and "console" parameters to CommandSpell