Code: public void blacklistItems(Player p) { if (p.hasPermission("pvprestore.blacklist.drop") && plugin.getConfig().getBoolean("blacklist.enabled") == true) { for (Integer itemList : plugin.getConfig().getIntegerList("blacklist.items")) { p.getInventory().remove(itemList); if (p.getInventory().getHelmet().getTypeId() == itemList) { p.getInventory().setHelmet(null); } } } } When I take out the Code: if (p.getInventory().getHelmet().getTypeId() == itemList) { p.getInventory().setHelmet(null); } portion, it works just fine. Thoughts? EDIT: This is run when the player first joins the server, for debugging purposes currently. Could that be why?
Why would you check helmet in each cycle ? You do setHelmet(null) and then try to getHelmet().getTypeId().
What if I made it: Code: if (p.getInventory().getHelmet().getTypeId() == itemList && p.getInventory().getHelmet() != null)
See, the iterator is checking all the values of itemList, which is a changing value in this situation. It needs to be checked for all values of itemList. The code I proposed also does not work. Even when I do the null check like I did above, it still fails...Definitely a strange error. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Yeah, it's an NPE whenever the code is called. Only while the helmet check code is in there, though. If I remove that, it compiles and works like normal (without checking and trying to remove a players helmet.)
if this throws NPE Code: if(p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getTypeId() == itemList) then do Code: if(p.getInventory().getHelmet() != null) if(p.getInventory().getHelmet().getTypeId() == itemList) you could maybe even store player's inventory as local variable before running loop, to not do p.getInventory() all the time
Works! Awesome! Thanks! I forgot this little trick from when I was learning C++ last year, you're a life saver!