First commit, converted to a truely maven project and switching over to my own repository for better management.

This commit is contained in:
graywolf336
2013-12-05 18:22:15 -06:00
commit 596c9de2ad
40 changed files with 3173 additions and 0 deletions

View File

@ -0,0 +1,95 @@
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();
}
}

View File

@ -0,0 +1,227 @@
package com.graywolf336.jail.beans;
import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Location;
/**
* Represents an instance of a player creating something, whether it be a jail or cell.
*
* @author graywolf336
* @since 3.0.0
* @version 1.1.0
*
*/
public class CreationPlayer {
private String jailName, cellName;
private int step;
private int x1, y1, z1, x2, y2, z2;
private String inWorld, freeWorld;
private double inX, inY, inZ, freeX, freeY, freeZ;
private float inPitch, inYaw, freePitch, freeYaw;
private HashSet<SimpleLocation> signs;
private Location chest;
/**
* Create a new instance of a CreationPlayer, given the name of the jail.
*
* @param jailName The name of the jail.
*/
public CreationPlayer(String jailName) {
this.jailName = jailName;
this.step = 1; //Set the default to 1 when creating this.
}
/**
* Creates a new instance of a CreationPlayer, give the name of the jail and cell.
*
* @param jailName The name of the jail.
* @param cellName The name of the cell.
*/
public CreationPlayer(String jailName, String cellName) {
this.jailName = jailName;
this.cellName = cellName;
this.signs = new HashSet<SimpleLocation>();
this.step = 1;
}
/** Gets the name of the jail. */
public String getJailName() {
return this.jailName;
}
/** Gets the name of the cell. */
public String getCellName() {
return this.cellName;
}
/**
* Returns the step the creation is in.
*
* <p>
*
* If it is a <strong>Jail</strong>, then when these numbers are returned it means the following:
* <ol>
* <li>Creating the first block of the Jail region.</li>
* <li>Creating the second block of the Jail region.</li>
* <li>Creating the teleport in location.</li>
* <li>Creating the teleport out location.</li>
* </ol>
*
* If it is a <strong>Cell</strong>, then when these numbers are returned it means the following:
* <ol>
* <li>Setting the teleport in location.</li>
* <li>Setting all the signs.</li>
* <li>Setting the double chest.</li>
* </ol>
*
* @return The step of the Jail/Cell Creation, as an integer.
*/
public int getStep() {
return this.step;
}
/**
* Sets the step of the creation.
*
* @param step The state of the creation, see {@link #getStep() getStep} for more information.
*/
public void setStep(int step) {
this.step = step;
}
/**
* Increments the current step up one.
*
* <p>
*
* <em>Notice:</em> Using this method can cause the step to go above four (three for cell),
* which might cause errors later on. Only use when you know that it won't
* be used again or you know for a fact that the next step is not above four (three for cell).
*
*/
public void nextStep() {
this.step++;
}
/** Sets the first corner with the given location. */
public void setCornerOne(Location loc) {
this.x1 = loc.getBlockX();
this.y1 = loc.getBlockY();
this.z1 = loc.getBlockZ();
}
/** Sets the first corner with the given x, y, and z. */
public void setCornerOne(int x, int y, int z) {
this.x1 = x;
this.y1 = y;
this.z1 = z;
}
/** Returns the <strong>first corner</strong> coords an array of int. <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong> */
public int[] getCornerOne() {
int[] t = {x1, y1, z1};
return t;
}
/** Sets the second corner with the given location. */
public void setCornerTwo(Location loc) {
this.x2 = loc.getBlockX();
this.y2 = loc.getBlockY();
this.z2 = loc.getBlockZ();
}
/** Sets the second corner with the given x, y, and z. */
public void setCornerTwo(int x, int y, int z) {
this.x2 = x;
this.y2 = y;
this.z2 = z;
}
/** Returns the <strong>second corner</strong> coords an array of int. <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong> */
public int[] getCornerTwo() {
int[] t = {x2, y2, z2};
return t;
}
/** Sets the teleport in coords from the given location. */
public void setTeleportIn(Location location) {
this.inWorld = location.getWorld().getName();
this.inX = location.getX();
this.inY = location.getY();
this.inZ = location.getZ();
this.inYaw = location.getYaw();
this.inPitch = location.getPitch();
}
/** Sets the teleport in coords from the given params. */
public void setTeleportIn(String world, double x, double y, double z, float yaw, float pitch) {
this.inWorld = world;
this.inX = x;
this.inY = y;
this.inZ = z;
this.inYaw = yaw;
this.inPitch = pitch;
}
/** Gets the teleport in location in a {@link Location}. */
public Location getTeleportIn() {
return new Location(Bukkit.getWorld(inWorld), inX, inY, inZ, inYaw, inPitch);
}
/** Gets the teleport in location in a {@link SimpleLocation}. */
public SimpleLocation getTeleportInSL() {
return new SimpleLocation(inWorld, inX, inY, inZ, inYaw, inPitch);
}
/** Sets the teleport free coords from the given location. */
public void setTeleportFree(Location location) {
this.freeWorld = location.getWorld().getName();
this.freeX = location.getX();
this.freeY = location.getY();
this.freeZ = location.getZ();
this.freeYaw = location.getYaw();
this.freePitch = location.getPitch();
}
/** Sets the teleport in coords from the given params. */
public void setTeleportFree(String world, double x, double y, double z, float yaw, float pitch) {
this.freeWorld = world;
this.freeX = x;
this.freeY = y;
this.freeZ = z;
this.freeYaw = yaw;
this.freePitch = pitch;
}
/** Gets the teleport free location in a {@link Location}. */
public Location getTeleportFree() {
return new Location(Bukkit.getWorld(freeWorld), freeX, freeY, freeZ, freeYaw, freePitch);
}
/** Gets the teleport free location in a {@link SimpleLocation}. */
public SimpleLocation getTeleportFreeSL() {
return new SimpleLocation(freeWorld, freeX, freeY, freeZ, freeYaw, freePitch);
}
/** Adds a sign to this cell. */
public void addSign(SimpleLocation sign) {
this.signs.add(sign);
}
/** Returns all the signs, null if none (usually null when a jail is being created). */
public HashSet<SimpleLocation> getSigns() {
return this.signs == null ? null : new HashSet<SimpleLocation>(this.signs);
}
/** Sets the chest's location, used mainly for cells. */
public void setChestLocation(Location loc) {
this.chest = loc;
}
/** Gets the chest's location. */
public Location getChestLocation() {
return this.chest;
}
}

