Git shows these files as changed

I assume this is due to line endings not being the same across all files
due to them being created on different operating systems.
This commit is contained in:
graywolf336 2015-05-07 11:27:18 -05:00
parent 97191a3f7d
commit 41717678c5
11 changed files with 963 additions and 963 deletions

View File

@ -1,71 +1,71 @@
package com.graywolf336.jail; package com.graywolf336.jail;
/** /**
* The static api interface for Jail plugin. * The static api interface for Jail plugin.
* *
* <p /> * <p />
* *
* If you're looking for non-static methods, please see the * If you're looking for non-static methods, please see the
* {@link JailMain} interface. * {@link JailMain} interface.
* *
* @author graywolf336 * @author graywolf336
* @version 3.0.0 * @version 3.0.0
* @since 3.0.0 * @since 3.0.0
*/ */
public class JailsAPI { public class JailsAPI {
private static JailMain pl; private static JailMain pl;
protected JailsAPI(JailMain plugin) { protected JailsAPI(JailMain plugin) {
pl = plugin; pl = plugin;
} }
/** /**
* The instance of the {@link JailManager} which contains all the jails and in return prisoners. * The instance of the {@link JailManager} which contains all the jails and in return prisoners.
* *
* @return instance of the {@link JailManager} * @return instance of the {@link JailManager}
* @see JailManager * @see JailManager
*/ */
public static JailManager getJailManager() { public static JailManager getJailManager() {
return pl.getJailManager(); return pl.getJailManager();
} }
/** /**
* The instance of the {@link PrisonerManager} which handles all the jailing of players. * The instance of the {@link PrisonerManager} which handles all the jailing of players.
* *
* @return instance of the {@link PrisonerManager} * @return instance of the {@link PrisonerManager}
* @see PrisonerManager * @see PrisonerManager
*/ */
public static PrisonerManager getPrisonerManager() { public static PrisonerManager getPrisonerManager() {
return pl.getPrisonerManager(); return pl.getPrisonerManager();
} }
/** /**
* The instance of the {@link JailStickManager} which handles all the jail sticks. * The instance of the {@link JailStickManager} which handles all the jail sticks.
* *
* @return instance of the {@link JailStickManager} * @return instance of the {@link JailStickManager}
* @see JailStickManager * @see JailStickManager
*/ */
public static JailStickManager getJailStickManager() { public static JailStickManager getJailStickManager() {
return pl.getJailStickManager(); return pl.getJailStickManager();
} }
/** /**
* The instance of the {@link HandCuffManager} which handles all the handcuffing of players. * The instance of the {@link HandCuffManager} which handles all the handcuffing of players.
* *
* @return instance of the {@link HandCuffManager} * @return instance of the {@link HandCuffManager}
* @see HandCuffManager * @see HandCuffManager
*/ */
public static HandCuffManager getHandCuffManager() { public static HandCuffManager getHandCuffManager() {
return pl.getHandCuffManager(); return pl.getHandCuffManager();
} }
/** /**
* The instance of the {@link JailVoteManager} which handles all the voting to jail players. * The instance of the {@link JailVoteManager} which handles all the voting to jail players.
* *
* @return instance of the {@link JailVoteManager} * @return instance of the {@link JailVoteManager}
* @see JailVoteManager * @see JailVoteManager
*/ */
public static JailVoteManager getJailVoteManager() { public static JailVoteManager getJailVoteManager() {
return pl.getJailVoteManager(); return pl.getJailVoteManager();
} }
} }

View File

