I'm trying to make a command that allows you to make any player invulnerable -- that is, god mode.
This is my code so far (though it's all boilerplate)
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instaceof Player) {
if(godModed.containsKey(event.getPlayer())) {
//This is where I need the code to go - something to cancel the damage.
}
}
}
godModed
is a HashMap godModed
which contains all the players who are currently godmoded. When they turn off godmode they are removed from the map.
The command itself is working fine - I currently have it send a message to the player who triggered it, and I also have it add the player to godModed if they are not already on. However, I can't figure out how to actually prevent the damage to the player. I want to stop it completely, not just heal them back afterwards; while the latter might work, it could also lead to unforeseen consequences if other mods look at onEntityDamage
to trigger things which a godmoded player shouldn't encounter.