Search in sources :

Example 1 with Spell

use of mc.dragons.spells.spells.Spell in project DragonsOnline by UniverseCraft.

the class BindSpellCommand method onCommand.

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender) || !requirePermission(sender, PermissionLevel.GM))
        return true;
    Player player = player(sender);
    if (label.equalsIgnoreCase("testspellbinding")) {
        SpellUtil.updateAllSpellItems(registry, player);
        sender.sendMessage("Held item: " + SpellUtil.sameItem(player.getItemInHand(), ItemLoader.fromBukkit(player.getItemInHand()).getItemStack()));
        sender.sendMessage("Computed slot: " + SpellUtil.getSlotOfItemStack(player, player.getItemInHand()));
        return true;
    }
    ItemStack itemStack = player.getInventory().getItemInMainHand();
    if (itemStack == null) {
        sender.sendMessage(ChatColor.RED + "Item stack is null");
        return true;
    }
    Item item = ItemLoader.fromBukkit(itemStack);
    if (item == null) {
        sender.sendMessage(ChatColor.RED + "Item stack is not an RPG item");
        return true;
    }
    Spell spell = registry.getSpellByName(args[0]);
    if (spell == null) {
        sender.sendMessage(ChatColor.RED + "Invalid spell name");
        return true;
    }
    sender.sendMessage("Bind status before: " + spell.bindStatus(item));
    spell.bind(player, item);
    sender.sendMessage("Bind status after: " + spell.bindStatus(item));
    // since we updated the lore
    player.getInventory().setItemInMainHand(item.getItemStack());
    return true;
}
Also used : Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell)

Example 2 with Spell

use of mc.dragons.spells.spells.Spell in project DragonsOnline by UniverseCraft.

the class SpellListeners method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    User user = UserLoader.fromPlayer(player);
    if (e.getInventory().getType() == InventoryType.FURNACE) {
        // 0 = smelting
        // 1 = fuel
        // 2 = result
        CraftInventory cc = (CraftInventory) e.getInventory();
        int i = 0;
        for (ItemStack is : cc.getContents()) {
            user.debug(i + ": " + is);
            i++;
        }
    }
    if (e.getView().getTitle().equals(SpellConstants.ENCHANTER_MENU_TITLE)) {
        user.debug("Interacted with the Enchanter menu. SlotType=" + e.getSlotType());
        CraftInventoryCustom cc = (CraftInventoryCustom) e.getInventory();
        if (e.getSlotType() == SlotType.RESULT) {
            user.debug("RESULT");
            user.debug("curr=" + e.getCurrentItem());
            user.debug("curs=" + e.getCursor());
            Item current = ItemLoader.fromBukkit(e.getCurrentItem());
            if (current == null)
                return;
            user.debug("receiving the updated item");
            current.setItemStack(e.getCurrentItem().clone());
            e.setCurrentItem(new ItemStack(Material.AIR));
            e.setCursor(current.getItemStack());
            cc.setItem(0, new ItemStack(Material.AIR));
            cc.setItem(1, new ItemStack(Material.AIR));
            cc.setItem(2, new ItemStack(Material.AIR));
            e.setResult(Result.DENY);
            e.setCancelled(false);
            return;
        }
        ItemStack cursorCopy = e.getCursor().clone();
        Item item = ItemLoader.fromBukkit(e.getCursor());
        if (item == null)
            return;
        if (e.getSlotType() == SlotType.FUEL && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellScroll"))) {
            user.debug("Using alternative fuel in furnace for enchanting");
            user.debug("curr=" + e.getCurrentItem() + ", cursor=" + e.getCursor());
            item.setItemStack(cursorCopy);
            if (e.getInventory().getType() == InventoryType.FURNACE) {
                int i = 0;
                for (ItemStack is : cc.getContents()) {
                    user.debug(i + ": " + is);
                    i++;
                }
                e.setCurrentItem(cursorCopy);
                e.setCursor(new ItemStack(Material.AIR));
                e.setCancelled(true);
            }
        }
        if (e.getSlotType() == SlotType.CRAFTING && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellCast"))) {
            // No fuel
            if (cc.getItem(1) == null)
                return;
            String spellDisplayName = ChatColor.stripColor(cc.getItem(1).getItemMeta().getDisplayName().replace("Scroll", "").trim());
            user.debug("binding spell " + spellDisplayName);
            Spell spell = registry.getSpellByDisplayName(spellDisplayName);
            user.debug("spell=" + spell);
            if (spell.bindStatus(item) == BindStatus.CAPABLE) {
                double gold = user.getGold();
                if (gold < 100.0) {
                    player.sendMessage(ChatColor.RED + "Binding spells costs 100 Gold. (Need " + (100 - gold) + " more)");
                    player.getInventory().addItem(cc.getItem(1) == null ? new ItemStack(Material.AIR) : cc.getItem(1));
                    player.getInventory().addItem(e.getCursor());
                    e.setCursor(new ItemStack(Material.AIR));
                    e.setCurrentItem(new ItemStack(Material.AIR));
                    e.setCancelled(true);
                    player.closeInventory();
                    return;
                }
                user.takeGold(100.0);
                spell.bind(player, item);
                cc.setItem(0, new ItemStack(Material.AIR));
                cc.setItem(1, new ItemStack(Material.AIR));
                cc.setItem(2, item.getItemStack());
                e.setCursor(new ItemStack(Material.AIR));
                e.setResult(Result.ALLOW);
                e.setCancelled(true);
                user.debug("bound spell and updated inventory");
                player.sendMessage(ChatColor.DARK_PURPLE + "Bound spell " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName() + ChatColor.DARK_PURPLE + " to " + ChatColor.LIGHT_PURPLE + item.getName());
            }
        }
        return;
    }
}
Also used : CraftInventoryCustom(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCustom) CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Spell