@ -1,172 +1,172 @@
package com.graywolf336.jail; package com.graywolf336.jail;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
public class Update { public class Update {
private JailMain plugin; private JailMain plugin;
// The project's unique ID // The project's unique ID
private static final int projectID = 31139; private static final int projectID = 31139;
// Static information for querying the API // Static information for querying the API
private static final String BUKKIT_API_QUERY = "https://api.curseforge.com/servermods/files?projectIds=" + projectID; private static final String BUKKIT_API_QUERY = "https://api.curseforge.com/servermods/files?projectIds=" + projectID;
private static final String CI_STABLEDEV_API_QUERY = "http://ci.graywolf336.com/job/Jail/lastStableBuild/api/json"; private static final String CI_STABLEDEV_API_QUERY = "http://ci.graywolf336.com/job/Jail/lastStableBuild/api/json";
private static final String CI_DEV_API_QUERY = "http://ci.graywolf336.com/job/Jail/lastSuccessfulBuild/api/json"; private static final String CI_DEV_API_QUERY = "http://ci.graywolf336.com/job/Jail/lastSuccessfulBuild/api/json";
private boolean needed = false; private boolean needed = false;
// The url for the new file and file version // The url for the new file and file version
private String fileUrl = "", version = ""; private String fileUrl = "", version = "";
protected Update(JailMain plugin) { protected Update(JailMain plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public void query() { public void query() {
String channel = plugin.getConfig().getString(Settings.UPDATECHANNEL.getPath(), "bukkit"); String channel = plugin.getConfig().getString(Settings.UPDATECHANNEL.getPath(), "bukkit");
URL url = null; URL url = null;
try { try {
if(channel.equalsIgnoreCase("stable-dev")) { if(channel.equalsIgnoreCase("stable-dev")) {
url = new URL(CI_STABLEDEV_API_QUERY); url = new URL(CI_STABLEDEV_API_QUERY);
}else if(channel.equalsIgnoreCase("dev")) { }else if(channel.equalsIgnoreCase("dev")) {
url = new URL(CI_DEV_API_QUERY); url = new URL(CI_DEV_API_QUERY);
}else { }else {
url = new URL(BUKKIT_API_QUERY); url = new URL(BUKKIT_API_QUERY);
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
plugin.getLogger().warning("The url for checking for an update was malformed, please open a ticket about this."); plugin.getLogger().warning("The url for checking for an update was malformed, please open a ticket about this.");
return; return;
} }
try { try {
// Open a connection and query the project // Open a connection and query the project
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
// Add the user-agent to identify the program // Add the user-agent to identify the program
conn.addRequestProperty("User-Agent", "Jail Update Checker"); conn.addRequestProperty("User-Agent", "Jail Update Checker");
// Read the response of the query // Read the response of the query
// The response will be in a JSON format, so only reading one line is necessary. // The response will be in a JSON format, so only reading one line is necessary.
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = reader.readLine(); String response = reader.readLine();
if(channel.equalsIgnoreCase("stable-dev") || channel.equalsIgnoreCase("dev")) { if(channel.equalsIgnoreCase("stable-dev") || channel.equalsIgnoreCase("dev")) {
// Parse the object from the response from the CI server // Parse the object from the response from the CI server
JSONObject obj = (JSONObject) JSONValue.parse(response); JSONObject obj = (JSONObject) JSONValue.parse(response);
// Get the latest build number // Get the latest build number
long number = Long.parseLong(obj.get("number").toString()); long number = Long.parseLong(obj.get("number").toString());
// Get the current running version // Get the current running version
String[] ver = plugin.getDescription().getVersion().split("-b"); String[] ver = plugin.getDescription().getVersion().split("-b");
// Let them know they're on a custom version when on build #0. // Let them know they're on a custom version when on build #0.
if(ver[ver.length - 1].equalsIgnoreCase("0")) { if(ver[ver.length - 1].equalsIgnoreCase("0")) {
plugin.getLogger().info("You are using a custom version, you can disable update checking."); plugin.getLogger().info("You are using a custom version, you can disable update checking.");
} }
// Parse the current build number to a number // Parse the current build number to a number
long curr = Long.parseLong(ver[ver.length - 1]); long curr = Long.parseLong(ver[ver.length - 1]);
plugin.debug(number + " verus " + curr); plugin.debug(number + " verus " + curr);
// Check if the build on the CI server is higher than the one we're running // Check if the build on the CI server is higher than the one we're running
needed = number > curr; needed = number > curr;
// Alert the console that an update is needed, if it is needed // Alert the console that an update is needed, if it is needed
if(needed) { if(needed) {
this.version = obj.get("fullDisplayName").toString(); this.version = obj.get("fullDisplayName").toString();
this.fileUrl = obj.get("url").toString(); this.fileUrl = obj.get("url").toString();
plugin.getLogger().info("New development version of Jail is available: " + this.version); plugin.getLogger().info("New development version of Jail is available: " + this.version);
plugin.getLogger().info(this.fileUrl); plugin.getLogger().info(this.fileUrl);
} }
}else { }else {
// Parse the array of files from the query's response // Parse the array of files from the query's response
JSONArray array = (JSONArray) JSONValue.parse(response); JSONArray array = (JSONArray) JSONValue.parse(response);
// Make sure there are results returned // Make sure there are results returned
if (array.size() > 0) { if (array.size() > 0) {
// Get the newest file's details // Get the newest file's details
JSONObject latest = (JSONObject) array.get(array.size() - 1); JSONObject latest = (JSONObject) array.get(array.size() - 1);
// Split the numbers into their own separate items // Split the numbers into their own separate items
String remoteVer = ((String) latest.get("name")).split(" v")[1]; String remoteVer = ((String) latest.get("name")).split(" v")[1];
// 3.0.0-SNAPSHOT-b0 // 3.0.0-SNAPSHOT-b0
String currentVer = plugin.getDescription().getVersion().split("-")[0]; String currentVer = plugin.getDescription().getVersion().split("-")[0];
plugin.debug(remoteVer + " verus " + currentVer); plugin.debug(remoteVer + " verus " + currentVer);
this.needed = this.versionCompare(remoteVer, currentVer) > 0; this.needed = this.versionCompare(remoteVer, currentVer) > 0;
if(needed) { if(needed) {
this.version = latest.get("name").toString(); this.version = latest.get("name").toString();
this.fileUrl = latest.get("fileUrl").toString(); this.fileUrl = latest.get("fileUrl").toString();
plugin.getLogger().info("New stable version of Jail is available: " + this.version); plugin.getLogger().info("New stable version of Jail is available: " + this.version);
plugin.getLogger().info(this.fileUrl); plugin.getLogger().info(this.fileUrl);
} }
} }
} }
} catch (IOException e) { } catch (IOException e) {
// There was an error reading the query // There was an error reading the query
e.printStackTrace(); e.printStackTrace();
plugin.getLogger().severe("There was an error checking for an update, please see the above stacktrace for details before reporting."); plugin.getLogger().severe("There was an error checking for an update, please see the above stacktrace for details before reporting.");
return; return;
} }
} }
/** /**
* Compares two version strings. * Compares two version strings.
* *
* Use this instead of String.compareTo() for a non-lexicographical * Use this instead of String.compareTo() for a non-lexicographical
* comparison that works for version strings. e.g. "1.10".compareTo("1.6"). * comparison that works for version strings. e.g. "1.10".compareTo("1.6").
* *
* @note It does not work if "1.10" is supposed to be equal to "1.10.0". * @note It does not work if "1.10" is supposed to be equal to "1.10.0".
* *
* @param str1 a string of ordinal numbers separated by decimal points. * @param str1 a string of ordinal numbers separated by decimal points.
* @param str2 a string of ordinal numbers separated by decimal points. * @param str2 a string of ordinal numbers separated by decimal points.
* @return The result is a negative integer if str1 is _numerically_ less than str2. * @return The result is a negative integer if str1 is _numerically_ less than str2.
* The result is a positive integer if str1 is _numerically_ greater than str2. * The result is a positive integer if str1 is _numerically_ greater than str2.
* The result is zero if the strings are _numerically_ equal. * The result is zero if the strings are _numerically_ equal.
*/ */
private Integer versionCompare(String str1, String str2) { private Integer versionCompare(String str1, String str2) {
String[] vals1 = str1.split("\\."); String[] vals1 = str1.split("\\.");
String[] vals2 = str2.split("\\."); String[] vals2 = str2.split("\\.");
int i = 0; int i = 0;
// set index to first non-equal ordinal or length of shortest version string // set index to first non-equal ordinal or length of shortest version string
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
i++; i++;
} }
// compare first non-equal ordinal number // compare first non-equal ordinal number
if (i < vals1.length && i < vals2.length) { if (i < vals1.length && i < vals2.length) {
return Integer.signum(Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]))); return Integer.signum(Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])));
} }
// the strings are equal or one string is a substring of the other // the strings are equal or one string is a substring of the other
// e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
else { else {
return Integer.signum(vals1.length - vals2.length); return Integer.signum(vals1.length - vals2.length);
} }
} }
/** Returns true if there is an update needed, false if not. */ /** Returns true if there is an update needed, false if not. */
public boolean isAvailable() { public boolean isAvailable() {
return this.needed; return this.needed;
} }
/** Returns the new version. */ /** Returns the new version. */
public String getNewVersion() { public String getNewVersion() {
return this.version; return this.version;
} }
/** Returns the new file url. */ /** Returns the new file url. */
public String getFileUrl() { public String getFileUrl() {
return this.fileUrl; return this.fileUrl;
} }
} }

