Let's start work on saving of the cells.

This commit is contained in:
graywolf336
2013-12-09 14:28:38 -06:00
parent 0272a3a241
commit d0273828b8
4 changed files with 293 additions and 175 deletions

View File

@ -1,95 +1,104 @@
package com.graywolf336.jail.beans;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
/** Represents a Cell inside of a {@link Jail}.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.1
*/
public class Cell {
private String name;
private Prisoner p;
private HashSet<SimpleLocation> signs;
private SimpleLocation teleport, chest;
public Cell(String name) {
this.name = name;
this.signs = new HashSet<SimpleLocation>();
}
/** Gets the name of the cell. */
public String getName() {
return this.name;
}
/** Sets the prisoner in this cell. */
public void setPrisoner(Prisoner prisoner) {
this.p = prisoner;
}
/** Gets the prisoner being held in this cell. */
public Prisoner getPrisoner() {
return this.p;
}
public void removePrisoner() {
this.p = null;
}
/** Returns true if there is currently a prisoner in this cell. */
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
}
/** Adds all the given signs to the cell. */
public void addAllSigns(HashSet<SimpleLocation> signs) {
this.signs.addAll(signs);
}
/** Adds a sign to the cell. */
public void addSign(SimpleLocation sign) {
this.signs.add(sign);
}
/** Sets the location of where the prisoner will be teleported at when jailed here. */
public void setTeleport(SimpleLocation location) {
this.teleport = location;
}
/** Gets the teleport location where the prisoner will be teleported at when jailed here. */
public Location getTeleport() {
return this.teleport.getLocation();
}
/** Sets the location of the chest. */
public void setChestLocation(Location location) {
this.chest = new SimpleLocation(location);
}
/**
* Gets the location of the chest, returns null if no chest is stored at this cell.
*
* @return The location of the chest, null if none.
*/
public Location getChestLocation() {
return this.chest.getLocation();
}
/**
* Gets the chest for this cell, returns null if there is no chest or the location we have is not a chest.
*
* @return The chest and its state.
*/
public Chest getChest() {
if(this.chest == null) return null;
if((this.chest.getLocation().getBlock() == null) || (this.chest.getLocation().getBlock().getType() != Material.CHEST)) return null;
return (Chest) this.chest.getLocation().getBlock().getState();
}
}
package com.graywolf336.jail.beans;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
/** Represents a Cell inside of a {@link Jail}.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.2
*/
public class Cell {
private String name;
private Prisoner p;
private HashSet<SimpleLocation> signs;
private SimpleLocation teleport, chest;
/** Creates a new Cell with the given name
*
* @param name The name of the cell.
*/
public Cell(String name) {
this.name = name;
this.signs = new HashSet<SimpleLocation>();
}
/** Gets the name of the cell. */
public String getName() {
return this.name;
}
/** Sets the prisoner in this cell. */
public void setPrisoner(Prisoner prisoner) {
this.p = prisoner;
}
/** Gets the prisoner being held in this cell. */
public Prisoner getPrisoner() {
return this.p;
}
public void removePrisoner() {
this.p = null;
}
/** Returns true if there is currently a prisoner in this cell. */
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
}
/** Adds all the given signs to the cell. */
public void addAllSigns(HashSet<SimpleLocation> signs) {
this.signs.addAll(signs);
}
/** Adds a sign to the cell. */
public void addSign(SimpleLocation sign) {
this.signs.add(sign);
}
/** Returns all the signs for this cell. */
public HashSet<SimpleLocation> getSigns() {
return this.signs;
}
/** Sets the location of where the prisoner will be teleported at when jailed here. */
public void setTeleport(SimpleLocation location) {
this.teleport = location;
}
/** Gets the teleport location where the prisoner will be teleported at when jailed here. */
public Location getTeleport() {
return this.teleport.getLocation();
}
/** Sets the location of the chest. */
public void setChestLocation(Location location) {
this.chest = new SimpleLocation(location);
}
/**
* Gets the location of the chest, returns null if no chest is stored at this cell.
*
* @return The location of the chest, null if none.
*/
public Location getChestLocation() {
return this.chest.getLocation();
}
/**
* Gets the chest for this cell, returns null if there is no chest or the location we have is not a chest.
*
* @return The chest and its state.
*/
public Chest getChest() {
if(this.chest == null) return null;
if((this.chest.getLocation().getBlock() == null) || (this.chest.getLocation().getBlock().getType() != Material.CHEST)) return null;
return (Chest) this.chest.getLocation().getBlock().getState();
}
}

