Search in sources :

Example 6 with CraftInventory

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory 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 7 with CraftInventory

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_10_R1 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 8 with CraftInventory

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_15_R1 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 9 with CraftInventory

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_16_R2 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 10 with CraftInventory

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_16_R3 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) Field(java.lang.reflect.Field)

Aggregations

Field (java.lang.reflect.Field)16 Inventory (org.bukkit.inventory.Inventory)10 CraftInventory (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)9 CraftInventory (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory)5 IInventory (net.minecraft.inventory.IInventory)4 PlayerEnderChestContainer (net.minecraft.world.inventory.PlayerEnderChestContainer)4 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)3 CraftInventory (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory)3 CraftInventory (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory)3 CompoundTagImpl (com.denizenscript.denizen.nms.v1_16.impl.jnbt.CompoundTagImpl)2 CompoundTagImpl (com.denizenscript.denizen.nms.v1_17.impl.jnbt.CompoundTagImpl)2 CompoundTagImpl (com.denizenscript.denizen.nms.v1_18.impl.jnbt.CompoundTagImpl)2 ChestBlock (net.minecraft.block.ChestBlock)2 MenuProvider (net.minecraft.world.MenuProvider)2 CraftInventory (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory)2 CraftInventory (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory)2 CraftInventory (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest)2 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest)2