View File

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

View File

@ -1,31 +1,31 @@
package com.graywolf336.jail.command; package com.graywolf336.jail.command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
/** /**
* The base of all the commands. * The base of all the commands.
* *
* @author graywolf336 * @author graywolf336
* @since 3.0.0 * @since 3.0.0
* @version 1.0.0 * @version 1.0.0
*/ */
public interface Command { public interface Command {
/** /**
* Execute the command given the arguments, returning whether the command handled it or not. * Execute the command given the arguments, returning whether the command handled it or not.
* *
* <p> * <p>
* *
* When the method returns false, the usage message is printed to the sender. If the method * When the method returns false, the usage message is printed to the sender. If the method
* handles the command in any way, such as sending a message to the sender or actually doing * handles the command in any way, such as sending a message to the sender or actually doing
* something, then it should return true so that the sender of the command doesn't get the * something, then it should return true so that the sender of the command doesn't get the
* usage message. * usage message.
* *
* @param jm An instance of the {@link JailManager} * @param jm An instance of the {@link JailManager}
* @param sender The {@link CommandSender sender} of the command * @param sender The {@link CommandSender sender} of the command
* @param args The args, in an array * @param args The args, in an array
* @return True if the method handled it in any way, false if we should send the usage message. * @return True if the method handled it in any way, false if we should send the usage message.
*/ */
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception; public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception;
} }

View File