View File

@ -1,32 +1,65 @@
package com.graywolf336.jail.beans;
/**
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
*
* @author graywolf336
* @since 2.x.x
* @version 2.0.0
*/
public class Prisoner {
private String name;
private boolean muted;
/**
* Creates a new prisoner with a name and whether they are muted or not.
*
* @param name
* @param muted
*/
public Prisoner(String name, boolean muted) {
this.name = name;
this.muted = muted;
}
public String getName() {
return this.name;
}
public boolean isMuted() {
return this.muted;
}
}
package com.graywolf336.jail.beans;
/**
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
*
* @author graywolf336
* @since 2.x.x
* @version 2.0.1
*/
public class Prisoner {
private String name;
private boolean muted;
private long time;
/**
* Creates a new prisoner with a name and whether they are muted or not.
*
* @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
*/
public Prisoner(String name, boolean muted, long time) {
this.name = name;
this.muted = muted;
this.time = time;
}
/** Gets the name of this player. */
public String getName() {
return this.name;
}
/** 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;
}
/** Gets the remaining time the prisoner has.
*
* <p />
*
* <strong>WARNING:</strong> The time system hasn't been implemented so this is likely to change.
*/
public long getRemainingTime() {
return this.time;
}
/**
* Sets the remaining time the prisoner has left.
*
* <p />
*
* <strong>WARNING:</strong> The time system hasn't been implemented so this is likely to change.
*
* @param time The amount of time left, in milliseconds.
*/
public void setRemainingTime(long time) {
this.time = time;
}
}

View File

@ -1,48 +1,52 @@
package com.graywolf336.jail.beans;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
/**
* Simple location class which doesn't store any instances of {@link World worlds} or {@link org.bukkit.block.Block blocks}, just uses strings, floats, and doubles.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.0
*/
public class SimpleLocation {
private String world;
private double x, y, z;
private float yaw, pitch;
public SimpleLocation(String world, double x, double y, double z, float yaw, float pitch) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public SimpleLocation(Location location) {
this.world = location.getWorld().getName();
this.x = location.getX();
this.y = location.getY();
this.z = location.getZ();
this.yaw = location.getYaw();
this.pitch = location.getPitch();
}
public World getWorld() {
return Bukkit.getWorld(world);
}
public String getWorldName() {
return this.world;
}
public Location getLocation() {
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
}
}
package com.graywolf336.jail.beans;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
/**
* Simple location class which doesn't store any instances of {@link World worlds} or {@link org.bukkit.block.Block blocks}, just uses strings, floats, and doubles.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.1
*/
public class SimpleLocation {
private String world;
private double x, y, z;
private float yaw, pitch;
public SimpleLocation(String world, double x, double y, double z, float yaw, float pitch) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public SimpleLocation(Location location) {
this.world = location.getWorld().getName();
this.x = location.getX();
this.y = location.getY();
this.z = location.getZ();
this.yaw = location.getYaw();
this.pitch = location.getPitch();
}
public World getWorld() {
return Bukkit.getWorld(world);
}
public String getWorldName() {
return this.world;
}
public Location getLocation() {
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
}
public String toString() {
return world + "," + x + "," + y + "," + z + "," + yaw + "," + pitch;
}
}