Solved Crafting Inventory Slot Null

Discussion in 'Plugin Development' started by mehboss, Feb 2, 2019.

  1. Offline

    mehboss

    When trying to get these inventory slots, some of them come up null, even though there is an item in the slot.

    Debug Code:
    Code:
                        if (inv.getItem(j) == null || inv.getItem(j).getType() == null) {
                            Bukkit.broadcastMessage(ChatColor.RED + String.valueOf(j));
                        }
    Code:
    Code:
                    for (int j = 0; j < 9; j++) {
    
                        if (inv.getItem(j) == null || inv.getItem(j).getType() == null) {
                            Bukkit.broadcastMessage(ChatColor.RED + String.valueOf(j));
                        }
    
                        if (inv.getItem(j) != null && inv.getItem(j).getType() != null) {
    
                            if (j == 0 && (inv.getItem(0).getItemMeta().getDisplayName().equals(letterSlot1))) {
                                recipeMatches = true;
                            }
    
                            if (j == 1 && (inv.getItem(1).getItemMeta().getDisplayName().equals(letterSlot2))) {
                                recipeMatches = true;
                            }
    
                            if (j == 2 && (inv.getItem(2).getItemMeta().getDisplayName().equals(letterSlot3))) {
                                recipeMatches = true;
                            }
    
                            if (j == 3 && (inv.getItem(3).getItemMeta().getDisplayName().equals(letterSlot4))) {
                                recipeMatches = true;
                            }
    
                            if (j == 4 && (inv.getItem(4).getItemMeta().getDisplayName().equals(letterSlot5))) {
                                recipeMatches = true;
                            }
    
                            if (j == 5 && (inv.getItem(5).getItemMeta().getDisplayName().equals(letterSlot6))) {
                                recipeMatches = true;
                            }
    
                            if (j == 6 && (inv.getItem(6).getItemMeta().getDisplayName().equals(letterSlot7))) {
                                recipeMatches = true;
                            }
    
                            if (j == 7 && (inv.getItem(7).getItemMeta().getDisplayName().equals(letterSlot8))) {
                                recipeMatches = true;
                            }
    
                            if (j == 8 && (inv.getItem(8).getItemMeta().getDisplayName().equals(letterSlot9))) {
                                recipeMatches = true;
                            }
                        }
                    }
    http://prntscr.com/mfqipz
    http://prntscr.com/mfqhru
     
  2. Offline

    DerDonut

    Cast the Inventory to CraftingInventory, take a look on what methods this class provides and try again.
     
  3. Offline

    mehboss

    I used the wrong crafting table slot numbers. Problem solved.


    Sent from my iPhone using Tapatalk
     
  4. Offline

    MrDaniel

    Please mark this thread as Solved
     
  5. Offline

    mehboss

    My bad, thought I already did.
     

Share This Page