Search in sources :

Example 16 with Wand

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

the class MagicItemDb method get.

@Nullable
@Override
public ItemStack get(final String id) throws Exception {
    if (id.startsWith("m:")) {
        String itemId = id.replace("m:", "");
        return controller.createItem(itemId);
    }
    if (id.startsWith("magic:")) {
        String itemId = id.replace("magic:", "");
        return controller.createItem(itemId);
    } else if (id.equals("wand")) {
        Wand wand = Wand.createWand(controller, "");
        if (wand != null) {
            return wand.getItem();
        }
    } else if (id.startsWith("wand:")) {
        String wandId = id.replace("wand:", "");
        Wand wand = Wand.createWand(controller, wandId.trim());
        if (wand != null) {
            return wand.getItem();
        }
    } else if (id.startsWith("w:")) {
        String wandId = id.replace("w:", "");
        Wand wand = Wand.createWand(controller, wandId.trim());
        if (wand != null) {
            return wand.getItem();
        }
    } else if (id.startsWith("book:")) {
        String bookCategory = id.replace("book:", "");
        SpellCategory category = null;
        if (bookCategory.length() > 0 && !bookCategory.equalsIgnoreCase("all")) {
            category = controller.getCategory(bookCategory);
        }
        ItemStack bookItem = controller.getSpellBook(category, 1);
        if (bookItem != null) {
            return bookItem;
        }
    } else if (id.startsWith("spell:")) {
        String spellKey = id.replace("spell:", "");
        ItemStack itemStack = Wand.createSpellItem(spellKey, controller, null, true);
        if (itemStack != null) {
            return itemStack;
        }
    } else if (id.startsWith("s:")) {
        String spellKey = id.replace("s:", "");
        ItemStack itemStack = Wand.createSpellItem(spellKey, controller, null, true);
        if (itemStack != null) {
            return itemStack;
        }
    } else if (id.startsWith("brush:")) {
        String brushKey = id.replace("brush:", "");
        ItemStack itemStack = Wand.createBrushItem(brushKey, controller, null, true);
        if (itemStack != null) {
            return itemStack;
        }
    } else if (id.startsWith("upgrade:")) {
        String wandId = id.replace("upgrade:", "");
        Wand wand = Wand.createWand(controller, wandId.trim());
        if (wand != null) {
            wand.makeUpgrade();
            return wand.getItem();
        }
    } else if (id.startsWith("item:")) {
        String wandId = id.replace("item:", "");
        return controller.createItem(wandId);
    }
    return super.get(id);
}
Also used : SpellCategory(com.elmakers.mine.bukkit.api.spell.SpellCategory) Wand(com.elmakers.mine.bukkit.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 17 with Wand

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

the class MagicController method giveItemToPlayer.

@Override
public void giveItemToPlayer(Player player, ItemStack itemStack) {
    // Bind item if configured to do so
    if (bindOnGive && Wand.isWand(itemStack)) {
        Wand wand = getWand(itemStack);
        if (wand.isBound()) {
            wand.tryToOwn(player);
            itemStack = wand.getItem();
        }
    }
    Mage mage = getMage(player);
    mage.giveItem(itemStack);
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.wand.LostWand)

Example 18 with Wand

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

the class MagicController method itemsAreEqual.

@Override
public boolean itemsAreEqual(ItemStack first, ItemStack second) {
    if (first == null || second == null)
        return false;
    if (first.getType() != second.getType() || first.getDurability() != second.getDurability())
        return false;
    boolean firstIsWand = Wand.isWandOrUpgrade(first);
    boolean secondIsWand = Wand.isWandOrUpgrade(second);
    if (firstIsWand || secondIsWand) {
        if (!firstIsWand || !secondIsWand)
            return false;
        Wand firstWand = getWand(InventoryUtils.getCopy(first));
        Wand secondWand = getWand(InventoryUtils.getCopy(second));
        String firstTemplate = firstWand.getTemplateKey();
        String secondTemplate = secondWand.getTemplateKey();
        if (firstTemplate == null || secondTemplate == null)
            return false;
        return firstTemplate.equalsIgnoreCase(secondTemplate);
    }
    String firstSpellKey = Wand.getSpell(first);
    String secondSpellKey = Wand.getSpell(second);
    if (firstSpellKey != null || secondSpellKey != null) {
        if (firstSpellKey == null || secondSpellKey == null)
            return false;
        return firstSpellKey.equalsIgnoreCase(secondSpellKey);
    }
    String firstBrushKey = Wand.getBrush(first);
    String secondBrushKey = Wand.getBrush(second);
    if (firstBrushKey != null || secondBrushKey != null) {
        if (firstBrushKey == null || secondBrushKey == null)
            return false;
        return firstBrushKey.equalsIgnoreCase(secondBrushKey);
    }
    String firstName = first.hasItemMeta() ? first.getItemMeta().getDisplayName() : null;
    String secondName = second.hasItemMeta() ? second.getItemMeta().getDisplayName() : null;
    return Objects.equals(firstName, secondName);
}
Also used : Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.wand.LostWand)

