Save the Jail when we add it.
This commit is contained in:
parent
af9d1a1f5b
commit
7976dec870
@ -1,269 +1,275 @@
|
|||||||
package com.graywolf336.jail;
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import com.graywolf336.jail.beans.CreationPlayer;
|
import com.graywolf336.jail.beans.CreationPlayer;
|
||||||
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.steps.CellCreationSteps;
|
import com.graywolf336.jail.steps.CellCreationSteps;
|
||||||
import com.graywolf336.jail.steps.JailCreationSteps;
|
import com.graywolf336.jail.steps.JailCreationSteps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles all things related to jails.
|
* Handles all things related to jails.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* Stores the following:
|
* Stores the following:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The {@link Jail jails}, which contains the prisoners and cells.</li>
|
* <li>The {@link Jail jails}, which contains the prisoners and cells.</li>
|
||||||
* <li>Players creating jails, see {@link CreationPlayer}.</li>
|
* <li>Players creating jails, see {@link CreationPlayer}.</li>
|
||||||
* <li>Players creating jail cells, see {@link CreationPlayer}.</li>
|
* <li>Players creating jail cells, see {@link CreationPlayer}.</li>
|
||||||
* <li>An instance of {@link JailCreationSteps} for stepping players through the Jail creation process.</li>
|
* <li>An instance of {@link JailCreationSteps} for stepping players through the Jail creation process.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author graywolf336
|
* @author graywolf336
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @version 1.1.0
|
* @version 1.1.0
|
||||||
*/
|
*/
|
||||||
public class JailManager {
|
public class JailManager {
|
||||||
private JailMain plugin;
|
private JailMain plugin;
|
||||||
private HashMap<String, Jail> jails;
|
private HashMap<String, Jail> jails;
|
||||||
private HashMap<String, CreationPlayer> jailCreators;
|
private HashMap<String, CreationPlayer> jailCreators;
|
||||||
private HashMap<String, CreationPlayer> cellCreators;
|
private HashMap<String, CreationPlayer> cellCreators;
|
||||||
private JailCreationSteps jcs;
|
private JailCreationSteps jcs;
|
||||||
private CellCreationSteps ccs;
|
private CellCreationSteps ccs;
|
||||||
|
|
||||||
public JailManager(JailMain plugin) {
|
public JailManager(JailMain plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.jails = new HashMap<String, Jail>();
|
this.jails = new HashMap<String, Jail>();
|
||||||
this.jailCreators = new HashMap<String, CreationPlayer>();
|
this.jailCreators = new HashMap<String, CreationPlayer>();
|
||||||
this.cellCreators = new HashMap<String, CreationPlayer>();
|
this.cellCreators = new HashMap<String, CreationPlayer>();
|
||||||
this.jcs = new JailCreationSteps();
|
this.jcs = new JailCreationSteps();
|
||||||
this.ccs = new CellCreationSteps();
|
this.ccs = new CellCreationSteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the instance of the plugin main class. */
|
/** Returns the instance of the plugin main class. */
|
||||||
public JailMain getPlugin() {
|
public JailMain getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a HashSet of all the jails. */
|
/** Returns a HashSet of all the jails. */
|
||||||
public HashSet<Jail> getJails() {
|
public HashSet<Jail> getJails() {
|
||||||
return new HashSet<Jail>(jails.values());
|
return new HashSet<Jail>(jails.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an array of all the names of the jails. */
|
/** Returns an array of all the names of the jails. */
|
||||||
public String[] getJailNames() {
|
public String[] getJailNames() {
|
||||||
return this.jails.keySet().toArray(new String[jails.size()]);
|
return this.jails.keySet().toArray(new String[jails.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a jail to the collection of them. */
|
/**
|
||||||
public void addJail(Jail jail) {
|
* Adds a jail to the collection of them.
|
||||||
this.jails.put(jail.getName(), jail);
|
*
|
||||||
}
|
* @param jail The jail to add
|
||||||
|
* @param n True if this is a new jail, false if it isn't.
|
||||||
/**
|
*/
|
||||||
* Gets a jail by the given name.
|
public void addJail(Jail jail, boolean n) {
|
||||||
*
|
this.jails.put(jail.getName(), jail);
|
||||||
* @param name The name of the jail to get.
|
if(n) plugin.getJailIO().saveJail(jail);
|
||||||
* @return The {@link Jail} with the given name, if no jail found this <strong>will</strong> return null.
|
}
|
||||||
*/
|
|
||||||
public Jail getJail(String name) {
|
/**
|
||||||
return this.jails.get(name);
|
* Gets a jail by the given name.
|
||||||
}
|
*
|
||||||
|
* @param name The name of the jail to get.
|
||||||
/**
|
* @return The {@link Jail} with the given name, if no jail found this <strong>will</strong> return null.
|
||||||
* Checks to see if the given name for a {@link Jail} is valid, returns true if it is a valid jail.
|
*/
|
||||||
*
|
public Jail getJail(String name) {
|
||||||
* @param name The name of the jail to check.
|
return this.jails.get(name);
|
||||||
* @return True if a valid jail was found, false if no jail was found.
|
}
|
||||||
*/
|
|
||||||
public boolean isValidJail(String name) {
|
/**
|
||||||
return this.jails.get(name) != null;
|
* Checks to see if the given name for a {@link Jail} is valid, returns true if it is a valid jail.
|
||||||
}
|
*
|
||||||
|
* @param name The name of the jail to check.
|
||||||
/**
|
* @return True if a valid jail was found, false if no jail was found.
|
||||||
* Gets the {@link Jail jail} the given player is in.
|
*/
|
||||||
*
|
public boolean isValidJail(String name) {
|
||||||
* @param name The name of the player whos jail we are getting.
|
return this.jails.get(name) != null;
|
||||||
* @return The jail the player is in, <strong>CAN BE NULL</strong>.
|
}
|
||||||
*/
|
|
||||||
public Jail getJailPlayerIsIn(String name) {
|
/**
|
||||||
Jail re = null;
|
* Gets the {@link Jail jail} the given player is in.
|
||||||
|
*
|
||||||
for(Jail j : jails.values()) {
|
* @param name The name of the player whos jail we are getting.
|
||||||
if(j.isPlayerAPrisoner(name)) {
|
* @return The jail the player is in, <strong>CAN BE NULL</strong>.
|
||||||
re = j;
|
*/
|
||||||
break;
|
public Jail getJailPlayerIsIn(String name) {
|
||||||
}
|
Jail re = null;
|
||||||
}
|
|
||||||
|
for(Jail j : jails.values()) {
|
||||||
return re;
|
if(j.isPlayerAPrisoner(name)) {
|
||||||
}
|
re = j;
|
||||||
|
break;
|
||||||
/**
|
}
|
||||||
* Gets if the given player is jailed or not, in all the jails and cells.
|
}
|
||||||
*
|
|
||||||
* @param name The name of the player to check.
|
return re;
|
||||||
* @return true if they are jailed, false if not.
|
}
|
||||||
*/
|
|
||||||
public boolean isPlayerJailed(String name) {
|
/**
|
||||||
boolean r = false;
|
* Gets if the given player is jailed or not, in all the jails and cells.
|
||||||
|
*
|
||||||
for(Jail j : jails.values()) {
|
* @param name The name of the player to check.
|
||||||
if(j.isPlayerAPrisoner(name)) {
|
* @return true if they are jailed, false if not.
|
||||||
r = true;
|
*/
|
||||||
break;
|
public boolean isPlayerJailed(String name) {
|
||||||
}
|
boolean r = false;
|
||||||
}
|
|
||||||
|
for(Jail j : jails.values()) {
|
||||||
return r;
|
if(j.isPlayerAPrisoner(name)) {
|
||||||
}
|
r = true;
|
||||||
|
break;
|
||||||
/**
|
}
|
||||||
* Gets the {@link Prisoner} data from for this user, if they are jailed.
|
}
|
||||||
*
|
|
||||||
* @param name The name of prisoner who's data to get
|
return r;
|
||||||
* @return {@link Prisoner prisoner} data.
|
}
|
||||||
*/
|
|
||||||
public Prisoner getPrisoner(String name) {
|
/**
|
||||||
Jail j = getJailPlayerIsIn(name);
|
* Gets the {@link Prisoner} data from for this user, if they are jailed.
|
||||||
|
*
|
||||||
if(j != null) {
|
* @param name The name of prisoner who's data to get
|
||||||
return j.getPrisoner(name);
|
* @return {@link Prisoner prisoner} data.
|
||||||
}else {
|
*/
|
||||||
return null;
|
public Prisoner getPrisoner(String name) {
|
||||||
}
|
Jail j = getJailPlayerIsIn(name);
|
||||||
}
|
|
||||||
|
if(j != null) {
|
||||||
/**
|
return j.getPrisoner(name);
|
||||||
* Returns whether or not the player is creating a jail or a cell.
|
}else {
|
||||||
*
|
return null;
|
||||||
* <p>
|
}
|
||||||
*
|
}
|
||||||
* 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.
|
* Returns whether or not the player is creating a jail or a cell.
|
||||||
* @return True if the player is creating a jail or cell, false if they're not creating anything.
|
*
|
||||||
*/
|
* <p>
|
||||||
public boolean isCreatingSomething(String name) {
|
*
|
||||||
return this.jailCreators.containsKey(name.toLowerCase()) || this.cellCreators.containsKey(name.toLowerCase());
|
* 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.
|
||||||
/** Returns a message used for telling them what they're creating and what step they're on. */
|
* @return True if the player is creating a jail or cell, false if they're not creating anything.
|
||||||
public String getStepMessage(String player) {
|
*/
|
||||||
String message = "";
|
public boolean isCreatingSomething(String name) {
|
||||||
|
return this.jailCreators.containsKey(name.toLowerCase()) || this.cellCreators.containsKey(name.toLowerCase());
|
||||||
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 ";
|
/** Returns a message used for telling them what they're creating and what step they're on. */
|
||||||
|
public String getStepMessage(String player) {
|
||||||
switch(cp.getStep()) {
|
String message = "";
|
||||||
case 1:
|
|
||||||
message += "set the teleport in location.";
|
if(isCreatingACell(player)) {//Check whether it is a jail cell
|
||||||
break;
|
CreationPlayer cp = this.getCellCreationPlayer(player);
|
||||||
case 2:
|
message = "You're already creating a Cell with the name '" + cp.getCellName() + "' and you still need to ";
|
||||||
message += "select all the signs.";
|
|
||||||
break;
|
switch(cp.getStep()) {
|
||||||
case 3:
|
case 1:
|
||||||
message += "set the double chest location.";
|
message += "set the teleport in location.";
|
||||||
break;
|
break;
|
||||||
}
|
case 2:
|
||||||
|
message += "select all the signs.";
|
||||||
}else if(isCreatingAJail(player)) {//If not a cell, then check if a jail.
|
break;
|
||||||
CreationPlayer cp = this.getJailCreationPlayer(player);
|
case 3:
|
||||||
message = "You're already creating a Jail with the name '" + cp.getJailName() + "' and you still need to ";
|
message += "set the double chest location.";
|
||||||
|
break;
|
||||||
switch(cp.getStep()) {
|
}
|
||||||
case 1:
|
|
||||||
message += "select the first point.";
|
}else if(isCreatingAJail(player)) {//If not a cell, then check if a jail.
|
||||||
break;
|
CreationPlayer cp = this.getJailCreationPlayer(player);
|
||||||
case 2:
|
message = "You're already creating a Jail with the name '" + cp.getJailName() + "' and you still need to ";
|
||||||
message += "select the second point.";
|
|
||||||
break;
|
switch(cp.getStep()) {
|
||||||
case 3:
|
case 1:
|
||||||
message += "set the teleport in location.";
|
message += "select the first point.";
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 2:
|
||||||
message += "set the release location.";
|
message += "select the second point.";
|
||||||
break;
|
break;
|
||||||
}
|
case 3:
|
||||||
}
|
message += "set the teleport in location.";
|
||||||
|
break;
|
||||||
return message;
|
case 4:
|
||||||
}
|
message += "set the release location.";
|
||||||
|
break;
|
||||||
/** Returns whether or not someone is creating a <strong>Jail</strong>. */
|
}
|
||||||
public boolean isCreatingAJail(String name) {
|
}
|
||||||
return this.jailCreators.containsKey(name.toLowerCase());
|
|
||||||
}
|
return message;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Method for setting a player to be creating a Jail, returns whether or not they were added successfully.
|
/** Returns whether or not someone is creating a <strong>Jail</strong>. */
|
||||||
*
|
public boolean isCreatingAJail(String name) {
|
||||||
* @param player The player who is creating a jail.
|
return this.jailCreators.containsKey(name.toLowerCase());
|
||||||
* @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) {
|
* Method for setting a player to be creating a Jail, returns whether or not they were added successfully.
|
||||||
if(isCreatingAJail(player)) {
|
*
|
||||||
return false;
|
* @param player The player who is creating a jail.
|
||||||
}else {
|
* @param jailName The name of the jail we are creating.
|
||||||
this.jailCreators.put(player.toLowerCase(), new CreationPlayer(jailName));
|
* @return True if they were added successfully, false if they are already creating a Jail.
|
||||||
return true;
|
*/
|
||||||
}
|
public boolean addCreatingJail(String player, String jailName) {
|
||||||
}
|
if(isCreatingAJail(player)) {
|
||||||
|
return false;
|
||||||
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
}else {
|
||||||
public CreationPlayer getJailCreationPlayer(String name) {
|
this.jailCreators.put(player.toLowerCase(), new CreationPlayer(jailName));
|
||||||
return this.jailCreators.get(name.toLowerCase());
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/** Removes a CreationPlayer with the given name from the jail creators. */
|
|
||||||
public void removeJailCreationPlayer(String name) {
|
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
||||||
this.jailCreators.remove(name.toLowerCase());
|
public CreationPlayer getJailCreationPlayer(String name) {
|
||||||
}
|
return this.jailCreators.get(name.toLowerCase());
|
||||||
|
}
|
||||||
/** Returns whether or not someone is creating a <strong>Cell</strong>. */
|
|
||||||
public boolean isCreatingACell(String name) {
|
/** Removes a CreationPlayer with the given name from the jail creators. */
|
||||||
return this.cellCreators.containsKey(name.toLowerCase());
|
public void removeJailCreationPlayer(String name) {
|
||||||
}
|
this.jailCreators.remove(name.toLowerCase());
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Method for setting a player to be creating a Cell, returns whether or not they were added successfully.
|
/** Returns whether or not someone is creating a <strong>Cell</strong>. */
|
||||||
*
|
public boolean isCreatingACell(String name) {
|
||||||
* @param player The player who is creating a jail.
|
return this.cellCreators.containsKey(name.toLowerCase());
|
||||||
* @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.
|
/**
|
||||||
*/
|
* Method for setting a player to be creating a Cell, returns whether or not they were added successfully.
|
||||||
public boolean addCreatingCell(String player, String jailName, String cellName) {
|
*
|
||||||
if(isCreatingACell(player)) {
|
* @param player The player who is creating a jail.
|
||||||
return false;
|
* @param jailName The name of the jail this cell is going.
|
||||||
}else {
|
* @param cellName The name of the cell we are creating.
|
||||||
this.cellCreators.put(player.toLowerCase(), new CreationPlayer(cellName));
|
* @return True if they were added successfully, false if they are already creating a Jail.
|
||||||
return true;
|
*/
|
||||||
}
|
public boolean addCreatingCell(String player, String jailName, String cellName) {
|
||||||
}
|
if(isCreatingACell(player)) {
|
||||||
|
return false;
|
||||||
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
}else {
|
||||||
public CreationPlayer getCellCreationPlayer(String name) {
|
this.cellCreators.put(player.toLowerCase(), new CreationPlayer(cellName));
|
||||||
return this.cellCreators.get(name.toLowerCase());
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/** Removes a CreationPlayer with the given name from the cell creators. */
|
|
||||||
public void removeCellCreationPlayer(String name) {
|
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
||||||
this.cellCreators.remove(name.toLowerCase());
|
public CreationPlayer getCellCreationPlayer(String name) {
|
||||||
}
|
return this.cellCreators.get(name.toLowerCase());
|
||||||
|
}
|
||||||
/** Gets the instance of the {@link JailCreationSteps}. */
|
|
||||||
public JailCreationSteps getJailCreationSteps() {
|
/** Removes a CreationPlayer with the given name from the cell creators. */
|
||||||
return this.jcs;
|
public void removeCellCreationPlayer(String name) {
|
||||||
}
|
this.cellCreators.remove(name.toLowerCase());
|
||||||
|
}
|
||||||
/** Gets the instance of the {@link CellCreationSteps}. */
|
|
||||||
public CellCreationSteps getCellCreationSteps() {
|
/** Gets the instance of the {@link JailCreationSteps}. */
|
||||||
return this.ccs;
|
public JailCreationSteps getJailCreationSteps() {
|
||||||
}
|
return this.jcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the instance of the {@link CellCreationSteps}. */
|
||||||
|
public CellCreationSteps getCellCreationSteps() {
|
||||||
|
return this.ccs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -135,7 +135,7 @@ public class JailCreationSteps {
|
|||||||
jail.setTeleportIn(cp.getTeleportInSL());
|
jail.setTeleportIn(cp.getTeleportInSL());
|
||||||
jail.setTeleportFree(cp.getTeleportFreeSL());
|
jail.setTeleportFree(cp.getTeleportFreeSL());
|
||||||
|
|
||||||
jm.addJail(jail);
|
jm.addJail(jail, true);
|
||||||
|
|
||||||
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
|
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user