From d0763b6c003b00359289f507725a51768e0df2d1 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Fri, 14 Feb 2014 23:58:17 -0600 Subject: [PATCH] Add the PrisonerReleasedEvent for #9. --- .../com/graywolf336/jail/PrisonerManager.java | 5 ++ .../jail/events/PrisonerReleasedEvent.java | 87 ++++++++++++++++--- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 699bd6d..046bfef 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -12,6 +12,7 @@ import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.events.PrisonerJailedEvent; +import com.graywolf336.jail.events.PrisonerReleasedEvent; /** * Provides methods, non-statically, that do the preparing of jails and handle all the good stuff like that. @@ -392,6 +393,10 @@ public class PrisonerManager { pl.getServer().dispatchCommand(pl.getServer().getConsoleSender(), command); } + //Call the prisoner released event as we have released them. + PrisonerReleasedEvent event = new PrisonerReleasedEvent(jail, cell, prisoner, player); + pl.getServer().getPluginManager().callEvent(event); + player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED)); } diff --git a/src/main/java/com/graywolf336/jail/events/PrisonerReleasedEvent.java b/src/main/java/com/graywolf336/jail/events/PrisonerReleasedEvent.java index 1bc4ea1..b380f2b 100644 --- a/src/main/java/com/graywolf336/jail/events/PrisonerReleasedEvent.java +++ b/src/main/java/com/graywolf336/jail/events/PrisonerReleasedEvent.java @@ -1,14 +1,73 @@ -package com.graywolf336.jail.events; - -/** - * Event thrown when a player is being released from jail, both offline and online players. - * - * This event is called whenever a player is being released from jail whether the player is offline or online, getPlayer() will always return null if isOnline() return false. - * - * @author graywolf336 - * @since 3.0.0 - * @version 0.0.0 - */ -public class PrisonerReleasedEvent { - -} +package com.graywolf336.jail.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.graywolf336.jail.beans.Cell; +import com.graywolf336.jail.beans.Jail; +import com.graywolf336.jail.beans.Prisoner; + +/** + * Event thrown after a prisoner is released. + * + *

+ * + * This event is called after everything for the releasing takes place. + * This event is called for informative purposes, see {@link PrePrisonerReleasedEvent} + * for the event called before they teleported out and all that fancy stuff. + * + * @author graywolf336 + * @since 3.0.0 + * @version 1.0.0 + */ +public class PrisonerReleasedEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private Jail jail; + private Cell cell; + private Prisoner prisoner; + private Player player; + + /** + * Creates a new {@link PrisonerReleasedEvent prisoner released event} for the given player. + * + * @param jail The jail the prisoner will be jailed at. + * @param cell The cell we're going to be sending the prisoner to, can be null. + * @param prisoner The prisoner data. + * @param player The player being jailed. + */ + public PrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) { + this.jail = jail; + this.cell = cell; + this.prisoner = prisoner; + this.player = player; + } + + /** Gets the {@link Jail} this prisoner is coming from. */ + public Jail getJail() { + return this.jail; + } + + /** Gets the cell where the prisoner was jailed in, null if they weren't in one. */ + public Cell getCell() { + return this.cell; + } + + /** Gets the {@link Prisoner} data for this prisoner. */ + public Prisoner getPrisoner() { + return this.prisoner; + } + + /** Gets the instance of the player being released. */ + public Player getPlayer() { + return this.player; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } +}