So I want to check if a player's inventory is empty and if it's not, I want to add his/her whole inventory to hashmap. I'm getting an NPE on this block of code: Code:java int i = 0; for (ItemStack item : player.getInventory().getContents()) { if (item != null){ i++; } if (i < 36){ plugin.getEventMain().inv.put(player, player.getInventory().getContents()); } } *cough* Bukkit team, add player.getInventory().isEmpty() *cough*
You have it set to read "if item is not equal to null" meaning if it even has one if wont execute the code. Did you mean for this?
dmoney12321 This exact thing works perfectly in my other plugin: Code:java public void Put(Player player){ if (player.getInventory().getArmorContents() != null) { plugin.getEventMain().armor.put(player, player.getInventory().getArmorContents()); } if (player.getInventory().getContents() != null) { plugin.getEventMain().inv.put(player, player.getInventory().getContents()); } if (!player.getActivePotionEffects().isEmpty()) { plugin.getEventMain().potion.put(player, player.getActivePotionEffects()); } for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } } But it's giving me errors in this one. So that's why I've been trying to do it different ways