Search in sources :

Example 6 with ItemData

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

use of com.elmakers.mine.bukkit.api.item.ItemData 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 8 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData 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 9 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MagicItemCommandExecutor method onItemDescribe.

public boolean onItemDescribe(Player player, ItemStack item, String[] args) {
    MaterialAndData material = new MaterialAndData(item);
    player.sendMessage(ChatColor.GOLD + material.getKey());
    YamlConfiguration configuration = new YamlConfiguration();
    if (ConfigurationUtils.loadAllTagsFromNBT(configuration, item)) {
        String itemString = null;
        if (args.length > 0) {
            Object target = configuration.get(args[0]);
            if (target == null) {
                itemString += ChatColor.AQUA + args[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)";
            } else {
                configuration = new YamlConfiguration();
                configuration.set(args[0], target);
                itemString = configuration.saveToString().replace(ChatColor.COLOR_CHAR, '&');
            }
        } else {
            itemString = configuration.saveToString().replace(ChatColor.COLOR_CHAR, '&');
        }
        player.sendMessage(itemString);
    }
    if (args.length == 0) {
        ItemData itemData = api.getController().getItem(item);
        if (itemData != null) {
            player.sendMessage(ChatColor.AQUA + "Give with: " + ChatColor.GRAY + "/mgive " + ChatColor.YELLOW + itemData.getKey());
            double worth = itemData.getWorth();
            if (worth > 0) {
                player.sendMessage(ChatColor.AQUA + " Worth " + ChatColor.GREEN + worth);
            }
        }
    }
    return true;
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Example 10 with ItemData

use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.

the class MountArmorStandAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    mountTarget = parameters.getBoolean("mount_target", false);
    armorStandInvisible = parameters.getBoolean("armor_stand_invisible", true);
    armorStandSmall = parameters.getBoolean("armor_stand_small", false);
    armorStandMarker = parameters.getBoolean("armor_stand_marker", true);
    armorStandGravity = parameters.getBoolean("armor_stand_gravity", true);
    armorStandPitch = parameters.getDouble("armor_stand_pitch", 0.0);
    armorStandRoll = parameters.getDouble("armor_stand_roll", 0.0);
    mountWand = parameters.getBoolean("mount_wand", false);
    mountName = parameters.getString("mount_name", null);
    if (parameters.contains("armor_stand_reason")) {
        String reasonText = parameters.getString("armor_stand_reason").toUpperCase();
        try {
            armorStandSpawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
        } catch (Exception ex) {
            context.getMage().sendMessage("Unknown spawn reason: " + reasonText);
        }
    }
    MageController controller = context.getController();
    ItemData itemType = controller.getOrCreateItem(parameters.getString("helmet_item"));
    if (itemType != null) {
        helmetItem = itemType.getItemStack(1);
        if (helmetItem != null) {
            InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(helmetItem));
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) ItemData(com.elmakers.mine.bukkit.api.item.ItemData)

Aggregations

ItemData (com.elmakers.mine.bukkit.api.item.ItemData)10 MageController (com.elmakers.mine.bukkit.api.magic.MageController)4 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)3 ItemStack (org.bukkit.inventory.ItemStack)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 SpellCategory (com.elmakers.mine.bukkit.spell.SpellCategory)1 LostWand (com.elmakers.mine.bukkit.wand.LostWand)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 ParseException (java.text.ParseException)1 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)1 Player (org.bukkit.entity.Player)1 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)1