Whoops, forgot this file in the previous commit.
Fixed!
This commit is contained in:
parent
3eedc4904f
commit
a5b1591dcb
@ -11,8 +11,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.graywolf336.jail.beans.AnyCell;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.NoCell;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Lang;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
@ -20,6 +22,7 @@ import com.graywolf336.jail.events.PrePrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerJailedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTransferredEvent;
|
||||
import com.graywolf336.jail.interfaces.ICell;
|
||||
|
||||
/**
|
||||
* Provides methods, non-statically, that do the preparing of jails, jailing, etc.
|
||||
@ -66,7 +69,7 @@ public class PrisonerManager {
|
||||
* <li>Checks if the jail is null, if so it throws an Exception</li>
|
||||
* <li>Checks if the prisoner is null, if so it throws an Exception</li>
|
||||
* <li>Sets the prisoner data to offline pending or not, player == null</li>
|
||||
* <li>If the cell is null, add the prisoner data to the jail otherwise we set the cell's prisoner to this one. <em>Check before here if the cell already contains a prisoner.</em></li>
|
||||
* <li>Determine which type of cell is provided, add the prisoner data to the jail otherwise we set the cell's prisoner to this one. <em>Check before here if the cell already contains a prisoner.</em></li>
|
||||
* <li>Saves the jail information, goes out to the {@link JailIO} to initate a save.</li>
|
||||
* <li>If the prisoner is <em>not</em> offline, we will actually {@link #jailPrisoner(Jail, Cell, Player, Prisoner) jail} them now.</li>
|
||||
* <li>Does checks to get the right message for the next two items.</li>
|
||||
@ -80,11 +83,14 @@ public class PrisonerManager {
|
||||
* @param prisoner The {@link Prisoner prisoner} file.
|
||||
* @throws Exception if the jail or prisoner are null.
|
||||
*/
|
||||
public void prepareJail(Jail jail, Cell cell, Player player, Prisoner prisoner) throws Exception {
|
||||
public void prepareJail(Jail jail, ICell cell, Player player, Prisoner prisoner) throws Exception {
|
||||
//Do some checks of whether the passed params are null.
|
||||
if(jail == null)
|
||||
throw new Exception("The jail can not be null.");
|
||||
|
||||
if(cell == null)
|
||||
cell = new NoCell();
|
||||
|
||||
if(prisoner == null)
|
||||
throw new Exception("Prisoner data can not be null.");
|
||||
|
||||
@ -92,8 +98,16 @@ public class PrisonerManager {
|
||||
prisoner.setOfflinePending(player == null);
|
||||
|
||||
//Now that we've got those checks out of the way, let's start preparing.
|
||||
if(cell == null) {
|
||||
if(cell instanceof NoCell) {
|
||||
jail.addPrisoner(prisoner);
|
||||
cell = null;
|
||||
}else if(cell instanceof AnyCell) {
|
||||
cell = jail.getFirstEmptyCell();
|
||||
|
||||
if(cell == null)
|
||||
jail.addPrisoner(prisoner);
|
||||
else
|
||||
cell.setPrisoner(prisoner);
|
||||
}else {
|
||||
cell.setPrisoner(prisoner);
|
||||
}
|
||||
@ -138,11 +152,16 @@ public class PrisonerManager {
|
||||
* Jails the prisoner with the proper information given.
|
||||
*
|
||||
* @param jail where they are going
|
||||
* @param cell where they are being placed in, can be null
|
||||
* @param cell where they are being placed in, can be null
|
||||
* @param player who is the prisoner
|
||||
* @param prisoner data containing everything pertaining to them
|
||||
*/
|
||||
protected void jailPrisoner(Jail jail, Cell cell, Player player, Prisoner prisoner) {
|
||||
protected void jailPrisoner(Jail jail, ICell cell, Player player, Prisoner prisoner) {
|
||||
if(cell instanceof NoCell)
|
||||
cell = null;
|
||||
else if(cell instanceof AnyCell)
|
||||
cell = null;
|
||||
|
||||
//If they have handcuffs on them, then let's remove them before we continue
|
||||
//this way the handcuff listeners and this aren't battleing each other
|
||||
if(pl.getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
@ -321,7 +340,7 @@ public class PrisonerManager {
|
||||
pl.getJailIO().saveJail(jail);
|
||||
|
||||
//Call our custom event for when a prisoner is actually jailed.
|
||||
PrisonerJailedEvent event = new PrisonerJailedEvent(jail, cell, prisoner, player);
|
||||
PrisonerJailedEvent event = new PrisonerJailedEvent(jail, cell == null ? null : (Cell)cell, prisoner, player);
|
||||
pl.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
@ -383,11 +402,16 @@ public class PrisonerManager {
|
||||
* @param sender The {@link CommandSender} who unjailed this player, can be null.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void unJail(Jail jail, Cell cell, Player player, Prisoner prisoner, CommandSender sender) throws Exception {
|
||||
public void unJail(Jail jail, ICell cell, Player player, Prisoner prisoner, CommandSender sender) throws Exception {
|
||||
//Do some checks of whether the passed params are null.
|
||||
if(jail == null)
|
||||
throw new Exception("The jail can not be null.");
|
||||
|
||||
if(cell instanceof NoCell)
|
||||
cell = null;
|
||||
else if(cell instanceof AnyCell)
|
||||
cell = null;
|
||||
|
||||
if(prisoner == null)
|
||||
throw new Exception("Prisoner data can not be null.");
|
||||
|
||||
@ -466,7 +490,7 @@ public class PrisonerManager {
|
||||
Util.restoreInventory(player, prisoner);
|
||||
}
|
||||
|
||||
pl.getJailIO().removePrisoner(jail, cell, prisoner);
|
||||
pl.getJailIO().removePrisoner(jail, cell == null ? null : (Cell)cell, prisoner);
|
||||
cell.removePrisoner();
|
||||
}else {
|
||||
Util.restoreInventory(player, prisoner);
|
||||
@ -488,7 +512,7 @@ public class PrisonerManager {
|
||||
}
|
||||
|
||||
//Call the prisoner released event as we have released them.
|
||||
PrisonerReleasedEvent event = new PrisonerReleasedEvent(jail, cell, prisoner, player);
|
||||
PrisonerReleasedEvent event = new PrisonerReleasedEvent(jail, cell == null ? null : (Cell)cell, prisoner, player);
|
||||
pl.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
player.sendMessage(Lang.UNJAILED.get());
|
||||
|
Loading…
Reference in New Issue
Block a user