2014-06-12 10:15:11 -05:00
|
|
|
package com.graywolf336.jail.beans;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Chest;
|
|
|
|
|
2015-05-22 15:41:54 -05:00
|
|
|
import com.graywolf336.jail.interfaces.ICell;
|
|
|
|
|
2014-06-12 10:15:11 -05:00
|
|
|
/** Represents a Cell inside of a {@link Jail}.
|
2015-05-22 15:41:54 -05:00
|
|
|
*
|
2014-06-12 10:15:11 -05:00
|
|
|
* @author graywolf336
|
|
|
|
* @since 3.0.0
|
2015-05-22 15:41:54 -05:00
|
|
|
* @version 1.1.4
|
2014-06-12 10:15:11 -05:00
|
|
|
*/
|
2015-05-22 15:41:54 -05:00
|
|
|
public class Cell implements ICell {
|
2014-07-27 14:46:25 -05:00
|
|
|
private String name;
|
|
|
|
private Prisoner p;
|
|
|
|
private HashSet<SimpleLocation> signs;
|
|
|
|
private SimpleLocation teleport, chest;
|
|
|
|
|
|
|
|
/** Creates a new Cell with the given name
|
2015-05-22 15:41:54 -05:00
|
|
|
*
|
2014-07-27 14:46:25 -05:00
|
|
|
* @param name The name of the cell.
|
|
|
|
*/
|
|
|
|
public Cell(String name) {
|
|
|
|
this.name = name;
|
|
|
|
this.signs = new HashSet<SimpleLocation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrisoner(Prisoner prisoner) {
|
|
|
|
this.p = prisoner;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Prisoner getPrisoner() {
|
|
|
|
return this.p;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removePrisoner() {
|
|
|
|
this.p = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPrisoner() {
|
|
|
|
return this.p != null; //Return true if prison is not null, as when it isn't null we have a prisoner in this cell
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addAllSigns(HashSet<SimpleLocation> signs) {
|
|
|
|
this.signs.addAll(signs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addSign(SimpleLocation sign) {
|
|
|
|
this.signs.add(sign);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HashSet<SimpleLocation> getSigns() {
|
|
|
|
return this.signs;
|
|
|
|
}
|
2015-05-22 15:41:54 -05:00
|
|
|
|
2014-08-19 14:19:30 -05:00
|
|
|
public boolean hasSigns() {
|
2015-05-22 15:41:54 -05:00
|
|
|
return !this.signs.isEmpty();
|
2014-08-19 14:19:30 -05:00
|
|
|
}
|
2014-07-27 14:46:25 -05:00
|
|
|
|
|
|
|
public String getSignString() {
|
|
|
|
String r = "";
|
|
|
|
|
|
|
|
for(SimpleLocation s : signs) {
|
|
|
|
if(r.isEmpty()) {
|
|
|
|
r = s.toString();
|
|
|
|
}else {
|
|
|
|
r += ";" + s.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTeleport(SimpleLocation location) {
|
|
|
|
this.teleport = location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getTeleport() {
|
|
|
|
return this.teleport.getLocation();
|
|
|
|
}
|
|
|
|
|
2015-01-27 18:08:44 -06:00
|
|
|
public void setChestLocation(SimpleLocation simpleLocation) {
|
|
|
|
this.chest = simpleLocation;
|
2014-07-27 14:46:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public Location getChestLocation() {
|
2015-02-09 23:38:30 -06:00
|
|
|
return this.chest == null ? null : this.chest.getLocation();
|
2014-07-27 14:46:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public Chest getChest() {
|
|
|
|
if(this.chest == null) return null;
|
2015-05-22 15:41:54 -05:00
|
|
|
if(this.chest.getLocation().getBlock() == null || this.chest.getLocation().getBlock().getType() != Material.CHEST) return null;
|
2014-07-27 14:46:25 -05:00
|
|
|
|
|
|
|
return (Chest) this.chest.getLocation().getBlock().getState();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasChest() {
|
|
|
|
Chest c = getChest();
|
|
|
|
if(c != null) {
|
|
|
|
if(c.getInventory().getSize() >= 40)
|
|
|
|
return true;
|
|
|
|
else {
|
|
|
|
Bukkit.getLogger().severe("The cell " + this.name + " has chest that isn't a double chest, please fix.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-12 10:15:11 -05:00
|
|
|
}
|