Inventory Help

Discussion in 'Plugin Development' started by Epicballzy, Apr 16, 2014.

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

    Epicballzy

    I've made 2 inventories, and I'd like to open one from inside an inventory by clicking an item... But when I click the item, the inventory wont open. Any suggestions?

    Would I have to close the open the inventory?
    Code:java
    1. p.closeInventory();
    2. p.openInventory(Main.vip);


    Inventory Code:
    Code:java
    1. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§a§lDonator Shop")) {
    2. p.openInventory(Main.vip);
    3. }

    The creation of the inventory is in my main class.
     
  2. Offline

    iTornado1234

    Does it give any errors? Can we see all of your code?
     
  3. Offline

    Epicballzy

    It doesn't throw any errors. The other items work the way they're supposed to, but for some reason the second inv isn't opening.

    Main class that creates the inv:
    Code:java
    1. public static Inventory shop; {
    2. shop = Bukkit.createInventory(null, 9, "§c§lKit/Item Shop");
    3. shop.setItem(0, createItem(Material.STONE_SWORD, 1, (short) 0, "§bMage", "§bCosts §60 §bCoins!"));
    4. shop.setItem(1, createItem(Material.BOW, 1, (short) 0, "§bArcher", "§bCosts §625 §bCoins!"));
    5. shop.setItem(7, createItem(Material.WOOD_DOOR, 1, (short) 0, "§4EXIT", "§bLeave The Shop"));
    6. shop.setItem(8, createItem(Material.EMERALD, 1, (short) 0, "§aDonator Shop", "§bOpens The Donator Shop"));
    7. }
    8.  
    9. public static Inventory vip; {
    10. vip = Bukkit.createInventory(null, 9, "§c§lDonator Shop");
    11. vip.setItem(0, createItem(Material.GOLD_SWORD, 1, (short) 0, "§bGifted", "§bCosts §60 §bCoins!"));
    12. }


    Class that handles the items:
    Code:java
    1. /* Member Shop */
    2. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§bMage")) {
    3. if(API.hasEnough(p, 0)) {
    4. if(kit.contains(p.getName())) {
    5. p.sendMessage(ChatColor.RED + "You already have a kit!");
    6. return;
    7. }
    8. kit.add(p.getName());
    9. p.performCommand("pvpkit mage");
    10. p.closeInventory();
    11. API.takeCoins(p, 0);
    12. } else {
    13. p.sendMessage("You Don't Have Enough Coins!");
    14. }
    15. }
    16.  
    17. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§bArcher")) {
    18. if(API.hasEnough(p, 25)) {
    19. if(kit.contains(p.getName())) {
    20. p.sendMessage(ChatColor.RED + "You already have a kit!");
    21. return;
    22. }
    23. kit.add(p.getName());
    24. p.performCommand("pvpkit archer");
    25. p.closeInventory();
    26. API.takeCoins(p, 25);
    27. } else {
    28. p.sendMessage("You Don't Have Enough Coins!");
    29. }
    30. }
    31.  
    32. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§4EXIT")) {
    33. p.closeInventory();
    34. }
    35.  
    36. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§a§lDonator Shop")) {
    37. p.openInventory(Main.vip);
    38. }
    39.  
    40. /* Donator Shop */
    41. if(e.getCurrentItem().getItemMeta().getDisplayName().equals("§bGifted")) {
    42. if(API.hasEnough(p, 0)) {
    43. if(kit.contains(p.getName())) {
    44. p.sendMessage(ChatColor.RED + "You already have a kit!");
    45. return;
    46. }
    47. kit.add(p.getName());
    48. p.performCommand("pvpvip gifted");
    49. p.closeInventory();
    50. API.takeCoins(p, 0);
    51. } else {
    52. p.sendMessage("You Don't Have Enough Coins!");
    53. }
    54. }
    55.  
    56. }
     
  4. Offline

    agent6262

    Epicballzy
    Yes you would have to close the current open inventory before you open a new one.
     
  5. Offline

    iTornado1234

    I've had the same issue as you before, I don't remember how I fixed it tho.
     
  6. Offline

    Epicballzy

    I've added p.closeInventory(); before openInventory(Main.vip); .. But it still doesn't work. Any suggestions?
     
  7. Offline

    agent6262

    Epicballzy
    Could i see the update section of your code
     
  8. Offline

    Epicballzy

    What do you mean "update section"? The onEnable?
     
  9. Offline

    agent6262

    Well in an earlier post on lines 36-38 you don't close the inventory. and have you been able to open either one
     
  10. Offline

    Epicballzy

    I'm able to open the first inv (shop) with a command.
     
Thread Status:
Not open for further replies.

Share This Page