Solved Error Finding Boots On Hit

Discussion in 'Spigot Help' started by GamerDuck123, May 28, 2016.

  1. 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):
            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!
  2. Try it this way(not tested):
    Code (Text):
        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) {

  3. electronicboy

    IRC Staff

    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.
  4. Omg thank you @Chemmic it does work
  5. And @electronicboy either way i would have found out how to do it if he explained it to me im not stupid
  6. electronicboy

    IRC Staff

    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.
  7. Because @electronicboy as of right now I really tired but I really want to get this done and I can't think that well
  8. 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
  9. 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
    • Winner Winner x 1