Inventory Issue

Discussion in 'Plugin Development' started by Tice, Mar 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Tice

    Hello! I'm trying to make an interactive inventory, where you can buy things etc. In this inventory, there is a first page, in this page there are different categories. When you press a category, for example "wardrobe", it opens an inventory called wardrobe and closes the previous one, in this inventory, there is a piece of paper called "Back". What it does is that when you click it, it returns you back to the category page. Only problem is, that when you click it, and you get returned to the category page, you can't click anything else. When you click wardrobe again, it doesn't open the wardrobe inventory.

    I'm really lost here!
     
  2. Offline

    2MBKindiegames

    Could you please post you code!
     
  3. Offline

    Tice

    Ofcourse

    My event:
    Code:java
    1. @EventHandler
    2. public void inventoryClick(InventoryClickEvent e) {
    3. Player p = (Player) e.getWhoClicked();
    4. //Shop
    5. if(e.getInventory().getName().equals("Cove Shop")) {
    6. e.setCancelled(true);
    7.  
    8.  
    9. if(e.getCurrentItem().getType().equals(Material.LEATHER_CHESTPLATE)) {
    10. p.closeInventory();
    11. p.openInventory(wardrobeInventory);
    12.  

    What this does is checks if I'm pressing the leather chestplate(wardrobe inventory) and opens up the wardrobe.

    Then, another if in the event:
    Code:java
    1. }
    2. //Wardrobe
    3. if(e.getInventory().getName().equals(ChatColor.YELLOW + "Choose what to customize!")){
    4. if(e.getCurrentItem().getType().equals(Material.LEATHER_HELMET)) {
    5.  
    6.  
    7. } else if(e.getCurrentItem().getType().equals(Material.LEATHER_CHESTPLATE)) {
    8.  
    9.  
    10. } else if(e.getCurrentItem().getType().equals(Material.LEATHER_LEGGINGS)) {
    11.  
    12. } else if(e.getCurrentItem().getType().equals(Material.LEATHER_BOOTS)) {
    13.  
    14. } else if(e.getCurrentItem().getType().equals(Material.PAPER)) {
    15. p.closeInventory();
    16. p.openInventory(shopInventory);
    17.  
    18.  
    19. }
    20. }
    21. }


    Now, when I press the paper, it opens up the shop inventory. But if I press the leather chestplate again, it doesnt open up the wardrobe again.

    Let me know if you need more code!

    Bump! Really need help with this, since it's quite advanced to be honest.

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

    paxi

    One question: Did you get some errors at the console?
    And how did you inistializated the variables? :)
     
  5. Offline

    Tice

    No errors

    Here is how I initialized the variables
    Code:java
    1. public static Inventory wardrobeInventory;
    2. public static Inventory shopInventory;


    And then, in my generateInventory() method
    Code:java
    1. shopInventory = Bukkit.createInventory(null, 27, "Cove Shop");
    2. wardrobeInventory = Bukkit.createInventory(null, 27, ChatColor.GOLD + "Choose what to customize!");
     
  6. Offline

    callum.thepro

    You need to create an inventory holder. instead of using the variable as null, you need to put your holder variable there, thats how I did it before.
     
  7. Offline

    Minnymin3

    Tice
    By the looks of it you need to make sure you are naming the inventory properly
     
Thread Status:
Not open for further replies.

Share This Page