Custom inventory items not being set

Discussion in 'Plugin Development' started by HeyAwesomePeople, Jul 1, 2014.

Thread Status:
Not open for further replies.
  1. I am trying to loop through a HashMap of classes, and get the itemstack, and set that itemstack in the inventory. Here is what I have:

    Code:java
    1. @EventHandler
    2. public void onInteractShopBook(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (p.getItemInHand() == null) return;
    5. if (plugin.playersInGame.contains(p.getName())) return;
    6. if (!p.getItemInHand().equals(plugin.classesdata.kitpvpclassshop)) return;
    7. if (e.getAction() == Action.LEFT_CLICK_AIR) return;
    8. if (e.getAction() == Action.LEFT_CLICK_BLOCK) return;
    9. e.setCancelled(true);
    10. Inventory cmdBook = Bukkit.createInventory(null, 9, plugin.config.classSaleBookInvName);
    11.  
    12. int classBookAmount = 0;
    13. for (String classK : plugin.classes.keySet()) {
    14. ClassAPI shopItem = plugin.classes.get(classK);
    15. if (shopItem.disabled == true) {
    16. cmdBook = plugin.inventorymethods.addItem(shopItem.shopItemStackDisabled, cmdBook, classBookAmount);
    17. classBookAmount++;
    18. continue;
    19. } else if (plugin.classmethods.playerHasClass(p, classK)) {
    20. cmdBook = plugin.inventorymethods.addItem(shopItem.shopItemStackAlreadyBought, cmdBook, classBookAmount);
    21. classBookAmount++;
    22. continue;
    23. }
    24. cmdBook = plugin.inventorymethods.addItem(shopItem.shopItemStack, cmdBook, classBookAmount);
    25. classBookAmount++;
    26. }
    27. p.openInventory(cmdBook);
    28. }


    Now, if the class is disabled, it returns a disabled itemstack. If the player already has the class, it returns the "already have that class" itemstack.

    But when I attempt to open the class, I just get an empty class. The "classes" hashmap is not empty(checked with debug msgs) and it is in fact running the addItem method(also checked with debug messages). This is what the addItem method does:

    Code:java
    1. public Inventory addItem(ItemStack superItem, Inventory inv,
    2. int loc) {
    3. inv.setItem(loc, superItem);
    4. return inv;
    5. }


    What's going on?
     
  2. Offline

    THEREDBARON24

    Perhaps just setItems with cmdBook.setItem(Whatever here)? Perhaps constantly setting it = to something else is causing the issue. Any Log issues?
     
Thread Status:
Not open for further replies.

Share This Page