Search in sources :

Example 31 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class BaseShopAction method checkContext.

public SpellResult checkContext(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = mage.getController();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (permissionNode != null && !player.hasPermission(permissionNode)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!requireWand) {
        return SpellResult.CAST;
    }
    Wand wand = mage.getActiveWand();
    if (wand == null) {
        context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
        return SpellResult.FAIL;
    }
    WandUpgradePath path = wand.getPath();
    if (requiredTemplate != null) {
        String template = wand.getTemplateKey();
        if (template == null || !template.equals(requiredTemplate)) {
            context.showMessage(context.getMessage("no_template", getDefaultMessage(context, "no_template")).replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
    }
    // Check path requirements
    if (requiredPath != null || exactPath != null) {
        if (path == null) {
            context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            WandUpgradePath requiresPath = controller.getPath(requiredPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_required_path", getDefaultMessage(context, "no_required_path")).replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in Shop action: " + requiredPath);
            }
            return SpellResult.FAIL;
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            WandUpgradePath requiresPath = controller.getPath(exactPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_path_exact", getDefaultMessage(context, "no_path_exact")).replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in Shop action: " + exactPath);
            }
            return SpellResult.FAIL;
        }
        if (requiresCompletedPath != null) {
            if (path.canEnchant(wand)) {
                context.showMessage(context.getMessage("no_path_end", getDefaultMessage(context, "no_path_end")).replace("$path", path.getName()));
                return SpellResult.FAIL;
            }
        }
    }
    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)

Example 32 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class BrushSelectAction method clicked.

