Skip to content

Commit

Permalink
Prevent contact and fire causing excessive damage to horses.
Browse files Browse the repository at this point in the history
When we prevent their rearing we stop the natural system that would keep
the damage in check.

Closes #62.
  • Loading branch information
LlmDl committed Dec 22, 2022
1 parent 7d771c9 commit 4538247
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
Expand Down Expand Up @@ -132,7 +133,8 @@ public void on (PlayerJoinEvent event) {
public void on (EntityDamageEvent event) {
if (!TownyCombatSettings.isTownyCombatEnabled())
return;
if (event.getEntity() instanceof AbstractHorse) {
// When it is a horse and it is not being hurt by a bush/cactus, try to prevent the rearing.
if (event.getEntity() instanceof AbstractHorse && !instantHorseDeathCause(event.getCause())) {
//No rearing when horse is damaged. Do this by cancelling the event, then applying the same damage in a simple set operation.
if(TownyCombatSettings.isHorseRearingPreventionEnabled()
&& event.getEntity().getPassengers().size() > 0
Expand All @@ -145,6 +147,14 @@ public void on (EntityDamageEvent event) {
}
}

/**
* @param cause DamageCause
* @return true if this is a DamageCause that shreds horse health.
*/
private boolean instantHorseDeathCause(DamageCause cause) {
return cause.equals(DamageCause.CONTACT) || cause.equals(DamageCause.FIRE);
}

@EventHandler (ignoreCancelled = true)
public void on (EntityDamageByEntityEvent event) {
if (!TownyCombatSettings.isTownyCombatEnabled())
Expand Down

0 comments on commit 4538247

Please sign in to comment.