Search in sources :

Example 16 with MageController

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

the class GiveItemAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    MageController controller = context.getController();
    permissionNode = parameters.getString("permission", null);
    String itemKey = parameters.getString("item");
    item = controller.createItem(itemKey);
    if (item == null) {
        context.getLogger().warning("Invalid item: " + itemKey);
    } else {
        String name = parameters.getString("name", null);
        List<String> lore = ConfigurationUtils.getStringList(parameters, "lore");
        if ((name != null && !name.isEmpty()) || (lore != null && !lore.isEmpty())) {
            ItemMeta meta = item.getItemMeta();
            if (name != null && !name.isEmpty()) {
                meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
            }
            if (lore != null && !lore.isEmpty()) {
                for (int i = 0; i < lore.size(); i++) {
                    lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i)));
                }
                meta.setLore(lore);
            }
            item.setItemMeta(meta);
        }
    }
    String costKey = parameters.getString("requires");
    if (costKey != null && !costKey.isEmpty()) {
        requireItem = controller.createItem(costKey);
        if (requireItem == null) {
            context.getLogger().warning("Invalid required item: " + costKey);
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 17 with MageController

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

the class GrowEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        context.registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        context.registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            context.registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        context.registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
        context.registerModified(li);
        Skeleton skeleton = (Skeleton) li;
        skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
    } else {
        return SpellResult.NO_TARGET;
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Skeleton(org.bukkit.entity.Skeleton) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 18 with MageController

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

the class CommandAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
    if (sender == null) {
        return SpellResult.FAIL;
    }
    Queue<String> conversationCommands = new ArrayDeque<>(commands.size());
    boolean isOp = sender.isOp();
    if (opPlayer && !isOp) {
        sender.setOp(true);
    }
    for (String command : commands) {
        try {
            String converted = context.parameterize(command);
            if (converted.contains("@arg")) {
                conversationCommands.add(converted);
            } else {
                controller.getPlugin().getServer().dispatchCommand(sender, converted);
            }
        } catch (Exception ex) {
            controller.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
        }
    }
    if (opPlayer && !isOp) {
        sender.setOp(false);
    }
    if (!conversationCommands.isEmpty()) {
        runConversations(context, conversationCommands, opPlayer);
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) CommandSender(org.bukkit.command.CommandSender) ArrayDeque(java.util.ArrayDeque)

Example 19 with MageController

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

the class CreateFieldAction method perform.

@Override
public SpellResult perform(CastContext context) {
    SpellResult result = super.perform(context);
    if (!result.isSuccess() || fieldType != context.getTargetBlock().getType()) {
        return result;
    }
    MageController apiController = context.getController();
    if (!(apiController instanceof MagicController)) {
        return SpellResult.FAIL;
    }
    MagicController controller = (MagicController) apiController;
    PreciousStonesManager preciousStones = controller.getPreciousStones();
    context.getMage().sendDebugMessage(ChatColor.GRAY + "Placing field", 7);
    if (!preciousStones.createField(context.getTargetLocation(), context.getMage().getPlayer())) {
        context.getMage().sendDebugMessage(ChatColor.RED + "Could not place field", 2);
        return SpellResult.NO_TARGET;
    }
    if (!rent.isEmpty() && !rentPeriod.isEmpty()) {
        if (!preciousStones.rentField(context.getTargetLocation().getBlock().getRelative(BlockFace.UP).getLocation(), context.getMage().getPlayer(), rent, rentPeriod, rentSignDirection)) {
            context.getMage().sendDebugMessage(ChatColor.RED + "Could not rent field", 2);
        }
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicController(com.elmakers.mine.bukkit.magic.MagicController) PreciousStonesManager(com.elmakers.mine.bukkit.protection.PreciousStonesManager) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

Example 20 with MageController

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

the class CreatePlotAction method perform.

@Override
public SpellResult perform(CastContext context) {
    MageController apiController = context.getController();
    if (!(apiController instanceof MagicController)) {
        return SpellResult.FAIL;
    }
    MagicController controller = (MagicController) apiController;
    TownyManager towny = controller.getTowny();
    if (!towny.createPlot(context.getTargetLocation(), price)) {
        return SpellResult.NO_TARGET;
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicController(com.elmakers.mine.bukkit.magic.MagicController) TownyManager(com.elmakers.mine.bukkit.protection.TownyManager)

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