@ -1,24 +1,24 @@
package com.graywolf336.jail.command.subcommands; package com.graywolf336.jail.command.subcommands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.command.Command; import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo; import com.graywolf336.jail.command.CommandInfo;
@CommandInfo( @CommandInfo(
maxArgs = 1, maxArgs = 1,
minimumArgs = 0, minimumArgs = 0,
needsPlayer = false, needsPlayer = false,
pattern = "help|h", pattern = "help|h",
permission = "jail.command.jailhelp", permission = "jail.command.jailhelp",
usage = "/jail help [page]" usage = "/jail help [page]"
) )
public class JailHelpCommand implements Command { public class JailHelpCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
sender.sendMessage(ChatColor.GREEN + "This command will be filled out shortly, use this link for now:"); sender.sendMessage(ChatColor.GREEN + "This command will be filled out shortly, use this link for now:");
sender.sendMessage(ChatColor.GREEN + "https://github.com/graywolf336/Jail/wiki/Commands"); sender.sendMessage(ChatColor.GREEN + "https://github.com/graywolf336/Jail/wiki/Commands");
return true; return true;
} }
} }

View File

@ -1,156 +1,156 @@
package com.graywolf336.jail.listeners; package com.graywolf336.jail.listeners;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.Util; import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.SimpleLocation; import com.graywolf336.jail.beans.SimpleLocation;
import com.graywolf336.jail.enums.Lang; import com.graywolf336.jail.enums.Lang;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
import com.graywolf336.jail.events.PrisonerJailedEvent; import com.graywolf336.jail.events.PrisonerJailedEvent;
import com.graywolf336.jail.events.PrisonerReleasedEvent; import com.graywolf336.jail.events.PrisonerReleasedEvent;
import com.graywolf336.jail.events.PrisonerTimeChangeEvent; import com.graywolf336.jail.events.PrisonerTimeChangeEvent;
import com.graywolf336.jail.events.PrisonerTransferredEvent; import com.graywolf336.jail.events.PrisonerTransferredEvent;
public class CellSignListener implements Listener { public class CellSignListener implements Listener {
private String lineOne, lineTwo, lineThree, lineFour; private String lineOne, lineTwo, lineThree, lineFour;
private JailMain pl; private JailMain pl;
public CellSignListener(JailMain plugin) { public CellSignListener(JailMain plugin) {
pl = plugin; pl = plugin;
List<String> lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath()); List<String> lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath());
lineOne = lines.get(0); lineOne = lines.get(0);
lineTwo = lines.get(1); lineTwo = lines.get(1);
lineThree = lines.get(2); lineThree = lines.get(2);
lineFour = lines.get(3); lineFour = lines.get(3);
} }
@EventHandler(ignoreCancelled=true, priority = EventPriority.MONITOR) @EventHandler(ignoreCancelled=true, priority = EventPriority.MONITOR)
public void changeTheCellSigns(final PrisonerTimeChangeEvent event) { public void changeTheCellSigns(final PrisonerTimeChangeEvent event) {
pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() { pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() {
public void run() { public void run() {
if (event.hasCell() && event.getCell().hasSigns()) { if (event.hasCell() && event.getCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getCell().getSigns(); HashSet<SimpleLocation> signs = event.getCell().getSigns();
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
for (SimpleLocation s : signs) { for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) { if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState(); Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, s1); sign.setLine(0, s1);
sign.setLine(1, s2); sign.setLine(1, s2);
sign.setLine(2, s3); sign.setLine(2, s3);
sign.setLine(3, s4); sign.setLine(3, s4);
sign.update(); sign.update();
} else { } else {
// Remove the sign from the cell since it isn't // Remove the sign from the cell since it isn't
// a valid sign // a valid sign
event.getCell().getSigns().remove(s); event.getCell().getSigns().remove(s);
} }
} }
} }
} }
}); });
} }
@EventHandler @EventHandler
public void changeCellSignsOnJail(PrisonerJailedEvent event) { public void changeCellSignsOnJail(PrisonerJailedEvent event) {
if (event.hasCell() && event.getCell().hasSigns()) { if (event.hasCell() && event.getCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getCell().getSigns(); HashSet<SimpleLocation> signs = event.getCell().getSigns();
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
for (SimpleLocation s : signs) { for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) { if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState(); Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, s1); sign.setLine(0, s1);
sign.setLine(1, s2); sign.setLine(1, s2);
sign.setLine(2, s3); sign.setLine(2, s3);
sign.setLine(3, s4); sign.setLine(3, s4);
sign.update(); sign.update();
} else { } else {
// Remove the sign from the cell since it isn't // Remove the sign from the cell since it isn't
// a valid sign // a valid sign
event.getCell().getSigns().remove(s); event.getCell().getSigns().remove(s);
} }
} }
} }
} }
@EventHandler @EventHandler
public void clearTheCellSigns(PrisonerReleasedEvent event) { public void clearTheCellSigns(PrisonerReleasedEvent event) {
if (event.hasCell() && event.getCell().hasSigns()) { if (event.hasCell() && event.getCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getCell().getSigns(); HashSet<SimpleLocation> signs = event.getCell().getSigns();
for (SimpleLocation s : signs) { for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) { if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState(); Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, ""); sign.setLine(0, "");
sign.setLine(1, Lang.CELLEMPTYSIGN.get()); sign.setLine(1, Lang.CELLEMPTYSIGN.get());
sign.setLine(2, ""); sign.setLine(2, "");
sign.setLine(3, ""); sign.setLine(3, "");
sign.update(); sign.update();
} else { } else {
// Remove the sign from the cell since it isn't // Remove the sign from the cell since it isn't
// a valid sign // a valid sign
event.getCell().getSigns().remove(s); event.getCell().getSigns().remove(s);
} }
} }
} }
} }
@EventHandler @EventHandler
public void handleSignsOnTransfer(PrisonerTransferredEvent event) { public void handleSignsOnTransfer(PrisonerTransferredEvent event) {
if (event.hasOriginalCell() && event.getOriginalCell().hasSigns()) { if (event.hasOriginalCell() && event.getOriginalCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getOriginalCell().getSigns(); HashSet<SimpleLocation> signs = event.getOriginalCell().getSigns();
for (SimpleLocation s : signs) { for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) { if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState(); Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, ""); sign.setLine(0, "");
sign.setLine(1, Lang.CELLEMPTYSIGN.get()); sign.setLine(1, Lang.CELLEMPTYSIGN.get());
sign.setLine(2, ""); sign.setLine(2, "");
sign.setLine(3, ""); sign.setLine(3, "");
sign.update(); sign.update();
} else { } else {
// Remove the sign from the cell since it isn't // Remove the sign from the cell since it isn't
// a valid sign // a valid sign
event.getOriginalCell().getSigns().remove(s); event.getOriginalCell().getSigns().remove(s);
} }
} }
} }
if (event.hasTargetCell() && event.getTargetCell().hasSigns()) { if (event.hasTargetCell() && event.getTargetCell().hasSigns()) {
HashSet<SimpleLocation> signs = event.getTargetCell().getSigns(); HashSet<SimpleLocation> signs = event.getTargetCell().getSigns();
String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne);
String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo);
String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree);
String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour);
for (SimpleLocation s : signs) { for (SimpleLocation s : signs) {
if (s.getLocation().getBlock().getState() instanceof Sign) { if (s.getLocation().getBlock().getState() instanceof Sign) {
Sign sign = (Sign) s.getLocation().getBlock().getState(); Sign sign = (Sign) s.getLocation().getBlock().getState();
sign.setLine(0, s1); sign.setLine(0, s1);
sign.setLine(1, s2); sign.setLine(1, s2);
sign.setLine(2, s3); sign.setLine(2, s3);
sign.setLine(3, s4); sign.setLine(3, s4);
sign.update(); sign.update();
} else { } else {
// Remove the sign from the cell since it isn't // Remove the sign from the cell since it isn't
// a valid sign // a valid sign
event.getTargetCell().getSigns().remove(s); event.getTargetCell().getSigns().remove(s);
} }
} }
} }
} }
} }