Example 19 with Wand

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

the class Mage method giveItem.

@Override
public void giveItem(ItemStack itemStack) {
    if (InventoryUtils.isEmpty(itemStack))
        return;
    // Check for wand upgrades if appropriate
    Wand activeWand = getActiveWand();
    if (activeWand != null) {
        if (activeWand.addItem(itemStack)) {
            return;
        }
    }
    if (hasStoredInventory()) {
        addToStoredInventory(itemStack);
        return;
    }
    // Place directly in hand if possible
    Player player = getPlayer();
    if (player == null)
        return;
    PlayerInventory inventory = player.getInventory();
    ItemStack inHand = inventory.getItemInMainHand();
    if (inHand == null || inHand.getType() == Material.AIR) {
        inventory.setItemInMainHand(itemStack);
        // Get the new item reference -
        // it might change when added to an Inventory! :|
        itemStack = inventory.getItemInMainHand();
        if (Wand.isWand(itemStack)) {
            checkWand();
        } else {
            if (itemStack.getType() == Material.MAP) {
                setLastHeldMapId(itemStack.getDurability());
            }
        }
    } else {
        HashMap<Integer, ItemStack> returned = player.getInventory().addItem(itemStack);
        if (returned.size() > 0) {
            player.getWorld().dropItem(player.getLocation(), itemStack);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 20 with Wand

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

the class Mage method findWand.

@Override
@Nullable
public Wand findWand(@Nonnull String template) {
    Player player = getPlayer();
    if (player == null)
        return null;
    Inventory inventory = player.getInventory();
    for (ItemStack itemStack : inventory.getContents()) {
        String itemTemplate = Wand.getWandTemplate(itemStack);
        if (itemTemplate != null && itemTemplate.equals(template)) {
            return new Wand(controller, itemStack);
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) Nullable(javax.annotation.Nullable)

Aggregations

Wand (com.elmakers.mine.bukkit.wand.Wand)36 Player (org.bukkit.entity.Player)24 ItemStack (org.bukkit.inventory.ItemStack)23 EventHandler (org.bukkit.event.EventHandler)17 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)11 Mage (com.elmakers.mine.bukkit.magic.Mage)11 PlayerInventory (org.bukkit.inventory.PlayerInventory)6 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 Nullable (javax.annotation.Nullable)5 LostWand (com.elmakers.mine.bukkit.wand.LostWand)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Inventory (org.bukkit.inventory.Inventory)4 GUIAction (com.elmakers.mine.bukkit.api.action.GUIAction)3 Messages (com.elmakers.mine.bukkit.api.magic.Messages)3 Location (org.bukkit.Location)3 Block (org.bukkit.block.Block)3 Entity (org.bukkit.entity.Entity)3 Item (org.bukkit.entity.Item)3