Skip to content

Commit

Permalink
cancel fall damage & keep knockback on hit
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Dec 17, 2023
1 parent 94ebd9f commit 36cf688
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;

import java.util.Optional;
Expand Down Expand Up @@ -60,22 +61,30 @@ public boolean isDamageAsScore() {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPinataDamage(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
if (!(damager instanceof Player)) return;
Player player = (Player) damager;

Entity entity = event.getEntity();
if (!pinataFeature.contains(entity)) return;
event.setCancelled(true);

Entity damager = event.getDamager();
if (damager instanceof Player) {
Player player = (Player) damager;

if (damageAsScore) {
pointFeature.applyPoint(player.getUniqueId(), (int) event.getFinalDamage());
} else {
pointFeature.applyPoint(player.getUniqueId(), Pinata.POINT_HIT);
}
event.setDamage(0);

if (damageAsScore) {
pointFeature.applyPoint(player.getUniqueId(), (int) event.getFinalDamage());
} else {
pointFeature.applyPoint(player.getUniqueId(), Pinata.POINT_HIT);
}
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPinataFallDamage(EntityDamageEvent event) {
if (event.getCause() != EntityDamageEvent.DamageCause.FALL) return;
if (!pinataFeature.contains(event.getEntity())) return;

event.setCancelled(true);
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPinataDeath(EntityDeathEvent event) {
Entity entity = event.getEntity();
Expand Down

0 comments on commit 36cf688

Please sign in to comment.