View File

@ -1,48 +1,48 @@
package com.graywolf336.jail.listeners; package com.graywolf336.jail.listeners;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.enums.Settings;
public class EntityListener implements Listener { public class EntityListener implements Listener {
private JailMain pl; private JailMain pl;
public EntityListener(JailMain plugin) { public EntityListener(JailMain plugin) {
this.pl = plugin; this.pl = plugin;
} }
@EventHandler(ignoreCancelled=true) @EventHandler(ignoreCancelled=true)
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
//Only do the checking if plugin has it enabled //Only do the checking if plugin has it enabled
//otherwise let's not go through all the blocks //otherwise let's not go through all the blocks
if(pl.getConfig().getBoolean(Settings.EXPLOSIONPROTECTION.getPath())) { if(pl.getConfig().getBoolean(Settings.EXPLOSIONPROTECTION.getPath())) {
//Loop through the blocklist and do stuff //Loop through the blocklist and do stuff
for(Block b : event.blockList()) { for(Block b : event.blockList()) {
//Check the current block and if it is inside a jail, //Check the current block and if it is inside a jail,
//then let's do something else //then let's do something else
if(pl.getJailManager().getJailFromLocation(b.getLocation()) != null) { if(pl.getJailManager().getJailFromLocation(b.getLocation()) != null) {
//Clear the blocklist, this way the explosion effect still happens //Clear the blocklist, this way the explosion effect still happens
event.blockList().clear(); event.blockList().clear();
return; return;
} }
} }
} }
} }
@EventHandler(ignoreCancelled=true) @EventHandler(ignoreCancelled=true)
public void protectFromEndermen(EntityChangeBlockEvent event) { public void protectFromEndermen(EntityChangeBlockEvent event) {
//If we are protecting the jails from endermen protection //If we are protecting the jails from endermen protection
if(pl.getConfig().getBoolean(Settings.ENDERMENPROTECTION.getPath())) { if(pl.getConfig().getBoolean(Settings.ENDERMENPROTECTION.getPath())) {
//Check if there are any jails where the block's location is //Check if there are any jails where the block's location is
if(pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) != null) { if(pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) != null) {
//Let's cancel the event so it doesn't happen //Let's cancel the event so it doesn't happen
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }
} }

View File

@ -1,30 +1,30 @@
package com.graywolf336.jail.listeners; package com.graywolf336.jail.listeners;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
public class WorldListener implements Listener { public class WorldListener implements Listener {
private JailMain pl; private JailMain pl;
public WorldListener(JailMain plugin) { public WorldListener(JailMain plugin) {
this.pl = plugin; this.pl = plugin;
} }
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
public void worldLoaded(WorldLoadEvent event) { public void worldLoaded(WorldLoadEvent event) {
for(Jail j : pl.getJailManager().getJails()) for(Jail j : pl.getJailManager().getJails())
if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true); if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true);
} }
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
public void worldUnload(WorldUnloadEvent event) { public void worldUnload(WorldUnloadEvent event) {
for(Jail j : pl.getJailManager().getJails()) for(Jail j : pl.getJailManager().getJails())
if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false); if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false);
} }
} }

