Class PlayerKillEvent
- All Implemented Interfaces:
org.bukkit.event.Cancellable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result -
Constructor Summary
ConstructorsConstructorDescriptionPlayerKillEvent(@NotNull ZentrixGame game, @NotNull ZentrixPlayer killer, @NotNull ZentrixPlayer victim, double currencyReward, boolean firstBlood) Constructs a new PlayerKillEvent. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCurrencyBonus(double bonus) Adds to the currency reward for this kill.doubleGets the currency reward for this kill.static @NotNull org.bukkit.event.HandlerListGets the static handler list for this event type.@NotNull org.bukkit.event.HandlerListGets the handler list for this event.@NotNull ZentrixPlayerGets the player who made the kill.@NotNull Optional<org.bukkit.entity.Player> Gets the Bukkit player instance of the killer, if online.intGets the killer's current kill count in this game (before this kill).intGets the killer's kill count after this kill is credited.intGets the killer's current kill streak.@NotNull StringGets the killer's name.@NotNull ZentrixPlayerGets the player who was killed.@NotNull Optional<org.bukkit.entity.Player> Gets the Bukkit player instance of the victim, if online.@NotNull StringGets the victim's name.booleanbooleanChecks if this kill was the first kill of the game (first blood).voidmultiplyCurrencyReward(double multiplier) Multiplies the currency reward for this kill.voidsetCancelled(boolean cancel) voidsetCurrencyReward(double amount) Sets the currency reward for this kill.booleanChecks if the killer and victim were on the same team.Methods inherited from class dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
getArenaName, getGame, getGameId, getGameState, getGameTypeName, getPlayerCountMethods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
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 occurredkiller- The player who got the killvictim- The player who was killedcurrencyReward- The base currency reward for the killfirstBlood- Whether this is the first kill of the game
-
-
Method Details
-
getKiller
Gets the player who made the kill.- Returns:
- The killer (never null)
-
getVictim
Gets the player who was killed.- Returns:
- The victim (never null)
-
getKillerBukkit
Gets the Bukkit player instance of the killer, if online.- Returns:
- Optional containing the killer's Bukkit player, or empty if offline
-
getVictimBukkit
Gets the Bukkit player instance of the victim, if online.- Returns:
- Optional containing the victim's Bukkit player, or empty if offline
-
getKillerName
Gets the killer's name.Convenience method equivalent to
getKiller().getName().- Returns:
- The killer's name (never null)
-
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:
trueif 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:
trueif killer and victim were teammates
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceorg.bukkit.event.Cancellable
-
setCancelled
public void setCancelled(boolean cancel) - Specified by:
setCancelledin interfaceorg.bukkit.event.Cancellable
-
getHandlers
@NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()Gets the handler list for this event.- Overrides:
getHandlersin classZentrixGameEvent- 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
-