Search in sources :

Example 41 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController 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 42 with MageController

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

the class BaseShopAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    permissionNode = parameters.getString("permission", null);
    sell = parameters.getBoolean("sell", false);
    showConfirmation = parameters.getBoolean("confirm", true);
    confirmFillMaterial = ConfigurationUtils.getMaterialAndData(parameters, "confirm_filler", new MaterialAndData(Material.AIR));
    requiredPath = parameters.getString("path", null);
    exactPath = parameters.getString("path_exact", null);
    requiresCompletedPath = parameters.getString("path_end", null);
    requiredTemplate = parameters.getString("require_template", null);
    autoUpgrade = parameters.getBoolean("auto_upgrade", false);
    upgradeLevels = parameters.getInt("upgrade_levels", 0);
    requireWand = parameters.getBoolean("require_wand", false);
    autoClose = parameters.getBoolean("auto_close", true);
    costScale = parameters.getDouble("scale", 1);
    filterBound = parameters.getBoolean("filter_bound", false);
    putInHand = parameters.getBoolean("put_in_hand", true);
    String worthItemKey = parameters.getString("worth_item", "");
    if (!worthItemKey.isEmpty()) {
        worthItem = context.getController().createItem(worthItemKey);
    } else {
        worthItem = null;
    }
    if (!autoClose) {
        showConfirmation = false;
    }
    if (requiresCompletedPath != null) {
        requiredPath = requiresCompletedPath;
        exactPath = requiresCompletedPath;
    }
    if (requiredPath != null || exactPath != null || requiredTemplate != null) {
        requireWand = true;
    }
    applyToWand = parameters.getBoolean("apply_to_wand", requireWand);
    MageController controller = context.getController();
    isXP = parameters.getBoolean("use_xp", false);
    isItems = parameters.getBoolean("use_items", false) && getWorthItem(controller) != null;
    isSkillPoints = parameters.getBoolean("use_sp", false) && controller.isSPEnabled();
    if (!isSkillPoints && !isXP && !isItems && !VaultController.hasEconomy()) {
        if (getWorthItem(controller) != null) {
            isItems = true;
        } else {
            isSkillPoints = true;
        }
    }
    finalResult = null;
    isActive = false;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

Example 43 with MageController

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

the class BaseShopAction method hasItemCosts.

protected boolean hasItemCosts(CastContext context, ShopItem shopItem) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    double worth = shopItem.getWorth();
    boolean hasCosts = true;
    if (worth > 0) {
        if (isXP) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
            hasCosts = mage.getExperience() >= (int) worth;
        } else if (isItems) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
            int hasAmount = getItemAmount(controller, mage);
            hasCosts = hasAmount >= worth;
        } else if (isSkillPoints) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
            hasCosts = mage.getSkillPoints() >= Math.ceil(worth);
        } else {
            worth = Math.ceil(costScale * worth * controller.getWorthBase());
            hasCosts = VaultController.getInstance().has(mage.getPlayer(), worth);
        }
    }
    return hasCosts;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 44 with MageController

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

the class BaseShopAction method getBalanceDescription.

protected String getBalanceDescription(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Messages messages = controller.getMessages();
    String description = "";
    if (isXP) {
        String xpAmount = Integer.toString(mage.getExperience());
        description = messages.get("costs.xp_amount").replace("$amount", xpAmount);
    } else if (isItems) {
        int itemAmount = getItemAmount(controller, mage);
        description = formatItemAmount(controller, itemAmount);
    } else if (isSkillPoints) {
        String spAmount = Integer.toString(mage.getSkillPoints());
        description = messages.get("costs.sp_amount").replace("$amount", spAmount);
    } else {
        double balance = VaultController.getInstance().getBalance(mage.getPlayer());
        description = VaultController.getInstance().format(balance);
    }
    return description;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Messages(com.elmakers.mine.bukkit.api.magic.Messages) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 45 with MageController

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

the class CancelAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (targetEntity == null || !controller.isMage(targetEntity)) {
        return SpellResult.NO_TARGET;
    }
    SpellResult result = SpellResult.NO_TARGET;
    Mage targetMage = controller.getMage(targetEntity);
    if (spellKeys == null) {
        Batch batch = targetMage.cancelPending(force);
        if (batch != null) {
            result = SpellResult.CAST;
            undoListName = batch.getName();
        }
    } else {
        for (String spellKey : spellKeys) {
            Batch batch = targetMage.cancelPending(spellKey, force);
            if (batch != null) {
                result = SpellResult.CAST;
                undoListName = batch.getName();
            }
        }
    }
    return result;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Batch(com.elmakers.mine.bukkit.api.batch.Batch) Mage(com.elmakers.mine.bukkit.api.magic.Mage) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

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