@Override
public void clicked(InventoryClickEvent event) {
    event.setCancelled(true);
    InventoryAction action = event.getAction();
    if (context != null) {
        Mage mage = context.getMage();
        if (action == InventoryAction.NOTHING) {
            int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
            page = page + direction;
            mage.deactivateGUI();
            perform(context);
            event.setCancelled(true);
            return;
        }
        ItemStack item = event.getCurrentItem();
        String set = InventoryUtils.getMetaString(item, "brush_set", null);
        if (set != null) {
            if (set.equals("schematics")) {
                String inventoryTitle = context.getMessage("schematics_title", "Schematics");
                int invSize = ((schematics.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack schematicItem : schematics) {
                    displayInventory.addItem(schematicItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            } else if (set.equals("variants")) {
                MaterialAndData baseMaterial = new MaterialAndData(item);
                String baseName = baseMaterial.getBaseName();
                String inventoryTitle = context.getMessage("variants_title", "$variant Types").replace("$variant", baseName);
                String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
                MaterialAndData brushMaterial = new MaterialAndData(brushKey);
                List<ItemStack> variantList = variants.get(brushMaterial.getMaterial());
                int invSize = ((variantList.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack variantItem : variantList) {
                    displayInventory.addItem(variantItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            }
        }
        mage.deactivateGUI();
        Wand wand = context.getWand();
        if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isBrush(item)) {
            String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
            wand.setActiveBrush(brushKey);
        }
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Example 33 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class AddSpellAction 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 (permissionNode != null && !player.hasPermission(permissionNode)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (wand == null || spellKey == null || spellKey.isEmpty()) {
        context.showMessage("no_wand", "You must be holding a wand!");
        return SpellResult.FAIL;
    }
    if (wand.hasSpell(spellKey)) {
        return SpellResult.NO_TARGET;
    }
    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;
        }
        MageController controller = context.getController();
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            WandUpgradePath requiresPath = controller.getPath(requiredPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_required_path", "You must be at least $path!").replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in AddSpell action: " + requiredPath);
            }
            return SpellResult.FAIL;
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            WandUpgradePath requiresPath = controller.getPath(exactPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_path_exact", "You must be at $path!").replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in AddSpell action: " + exactPath);
            }
            return SpellResult.FAIL;
        }
        if (requiresCompletedPath != null) {
            WandUpgradePath pathUpgrade = path.getUpgrade();
            if (pathUpgrade == null) {
                context.showMessage(context.getMessage("no_upgrade", "There is nothing more for you here.").replace("$wand", wand.getName()));
                return SpellResult.FAIL;
            }
            if (path.canEnchant(wand)) {
                context.showMessage(context.getMessage("no_path_end", "You must be ready to advance to $path!").replace("$path", pathUpgrade.getName()));
                return SpellResult.FAIL;
            }
        }
    }
    if (!wand.addSpell(spellKey)) {
        return SpellResult.NO_TARGET;
    }
    wand.setActiveSpell(spellKey);
    if (autoUpgrade) {
        com.elmakers.mine.bukkit.api.wand.WandUpgradePath path = wand.getPath();
        WandUpgradePath nextPath = path != null ? path.getUpgrade() : null;
        if (nextPath != null && path.checkUpgradeRequirements(wand, null) && !path.canEnchant(wand)) {
            path.upgrade(wand, mage);
        }
    }
    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) WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Example 34 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class MagicRecipe method load.

public boolean load(ConfigurationSection configuration) {
    outputKey = configuration.getString("output");
    if (outputKey == null) {
        return false;
    }
    substitue = ConfigurationUtils.getMaterial(configuration, "substitue", null);
    disableDefaultRecipe = configuration.getBoolean("disable_default", false);
    if (disableDefaultRecipe) {
        controller.getLogger().warning("Recipe " + key + " has disable_default: true, ignoring because trying to remove a recipe now throws an error.");
        disableDefaultRecipe = false;
    }
    outputItemType = configuration.getString("output_type", "item");
    ItemStack item = null;
    if (outputItemType.equalsIgnoreCase("wand")) {
        Wand wand = !outputKey.isEmpty() ? controller.createWand(outputKey) : null;
        if (wand != null) {
            item = wand.getItem();
        } else {
            controller.getLogger().warning("Unable to load recipe output wand: " + outputKey);
        }
    } else if (outputItemType.equalsIgnoreCase("spell")) {
        item = controller.createSpellItem(outputKey);
    } else if (outputItemType.equalsIgnoreCase("brush")) {
        item = controller.createBrushItem(outputKey);
    } else if (outputItemType.equalsIgnoreCase("item")) {
        item = controller.createItem(outputKey);
    } else {
        return false;
    }
    if (item != null) {
        outputType = item.getType();
        ShapedRecipe shaped = new ShapedRecipe(item);
        List<String> rows = new ArrayList<>();
        for (int i = 1; i <= 3; i++) {
            String recipeRow = configuration.getString("row_" + i, "");
            if (recipeRow.length() > 0) {
                rows.add(recipeRow);
            }
        }
        if (rows.size() > 0) {
            shaped = shaped.shape(rows.toArray(new String[0]));
            ConfigurationSection materials = configuration.getConfigurationSection("ingredients");
            if (materials == null) {
                materials = configuration.getConfigurationSection("materials");
            }
            Set<String> keys = materials.getKeys(false);
            for (String key : keys) {
                String materialKey = materials.getString(key);
                ItemData ingredient = controller.getOrCreateItem(materialKey);
                MaterialData material = ingredient == null ? null : ingredient.getMaterialData();
                if (material == null) {
                    outputType = null;
                    controller.getLogger().warning("Unable to load recipe ingredient " + materialKey);
                    return false;
                }
                shaped.setIngredient(key.charAt(0), material);
                ingredients.put(key.charAt(0), ingredient);
            }
            recipe = shaped;
        }
    }
    return outputType != null;
}
Also used : ShapedRecipe(org.bukkit.inventory.ShapedRecipe) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.api.wand.Wand) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 35 with Wand

use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.

the class PlaceholderAPIManager method onPlaceholderRequest.

@Override
public String onPlaceholderRequest(Player player, String placeholder) {
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    Wand wand = mage.getActiveWand();
    Spell spell = wand == null ? null : wand.getActiveSpell();
    if (spell == null) {
        ItemStack item = player.getInventory().getItemInMainHand();
        String spellKey = controller.getSpell(item);
        if (spellKey != null) {
            spell = mage.getSpell(spellKey);
        }
    }
    if (spell == null) {
        ItemStack item = player.getInventory().getItemInOffHand();
        String spellKey = controller.getSpell(item);
        if (spellKey != null) {
            spell = mage.getSpell(spellKey);
        }
    }
    CasterProperties casterProperties = mage.getActiveProperties();
    switch(placeholder) {
        case "path":
            ProgressionPath path = casterProperties.getPath();
            return path == null ? "" : path.getName();
        case "class":
            return activeClass == null ? "" : activeClass.getName();
        case "wand":
            return wand == null ? "" : wand.getName();
        case "spell":
            return spell == null ? "" : spell.getName();
    }
    return "";
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Aggregations

Wand (com.elmakers.mine.bukkit.api.wand.Wand)60 Mage (com.elmakers.mine.bukkit.api.magic.Mage)47 ItemStack (org.bukkit.inventory.ItemStack)20 Player (org.bukkit.entity.Player)18 MageController (com.elmakers.mine.bukkit.api.magic.MageController)14 Entity (org.bukkit.entity.Entity)10 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)7 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)7 ArrayList (java.util.ArrayList)7 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)6 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)5 Inventory (org.bukkit.inventory.Inventory)5 ItemMeta (org.bukkit.inventory.meta.ItemMeta)5 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)4 Spell (com.elmakers.mine.bukkit.api.spell.Spell)4 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)4 Nullable (javax.annotation.Nullable)4 Checker (ch.njol.util.Checker)3 IOException (java.io.IOException)3 Block (org.bukkit.block.Block)3