Hello, I am trying to make it so when you are hit it checks to see if you have diamond boots on but when I go to test it it doesn't work at all here is my code: Code (Text): @EventHandler public void onDmg(EntityDamageByEntityEvent event) { if (event.getEntity().getLastDamageCause() instanceof Player) { Player victim1 = (Player) event.getEntity(); if(((Object) victim1.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS)) { victim1.sendMessage("You have diamond boots"); } } } Thank you for your help!
Try it this way(not tested): Code (Text): @EventHandler public void Dmg(EntityDamageByEntityEvent e) { if(e.getEntity() instanceof Player) { if(e.getDamager() instanceof Player) { Player p = (Player) e.getEntity(); if(p.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS) { p.sendMessage("test"); } } } }
getLastDamageCause() will never be an instance of a player. Also, Spoonfeeding code teaches nothing. The API documentation is fairly clear on the event that the person is trying to use and referring to that would teach more than throwing code to somebody.
And @electronicboy either way i would have found out how to do it if he explained it to me im not stupid
If you would have found out, Why post on the forums for something that is trivial? Also, that code is likely to cause an NPE. The API documentation is there, It should be your first port of call.
Because @electronicboy as of right now I really tired but I really want to get this done and I can't think that well
If you can't understand something in the code just ask, sorry yeah probably @electronicboy is right. btw. maybe do: if(p.getInventory().getBoots() != null && p.getInventory().getBoots().getType() == Material.DIAMOND_BOOTS) to avoid a NPE
Actually @Chemmic i fixed it, thanks again for your help, and i see your concern thank you. And actually i changed it to check if the boots are not null and have a lore and it works fine xD