Search in sources :

Example 31 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class HatSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    Block target = getTargetBlock();
    if (target == null) {
        return SpellResult.NO_TARGET;
    }
    MaterialAndData material = new MaterialAndData(target);
    if (material.getMaterial() == Material.AIR) {
        return SpellResult.NO_TARGET;
    }
    ItemStack hatItem = material.getItemStack(1);
    ItemStack itemStack = player.getInventory().getHelmet();
    ItemMeta meta = hatItem.getItemMeta();
    meta.setDisplayName(getMessage("hat_name").replace("$material", material.getName()));
    List<String> lore = new ArrayList<>();
    lore.add(getMessage("hat_lore"));
    meta.setLore(lore);
    hatItem.setItemMeta(meta);
    hatItem = InventoryUtils.makeReal(hatItem);
    NMSUtils.makeTemporary(hatItem, getMessage("removed").replace("$material", material.getName()));
    player.getInventory().setHelmet(hatItem);
    if (itemStack != null && itemStack.getType() != Material.AIR && !NMSUtils.isTemporary(itemStack)) {
        player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
    }
    return SpellResult.CAST;
}
Also used : Player(org.bukkit.entity.Player) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 32 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class SelectorAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    this.context = context;
    defaultConfiguration = new SelectorConfiguration(parameters);
    confirmFillMaterial = ConfigurationUtils.getMaterialAndData(parameters, "confirm_filler", new MaterialAndData(Material.AIR));
    autoClose = parameters.getBoolean("auto_close", true);
    costScale = parameters.getDouble("scale", 1);
    title = parameters.getString("title");
    confirmTitle = parameters.getString("confirm_title");
    confirmUnlockTitle = parameters.getString("unlock_confirm_title");
    finalResult = null;
    isActive = false;
    numSlots = 0;
    showingItems = new HashMap<>();
    has = 0;
    Collection<ConfigurationSection> optionConfigs = ConfigurationUtils.getNodeList(parameters, "options");
    if (optionConfigs != null) {
        // Gather list of selector options first, to compute limits
        List<SelectorOption> options = new ArrayList<>();
        for (ConfigurationSection option : optionConfigs) {
            SelectorOption newOption = new SelectorOption(defaultConfiguration, option, context, this);
            if (newOption.hasLimit() && newOption.has(context)) {
                has++;
            }
            options.add(newOption);
        }
        for (SelectorOption option : options) {
            if (option.isUnavailable() && !option.showIfUnavailable()) {
                continue;
            }
            Integer targetSlot = option.getSlot();
            int slot = targetSlot == null ? numSlots : targetSlot;
            showingItems.put(slot, option);
            numSlots = Math.max(slot + 1, numSlots);
        }
    }
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ArrayList(java.util.ArrayList) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 33 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class RecallAction method getIcon.

@Nullable
protected MaterialAndData getIcon(CastContext context, ConfigurationSection parameters, String key) {
    String iconKey = parameters.getString(key);
    if (iconKey == null || iconKey.isEmpty())
        return null;
    MaterialAndData material = ConfigurationUtils.getMaterialAndData(parameters, key);
    if (material == null || !material.isValid() || material.getMaterial() == null) {
        context.getLogger().warning("Invalid material specified for " + context.getSpell().getKey() + " " + key + ": " + iconKey);
        return null;
    }
    return material;
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Nullable(javax.annotation.Nullable)

Example 34 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class RecallAction method showMarkerConfirm.

protected void showMarkerConfirm(CastContext context) {
    options.clear();
    String inventoryTitle = context.getMessage("move_marker_title", "Move Marker");
    Inventory displayInventory = CompatibilityUtils.createInventory(null, 9, inventoryTitle);
    MaterialAndData iconType = getIcon(context, parameters, "icon_move_marker");
    ItemStack markerItem = iconType.getItemStack(1);
    ItemMeta meta = markerItem.getItemMeta();
    meta.setDisplayName(context.getMessage("title_move_marker"));
    String description = context.getMessage("description_move_marker");
    if (description != null && description.length() > 0) {
        List<String> lore = new ArrayList<>();
        lore.add(description);
        meta.setLore(lore);
    }
    markerItem.setItemMeta(meta);
    markerItem = InventoryUtils.makeReal(markerItem);
    InventoryUtils.hideFlags(markerItem, (byte) 63);
    InventoryUtils.setMeta(markerItem, "move_marker", "true");
    displayInventory.setItem(4, markerItem);
    context.getMage().activateGUI(this, displayInventory);
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 35 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class RecurseAction method step.

@Override
public SpellResult step(CastContext context) {
    StackEntry current = stack.peek();
    Block block = current.block;
    int faceIndex = current.face++;
    if (faceIndex >= 0) {
        block = directions.get(faceIndex).getRelative(block);
    }
    long id = BlockData.getBlockId(block);
    if (touched.contains(id)) {
        return SpellResult.NO_TARGET;
    }
    if (!context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
        return SpellResult.NO_TARGET;
    }
    if (faceIndex >= 0 && stack.size() <= recursionDepth) {
        if (checker) {
            BlockFace direction = directions.get(faceIndex);
            block = direction.getRelative(block);
        }
        stack.push(new StackEntry(block));
    }
    touched.add(id);
    actionContext.setTargetLocation(block.getLocation());
    actionContext.playEffects("recurse");
    return startActions();
}
Also used : BlockFace(com.elmakers.mine.bukkit.block.BlockFace) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block)

Aggregations

MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)47 Block (org.bukkit.block.Block)20 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)10 Material (org.bukkit.Material)8 Nullable (javax.annotation.Nullable)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 Target (com.elmakers.mine.bukkit.utility.Target)5 Player (org.bukkit.entity.Player)5 MageController (com.elmakers.mine.bukkit.api.magic.MageController)4 Wand (com.elmakers.mine.bukkit.api.wand.Wand)4 List (java.util.List)4 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)3 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)3 IOException (java.io.IOException)3 Location (org.bukkit.Location)3 CurrencyItem (com.elmakers.mine.bukkit.api.block.CurrencyItem)2 ParseException (java.text.ParseException)2