View File

@ -0,0 +1,231 @@
package com.graywolf336.jail.beans;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.graywolf336.jail.JailMain;
/** Represents a Jail, contains the prisoners and the cells.
*
* @author graywolf336
* @since 3.0.0
* @version 1.0.2
*/
public class Jail {
private JailMain plugin;
private HashMap<String, Cell> cells;
private HashSet<Prisoner> nocellPrisoners;//prisoners who aren't in a cell
private String name = "", world = "";
private int minX, minY, minZ, maxX, maxY, maxZ;
private SimpleLocation in, free;
public Jail(JailMain plugin, String name) {
this.plugin = plugin;
this.name = name;
cells = new HashMap<String, Cell>();
nocellPrisoners = new HashSet<Prisoner>();
}
/** Gets the instance of the plugin's main class. */
public JailMain getPlugin() {
return this.plugin;
}
/** Sets the name of the jail. */
public void setName(String name) {
this.name = name;
}
/** Gets the name of the jail. */
public String getName() {
return this.name;
}
/** Sets the location of the <b>minimum</b> point to the given location's coordinates. */
public void setMinPoint(Location location) {
if(this.world.isEmpty()) this.world = location.getWorld().getName();
this.minX = location.getBlockX();
this.minY = location.getBlockY();
this.minZ = location.getBlockZ();
}
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
public void setMinPoint(int[] coords) {
if(coords.length != 3) return;
this.minX = coords[0];
this.minY = coords[1];
this.minZ = coords[2];
}
/** Gets the minimum point as a Bukkit Location class. */
public Location getMinPoint() {
return new Location(Bukkit.getServer().getWorld(world), minX, minY, minZ);
}
/** Sets the location of the <b>maximum</b> point to the given location's coordinates. */
public void setMaxPoint(Location location) {
if(this.world.isEmpty()) this.world = location.getWorld().getName();
this.maxX = location.getBlockX();
this.maxY = location.getBlockY();
this.maxZ = location.getBlockZ();
}
/** Gets the minimum point as a Bukkit Location class. */
public Location getMaxPoint() {
return new Location(Bukkit.getServer().getWorld(world), maxX, maxY, maxZ);
}
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
public void setMaxPoint(int[] coords) {
if(coords.length != 3) return;
this.maxX = coords[0];
this.maxY = coords[1];
this.maxZ = coords[2];
}
/** Sets the {@link SimpleLocation location} of the teleport <strong>in</strong>. */
public void setTeleportIn(SimpleLocation location) {
if(this.world.isEmpty()) this.world = location.getWorldName();
this.in = location;
}
/** Gets the {@link Location location} of the teleport in. */
public Location getTeleportIn() {
return this.in.getLocation();
}
/** Sets the {@link SimpleLocation location} of the teleport for the <strong>free</strong> spot. */
public void setTeleportFree(SimpleLocation location) {
this.free = location;
}
/** Gets the {@link Location location} of the teleport free spot.*/
public Location getTeleportFree() {
return this.free.getLocation();
}
/** Adds a cell to the Jail. */
public void addCell(Cell cell) {
this.cells.put(cell.getName(), cell);
}
/** Gets the cell with the given name. */
public Cell getCell(String name) {
return this.cells.get(name);
}
/** Returns the first empty cell, returns null if there aren't any cells or any free cells. */
public Cell getFirstEmptyCell() {
for(Cell c : getCells())
if(c.hasPrisoner())
continue;
else
return c;
return null;
}
/** Gets the amount of cells the jail. */
public int getCellCount() {
return this.cells.size();
}
/** Gets all the cells in the jail. */
public HashSet<Cell> getCells() {
return new HashSet<Cell>(this.cells.values());
}
/** Gets a HashSet of <b>all</b> the prisoners, the ones in cells and ones who aren't. */
public HashSet<Prisoner> getAllPrisoners() {
HashSet<Prisoner> all = new HashSet<Prisoner>(nocellPrisoners); //initalize the temp one to return with the prisoners not in any cells
for(Cell c : cells.values())
if(c.hasPrisoner())
all.add(c.getPrisoner());
return all;
}
/** Gets a HashSet of the prisoners <b>in cells</b>. */
public HashSet<Prisoner> getPrisonersInCells() {
HashSet<Prisoner> all = new HashSet<Prisoner>();
for(Cell c : getCells())
if(c.hasPrisoner())
all.add(c.getPrisoner());
return all;
}
/** Gets a HashSet of the prisoners <b>not</b> in cells.*/
public HashSet<Prisoner> getPrisonersNotInCells() {
return this.nocellPrisoners;
}
/**
* Returns whether the player is a prisoner in the system, whether in a cell or no cell.
*
* @param player The {@link Player player instance} of the person we're checking.
* @return true if is jailed, false if not.
*/
public boolean isPlayerJailed(Player player) {
return this.isPlayerAPrisoner(player.getName());
}
/**
* Returns whether the name of a player is a prisoner in the system, whether in a cell or no cell.
*
* @param name The name of the person we're checking.
* @return true if is jailed, false if not.
*/
public boolean isPlayerJailed(String name) {
return this.isPlayerAPrisoner(name);
}
/**
* Returns whether the name of a player is a prisoner in the system, whether in a cell or no cell.
*
* @param name The name of the person we're checking.
* @return true if is a prisoner, false if not.
*/
public boolean isPlayerAPrisoner(String name) {
boolean is = false;
for(Prisoner p : this.getAllPrisoners()) {
if(p.getName().equalsIgnoreCase(name)) {
is = true;
break;
}
}
return is;
}
/**
* Gets the {@link Prisoner prisoner} instance for the given name.
*
* @param name The name of the prisoner to get.
* @return the prisoner instance, can be null
*/
public Prisoner getPrisoner(String name) {
Prisoner r = null;
for(Prisoner p : this.getAllPrisoners()) {
if(p.getName().equalsIgnoreCase(name)) {
r = p;
break;
}
}
return r;
}
}

View File

@ -0,0 +1,32 @@
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;
}
}

View File

@ -0,0 +1,48 @@
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);
}
}