View File

@ -1,99 +1,99 @@
package test.java.com.graywolf336.jail; package test.java.com.graywolf336.jail;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator; import test.java.com.graywolf336.jail.util.TestInstanceCreator;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.JailsAPI; import com.graywolf336.jail.JailsAPI;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) @PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class TestJailAPI { public class TestJailAPI {
private static TestInstanceCreator creator; private static TestInstanceCreator creator;
private static JailMain main; private static JailMain main;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
creator = new TestInstanceCreator(); creator = new TestInstanceCreator();
assertNotNull("The instance creator is null.", creator); assertNotNull("The instance creator is null.", creator);
assertTrue(creator.setup()); assertTrue(creator.setup());
main = creator.getMain(); main = creator.getMain();
assertNotNull("The JailMain class is null.", main); assertNotNull("The JailMain class is null.", main);
assertTrue("The adding of a jail failed.", creator.addJail("TestJailAPI")); assertTrue("The adding of a jail failed.", creator.addJail("TestJailAPI"));
} }
@AfterClass @AfterClass
public static void tearDown() throws Exception { public static void tearDown() throws Exception {
creator.tearDown(); creator.tearDown();
main = null; main = null;
} }
@Test @Test
public void testManagersAreThere() { public void testManagersAreThere() {
assertNotNull(main.getHandCuffManager()); assertNotNull(main.getHandCuffManager());
assertNotNull(main.getJailManager()); assertNotNull(main.getJailManager());
assertNotNull(main.getPrisonerManager()); assertNotNull(main.getPrisonerManager());
assertNotNull(main.getJailVoteManager()); assertNotNull(main.getJailVoteManager());
} }
@Test @Test
public void verifyManagersAreTheSame() { public void verifyManagersAreTheSame() {
assertThat("The HandCuff Manager references are different.", JailsAPI.getHandCuffManager(), is(main.getHandCuffManager())); assertThat("The HandCuff Manager references are different.", JailsAPI.getHandCuffManager(), is(main.getHandCuffManager()));
assertThat("The Jail Manager references are different.", JailsAPI.getJailManager(), is(main.getJailManager())); assertThat("The Jail Manager references are different.", JailsAPI.getJailManager(), is(main.getJailManager()));
assertThat("The Prisoner Manager references are different.", JailsAPI.getPrisonerManager(), is(main.getPrisonerManager())); assertThat("The Prisoner Manager references are different.", JailsAPI.getPrisonerManager(), is(main.getPrisonerManager()));
assertThat("The Jail Stick Manager references are different.", JailsAPI.getJailStickManager(), is(main.getJailStickManager())); assertThat("The Jail Stick Manager references are different.", JailsAPI.getJailStickManager(), is(main.getJailStickManager()));
assertThat("The Jail Vote Manager references are different.", JailsAPI.getJailVoteManager(), is(main.getJailVoteManager())); assertThat("The Jail Vote Manager references are different.", JailsAPI.getJailVoteManager(), is(main.getJailVoteManager()));
} }
@Test @Test
public void testHandCuffManagerAPI() { public void testHandCuffManagerAPI() {
UUID id = UUID.randomUUID(); UUID id = UUID.randomUUID();
Location loc = new Location(main.getServer().getWorld("world"), 11.469868464778077, 65.0, -239.27944647045672, Float.valueOf("38.499817"), Float.valueOf("2.0000453")); Location loc = new Location(main.getServer().getWorld("world"), 11.469868464778077, 65.0, -239.27944647045672, Float.valueOf("38.499817"), Float.valueOf("2.0000453"));
assertFalse("The test id of someone is already handcuffed.", JailsAPI.getHandCuffManager().isHandCuffed(id)); assertFalse("The test id of someone is already handcuffed.", JailsAPI.getHandCuffManager().isHandCuffed(id));
JailsAPI.getHandCuffManager().addHandCuffs(id, loc); JailsAPI.getHandCuffManager().addHandCuffs(id, loc);
assertTrue(JailsAPI.getHandCuffManager().isHandCuffed(id)); assertTrue(JailsAPI.getHandCuffManager().isHandCuffed(id));
assertThat(JailsAPI.getHandCuffManager().getLocation(id), is(loc)); assertThat(JailsAPI.getHandCuffManager().getLocation(id), is(loc));
JailsAPI.getHandCuffManager().removeHandCuffs(id); JailsAPI.getHandCuffManager().removeHandCuffs(id);
assertFalse(JailsAPI.getHandCuffManager().isHandCuffed(id)); assertFalse(JailsAPI.getHandCuffManager().isHandCuffed(id));
assertNull(JailsAPI.getHandCuffManager().getLocation(id)); assertNull(JailsAPI.getHandCuffManager().getLocation(id));
} }
@Test @Test
public void testJailManagerAPI() { public void testJailManagerAPI() {
assertThat("The Jail Manager reference to the plugin is different.", JailsAPI.getJailManager().getPlugin(), is(main)); assertThat("The Jail Manager reference to the plugin is different.", JailsAPI.getJailManager().getPlugin(), is(main));
assertNotNull("The getJails method returned a null value.", JailsAPI.getJailManager().getJails()); assertNotNull("The getJails method returned a null value.", JailsAPI.getJailManager().getJails());
assertEquals("There isn't a Jail in the returned Jails.", 1, JailsAPI.getJailManager().getJails().size()); assertEquals("There isn't a Jail in the returned Jails.", 1, JailsAPI.getJailManager().getJails().size());
assertThat("Jail Names aren't equal..", new String[] { "TestJailAPI" }, is(JailsAPI.getJailManager().getJailNames())); assertThat("Jail Names aren't equal..", new String[] { "TestJailAPI" }, is(JailsAPI.getJailManager().getJailNames()));
assertTrue("The adding of a new jail, furtherTesting, wasn't successful.", creator.addJail("furtherTesting")); assertTrue("The adding of a new jail, furtherTesting, wasn't successful.", creator.addJail("furtherTesting"));
assertTrue("The added jail, furtherTesting, doesn't exist.", JailsAPI.getJailManager().isValidJail("furtherTesting")); assertTrue("The added jail, furtherTesting, doesn't exist.", JailsAPI.getJailManager().isValidJail("furtherTesting"));
JailsAPI.getJailManager().removeJail("furtherTesting"); JailsAPI.getJailManager().removeJail("furtherTesting");
assertFalse("The jail furtherTesting wasn't successfully removed.", JailsAPI.getJailManager().isValidJail("furtherTesting")); assertFalse("The jail furtherTesting wasn't successfully removed.", JailsAPI.getJailManager().isValidJail("furtherTesting"));
assertNull("The jail furtherTesting is not null.", JailsAPI.getJailManager().getJail("furtherTesting")); assertNull("The jail furtherTesting is not null.", JailsAPI.getJailManager().getJail("furtherTesting"));
assertNotNull("The jail TestJailAPI is null.", JailsAPI.getJailManager().getJail("TestJailAPI")); assertNotNull("The jail TestJailAPI is null.", JailsAPI.getJailManager().getJail("TestJailAPI"));
assertNotNull("An empty string returned a null value even though there is one jail.", JailsAPI.getJailManager().getJail("")); assertNotNull("An empty string returned a null value even though there is one jail.", JailsAPI.getJailManager().getJail(""));
assertNotNull("The first jail is null from the console sender.", JailsAPI.getJailManager().getNearestJail(creator.getCommandSender())); assertNotNull("The first jail is null from the console sender.", JailsAPI.getJailManager().getNearestJail(creator.getCommandSender()));
assertNotNull("The nearest jail from the player sender is null.", JailsAPI.getJailManager().getNearestJail(creator.getPlayerCommandSender())); assertNotNull("The nearest jail from the player sender is null.", JailsAPI.getJailManager().getNearestJail(creator.getPlayerCommandSender()));
assertNotNull("The cells object returned is null.", JailsAPI.getJailManager().getAllCells()); assertNotNull("The cells object returned is null.", JailsAPI.getJailManager().getAllCells());
assertTrue("There are some cells even though there shouldn't be.", JailsAPI.getJailManager().getAllCells().isEmpty()); assertTrue("There are some cells even though there shouldn't be.", JailsAPI.getJailManager().getAllCells().isEmpty());
} }
} }

