Skip to content

Commit

Permalink
Only teleport when damage cause is void
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jan 19, 2025
1 parent d4415e0 commit acf0853
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.jspecify.annotations.NullMarked;

Expand All @@ -33,10 +34,19 @@ public void onPlayerJoin(PlayerJoinEvent event) {
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player player) {
event.setCancelled(true);
teleport(player);

if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
teleport(player);
}
}
}

@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
event.setCancelled(true);
teleport(event.getEntity());
}

private void teleport(Player player) {
player.teleport(spawn);
player.setFallDistance(0);
Expand Down

0 comments on commit acf0853

Please sign in to comment.