Add a PrePrisonerTransferredEvent #9.
This commit is contained in:
		@@ -14,6 +14,7 @@ import com.graywolf336.jail.command.Command;
 | 
				
			|||||||
import com.graywolf336.jail.command.CommandInfo;
 | 
					import com.graywolf336.jail.command.CommandInfo;
 | 
				
			||||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
 | 
					import com.graywolf336.jail.command.commands.jewels.Transfer;
 | 
				
			||||||
import com.graywolf336.jail.enums.LangString;
 | 
					import com.graywolf336.jail.enums.LangString;
 | 
				
			||||||
 | 
					import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
 | 
				
			||||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
 | 
					import com.lexicalscope.jewel.cli.ArgumentValidationException;
 | 
				
			||||||
import com.lexicalscope.jewel.cli.CliFactory;
 | 
					import com.lexicalscope.jewel.cli.CliFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,7 +101,24 @@ public class JailTransferCommand implements Command {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		jm.getPlugin().debug("Sending the transferring off, jail and cell check all came out clean.");
 | 
							jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean.");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							//Throw the custom event before transferring them, allowing another plugin to cancel it.
 | 
				
			||||||
 | 
							PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(params.getPlayer()),
 | 
				
			||||||
 | 
									jm.getJailPlayerIsIn(params.getPlayer()).getCellPrisonerIsIn(params.getPlayer()),
 | 
				
			||||||
 | 
									target, targetCell, jm.getPrisoner(params.getPlayer()), jm.getPlugin().getServer().getPlayer(params.getPlayer()), sender.getName());
 | 
				
			||||||
 | 
							jm.getPlugin().getServer().getPluginManager().callEvent(event);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(event.isCancelled()) {
 | 
				
			||||||
 | 
								if(event.getCancelledMessage().isEmpty()) {
 | 
				
			||||||
 | 
									//The plugin didn't provide a cancel message/reason so send the default one
 | 
				
			||||||
 | 
									sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCANCELLEDBYANOTHERPLUGIN, params.getPlayer()));
 | 
				
			||||||
 | 
								}else {
 | 
				
			||||||
 | 
									sender.sendMessage(event.getCancelledMessage());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Start the transferring of the prisoner
 | 
							//Start the transferring of the prisoner
 | 
				
			||||||
		jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()),
 | 
							jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(params.getPlayer()),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,6 +78,8 @@ public enum LangString {
 | 
				
			|||||||
	TELEOUT ("jailing"),
 | 
						TELEOUT ("jailing"),
 | 
				
			||||||
	/** The message sent to the sender when they transfer all a jail's prisoners to another jail. */
 | 
						/** The message sent to the sender when they transfer all a jail's prisoners to another jail. */
 | 
				
			||||||
	TRANSFERALLCOMPLETE ("jailing"),
 | 
						TRANSFERALLCOMPLETE ("jailing"),
 | 
				
			||||||
 | 
						/** The message sent when another plugin cancels the transferring but doesn't provide a reason why. */
 | 
				
			||||||
 | 
						TRANSFERCANCELLEDBYANOTHERPLUGIN ("jailing"),
 | 
				
			||||||
	/** The message sent to the sender when they transfer someone to a jail and a cell. */
 | 
						/** The message sent to the sender when they transfer someone to a jail and a cell. */
 | 
				
			||||||
	TRANSFERCOMPLETECELL ("jailing"),
 | 
						TRANSFERCOMPLETECELL ("jailing"),
 | 
				
			||||||
	/** The message sent to the sender when they transfer someone to a jail. */
 | 
						/** The message sent to the sender when they transfer someone to a jail. */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,151 @@
 | 
				
			|||||||
 | 
					package com.graywolf336.jail.events;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.event.Cancellable;
 | 
				
			||||||
 | 
					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 before we transfer a prisoner, both offline and online prisoner.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * <p />
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This event is called right before we actually transfer a prisoner, and is cancellable, whether the prisoner is offline or online, getPlayer() will always return null if isOnline() return false.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @author graywolf336
 | 
				
			||||||
 | 
					 * @since 3.0.0
 | 
				
			||||||
 | 
					 * @version 1.0.0
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class PrePrisonerTransferredEvent extends Event implements Cancellable {
 | 
				
			||||||
 | 
						private static final HandlerList handlers = new HandlerList();
 | 
				
			||||||
 | 
						private boolean cancelled = false;
 | 
				
			||||||
 | 
						private Jail originalJail, targetJail;
 | 
				
			||||||
 | 
						private Cell originalCell, targetCell;
 | 
				
			||||||
 | 
						private Prisoner prisoner;
 | 
				
			||||||
 | 
						private Player player;
 | 
				
			||||||
 | 
						private String transferor, cancelMsg;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Creates a new {@link PrePrisonerTransferredEvent prisoner transferred event} for the given player before they get transferred to their jail and cell.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @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 PrePrisonerTransferredEvent(Jail originalJail, Cell originalCell, Jail targetJail, Cell targetCell, Prisoner prisoner, Player player, String transferor) {
 | 
				
			||||||
 | 
							this.originalJail = originalJail;
 | 
				
			||||||
 | 
							this.originalCell = originalCell;
 | 
				
			||||||
 | 
							this.targetJail = targetJail;
 | 
				
			||||||
 | 
							this.targetCell = targetCell;
 | 
				
			||||||
 | 
							this.prisoner = prisoner;
 | 
				
			||||||
 | 
							this.player = player;
 | 
				
			||||||
 | 
							this.transferor = transferor;
 | 
				
			||||||
 | 
							this.cancelMsg = "";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the {@link Jail} this prisoner is coming from. */
 | 
				
			||||||
 | 
						public Jail getOriginalJail() {
 | 
				
			||||||
 | 
							return this.originalJail;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the {@link Cell} this prisoner is coming from, can be null. */
 | 
				
			||||||
 | 
						public Cell getOriginalCell() {
 | 
				
			||||||
 | 
							return this.originalCell;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the {@link Jail} this prisoner is being transferred to. */
 | 
				
			||||||
 | 
						public Jail getTargetJail() {
 | 
				
			||||||
 | 
							return this.targetJail;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Sets the target jail where this prisoner is being sent to.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param jail The {@link Jail} this prisoner should be sent to instead of what it was.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public void setTargetJail(Jail jail) {
 | 
				
			||||||
 | 
							this.targetJail = jail;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the {@link Cell} this prisoner is being sent to, can be null.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * Will return null if the cell is not in the targetJail.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public Cell getTargetCell() {
 | 
				
			||||||
 | 
							if(this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
 | 
				
			||||||
 | 
							else return null;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Sets the target {@link Cell} this prisoner is being sent to.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param cell The {@link Cell} this prisoner should be sent to instead of what it was.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public void setTargetCell(Cell cell) {
 | 
				
			||||||
 | 
							this.targetCell = cell;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the {@link Prisoner} data for this prisoner. */
 | 
				
			||||||
 | 
						public Prisoner getPrisoner() {
 | 
				
			||||||
 | 
							return this.prisoner;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the instance of the player being transferred <strong>but will return null if {@link #isOnline()} returns false</strong>. */
 | 
				
			||||||
 | 
						public Player getPlayer() {
 | 
				
			||||||
 | 
							return this.player;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets whether the prisoner being transferred is online or not. */
 | 
				
			||||||
 | 
						public boolean isOnline() {
 | 
				
			||||||
 | 
							return player == null;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Gets the name of what is transferring this prisoner. */
 | 
				
			||||||
 | 
						public String getTransferor() {
 | 
				
			||||||
 | 
							return this.transferor;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Sets the prisoner whom the data should say jailed this prisoner.
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param jailer The name to put who is the jailer for this prisoner.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public void setTransferor(String transferor) {
 | 
				
			||||||
 | 
							this.transferor = transferor;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Checks whether this event is cancelled or not. */
 | 
				
			||||||
 | 
						public boolean isCancelled() {
 | 
				
			||||||
 | 
							return this.cancelled;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** Sets whether this event should be cancelled. */
 | 
				
			||||||
 | 
						public void setCancelled(boolean cancel) {
 | 
				
			||||||
 | 
							this.cancelled = cancel;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Returns the cancelled message. */
 | 
				
			||||||
 | 
						public String getCancelledMessage() {
 | 
				
			||||||
 | 
							return this.cancelMsg;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/** Sets the cancelled message. */
 | 
				
			||||||
 | 
						public void setCancelledMessage(String msg) {
 | 
				
			||||||
 | 
							this.cancelMsg = msg;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public static HandlerList getHandlerList() {
 | 
				
			||||||
 | 
							return handlers;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public HandlerList getHandlers() {
 | 
				
			||||||
 | 
							return handlers;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -61,6 +61,7 @@ language:
 | 
				
			|||||||
    telein: "&9Teleported %0% to %1%'s teleport in location."
 | 
					    telein: "&9Teleported %0% to %1%'s teleport in location."
 | 
				
			||||||
    teleout: "&9Teleported %0% to %1%'s teleport out location."
 | 
					    teleout: "&9Teleported %0% to %1%'s teleport out location."
 | 
				
			||||||
    transferallcomplete: '&2Successfully transferred all the prisoners from %0% to %1%.'
 | 
					    transferallcomplete: '&2Successfully transferred all the prisoners from %0% to %1%.'
 | 
				
			||||||
 | 
					    transfercancelledbyanotherplugin: '&cTransferring %0% was cancelled by another plugin and they did not leave you a message.'
 | 
				
			||||||
    transfercompletecell: '&2Successfully transferred %0% to %1% in the cell %2%.'
 | 
					    transfercompletecell: '&2Successfully transferred %0% to %1% in the cell %2%.'
 | 
				
			||||||
    transfercompletenocell: '&2Successfully transferred %0% to %1%.'
 | 
					    transfercompletenocell: '&2Successfully transferred %0% to %1%.'
 | 
				
			||||||
    transferred: '&9You have been transferred to %0%.'
 | 
					    transferred: '&9You have been transferred to %0%.'
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user