View File

@ -1,73 +1,73 @@
package test.java.com.graywolf336.jail; package test.java.com.graywolf336.jail;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator; import test.java.com.graywolf336.jail.util.TestInstanceCreator;
import com.graywolf336.jail.JailMain; import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.Util; import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.beans.Prisoner;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) @PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class TestJailCommands { public class TestJailCommands {
private static TestInstanceCreator creator; private static TestInstanceCreator creator;
private static JailMain main; private static JailMain main;
private static final String name = "TestJailCommands"; private static final String name = "TestJailCommands";
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
creator = new TestInstanceCreator(); creator = new TestInstanceCreator();
assertNotNull("The instance creator is null.", creator); assertNotNull("The instance creator is null.", creator);
assertTrue(creator.setup()); assertTrue(creator.setup());
main = creator.getMain(); main = creator.getMain();
assertNotNull("The JailMain class is null.", main); assertNotNull("The JailMain class is null.", main);
assertTrue("The adding of a jail failed.", creator.addJail(name)); assertTrue("The adding of a jail failed.", creator.addJail(name));
assertTrue("The jail " + name + " is not a valid jail.", main.getJailManager().isValidJail(name)); assertTrue("The jail " + name + " is not a valid jail.", main.getJailManager().isValidJail(name));
} }
@AfterClass @AfterClass
public static void tearDown() throws Exception { public static void tearDown() throws Exception {
creator.tearDown(); creator.tearDown();
main = null; main = null;
} }
@Test @Test
public void testJailTimeCommand() throws Exception { public void testJailTimeCommand() throws Exception {
Long time = Util.getTime("30m"); Long time = Util.getTime("30m");
assertEquals("The util didn't return the proper time.", 1800000L, time, 0); assertEquals("The util didn't return the proper time.", 1800000L, time, 0);
Prisoner p = new Prisoner(creator.getPlayer().getUniqueId().toString(), creator.getPlayer().getName(), true, time, "UnitTeting", "Testing out the jail time command."); Prisoner p = new Prisoner(creator.getPlayer().getUniqueId().toString(), creator.getPlayer().getName(), true, time, "UnitTeting", "Testing out the jail time command.");
main.getPrisonerManager().prepareJail(main.getJailManager().getJail(name), null, creator.getPlayer(), p); main.getPrisonerManager().prepareJail(main.getJailManager().getJail(name), null, creator.getPlayer(), p);
assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by UUID.", main.getJailManager().isPlayerJailed(creator.getPlayer().getUniqueId())); assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by UUID.", main.getJailManager().isPlayerJailed(creator.getPlayer().getUniqueId()));
assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by username.", main.getJailManager().isPlayerJailedByLastKnownUsername(creator.getPlayer().getName())); assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by username.", main.getJailManager().isPlayerJailedByLastKnownUsername(creator.getPlayer().getName()));
//jail time show graywolf336 //jail time show graywolf336
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "show", creator.getPlayer().getName() })); assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "show", creator.getPlayer().getName() }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 30 minutes remaining."); verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 30 minutes remaining.");
//jail time add graywolf336 30m //jail time add graywolf336 30m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "add", creator.getPlayer().getName(), "30m" })); assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "add", creator.getPlayer().getName(), "30m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 60 minutes remaining."); verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 60 minutes remaining.");
//jail time remove graywolf336 10m //jail time remove graywolf336 10m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "remove", creator.getPlayer().getName(), "10m" })); assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "remove", creator.getPlayer().getName(), "10m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 50 minutes remaining."); verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 50 minutes remaining.");
//jail time set graywolf336 25m //jail time set graywolf336 25m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "set", creator.getPlayer().getName(), "25m" })); assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "set", creator.getPlayer().getName(), "25m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 25 minutes remaining."); verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 25 minutes remaining.");
} }
} }

