2013-12-09 14:28:38 -06:00
|
|
|
package com.graywolf336.jail.beans;
|
|
|
|
|
2014-04-21 22:58:15 -05:00
|
|
|
import java.util.UUID;
|
2013-12-24 22:25:14 -06:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2013-12-25 21:56:01 -06:00
|
|
|
import org.bukkit.Bukkit;
|
2013-12-25 22:57:09 -06:00
|
|
|
import org.bukkit.GameMode;
|
2013-12-25 21:56:01 -06:00
|
|
|
import org.bukkit.Location;
|
|
|
|
|
2013-12-09 14:28:38 -06:00
|
|
|
/**
|
|
|
|
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
|
|
|
*
|
|
|
|
* @author graywolf336
|
|
|
|
* @since 2.x.x
|
2014-03-15 14:40:50 -05:00
|
|
|
* @version 3.0.1
|
2013-12-09 14:28:38 -06:00
|
|
|
*/
|
|
|
|
public class Prisoner {
|
2014-04-21 22:58:15 -05:00
|
|
|
private String uuid, name, jailer, reason, inventory, armor;
|
2014-02-04 13:30:12 -06:00
|
|
|
private boolean muted, offlinePending, teleporting, toBeTransferred;
|
2014-01-03 14:10:38 -06:00
|
|
|
private long time, afk;
|
2013-12-25 21:56:01 -06:00
|
|
|
private Location previousPosition;
|
2013-12-25 22:57:09 -06:00
|
|
|
private GameMode previousGameMode;
|
2013-12-09 14:28:38 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new prisoner with a name and whether they are muted or not.
|
|
|
|
*
|
2014-04-21 22:58:15 -05:00
|
|
|
* @param uuid The uuid of the prisoner
|
2013-12-09 14:28:38 -06:00
|
|
|
* @param name The name of the prisoner
|
|
|
|
* @param muted Whether the prisoner is muted or not
|
|
|
|
* @param time The amount of remaining time the prisoner has
|
2014-01-21 19:56:14 -06:00
|
|
|
* @param jailer The name of the person who jailed this prisoner
|
|
|
|
* @param reason The reason why this prisoner is in jail
|
2013-12-09 14:28:38 -06:00
|
|
|
*/
|
2014-04-21 22:58:15 -05:00
|
|
|
public Prisoner(String uuid, String name, boolean muted, long time, String jailer, String reason) {
|
|
|
|
this.uuid = uuid;
|
2013-12-09 14:28:38 -06:00
|
|
|
this.name = name;
|
|
|
|
this.muted = muted;
|
|
|
|
this.time = time;
|
2014-01-21 19:56:14 -06:00
|
|
|
this.jailer = jailer;
|
2013-12-25 21:56:01 -06:00
|
|
|
this.reason = reason;
|
|
|
|
this.offlinePending = false;
|
|
|
|
this.teleporting = false;
|
2014-02-04 13:30:12 -06:00
|
|
|
this.toBeTransferred = false;
|
2013-12-25 21:56:01 -06:00
|
|
|
this.previousPosition = null;
|
2013-12-28 15:08:24 -06:00
|
|
|
this.previousGameMode = GameMode.SURVIVAL;
|
2013-12-27 18:19:47 -06:00
|
|
|
this.inventory = "";
|
|
|
|
this.armor = "";
|
2014-01-03 14:10:38 -06:00
|
|
|
this.afk = 0;
|
2013-12-09 14:28:38 -06:00
|
|
|
}
|
|
|
|
|
2014-04-21 22:58:15 -05:00
|
|
|
/** Returns the UUID of the prisoner. */
|
|
|
|
public UUID getUUID() {
|
|
|
|
return UUID.fromString(this.uuid);
|
|
|
|
}
|
|
|
|
|
2014-04-29 13:20:33 -05:00
|
|
|
/** Gets the name of this prisoner. */
|
|
|
|
public String getLastKnownName() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the name of this prisoner. */
|
|
|
|
public String setLastKnownName(String username) {
|
|
|
|
this.name = username;
|
2013-12-09 14:28:38 -06:00
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2013-12-25 21:56:01 -06:00
|
|
|
/** 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;
|
|
|
|
}
|
|
|
|
|
2014-01-21 19:56:14 -06:00
|
|
|
/** Gets the person who jailed this prisoner. */
|
|
|
|
public String getJailer() {
|
|
|
|
return this.jailer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the person who jailed this prisoner. */
|
|
|
|
public void setJailer(String jailer) {
|
|
|
|
this.jailer = jailer;
|
|
|
|
}
|
|
|
|
|
2013-12-09 14:28:38 -06:00
|
|
|
/** Gets whether the prisoner is muted or not. */
|
|
|
|
public boolean isMuted() {
|
|
|
|
return this.muted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets whether the prisoner is muted or not. */
|
|
|
|
public void setMuted(boolean muted) {
|
|
|
|
this.muted = muted;
|
|
|
|
}
|
|
|
|
|
2013-12-24 22:25:14 -06:00
|
|
|
/** Gets the remaining time the prisoner has. */
|
2013-12-09 14:28:38 -06:00
|
|
|
public long getRemainingTime() {
|
|
|
|
return this.time;
|
|
|
|
}
|
|
|
|
|
2013-12-24 22:25:14 -06:00
|
|
|
/** Gets the remaining time the prisoner has in minutes. */
|
|
|
|
public long getRemainingTimeInMinutes() {
|
|
|
|
return TimeUnit.MINUTES.convert(time, TimeUnit.MILLISECONDS);
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:59:47 -05:00
|
|
|
/** Gets the remaining time the prison has in minutes except only in int format. */
|
|
|
|
public int getRemainingTimeInMinutesInt() {
|
|
|
|
return (int) this.getRemainingTimeInMinutes();
|
|
|
|
}
|
|
|
|
|
2013-12-09 14:28:38 -06:00
|
|
|
/**
|
|
|
|
* Sets the remaining time the prisoner has left.
|
|
|
|
*
|
|
|
|
* @param time The amount of time left, in milliseconds.
|
|
|
|
*/
|
|
|
|
public void setRemainingTime(long time) {
|
|
|
|
this.time = time;
|
|
|
|
}
|
2013-12-24 22:25:14 -06:00
|
|
|
|
2014-01-19 14:40:39 -06:00
|
|
|
/**
|
|
|
|
* Adds the given time to the remaining time the prisoner has left.
|
|
|
|
*
|
|
|
|
* @param time to add to the prisoner's remaining time.
|
2014-03-15 14:40:50 -05:00
|
|
|
* @return the new remaining time the prisoner has
|
2014-01-19 14:40:39 -06:00
|
|
|
*/
|
2014-03-15 14:40:50 -05:00
|
|
|
public long addTime(long time) {
|
2014-01-19 14:40:39 -06:00
|
|
|
this.time += time;
|
2014-03-15 14:40:50 -05:00
|
|
|
return this.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts the given time from the remaining time the prisoner has left.
|
|
|
|
*
|
|
|
|
* @param time to subtract from the prisoner's remaining time.
|
|
|
|
* @return the new remaining time the prisoner has
|
|
|
|
*/
|
|
|
|
public long subtractTime(long time) {
|
|
|
|
this.time -= time;
|
|
|
|
return this.time;
|
2014-01-19 14:40:39 -06:00
|
|
|
}
|
|
|
|
|
2013-12-24 22:25:14 -06:00
|
|
|
/** Gets whether the player is offline or not. */
|
|
|
|
public boolean isOfflinePending() {
|
|
|
|
return this.offlinePending;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets whether the player is offline or not. */
|
|
|
|
public void setOfflinePending(boolean offline) {
|
|
|
|
this.offlinePending = offline;
|
|
|
|
}
|
2013-12-25 21:56:01 -06:00
|
|
|
|
|
|
|
/** 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;
|
|
|
|
}
|
|
|
|
|
2014-02-04 13:30:12 -06:00
|
|
|
/** Gets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
|
|
|
public boolean isToBeTransferred() {
|
|
|
|
return this.toBeTransferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
|
|
|
public void setToBeTransferred(boolean transferred) {
|
|
|
|
this.toBeTransferred = transferred;
|
|
|
|
}
|
|
|
|
|
2013-12-25 21:56:01 -06:00
|
|
|
/** 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) {
|
2013-12-25 22:06:57 -06:00
|
|
|
if(location == null) return;
|
2013-12-25 22:41:01 -06:00
|
|
|
if(location.isEmpty()) return;
|
2013-12-25 22:06:57 -06:00
|
|
|
|
2013-12-25 21:56:01 -06:00
|
|
|
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]));
|
|
|
|
}
|
2013-12-25 22:57:09 -06:00
|
|
|
|
|
|
|
/** Gets the previous gamemode of this player. */
|
|
|
|
public GameMode getPreviousGameMode() {
|
|
|
|
return this.previousGameMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the previous gamemode of this player. */
|
|
|
|
public void setPreviousGameMode(GameMode previous) {
|
|
|
|
this.previousGameMode = previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the previous gamemode of this player based upon the provided string. */
|
|
|
|
public void setPreviousGameMode(String previous) {
|
|
|
|
if(previous == null) return;
|
|
|
|
else if(previous.isEmpty()) return;
|
|
|
|
else this.previousGameMode = GameMode.valueOf(previous);
|
|
|
|
}
|
2013-12-27 18:19:47 -06:00
|
|
|
|
|
|
|
/** Gets the inventory string for this player, it is encoded in Base64 string. */
|
|
|
|
public String getInventory() {
|
|
|
|
return this.inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the inventory Base64 string. */
|
|
|
|
public void setInventory(String inventory) {
|
|
|
|
this.inventory = inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Gets the armor content, encoded in Base64 string. */
|
|
|
|
public String getArmor() {
|
|
|
|
return this.armor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the armor inventory Base64 string. */
|
|
|
|
public void setArmor(String armor) {
|
|
|
|
this.armor = armor;
|
|
|
|
}
|
2014-01-03 14:10:38 -06:00
|
|
|
|
|
|
|
/** Gets the time, in milliseconds, this prisoner has been afk. */
|
|
|
|
public long getAFKTime() {
|
|
|
|
return this.afk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets the time, in milliseconds, this prisoner has been afk. */
|
|
|
|
public void setAFKTime(long time) {
|
|
|
|
this.afk = time;
|
|
|
|
}
|
2013-12-09 14:28:38 -06:00
|
|
|
}
|