From c84b833ebbeffd2add465ea3fbe24b5504f9574c Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Fri, 14 Feb 2014 23:50:23 -0600 Subject: [PATCH] Add the PrisonerJailedEvent, mark it off #9. --- .../com/graywolf336/jail/PrisonerManager.java | 5 ++ .../jail/events/PrePrisonerJailedEvent.java | 2 +- .../jail/events/PrisonerJailedEvent.java | 80 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/graywolf336/jail/events/PrisonerJailedEvent.java diff --git a/src/main/java/com/graywolf336/jail/PrisonerManager.java b/src/main/java/com/graywolf336/jail/PrisonerManager.java index a652e66..699bd6d 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.PrisonerJailedEvent; /** * Provides methods, non-statically, that do the preparing of jails and handle all the good stuff like that. @@ -263,6 +264,10 @@ public class PrisonerManager { pl.getServer().dispatchCommand(pl.getServer().getConsoleSender(), command); } + //Call our custom event for when a prisoner is actually jailed. + PrisonerJailedEvent event = new PrisonerJailedEvent(jail, cell, prisoner, player); + pl.getServer().getPluginManager().callEvent(event); + //Save the data, as we have changed it pl.getJailIO().saveJail(jail); } diff --git a/src/main/java/com/graywolf336/jail/events/PrePrisonerJailedEvent.java b/src/main/java/com/graywolf336/jail/events/PrePrisonerJailedEvent.java index 5d7efad..55b3dd5 100644 --- a/src/main/java/com/graywolf336/jail/events/PrePrisonerJailedEvent.java +++ b/src/main/java/com/graywolf336/jail/events/PrePrisonerJailedEvent.java @@ -31,7 +31,7 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable { private String jailer, cancelMsg; /** - * Creates a new {@link PrePrisonerJailedEvent prisoner jailed event} for the given player. + * Creates a new {@link PrePrisonerJailedEvent prisoner jailed event} for the given player before they get sent to jail. * * @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. diff --git a/src/main/java/com/graywolf336/jail/events/PrisonerJailedEvent.java b/src/main/java/com/graywolf336/jail/events/PrisonerJailedEvent.java new file mode 100644 index 0000000..f2b8d60 --- /dev/null +++ b/src/main/java/com/graywolf336/jail/events/PrisonerJailedEvent.java @@ -0,0 +1,80 @@ +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 put into jail. + * + *

+ * + * This event is called after everything for the jailing takes place. + * This event is called for informative purposes, see {@link PrePrisonerJailedEvent} + * for the event called before they teleported in and all that fancy stuff. + * + * @author graywolf336 + * @since 3.0.0 + * @version 1.0.0 + */ +public class PrisonerJailedEvent 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 PrisonerJailedEvent prisoner jailed 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. + * @param online Whether the player is online or not. + * @param jailer The name of what jailed this prisoner. + */ + public PrisonerJailedEvent(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 being sent to. */ + public Jail getJail() { + return this.jail; + } + + /** Gets the cell we're going to be sending the prisoner to, can be null. */ + 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 jailed but will return null if {@link #isOnline()} returns false. */ + public Player getPlayer() { + return this.player; + } + + /** Gets the jailer who jailed this prisoner. */ + public String getJailer() { + return this.prisoner.getJailer(); + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } +}