From 22f2b66cf519121b48d0a54f32b66c743a8a856e Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sat, 15 Feb 2014 00:05:32 -0600 Subject: [PATCH] Add the PrePrisonerReleasedEvent for #9, not all that useful event tbh. --- .../com/graywolf336/jail/PrisonerManager.java | 5 ++ .../jail/events/PrePrisonerReleasedEvent.java | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/main/java/com/graywolf336/jail/events/PrePrisonerReleasedEvent.java diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index 046bfef..b175c0e 100644 --- a/src/main/java/com/graywolf336/jail/PrisonerManager.java +++ b/src/main/java/com/graywolf336/jail/PrisonerManager.java @@ -11,6 +11,7 @@ import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.enums.Settings; +import com.graywolf336.jail.events.PrePrisonerReleasedEvent; import com.graywolf336.jail.events.PrisonerJailedEvent; import com.graywolf336.jail.events.PrisonerReleasedEvent; @@ -316,6 +317,10 @@ public class PrisonerManager { if(prisoner == null) throw new Exception("Prisoner data can not be null."); + //Throw the custom event which is called before we start releasing them + PrePrisonerReleasedEvent preEvent = new PrePrisonerReleasedEvent(jail, cell, prisoner, player); + pl.getServer().getPluginManager().callEvent(preEvent); + //We are getting ready to teleport them, so set it to true so that //the *future* move checkers won't be canceling our moving. prisoner.setTeleporting(true); diff --git a/src/main/java/com/graywolf336/jail/events/PrePrisonerReleasedEvent.java b/src/main/java/com/graywolf336/jail/events/PrePrisonerReleasedEvent.java new file mode 100644 index 0000000..d761515 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/events/PrePrisonerReleasedEvent.java @@ -0,0 +1,73 @@ +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 before everything for the releasing takes place. + * This event is called for informative purposes, see {@link PrisonerReleasedEvent} + * for the event called after they get teleported out and all that fancy stuff. + * + * @author graywolf336 + * @since 3.0.0 + * @version 1.0.0 + */ +public class PrePrisonerReleasedEvent 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 PrePrisonerReleasedEvent pre-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 PrePrisonerReleasedEvent(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; + } +}