Search in sources :

Example 66 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class DeactivateAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    Mage targetMage = targetEntity != null && controller.isMage(targetEntity) ? controller.getMage(targetEntity) : null;
    if (targetMage == null) {
        return SpellResult.NO_TARGET;
    }
    targetMage.deactivateAllSpells(true, false);
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 67 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class MountArmorStandAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    mountTarget = parameters.getBoolean("mount_target", false);
    armorStandInvisible = parameters.getBoolean("armor_stand_invisible", true);
    armorStandSmall = parameters.getBoolean("armor_stand_small", false);
    armorStandMarker = parameters.getBoolean("armor_stand_marker", true);
    armorStandGravity = parameters.getBoolean("armor_stand_gravity", true);
    armorStandPitch = parameters.getDouble("armor_stand_pitch", 0.0);
    armorStandRoll = parameters.getDouble("armor_stand_roll", 0.0);
    mountWand = parameters.getBoolean("mount_wand", false);
    mountName = parameters.getString("mount_name", null);
    if (parameters.contains("armor_stand_reason")) {
        String reasonText = parameters.getString("armor_stand_reason").toUpperCase();
        try {
            armorStandSpawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
        } catch (Exception ex) {
            context.getMage().sendMessage("Unknown spawn reason: " + reasonText);
        }
    }
    MageController controller = context.getController();
    ItemData itemType = controller.getOrCreateItem(parameters.getString("helmet_item"));
    if (itemType != null) {
        helmetItem = itemType.getItemStack(1);
        if (helmetItem != null) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(helmetItem));
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 68 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class DropItemAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    MageController controller = context.getController();
    String itemKey = parameters.getString("item");
    item = controller.createItem(itemKey);
    if (item == null) {
        context.getLogger().warning("Invalid item: " + itemKey);
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController)

Example 69 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class EnchantWandAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (levels <= 0) {
        return SpellResult.FAIL;
    }
    if (wand == null) {
        context.showMessage("no_wand", "You must be holding a wand!");
        return SpellResult.FAIL;
    }
    if (requiredPath != null || exactPath != null) {
        WandUpgradePath path = wand.getPath();
        if (path == null) {
            context.showMessage(context.getMessage("no_upgrade", "You may not learn with that $wand.").replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
        if ((requiredPath != null && !path.hasPath(requiredPath)) || (exactPath != null && !exactPath.equals(path.getKey()))) {
            WandUpgradePath requiresPath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_path", "You may not learn with that $wand.").replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in EnchantWand action: " + requiredPath);
            }
            return SpellResult.FAIL;
        }
    }
    if (requireItem != null) {
        MageController controller = context.getController();
        boolean foundItem = false;
        ItemStack[] contents = player.getInventory().getContents();
        for (int i = 0; i < contents.length; i++) {
            ItemStack item = contents[i];
            if (controller.itemsAreEqual(item, requireItem)) {
                player.getInventory().setItem(i, null);
                foundItem = true;
                break;
            }
        }
        if (!foundItem) {
            context.showMessage("insufficient_resources", "You must have a $requires");
            return SpellResult.INSUFFICIENT_RESOURCES;
        }
    }
    int xpLevels = levels;
    if (useXp) {
        xpLevels = mage.getLevel();
    }
    int levelsUsed = wand.enchant(xpLevels, mage);
    if (levelsUsed == 0) {
        return SpellResult.FAIL;
    }
    if (useXp) {
        mage.setLevel(Math.max(0, mage.getLevel() - levelsUsed));
    }
    return SpellResult.CAST;
}
Also used : WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack)

Example 70 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class EnchantWandAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    levels = parameters.getInt("levels", 1);
    useXp = parameters.getBoolean("use_xp", false);
    requiredPath = parameters.getString("path", null);
    exactPath = parameters.getString("path_exact", null);
    String costKey = parameters.getString("requires");
    if (costKey != null && !costKey.isEmpty()) {
        MageController controller = context.getController();
        requireItem = controller.createItem(costKey);
        if (requireItem == null) {
            context.getLogger().warning("Invalid required item: " + costKey);
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController)

Aggregations

MageController (com.elmakers.mine.bukkit.api.magic.MageController)76 Mage (com.elmakers.mine.bukkit.api.magic.Mage)45 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)26 Location (org.bukkit.Location)16 ItemStack (org.bukkit.inventory.ItemStack)16 Wand (com.elmakers.mine.bukkit.api.wand.Wand)14 Block (org.bukkit.block.Block)11 LivingEntity (org.bukkit.entity.LivingEntity)11 ArrayList (java.util.ArrayList)10 Inventory (org.bukkit.inventory.Inventory)9 ItemMeta (org.bukkit.inventory.meta.ItemMeta)8 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 MagicController (com.elmakers.mine.bukkit.magic.MagicController)5 Nullable (javax.annotation.Nullable)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)4 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)4 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)4 File (java.io.File)4