How can you program with a Minecraft plugin that you can't be hit by the Rod?

pr
- in Plugins
1

How can you program with a Minecraft plugin that you can't be hit by the Rod?

Va

You create an event handler for an EntityDamageByEntityEvent and then check whether the attacking player has a fishing rod in hand.

@EventHandler
public void onEntityDamageByEntity (EntityDamageByEntityEvent e) {
Player damager = (Player) e.getDamager ();
ItemStack rod = new ItemStack (Material.FISHING_ROD, 1);

if (damager.getInventory (). GetItemInMainHand (). Equals (rod)) {
e.setCancelled (true);
}
}

I haven't tested it, but that's how it should work.