Search in sources :

Example 51 with MageController

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

the class MagicConfigurableExecutor method onLevelSpells.

protected boolean onLevelSpells(String command, CommandSender sender, Player player, CasterProperties caster, Integer maxLevel) {
    Collection<String> spells = caster.getSpells();
    MageController controller = api.getController();
    int levelledCount = 0;
    for (String spellKey : spells) {
        SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
        if (spellTemplate == null)
            continue;
        SpellKey key = spellTemplate.getSpellKey();
        int currentLevel = key.getLevel();
        if (maxLevel != null && currentLevel >= maxLevel)
            continue;
        int targetLevel = key.getLevel();
        while (spellTemplate != null && (maxLevel == null || targetLevel < maxLevel)) {
            key = new SpellKey(key.getBaseKey(), targetLevel + 1);
            spellTemplate = controller.getSpellTemplate(key.getKey());
            if (spellTemplate != null) {
                targetLevel++;
            }
        }
        if (currentLevel >= targetLevel)
            continue;
        key = new SpellKey(key.getBaseKey(), targetLevel);
        caster.addSpell(key.getKey());
        levelledCount++;
    }
    if (sender != player) {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_not_levelled", "$name", player.getName()));
        }
    } else {
        if (levelledCount > 0) {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
        } else {
            sender.sendMessage(api.getMessages().getParameterized(command + ".spells_not_levelled", "$name", player.getName()));
        }
    }
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 52 with MageController

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

the class MagicItemCommandExecutor method onItemSave.

public boolean onItemSave(Player player, ItemStack item, String[] parameters) {
    if (parameters.length < 1) {
        player.sendMessage("Use: /mitem save <filename> [worth]");
        return true;
    }
    MageController controller = api.getController();
    String template = parameters[0];
    ItemData existing = controller.getItem(template);
    if (existing != null && !player.hasPermission("Magic.item.overwrite")) {
        String creatorId = existing.getCreatorId();
        boolean isCreator = creatorId != null && creatorId.equalsIgnoreCase(player.getUniqueId().toString());
        if (!player.hasPermission("Magic.item.overwrite_own") || !isCreator) {
            player.sendMessage(ChatColor.RED + "The " + template + " item already exists and you don't have permission to overwrite it.");
            return true;
        }
    }
    double worth = 0;
    if (parameters.length > 1) {
        try {
            worth = Double.parseDouble(parameters[1]);
        } catch (Exception ex) {
            player.sendMessage("Use: /mitem save <filename> [worth]");
            return true;
        }
    } else if (existing != null) {
        worth = existing.getWorth();
    }
    // We always save items with a quantity of 1!
    item.setAmount(1);
    YamlConfiguration itemConfig = new YamlConfiguration();
    ConfigurationSection itemSection = itemConfig.createSection(template);
    itemSection.set("creator_id", player.getUniqueId().toString());
    itemSection.set("creator", player.getName());
    itemSection.set("worth", worth);
    itemSection.set("item", item);
    File itemFolder = new File(controller.getConfigFolder(), "items");
    File itemFile = new File(itemFolder, template + ".yml");
    itemFolder.mkdirs();
    try {
        itemConfig.save(itemFile);
    } catch (IOException ex) {
        ex.printStackTrace();
        player.sendMessage(ChatColor.RED + "Can't write to file " + itemFile.getName());
        return true;
    }
    controller.loadItemTemplate(template, itemSection);
    player.sendMessage(ChatColor.WHITE + "Item saved as " + ChatColor.GOLD + template + " worth " + ChatColor.GREEN + worth);
    if (existing != null) {
        player.sendMessage(ChatColor.YELLOW + " Replaced Worth " + ChatColor.DARK_GREEN + existing.getWorth());
    }
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) IOException(java.io.IOException) ItemData(com.elmakers.mine.bukkit.api.item.ItemData) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 53 with MageController

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

the class MagicItemCommandExecutor method onItemDelete.

public boolean onItemDelete(CommandSender sender, String itemKey) {
    MageController controller = api.getController();
    ItemData existing = controller.getItem(itemKey);
    if (existing == null) {
        sender.sendMessage(ChatColor.RED + "Unknown item: " + itemKey);
        return true;
    }
    boolean hasPermission = true;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.hasPermission("Magic.item.overwrite")) {
            if (player.hasPermission("Magic.item.overwrite_own")) {
                String creatorId = existing.getCreatorId();
                hasPermission = creatorId != null && creatorId.equalsIgnoreCase(player.getUniqueId().toString());
            } else {
                hasPermission = false;
            }
        }
    }
    if (!hasPermission) {
        sender.sendMessage(ChatColor.RED + "You don't have permission to delete " + itemKey);
        return true;
    }
    File itemFolder = new File(controller.getConfigFolder(), "items");
    File itemFile = new File(itemFolder, itemKey + ".yml");
    if (!itemFile.exists()) {
        sender.sendMessage(ChatColor.RED + "File doesn't exist: " + itemFile.getName());
        return true;
    }
    itemFile.delete();
    controller.unloadItemTemplate(itemKey);
    sender.sendMessage("Deleted item " + itemKey);
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) File(java.io.File) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 54 with MageController

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

the class MagicItemCommandExecutor method onItemWorth.

public boolean onItemWorth(Player player, ItemStack item) {
    MageController controller = api.getController();
    Double worth = controller.getWorth(item);
    if (worth == null) {
        player.sendMessage(ChatColor.RED + "No worth defined for that item");
        return true;
    }
    String worthDescription = null;
    int amount = item.getAmount();
    double totalWorth = worth * amount;
    if (VaultController.hasEconomy()) {
        VaultController vault = VaultController.getInstance();
        worthDescription = vault.format(totalWorth);
        if (amount > 1) {
            worthDescription = worthDescription + ChatColor.WHITE + " (" + ChatColor.GOLD + vault.format(worth) + ChatColor.WHITE + " each)";
        }
    } else {
        worthDescription = Double.toString(totalWorth);
        if (amount > 1) {
            worthDescription = worthDescription + ChatColor.WHITE + " (" + ChatColor.GOLD + Double.toString(worth) + ChatColor.WHITE + " each)";
        }
    }
    player.sendMessage("That item is worth " + ChatColor.GOLD + worthDescription);
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) VaultController(com.elmakers.mine.bukkit.integration.VaultController)

Example 55 with MageController

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

the class HeroesSpellSkill method getSkillName.

/**
 * This code is redudant, but unfortunately it needs to be since we need to know the
 * skill name for the super() constructor call.
 */
private static String getSkillName(Heroes heroes, String spellKey) {
    Plugin magicPlugin = heroes.getServer().getPluginManager().getPlugin("Magic");
    if (magicPlugin == null || (!(magicPlugin instanceof MagicAPI) && !magicPlugin.isEnabled())) {
        heroes.getLogger().warning("MagicHeroes skills require the Magic plugin");
        throw new RuntimeException("MagicHeroes skills require the Magic plugin");
    }
    MagicAPI api = (MagicAPI) magicPlugin;
    MageController controller = api.getController();
    SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
    if (spellTemplate == null) {
        controller.getLogger().warning("Failed to load Magic skill spell: " + spellKey);
        throw new RuntimeException("Failed to load Magic skill spell: " + spellKey);
    }
    String baseName = ChatColor.stripColor(spellTemplate.getName().replace(" ", ""));
    return controller.getHeroesSkillPrefix() + baseName;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) MagicAPI(com.elmakers.mine.bukkit.api.magic.MagicAPI) Plugin(org.bukkit.plugin.Plugin) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

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