use of mc.dragons.spells.spells.Spell in project DragonsOnline by UniverseCraft.

the class SpellUtil method updateItemData.

public static void updateItemData(SpellRegistry registry, Player player, int slot, Item item) {
    ItemMeta meta = item.getItemStack().getItemMeta();
    List<String> lore = Item.getCompleteLore(item.getData(), item.getLore().toArray(new String[item.getLore().size()]), item.getUUID(), item.isCustom(), item.getItemClass());
    List<Spell> spells = registry.getSpells(item);
    lore.add(" ");
    if (spells.size() == 0) {
        lore.add(ChatColor.LIGHT_PURPLE + "Magic Item");
        lore.add(ChatColor.RED + "No spells are bound to");
        lore.add(ChatColor.RED + "this item yet!");
    } else if (!item.getName().contains(SpellConstants.MAGIC_ITEM_TITLE_PREFIX)) {
        item.setName(SpellConstants.MAGIC_ITEM_TITLE_PREFIX + ChatColor.stripColor(item.getName()));
        item.setCustom(true);
        meta.setDisplayName(item.getName());
    }
    lore.addAll(spells.stream().map(spell -> ChatColor.DARK_PURPLE + "[" + spell.getSpellCombo() + "] " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName()).collect(Collectors.toList()));
    meta.setLore(lore);
    item.getItemStack().setItemMeta(meta);
    if (slot != -1) {
        player.getInventory().setItem(slot, item.getItemStack());
    }
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta) Spell(mc.dragons.spells.spells.Spell)

Example 4 with Spell

use of mc.dragons.spells.spells.Spell in project DragonsOnline by UniverseCraft.

the class SpellCastAddon method onCombo.

@Override
public void onCombo(User user, String combo) {
    user.debug("Combo " + combo);
    ItemStack itemStack = user.getPlayer().getInventory().getItemInMainHand();
    Item item = ItemLoader.fromBukkit(itemStack);
    List<Spell> spells = registry.getSpellsByCombo(combo);
    for (Spell spell : spells) {
        if (spell.bindStatus(item) == BindStatus.BOUND) {
            user.sendActionBar(ChatColor.DARK_PURPLE + "Cast " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName());
            spell.execute(user);
            return;
        }
    }
    user.sendActionBar(ChatColor.RED + "No spell with that combo is bound to this item!");
}
Also used : Item(mc.dragons.core.gameobject.item.Item) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell)

Aggregations

Spell (mc.dragons.spells.spells.Spell)4 Item (mc.dragons.core.gameobject.item.Item)3 ItemStack (org.bukkit.inventory.ItemStack)3 Player (org.bukkit.entity.Player)2 User (mc.dragons.core.gameobject.user.User)1 CraftInventory (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)1 CraftInventoryCustom (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCustom)1 EventHandler (org.bukkit.event.EventHandler)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1