package com.graywolf336.jail; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.graywolf336.jail.beans.Cell; import com.graywolf336.jail.beans.ConfirmPlayer; import com.graywolf336.jail.beans.CreationPlayer; import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.enums.Confirmation; import com.graywolf336.jail.enums.LangString; import com.graywolf336.jail.steps.CellCreationSteps; import com.graywolf336.jail.steps.JailCreationSteps; /** * Handles all things related to jails. * *
* * Stores the following: *
* * If you want to check to see if they're just creating a jail then use {@link #isCreatingAJail(String) isCreatingAJail} or if you want to see if they're creating a cell then use {@link #isCreatingACell(String) isCreatingACell}. * * @param name The name of the player, in any case as we convert it to lowercase. * @return True if the player is creating a jail or cell, false if they're not creating anything. */ public boolean isCreatingSomething(String name) { return this.jailCreators.containsKey(name.toLowerCase()) || this.cellCreators.containsKey(name.toLowerCase()); } /** Returns a message used for telling them what they're creating and what step they're on. */ public String getStepMessage(String player) { String message = ""; if(isCreatingACell(player)) {//Check whether it is a jail cell CreationPlayer cp = this.getCellCreationPlayer(player); message = "You're already creating a Cell with the name '" + cp.getCellName() + "' and you still need to "; switch(cp.getStep()) { case 1: message += "set the teleport in location."; break; case 2: message += "select all the signs."; break; case 3: message += "set the double chest location."; break; } }else if(isCreatingAJail(player)) {//If not a cell, then check if a jail. CreationPlayer cp = this.getJailCreationPlayer(player); message = "You're already creating a Jail with the name '" + cp.getJailName() + "' and you still need to "; switch(cp.getStep()) { case 1: message += "select the first point."; break; case 2: message += "select the second point."; break; case 3: message += "set the teleport in location."; break; case 4: message += "set the release location."; break; } } return message; } /** Returns whether or not someone is creating a Jail. */ public boolean isCreatingAJail(String name) { return this.jailCreators.containsKey(name.toLowerCase()); } /** * Method for setting a player to be creating a Jail, returns whether or not they were added successfully. * * @param player The player who is creating a jail. * @param jailName The name of the jail we are creating. * @return True if they were added successfully, false if they are already creating a Jail. */ public boolean addCreatingJail(String player, String jailName) { if(isCreatingAJail(player)) { return false; }else { this.jailCreators.put(player.toLowerCase(), new CreationPlayer(jailName)); return true; } } /** Returns the instance of the CreationPlayer for this player, null if there was none found. */ public CreationPlayer getJailCreationPlayer(String name) { return this.jailCreators.get(name.toLowerCase()); } /** Removes a CreationPlayer with the given name from the jail creators. */ public void removeJailCreationPlayer(String name) { this.jailCreators.remove(name.toLowerCase()); } /** Returns whether or not someone is creating a Cell. */ public boolean isCreatingACell(String name) { return this.cellCreators.containsKey(name.toLowerCase()); } /** * Method for setting a player to be creating a Cell, returns whether or not they were added successfully. * * @param player The player who is creating a jail. * @param jailName The name of the jail this cell is going. * @param cellName The name of the cell we are creating. * @return True if they were added successfully, false if they are already creating a Jail. */ public boolean addCreatingCell(String player, String jailName, String cellName) { if(isCreatingACell(player)) { return false; }else { this.cellCreators.put(player.toLowerCase(), new CreationPlayer(jailName, cellName)); return true; } } /** Returns the instance of the CreationPlayer for this player, null if there was none found. */ public CreationPlayer getCellCreationPlayer(String name) { return this.cellCreators.get(name.toLowerCase()); } /** Removes a CreationPlayer with the given name from the cell creators. */ public void removeCellCreationPlayer(String name) { this.cellCreators.remove(name.toLowerCase()); } /** Gets the instance of the {@link JailCreationSteps}. */ public JailCreationSteps getJailCreationSteps() { return this.jcs; } /** Gets the instance of the {@link CellCreationSteps}. */ public CellCreationSteps getCellCreationSteps() { return this.ccs; } /** Adds something to the confirming list. */ public void addConfirming(String name, ConfirmPlayer confirmer) { this.confirms.put(name, confirmer); } /** Removes a name from the confirming list. */ public void removeConfirming(String name) { this.confirms.remove(name); } /** Checks if the given name is confirming something. */ public boolean isConfirming(String name) { if(this.confirms.containsKey(name)) { if(this.confirmingHasExpired(name)) this.removeConfirming(name); return this.confirms.containsKey(name); }else { return false; } } /** Returns true if the confirmation has expired, false if it is still valid. */ public boolean confirmingHasExpired(String name) { return this.confirms.get(name).getExpiryTime() <= (System.currentTimeMillis() + 5000L); } /** Returns the original arguments for what we are confirming. */ public String[] getOriginalArgs(String name) { return this.confirms.get(name).getArguments(); } /** Returns what the given name is confirming. */ public Confirmation getWhatIsConfirming(String name) { return this.confirms.get(name).getConfirming(); } }