Create Custom Inventory

Discussion in 'Plugin Development' started by CapitanChewbacca, Aug 8, 2015.

Thread Status:
Not open for further replies.
  1. I'm currently trying to make a custom inventory, that way when an event involving this inventory is called I would be able to cast this inventory to my custom one and use the custom characteristics of it.
    I tried extending the CraftInventoryCustom class and using an instance of this custom class on the player.openInventory(Inventory inv) but when I listen to the event comming from that inventory (click event for example), I'm not able to cast the inventory to my custom one.
    Any idea of why or if there is another way to make a "custom inventory" and cast it later? Thank you.
     
  2. Offline

    AcePilot10

  3. Offline

    webbhead

    A way I like to make inventories is:
    Code:
    public static Inventory getInv() {
    
    Inventory inv = Bukkit.createInventory(null, 9, "Cool GUI");
    
    {
    ItemStack i = new ItemStack(Material.CHEST);
    inv.setItem(0, i);
    }
    
    return inv;
    }
    Then you can call player.openInventory(<Class>.getInv());

    Tabbing is not correct at all so :p
     
  4. Ty but this isn't what I'm looking for exactly. I'm trying to track the Inventory, not create one :/
     
  5. Offline

    webbhead

    @CapitanChewbacca What do you want to cast? Are you wanting to get the Inventories name, and all the other Inventory options?
     
  6. @webbhead I want a custom inventory to have a few custom variables inside so when I listen to an event (click for example) I can cast event.getInventory() to my custom inventory and get this variables.
     
  7. Offline

    AcePilot10

    @CapitanChewbacca
    Code:
    Inventory inv = Bukkit.createInventory(null, 9);
    
    @EventHandler
    public void onInventoryClick(InventoryClickEvent e) {
    if(e.getInventory instanceof inv) {
    //do stuff
     
  8. @AcePilot10 That's what I did. Doesn't work. And it doesn't even recognize it as a CraftInventoryCustom that is the class extending mine. But in the case of a furnace or something like that it is able to cast it to CraftInventoryFurnace, I don't know what this might mean...

    @AcePilot10 [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Offline

    AcePilot10

    @CapitanChewbacca it's probably more efficient to have all your custom inventories a certain name, then listen to see if the inventory they clicked in was by said name. Could you please explain why you said it wasn't working. You shouldn't be extending any class for this.
     
Thread Status:
Not open for further replies.

Share This Page