Search in sources :

Example 21 with MageController

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

the class ModifyManaAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity target = context.getTargetEntity();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    MageController controller = context.getController();
    Mage mage = controller.getRegisteredMage(target);
    if (mage == null) {
        return SpellResult.NO_TARGET;
    }
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    double currentMana = mage.getMana();
    if (mana < 0 && currentMana <= 0) {
        return SpellResult.NO_TARGET;
    }
    int manaMax = mage.getManaMax();
    if (mana > 0 && currentMana >= manaMax) {
        return SpellResult.NO_TARGET;
    }
    if (fillMana) {
        currentMana = manaMax;
    } else {
        currentMana = Math.min(Math.max(0, currentMana + mana), manaMax);
    }
    mage.setMana((float) currentMana);
    mage.updateMana();
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 22 with MageController

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

the class ModifySPAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    int currentSP = mage.getSkillPoints();
    if (sp < 0 && currentSP <= 0) {
        return SpellResult.NO_TARGET;
    }
    int spMax = controller.getSPMaximum();
    if (sp > 0 && currentSP >= spMax) {
        return SpellResult.NO_TARGET;
    }
    mage.addSkillPoints(sp);
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 23 with MageController

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

the class IgniteAction method perform.

@Override
public SpellResult perform(CastContext context) {
    int ticks = duration * 20 / 1000;
    Entity entity = context.getTargetEntity();
    MageController controller = context.getController();
    boolean isElemental = controller.isElemental(entity);
    if (!isElemental && entity.getFireTicks() == ticks) {
        return SpellResult.NO_TARGET;
    }
    context.registerDamaged(entity);
    if (isElemental) {
        Mage mage = context.getMage();
        controller.damageElemental(entity, 0, ticks, mage.getCommandSender());
    } else {
        entity.setFireTicks(ticks);
    }
    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 24 with MageController

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

the class InventoryAction method perform.

@Override
public SpellResult perform(CastContext context) {
    MageController controller = context.getController();
    Entity targetEntity = context.getTargetEntity();
    Mage showMage = context.getMage();
    Player showPlayer = showMage.getPlayer();
    if (showPlayer == null)
        return SpellResult.PLAYER_REQUIRED;
    // Make sure to close the player's wand
    Wand activeWand = showMage.getActiveWand();
    if (activeWand != null) {
        activeWand.closeInventory();
    }
    switch(inventoryType) {
        case CRAFTING:
            if (targetEntity == null || !(targetEntity instanceof Player)) {
                return SpellResult.NO_TARGET;
            }
            Mage mage = controller.getMage(targetEntity);
            Inventory craftingInventory = mage.getInventory();
            showPlayer.openInventory(craftingInventory);
            break;
        case ENDER_CHEST:
            if (targetEntity == null || !(targetEntity instanceof HumanEntity)) {
                return SpellResult.NO_TARGET;
            }
            HumanEntity humanTarget = (HumanEntity) targetEntity;
            Inventory enderInventory = humanTarget.getEnderChest();
            showPlayer.openInventory(enderInventory);
            break;
        case WORKBENCH:
            showPlayer.openWorkbench(null, true);
            break;
        case CHEST:
            if (disposal) {
                showGenericInventory(showPlayer);
                break;
            }
            Block targetBlock = context.getTargetBlock();
            if (targetBlock == null)
                return SpellResult.NO_TARGET;
            BlockState state = targetBlock.getState();
            if (!(state instanceof InventoryHolder))
                return SpellResult.NO_TARGET;
            InventoryHolder holder = (InventoryHolder) state;
            showPlayer.openInventory(holder.getInventory());
            break;
        default:
            // Probably wont' work very well, but sure why not.
            showGenericInventory(showPlayer);
            break;
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) Mage(com.elmakers.mine.bukkit.api.magic.Mage) HumanEntity(org.bukkit.entity.HumanEntity) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Block(org.bukkit.block.Block) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory)

Example 25 with MageController

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

the class BrushSelectAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Wand wand = context.getWand();
    schematics.clear();
    variants.clear();
    this.context = context;
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (wand == null) {
        return SpellResult.FAIL;
    }
    List<String> brushKeys = new ArrayList<>(wand.getBrushes());
    Collections.sort(brushKeys);
    List<ItemStack> brushes = new ArrayList<>();
    List<ItemStack> specials = new ArrayList<>();
    MaterialAndData previous = null;
    for (String brushKey : brushKeys) {
        ItemStack brushItem = com.elmakers.mine.bukkit.wand.Wand.createBrushItem(brushKey, controller, null, false);
        if (MaterialBrush.isSchematic(brushKey)) {
            schematics.add(brushItem);
            continue;
        }
        if (MaterialBrush.isSpecialMaterialKey(brushKey)) {
            specials.add(brushItem);
            continue;
        }
        if (brushItem != null) {
            MaterialAndData material = new MaterialAndData(brushKey);
            if (previous != null && material.getMaterial() == previous.getMaterial()) {
                List<ItemStack> variantList = variants.get(material.getMaterial());
                ItemStack lastAdded = brushes.get(brushes.size() - 1);
                if (variantList == null) {
                    String baseName = material.getBaseName();
                    variantList = new ArrayList<>();
                    variantList.add(lastAdded);
                    brushes.remove(brushes.size() - 1);
                    ItemStack category = InventoryUtils.getCopy(lastAdded);
                    ItemMeta meta = category.getItemMeta();
                    String name = context.getMessage("variant_name", "" + ChatColor.AQUA + "$variant");
                    meta.setDisplayName(name.replace("$variant", baseName));
                    List<String> lore = new ArrayList<>();
                    String description = context.getMessage("variant_description", "Choose a type of $variant");
                    lore.add(description.replace("$variant", baseName));
                    meta.setLore(lore);
                    category.setItemMeta(meta);
                    InventoryUtils.setMeta(category, "brush_set", "variants");
                    variants.put(material.getMaterial(), variantList);
                    brushes.add(category);
                }
                variantList.add(brushItem);
            } else {
                brushes.add(brushItem);
            }
            previous = material;
        }
    }
    ItemStack schematicItem = null;
    if (schematics.size() == 1) {
        schematicItem = schematics.get(0);
    } else if (schematics.size() > 0) {
        schematicItem = InventoryUtils.getCopy(schematics.get(0));
        ItemMeta meta = schematicItem.getItemMeta();
        meta.setDisplayName(context.getMessage("schematics_name", "" + ChatColor.AQUA + "Schematics"));
        List<String> lore = new ArrayList<>();
        lore.add(context.getMessage("schematics_description", "Choose a schematic"));
        meta.setLore(lore);
        schematicItem.setItemMeta(meta);
        InventoryUtils.setMeta(schematicItem, "brush_set", "schematics");
    }
    if (schematicItem != null) {
        brushes.add(schematicItem);
    }
    brushes.addAll(specials);
    if (brushes.size() == 0) {
        return SpellResult.NO_TARGET;
    }
    int inventorySize = 9 * INVENTORY_ROWS;
    int numPages = (int) Math.ceil((float) brushes.size() / inventorySize);
    if (page < 1)
        page = numPages;
    else if (page > numPages)
        page = 1;
    int pageIndex = page - 1;
    int startIndex = pageIndex * inventorySize;
    int maxIndex = (pageIndex + 1) * inventorySize - 1;
    List<ItemStack> showBrushes = new ArrayList<>();
    for (int i = startIndex; i <= maxIndex && i < brushes.size(); i++) {
        showBrushes.add(brushes.get(i));
    }
    String inventoryTitle = context.getMessage("title", "Brushes");
    if (numPages > 1) {
        inventoryTitle += " (" + page + "/" + numPages + ")";
    }
    int invSize = (int) Math.ceil(showBrushes.size() / 9.0f) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (ItemStack brush : showBrushes) {
        displayInventory.addItem(brush);
    }
    mage.activateGUI(this, displayInventory);
    return SpellResult.CAST;
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.api.wand.Wand) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Inventory(org.bukkit.inventory.Inventory)

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