View File

@ -1,32 +1,32 @@
package test.java.com.graywolf336.jail.util; package test.java.com.graywolf336.jail.util;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
/** Formatter to format log-messages in tests */ /** Formatter to format log-messages in tests */
public class TestLogFormatter extends Formatter { public class TestLogFormatter extends Formatter {
private static final DateFormat df = new SimpleDateFormat("HH:mm:ss"); private static final DateFormat df = new SimpleDateFormat("HH:mm:ss");
public String format(LogRecord record) { public String format(LogRecord record) {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();
ret.append("[").append(df.format(record.getMillis())).append("] [") ret.append("[").append(df.format(record.getMillis())).append("] [")
.append(record.getLoggerName()).append("] [") .append(record.getLoggerName()).append("] [")
.append(record.getLevel().getLocalizedName()).append("] "); .append(record.getLevel().getLocalizedName()).append("] ");
ret.append(record.getMessage()); ret.append(record.getMessage());
ret.append('\n'); ret.append('\n');
if (record.getThrown() != null) { if (record.getThrown() != null) {
// An Exception was thrown! Let's print the StackTrace! // An Exception was thrown! Let's print the StackTrace!
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
record.getThrown().printStackTrace(new PrintWriter(writer)); record.getThrown().printStackTrace(new PrintWriter(writer));
ret.append(writer); ret.append(writer);
} }
return ret.toString(); return ret.toString();
} }
} }