Class PlayerKillEvent

java.lang.Object
org.bukkit.event.Event
All Implemented Interfaces:
org.bukkit.event.Cancellable

public class PlayerKillEvent extends ZentrixGameEvent implements org.bukkit.event.Cancellable
Called when a player kills another player in a Zentrix game.

This event is fired after a player has killed another player but before kill rewards and statistics are processed. At this point:

  • The victim has been eliminated
  • Kill credit has not yet been awarded
  • Currency rewards have not yet been given
  • Statistics have not yet been updated

This event is cancellable. Cancelling prevents kill credit, currency rewards, and statistic updates from being processed.

Example Usage


 @EventHandler
 public void onPlayerKill(PlayerKillEvent event) {
     ZentrixPlayer killer = event.getKiller();
     ZentrixPlayer victim = event.getVictim();
     ZentrixGame game = event.getGame();

     // Log the kill
     getLogger().info(killer.getName() + " killed " + victim.getName() +
                      " in arena " + event.getArenaName());

     // Double rewards during final phase
     game.getCurrentPhase().ifPresent(phase -> {
         if (phase.getName().contains("final")) {
             event.setCurrencyReward(event.getCurrencyReward() * 2);
             killer.getBukkitPlayer().ifPresent(p -> {
                 p.sendMessage("&6Double kill reward during final phase!");
             });
         }
     });

     // Award bonus for first blood
     if (event.isFirstBlood()) {
         event.setCurrencyReward(event.getCurrencyReward() + 50);
     }
 }
 
Since:
1.0.0
See Also:
  • Constructor Details

    • PlayerKillEvent

      public PlayerKillEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull ZentrixPlayer killer, @NotNull @NotNull ZentrixPlayer victim, double currencyReward, boolean firstBlood)
      Constructs a new PlayerKillEvent.
      Parameters:
      game - The game where the kill occurred
      killer - The player who got the kill
      victim - The player who was killed
      currencyReward - The base currency reward for the kill
      firstBlood - Whether this is the first kill of the game
  • Method Details

    • getKiller

      @NotNull public @NotNull ZentrixPlayer getKiller()
      Gets the player who made the kill.
      Returns:
      The killer (never null)
    • getVictim

      @NotNull public @NotNull ZentrixPlayer getVictim()
      Gets the player who was killed.
      Returns:
      The victim (never null)
    • getKillerBukkit

      @NotNull public @NotNull Optional<org.bukkit.entity.Player> getKillerBukkit()
      Gets the Bukkit player instance of the killer, if online.
      Returns:
      Optional containing the killer's Bukkit player, or empty if offline
    • 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
    • getKillerName

      @NotNull public @NotNull String getKillerName()
      Gets the killer's name.

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

      Returns:
      The killer's name (never null)
    • getVictimName

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

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

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

      public boolean isFirstBlood()
      Checks if this kill was the first kill of the game (first blood).
      Returns:
      true if this is the first kill in the game
    • getCurrencyReward

      public double getCurrencyReward()
      Gets the currency reward for this kill.

      This is the amount of currency that will be awarded to the killer. Can be modified by addons before the event completes.

      Returns:
      The currency reward amount
    • setCurrencyReward

      public void setCurrencyReward(double amount)
      Sets the currency reward for this kill.

      Allows addons to modify the reward amount. Set to 0 to prevent any currency from being awarded (without cancelling the kill credit).

      Parameters:
      amount - The new reward amount (can be 0 or negative)
    • addCurrencyBonus

      public void addCurrencyBonus(double bonus)
      Adds to the currency reward for this kill.

      Convenience method to add a bonus without knowing the current reward.

      Parameters:
      bonus - The amount to add (can be negative to reduce)
    • multiplyCurrencyReward

      public void multiplyCurrencyReward(double multiplier)
      Multiplies the currency reward for this kill.

      Convenience method to apply a multiplier to the current reward.

      Parameters:
      multiplier - The multiplier to apply
    • getKillerKillCount

      public int getKillerKillCount()
      Gets the killer's current kill count in this game (before this kill).

      Convenience method equivalent to getKiller().getGameKills().

      Returns:
      The killer's current kill count
    • getKillerKillCountAfter

      public int getKillerKillCountAfter()
      Gets the killer's kill count after this kill is credited.
      Returns:
      The killer's kill count after this kill
    • getKillerKillStreak

      public int getKillerKillStreak()
      Gets the killer's current kill streak.

      Convenience method equivalent to getKiller().getKillStreak().

      Returns:
      The killer's current kill streak
    • wasTeamKill

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

      This should normally not happen if friendly fire is disabled, but can occur if friendly fire is enabled for certain teams.

      Returns:
      true if killer and victim were teammates
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface org.bukkit.event.Cancellable
    • setCancelled

      public void setCancelled(boolean cancel)
      Specified by:
      setCancelled in interface org.bukkit.event.Cancellable
    • 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