Class PlayerDeathGameEvent

java.lang.Object
org.bukkit.event.Event
dev.itsharshxd.zentrix.api.events.ZentrixEvent
dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
dev.itsharshxd.zentrix.api.events.player.PlayerDeathGameEvent

public class PlayerDeathGameEvent extends ZentrixGameEvent
Called when a player is eliminated (dies) in a Zentrix game.

This event is fired after a player dies and is about to be converted to a spectator. At this point:

  • The player has died
  • Death message has been prepared
  • The player is about to become a spectator
  • Team elimination may be triggered if this was the last team member

This event is NOT cancellable.

Example Usage


 @EventHandler
 public void onPlayerDeath(PlayerDeathGameEvent event) {
     ZentrixPlayer victim = event.getVictim();
     ZentrixGame game = event.getGame();

     // Check if killed by another player
     if (event.hasKiller()) {
         ZentrixPlayer killer = event.getKiller().get();
         getLogger().info(victim.getName() + " was killed by " + killer.getName());
     } else {
         getLogger().info(victim.getName() + " died to environmental damage");
     }

     // Check if this death eliminates a team
     if (event.eliminatesTeam()) {
         event.getVictimTeam().ifPresent(team -> {
             game.broadcast("&c" + team.getDisplayName() + " has been eliminated!");
         });
     }

     // Get death location for custom effects
     Location deathLoc = event.getDeathLocation();
     deathLoc.getWorld().strikeLightningEffect(deathLoc);
 }
 
Since:
1.0.0
See Also:
  • Constructor Details

    • PlayerDeathGameEvent

      public PlayerDeathGameEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull ZentrixPlayer victim, @Nullable @Nullable ZentrixPlayer killer, @Nullable @Nullable ZentrixTeam victimTeam, @NotNull @NotNull org.bukkit.Location deathLocation, @NotNull @NotNull PlayerDeathGameEvent.DeathCause deathCause, boolean eliminatesTeam, int remainingPlayers, int remainingTeams)
      Constructs a new PlayerDeathGameEvent.
      Parameters:
      game - The game where the death occurred
      victim - The player who died
      killer - The player who killed the victim (null if environmental death)
      victimTeam - The victim's team (null if not on a team)
      deathLocation - The location where the player died
      deathCause - The cause of death
      eliminatesTeam - Whether this death eliminates the victim's team
      remainingPlayers - The number of players remaining after this death
      remainingTeams - The number of teams remaining after this death
  • Method Details

    • getVictim

      @NotNull public @NotNull ZentrixPlayer getVictim()
      Gets the player who died.
      Returns:
      The victim (never null)
    • getKiller

      @NotNull public @NotNull Optional<ZentrixPlayer> getKiller()
      Gets the player who killed the victim, if any.

      Returns empty if the victim died to environmental damage (fall damage, border damage, drowning, etc.).

      Returns:
      Optional containing the killer, or empty if environmental death
    • hasKiller

      public boolean hasKiller()
      Checks if the victim was killed by another player.
      Returns:
      true if there is a killer
    • getVictimBukkit

      @NotNull public @NotNull Optional<org.bukkit.entity.Player> getVictimBukkit()
      Gets the Bukkit player instance of the victim, if online.
      Returns:
      Optional containing the victim's Bukkit player, or empty if offline
    • getKillerBukkit

      @NotNull public @NotNull Optional<org.bukkit.entity.Player> getKillerBukkit()
      Gets the Bukkit player instance of the killer, if any and online.
      Returns:
      Optional containing the killer's Bukkit player, or empty if no killer or offline
    • getVictimName

      @NotNull public @NotNull String getVictimName()
      Gets the victim's name.

      Convenience method equivalent to getVictim().getName().

      Returns:
      The victim's name (never null)
    • getKillerName

      @NotNull public @NotNull Optional<String> getKillerName()
      Gets the killer's name, if any.
      Returns:
      Optional containing the killer's name, or empty if no killer
    • getVictimTeam

      @NotNull public @NotNull Optional<ZentrixTeam> getVictimTeam()
      Gets the victim's team.
      Returns:
      Optional containing the victim's team, or empty if not on a team
    • getDeathLocation

      @NotNull public @NotNull org.bukkit.Location getDeathLocation()
      Gets the location where the player died.

      Returns a clone to prevent modification of the original location.

      Returns:
      A clone of the death location (never null)
    • getDeathCause

      @NotNull public @NotNull PlayerDeathGameEvent.DeathCause getDeathCause()
      Gets the cause of death.
      Returns:
      The death cause (never null)
    • eliminatesTeam

      public boolean eliminatesTeam()
      Checks if this death eliminates the victim's team.

      Returns true if the victim was the last alive member of their team.

      Returns:
      true if this death eliminates the team
    • getRemainingPlayers

      public int getRemainingPlayers()
      Gets the number of players remaining after this death.
      Returns:
      Remaining player count
    • getRemainingTeams

      public int getRemainingTeams()
      Gets the number of teams remaining after this death.
      Returns:
      Remaining team count
    • wasPlayerKill

      public boolean wasPlayerKill()
      Checks if this death was caused by another player.
      Returns:
      true if killed by another player
    • wasBorderDeath

      public boolean wasBorderDeath()
      Checks if this death was caused by border damage.
      Returns:
      true if killed by the border
    • wasEnvironmentalDeath

      public boolean wasEnvironmentalDeath()
      Checks if this death was environmental (not by another player).
      Returns:
      true if environmental death
    • getSurvivalTime

      public long getSurvivalTime()
      Gets the victim's survival time in this game, in seconds.
      Returns:
      Survival time in seconds
    • getVictimKills

      public int getVictimKills()
      Gets the victim's kill count before dying.
      Returns:
      The victim's kill count
    • couldTriggerWin

      public boolean couldTriggerWin()
      Checks if this death could trigger a win condition.

      Returns true if only one team remains after this death.

      Returns:
      true if this death may end the game
    • wasTeamKill

      public boolean wasTeamKill()
      Checks if the killer and victim were on the same team.

      This can happen when friendly fire is enabled.

      Returns:
      true if this was a team kill
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Gets the handler list for this event.
      Overrides:
      getHandlers in class ZentrixGameEvent
      Returns:
      The handler list
    • getHandlerList

      @NotNull public static @NotNull org.bukkit.event.HandlerList getHandlerList()
      Gets the static handler list for this event type.
      Returns:
      The handler list