Work on the actual jailing of the player.

Lots of work done here, untested.
This commit is contained in:
graywolf336
2013-12-25 21:56:01 -06:00
parent 7e614a121f
commit a72f6c273b
11 changed files with 187 additions and 22 deletions

View File

@ -145,6 +145,16 @@ public class Jail {
return this.cells.get(name);
}
/** Returns the cell which the given player name is jailed in, null if not. */
public Cell getCellPrisonerIsIn(String name) {
for(Cell c : cells.values())
if(c.getPrisoner() != null)
if(c.getPrisoner().getName().equalsIgnoreCase(name))
return c;
return null;
}
/** Returns the first empty cell, returns null if there aren't any cells or any free cells. */
public Cell getFirstEmptyCell() {
for(Cell c : getCells())
@ -232,6 +242,25 @@ public class Jail {
return is;
}
/**
* Checks if the given name is a prisoner in a cell.
*
* @param name of the prisoner to check.
* @return true if is jailed in a cell, false if not.
*/
public boolean isJailedInACell(String name) {
for(Prisoner p : nocellPrisoners)
if(p.getName().equalsIgnoreCase(name))
return false;
for(Cell c : cells.values())
if(c.getPrisoner() != null)
if(c.getPrisoner().getName().equalsIgnoreCase(name))
return true;
return false;
}
/**
* Gets the {@link Prisoner prisoner} instance for the given name.
*

View File

@ -2,6 +2,9 @@ package com.graywolf336.jail.beans;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.Location;
/**
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
*
@ -10,9 +13,10 @@ import java.util.concurrent.TimeUnit;
* @version 2.0.1
*/
public class Prisoner {
private String name;
private boolean muted, offlinePending;
private String name, reason;
private boolean muted, offlinePending, teleporting;
private long time;
private Location previousPosition;
/**
* Creates a new prisoner with a name and whether they are muted or not.
@ -21,10 +25,14 @@ public class Prisoner {
* @param muted Whether the prisoner is muted or not
* @param time The amount of remaining time the prisoner has
*/
public Prisoner(String name, boolean muted, long time) {
public Prisoner(String name, boolean muted, long time, String reason) {
this.name = name;
this.muted = muted;
this.time = time;
this.reason = reason;
this.offlinePending = false;
this.teleporting = false;
this.previousPosition = null;
}
/** Gets the name of this player. */
@ -32,6 +40,16 @@ public class Prisoner {
return this.name;
}
/** Gets the reason this player was jailed for. */
public String getReason() {
return this.reason;
}
/** Sets the reason this player was jailed for. */
public void setReason(String reason) {
this.reason = reason;
}
/** Gets whether the prisoner is muted or not. */
public boolean isMuted() {
return this.muted;
@ -70,4 +88,46 @@ public class Prisoner {
public void setOfflinePending(boolean offline) {
this.offlinePending = offline;
}
/** Gets whether the player is being teleported or not. */
public boolean isTeleporting() {
return this.teleporting;
}
/** Sets whether the player is being teleported or not. */
public void setTeleporting(boolean teleport) {
this.teleporting = teleport;
}
/** Gets the previous location of this player, can be null. */
public Location getPreviousLocation() {
return this.previousPosition;
}
/** Gets the previous location of this player, separated by a comma. */
public String getPreviousLocationString() {
if(previousPosition == null) return "";
else return previousPosition.getWorld().getName() + "," +
previousPosition.getX() + "," +
previousPosition.getY() + "," +
previousPosition.getZ() + "," +
previousPosition.getYaw() + "," +
previousPosition.getPitch();
}
/** Sets the previous location of this player. */
public void setPreviousPosition(Location location) {
this.previousPosition = location;
}
/** Sets the previous location of this player from a comma separated string. */
public void setPreviousPosition(String location) {
String[] s = location.split(",");
this.previousPosition = new Location(Bukkit.getWorld(s[0]),
Double.valueOf(s[1]),
Double.valueOf(s[2]),
Double.valueOf(s[3]),
Float.valueOf(s[4]),
Float.valueOf(s[5]));
}
}