Let's try to use the new preparing method, see what errors we get.

This commit is contained in:
graywolf336 2013-12-24 23:12:24 -06:00
parent a9d58e85e7
commit 57d61717fe
3 changed files with 54 additions and 20 deletions

View File

@ -18,8 +18,11 @@ public class PrisonerManager {
/** /**
* Prepare the jailing of this player. * Prepare the jailing of this player.
* *
* @param jail The jail instance we are sending this prisoner to
* @param cell The name of the cell we are sending this prisoner to
* @param player The player we are preparing the jail for. * @param player The player we are preparing the jail for.
* @param prisoner The prisoner file. * @param prisoner The 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, Cell cell, Player player, Prisoner prisoner) throws Exception {
//Do some checks of whether the passed params are null. //Do some checks of whether the passed params are null.
@ -42,10 +45,8 @@ public class PrisonerManager {
//Save the jail after adding them to the jail //Save the jail after adding them to the jail
pl.getJailIO().saveJail(jail); pl.getJailIO().saveJail(jail);
//If they are offline, handle different..? //If they are NOT offline, jail them
if(prisoner.isOfflinePending()) { if(!prisoner.isOfflinePending()) {
}else {
} }

View File

@ -10,6 +10,7 @@ import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.Util; import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
@ -34,8 +35,9 @@ public class JailCommand implements Command {
* *
* - If there are any jails. * - If there are any jails.
* - If the command can be parsed correctly. * - If the command can be parsed correctly.
* - If the specified jail is null (TODO: if no jail given then find one close to them)
* - If the given time can be parsed correctly, defaults to what is defined in the config * - If the given time can be parsed correctly, defaults to what is defined in the config
* - If the jail is reasonable or not, else sets the one from the config
* - If the cell is not empty then checks to be sure that cell exists
* - If the prisoner is online or not. * - If the prisoner is online or not.
*/ */
public boolean execute(JailManager jm, CommandSender sender, String... args) { public boolean execute(JailManager jm, CommandSender sender, String... args) {
@ -54,6 +56,22 @@ public class JailCommand implements Command {
return true; return true;
} }
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
//from the config and if that isn't there then we default to thirty minutes.
Long time = 10L;
try {
if(params.time().isEmpty()) {
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
}else if(Integer.valueOf(params.time()) == -1) {
time = -1L;
}else {
time = Util.getTime(params.time());
}
}catch(Exception e) {
sender.sendMessage(ChatColor.RED + "Number format is incorrect.");
return true;
}
//Check the jail params. If it is empty, let's get the default jail //Check the jail params. If it is empty, let's get the default jail
//from the config. If that is nearest, let's make a call to getting the nearest jail to //from the config. If that is nearest, let's make a call to getting the nearest jail to
//the sender but otherwise if it isn't nearest then let's set it to the default jail //the sender but otherwise if it isn't nearest then let's set it to the default jail
@ -72,24 +90,17 @@ public class JailCommand implements Command {
return true; return true;
} }
//Try to parse the time, if they give us nothing in the time parameter then we get the default time //Check if the cell is defined, and if so check to be sure it exists.
//from the config and if that isn't there then we default to thirty minutes. if(!params.cell().isEmpty()) {
Long time = 10L; if(jm.getJail(params.jail()).getCell(params.cell()) == null) {
try { sender.sendMessage(ChatColor.RED + "The cell provided does not exist.");
if(params.time().isEmpty()) { return true;
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
}else if(Integer.valueOf(params.time()) == -1) {
time = -1L;
}else {
time = Util.getTime(params.time());
} }
}catch(Exception e) {
sender.sendMessage(ChatColor.RED + "Number format is incorrect.");
return true;
} }
//Get the jail instance from the name of jail in the params. //Get the jail instance from the name of jail in the params.
Jail j = jm.getJail(params.jail()); Jail j = jm.getJail(params.jail());
Cell c = j.getCell(params.cell());
Prisoner pris = new Prisoner(params.player(), params.muted(), time); Prisoner pris = new Prisoner(params.player(), params.muted(), time);
Player p = jm.getPlugin().getServer().getPlayer(params.player()); Player p = jm.getPlugin().getServer().getPlayer(params.player());
@ -101,7 +112,7 @@ public class JailCommand implements Command {
} }
//call the event //call the event
PrisonerJailedEvent event = new PrisonerJailedEvent(j, pris, p, p == null, sender.getName()); PrisonerJailedEvent event = new PrisonerJailedEvent(j, c, pris, p, p == null, sender.getName());
jm.getPlugin().getServer().getPluginManager().callEvent(event); jm.getPlugin().getServer().getPluginManager().callEvent(event);
//check if the event is cancelled //check if the event is cancelled
@ -116,10 +127,18 @@ public class JailCommand implements Command {
//recall data from the event //recall data from the event
j = event.getJail(); j = event.getJail();
c = event.getCell();
pris = event.getPrisoner(); pris = event.getPrisoner();
p = event.getPlayer(); p = event.getPlayer();
String jailer = event.getJailer(); String jailer = event.getJailer();
try {
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
return true;
}
//Player is not online //Player is not online
if(p == null) { if(p == null) {
sender.sendMessage(pris.getName() + " is offline and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + " in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + "."); sender.sendMessage(pris.getName() + " is offline and will be jailed for " + pris.getRemainingTime() + " milliseconds in the jail " + params.jail() + " in the cell " + params.cell() + " and will be muted: " + pris.isMuted() + ".");

View File

@ -5,6 +5,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.beans.Prisoner;
@ -22,6 +23,7 @@ public class PrisonerJailedEvent extends Event implements Cancellable {
private boolean cancelled; private boolean cancelled;
private boolean online; private boolean online;
private Jail jail; private Jail jail;
private Cell cell;
private Prisoner prisoner; private Prisoner prisoner;
private Player player; private Player player;
private String jailer, cancelMsg; private String jailer, cancelMsg;
@ -30,13 +32,15 @@ public class PrisonerJailedEvent extends Event implements Cancellable {
* Creates a new {@link PrisonerJailedEvent prisoner jailed event} for the given player. * Creates a new {@link PrisonerJailedEvent prisoner jailed event} for the given player.
* *
* @param jail The jail the prisoner will be jailed at. * @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 prisoner The prisoner data.
* @param player The player being jailed. * @param player The player being jailed.
* @param online Whether the player is online or not. * @param online Whether the player is online or not.
* @param jailer The name of what jailed this prisoner. * @param jailer The name of what jailed this prisoner.
*/ */
public PrisonerJailedEvent(Jail jail, Prisoner prisoner, Player player, boolean online, String jailer) { public PrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, boolean online, String jailer) {
this.jail = jail; this.jail = jail;
this.cell = cell;
this.prisoner = prisoner; this.prisoner = prisoner;
this.player = player; this.player = player;
this.online = online; this.online = online;
@ -49,6 +53,16 @@ public class PrisonerJailedEvent extends Event implements Cancellable {
return this.jail; return this.jail;
} }
/** Gets the cell we're going to be sending the prisoner to. */
public Cell getCell() {
return this.cell;
}
/** Sets the cell we're going to be sending the prisoner to. */
public void setCell(Cell cell) {
this.cell = cell;
}
/** Gets the {@link Prisoner} data for this prisoner. */ /** Gets the {@link Prisoner} data for this prisoner. */
public Prisoner getPrisoner() { public Prisoner getPrisoner() {
return this.prisoner; return this.prisoner;