Add a prisoner death event, closes #28

This commit is contained in:
graywolf336 2014-07-14 18:39:38 -05:00
parent 3912dbfabc
commit a38ae137ee
2 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,76 @@
package com.graywolf336.jail.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.PlayerDeathEvent;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
/**
* Event thrown when a prisoner dies.
*
* @author graywolf336
* @since 3.0.0
* @version 1.0.0
*/
public class PrisonerDeathEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private PlayerDeathEvent event;
private Jail jail;
private Cell cell;
private Prisoner prisoner;
private Player player;
/**
* Creates a new {@link PrisonerDeathEvent prisoner death event} for the given player.
*
* @param event The {@link PlayerDeathEvent} which triggered this event.
* @param jail The jail the prisoner is in.
* @param cell The cell the prisoner is in, can be null.
* @param prisoner The prisoner's data.
* @param player The player being jailed.
*/
public PrisonerDeathEvent(PlayerDeathEvent event, Jail jail, Cell cell, Prisoner prisoner, Player player) {
this.event = event;
this.jail = jail;
this.cell = cell;
this.prisoner = prisoner;
this.player = player;
}
/** Gets the {@link PlayerDeathEvent} which triggered this PrisonerDeathEvent. */
public PlayerDeathEvent getPlayerDeathEvent() {
return this.event;
}
/** Gets the {@link Jail} this prisoner is in. */
public Jail getJail() {
return this.jail;
}
/** Gets the cell the prisoner is in, can be null. */
public Cell getCell() {
return this.cell;
}
/** Gets the {@link Prisoner}'s data. */
public Prisoner getPrisoner() {
return this.prisoner;
}
/** Gets the instance of the player who died. */
public Player getPlayer() {
return this.player;
}
public static HandlerList getHandlerList() {
return handlers;
}
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -12,6 +12,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -29,6 +30,7 @@ import com.graywolf336.jail.beans.Stick;
import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.enums.LangString;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent; import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
import com.graywolf336.jail.events.PrisonerDeathEvent;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
private JailMain pl; private JailMain pl;
@ -170,6 +172,16 @@ public class PlayerListener implements Listener {
} }
} }
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
if(pl.getJailManager().isPlayerJailed(event.getEntity().getUniqueId())) {
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getEntity().getUniqueId());
PrisonerDeathEvent prisonerEvent = new PrisonerDeathEvent(event, j, j.getCellPrisonerIsIn(event.getEntity().getUniqueId()), j.getPrisoner(event.getEntity().getUniqueId()), event.getEntity());
pl.getServer().getPluginManager().callEvent(prisonerEvent);
}
}
@EventHandler @EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) { if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {