From 41717678c5ba208dd508eec75f358005932905ba Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Thu, 7 May 2015 11:27:18 -0500 Subject: [PATCH] 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. --- .../java/com/graywolf336/jail/JailsAPI.java | 142 +++--- .../java/com/graywolf336/jail/Update.java | 344 ++++++------- .../jail/beans/CreationPlayer.java | 454 +++++++++--------- .../com/graywolf336/jail/command/Command.java | 62 +-- .../command/subcommands/JailHelpCommand.java | 48 +- .../jail/listeners/CellSignListener.java | 312 ++++++------ .../jail/listeners/EntityListener.java | 96 ++-- .../jail/listeners/WorldListener.java | 60 +-- .../com/graywolf336/jail/TestJailAPI.java | 198 ++++---- .../graywolf336/jail/TestJailCommands.java | 146 +++--- .../jail/util/TestLogFormatter.java | 64 +-- 11 files changed, 963 insertions(+), 963 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailsAPI.java b/src/main/java/com/graywolf336/jail/JailsAPI.java index 1324fe7..524adf2 100644 --- a/src/main/java/com/graywolf336/jail/JailsAPI.java +++ b/src/main/java/com/graywolf336/jail/JailsAPI.java @@ -1,71 +1,71 @@ -package com.graywolf336.jail; - -/** - * The static api interface for Jail plugin. - * - *

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

+ * + * If you're looking for non-static methods, please see the + * {@link JailMain} interface. + * + * @author graywolf336 + * @version 3.0.0 + * @since 3.0.0 + */ +public class JailsAPI { + private static JailMain pl; + + protected JailsAPI(JailMain plugin) { + pl = plugin; + } + + /** + * The instance of the {@link JailManager} which contains all the jails and in return prisoners. + * + * @return instance of the {@link JailManager} + * @see JailManager + */ + public static JailManager getJailManager() { + return pl.getJailManager(); + } + + /** + * The instance of the {@link PrisonerManager} which handles all the jailing of players. + * + * @return instance of the {@link PrisonerManager} + * @see PrisonerManager + */ + public static PrisonerManager getPrisonerManager() { + return pl.getPrisonerManager(); + } + + /** + * The instance of the {@link JailStickManager} which handles all the jail sticks. + * + * @return instance of the {@link JailStickManager} + * @see JailStickManager + */ + public static JailStickManager getJailStickManager() { + return pl.getJailStickManager(); + } + + /** + * The instance of the {@link HandCuffManager} which handles all the handcuffing of players. + * + * @return instance of the {@link HandCuffManager} + * @see HandCuffManager + */ + public static HandCuffManager getHandCuffManager() { + return pl.getHandCuffManager(); + } + + /** + * The instance of the {@link JailVoteManager} which handles all the voting to jail players. + * + * @return instance of the {@link JailVoteManager} + * @see JailVoteManager + */ + public static JailVoteManager getJailVoteManager() { + return pl.getJailVoteManager(); + } +} diff --git a/src/main/java/com/graywolf336/jail/Update.java b/src/main/java/com/graywolf336/jail/Update.java index bc58533..604331b 100644 --- a/src/main/java/com/graywolf336/jail/Update.java +++ b/src/main/java/com/graywolf336/jail/Update.java @@ -1,172 +1,172 @@ -package com.graywolf336.jail; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; - -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -import com.graywolf336.jail.enums.Settings; - -public class Update { - private JailMain plugin; - - // The project's unique ID - private static final int projectID = 31139; - - // 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 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 boolean needed = false; - - // The url for the new file and file version - private String fileUrl = "", version = ""; - - protected Update(JailMain plugin) { - this.plugin = plugin; - } - - public void query() { - String channel = plugin.getConfig().getString(Settings.UPDATECHANNEL.getPath(), "bukkit"); - URL url = null; - - try { - if(channel.equalsIgnoreCase("stable-dev")) { - url = new URL(CI_STABLEDEV_API_QUERY); - }else if(channel.equalsIgnoreCase("dev")) { - url = new URL(CI_DEV_API_QUERY); - }else { - url = new URL(BUKKIT_API_QUERY); - } - } catch (MalformedURLException e) { - plugin.getLogger().warning("The url for checking for an update was malformed, please open a ticket about this."); - return; - } - - try { - // Open a connection and query the project - URLConnection conn = url.openConnection(); - - // Add the user-agent to identify the program - conn.addRequestProperty("User-Agent", "Jail Update Checker"); - - // Read the response of the query - // The response will be in a JSON format, so only reading one line is necessary. - final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String response = reader.readLine(); - - if(channel.equalsIgnoreCase("stable-dev") || channel.equalsIgnoreCase("dev")) { - // Parse the object from the response from the CI server - JSONObject obj = (JSONObject) JSONValue.parse(response); - // Get the latest build number - long number = Long.parseLong(obj.get("number").toString()); - // Get the current running version - String[] ver = plugin.getDescription().getVersion().split("-b"); - // Let them know they're on a custom version when on build #0. - if(ver[ver.length - 1].equalsIgnoreCase("0")) { - plugin.getLogger().info("You are using a custom version, you can disable update checking."); - } - - // Parse the current build number to a number - long curr = Long.parseLong(ver[ver.length - 1]); - plugin.debug(number + " verus " + curr); - // Check if the build on the CI server is higher than the one we're running - needed = number > curr; - - // Alert the console that an update is needed, if it is needed - if(needed) { - this.version = obj.get("fullDisplayName").toString(); - this.fileUrl = obj.get("url").toString(); - plugin.getLogger().info("New development version of Jail is available: " + this.version); - plugin.getLogger().info(this.fileUrl); - } - }else { - // Parse the array of files from the query's response - JSONArray array = (JSONArray) JSONValue.parse(response); - - // Make sure there are results returned - if (array.size() > 0) { - // Get the newest file's details - JSONObject latest = (JSONObject) array.get(array.size() - 1); - - // Split the numbers into their own separate items - String remoteVer = ((String) latest.get("name")).split(" v")[1]; - - // 3.0.0-SNAPSHOT-b0 - String currentVer = plugin.getDescription().getVersion().split("-")[0]; - - plugin.debug(remoteVer + " verus " + currentVer); - this.needed = this.versionCompare(remoteVer, currentVer) > 0; - - if(needed) { - this.version = latest.get("name").toString(); - this.fileUrl = latest.get("fileUrl").toString(); - plugin.getLogger().info("New stable version of Jail is available: " + this.version); - plugin.getLogger().info(this.fileUrl); - } - } - } - } catch (IOException e) { - // There was an error reading the query - e.printStackTrace(); - plugin.getLogger().severe("There was an error checking for an update, please see the above stacktrace for details before reporting."); - return; - } - } - - /** - * Compares two version strings. - * - * Use this instead of String.compareTo() for a non-lexicographical - * 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". - * - * @param str1 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. - * The result is a positive integer if str1 is _numerically_ greater than str2. - * The result is zero if the strings are _numerically_ equal. - */ - private Integer versionCompare(String str1, String str2) { - String[] vals1 = str1.split("\\."); - String[] vals2 = str2.split("\\."); - int i = 0; - // 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])) { - i++; - } - - // compare first non-equal ordinal number - if (i < vals1.length && i < vals2.length) { - 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 - // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" - else { - return Integer.signum(vals1.length - vals2.length); - } - } - - /** Returns true if there is an update needed, false if not. */ - public boolean isAvailable() { - return this.needed; - } - - /** Returns the new version. */ - public String getNewVersion() { - return this.version; - } - - /** Returns the new file url. */ - public String getFileUrl() { - return this.fileUrl; - } -} +package com.graywolf336.jail; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +import com.graywolf336.jail.enums.Settings; + +public class Update { + private JailMain plugin; + + // The project's unique ID + private static final int projectID = 31139; + + // 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 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 boolean needed = false; + + // The url for the new file and file version + private String fileUrl = "", version = ""; + + protected Update(JailMain plugin) { + this.plugin = plugin; + } + + public void query() { + String channel = plugin.getConfig().getString(Settings.UPDATECHANNEL.getPath(), "bukkit"); + URL url = null; + + try { + if(channel.equalsIgnoreCase("stable-dev")) { + url = new URL(CI_STABLEDEV_API_QUERY); + }else if(channel.equalsIgnoreCase("dev")) { + url = new URL(CI_DEV_API_QUERY); + }else { + url = new URL(BUKKIT_API_QUERY); + } + } catch (MalformedURLException e) { + plugin.getLogger().warning("The url for checking for an update was malformed, please open a ticket about this."); + return; + } + + try { + // Open a connection and query the project + URLConnection conn = url.openConnection(); + + // Add the user-agent to identify the program + conn.addRequestProperty("User-Agent", "Jail Update Checker"); + + // Read the response of the query + // The response will be in a JSON format, so only reading one line is necessary. + final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String response = reader.readLine(); + + if(channel.equalsIgnoreCase("stable-dev") || channel.equalsIgnoreCase("dev")) { + // Parse the object from the response from the CI server + JSONObject obj = (JSONObject) JSONValue.parse(response); + // Get the latest build number + long number = Long.parseLong(obj.get("number").toString()); + // Get the current running version + String[] ver = plugin.getDescription().getVersion().split("-b"); + // Let them know they're on a custom version when on build #0. + if(ver[ver.length - 1].equalsIgnoreCase("0")) { + plugin.getLogger().info("You are using a custom version, you can disable update checking."); + } + + // Parse the current build number to a number + long curr = Long.parseLong(ver[ver.length - 1]); + plugin.debug(number + " verus " + curr); + // Check if the build on the CI server is higher than the one we're running + needed = number > curr; + + // Alert the console that an update is needed, if it is needed + if(needed) { + this.version = obj.get("fullDisplayName").toString(); + this.fileUrl = obj.get("url").toString(); + plugin.getLogger().info("New development version of Jail is available: " + this.version); + plugin.getLogger().info(this.fileUrl); + } + }else { + // Parse the array of files from the query's response + JSONArray array = (JSONArray) JSONValue.parse(response); + + // Make sure there are results returned + if (array.size() > 0) { + // Get the newest file's details + JSONObject latest = (JSONObject) array.get(array.size() - 1); + + // Split the numbers into their own separate items + String remoteVer = ((String) latest.get("name")).split(" v")[1]; + + // 3.0.0-SNAPSHOT-b0 + String currentVer = plugin.getDescription().getVersion().split("-")[0]; + + plugin.debug(remoteVer + " verus " + currentVer); + this.needed = this.versionCompare(remoteVer, currentVer) > 0; + + if(needed) { + this.version = latest.get("name").toString(); + this.fileUrl = latest.get("fileUrl").toString(); + plugin.getLogger().info("New stable version of Jail is available: " + this.version); + plugin.getLogger().info(this.fileUrl); + } + } + } + } catch (IOException e) { + // There was an error reading the query + e.printStackTrace(); + plugin.getLogger().severe("There was an error checking for an update, please see the above stacktrace for details before reporting."); + return; + } + } + + /** + * Compares two version strings. + * + * Use this instead of String.compareTo() for a non-lexicographical + * 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". + * + * @param str1 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. + * The result is a positive integer if str1 is _numerically_ greater than str2. + * The result is zero if the strings are _numerically_ equal. + */ + private Integer versionCompare(String str1, String str2) { + String[] vals1 = str1.split("\\."); + String[] vals2 = str2.split("\\."); + int i = 0; + // 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])) { + i++; + } + + // compare first non-equal ordinal number + if (i < vals1.length && i < vals2.length) { + 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 + // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" + else { + return Integer.signum(vals1.length - vals2.length); + } + } + + /** Returns true if there is an update needed, false if not. */ + public boolean isAvailable() { + return this.needed; + } + + /** Returns the new version. */ + public String getNewVersion() { + return this.version; + } + + /** Returns the new file url. */ + public String getFileUrl() { + return this.fileUrl; + } +} diff --git a/src/main/java/com/graywolf336/jail/beans/CreationPlayer.java b/src/main/java/com/graywolf336/jail/beans/CreationPlayer.java index 4b846db..7cc53a5 100644 --- a/src/main/java/com/graywolf336/jail/beans/CreationPlayer.java +++ b/src/main/java/com/graywolf336/jail/beans/CreationPlayer.java @@ -1,227 +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 signs; - private SimpleLocation 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(); - 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. - * - *

- * - * If it is a Jail, then when these numbers are returned it means the following: - *

    - *
  1. Creating the first block of the Jail region.
  2. - *
  3. Creating the second block of the Jail region.
  4. - *
  5. Creating the teleport in location.
  6. - *
  7. Creating the teleport out location.
  8. - *
- * - * If it is a Cell, then when these numbers are returned it means the following: - *
    - *
  1. Setting the teleport in location.
  2. - *
  3. Setting all the signs.
  4. - *
  5. Setting the double chest.
  6. - *
- * - * @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. - * - *

- * - * Notice: 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 first corner coords an array of int. 0 = x, 1 = y, 2 = z */ - 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 second corner coords an array of int. 0 = x, 1 = y, 2 = z */ - 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 getSigns() { - return this.signs == null ? null : new HashSet(this.signs); - } - - /** Sets the chest's location, used mainly for cells. */ - public void setChestLocation(SimpleLocation loc) { - this.chest = loc; - } - - /** Gets the chest's location. */ - public SimpleLocation getChestLocation() { - return this.chest; - } -} +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 signs; + private SimpleLocation 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(); + 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. + * + *

+ * + * If it is a Jail, then when these numbers are returned it means the following: + *

    + *
  1. Creating the first block of the Jail region.
  2. + *
  3. Creating the second block of the Jail region.
  4. + *
  5. Creating the teleport in location.
  6. + *
  7. Creating the teleport out location.
  8. + *
+ * + * If it is a Cell, then when these numbers are returned it means the following: + *
    + *
  1. Setting the teleport in location.
  2. + *
  3. Setting all the signs.
  4. + *
  5. Setting the double chest.
  6. + *
+ * + * @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. + * + *

+ * + * Notice: 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 first corner coords an array of int. 0 = x, 1 = y, 2 = z */ + 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 second corner coords an array of int. 0 = x, 1 = y, 2 = z */ + 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 getSigns() { + return this.signs == null ? null : new HashSet(this.signs); + } + + /** Sets the chest's location, used mainly for cells. */ + public void setChestLocation(SimpleLocation loc) { + this.chest = loc; + } + + /** Gets the chest's location. */ + public SimpleLocation getChestLocation() { + return this.chest; + } +} diff --git a/src/main/java/com/graywolf336/jail/command/Command.java b/src/main/java/com/graywolf336/jail/command/Command.java index 046fbbf..d4dc847 100644 --- a/src/main/java/com/graywolf336/jail/command/Command.java +++ b/src/main/java/com/graywolf336/jail/command/Command.java @@ -1,31 +1,31 @@ -package com.graywolf336.jail.command; - -import org.bukkit.command.CommandSender; - -import com.graywolf336.jail.JailManager; - -/** - * The base of all the commands. - * - * @author graywolf336 - * @since 3.0.0 - * @version 1.0.0 - */ -public interface Command { - /** - * Execute the command given the arguments, returning whether the command handled it or not. - * - *

- * - * 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 - * something, then it should return true so that the sender of the command doesn't get the - * usage message. - * - * @param jm An instance of the {@link JailManager} - * @param sender The {@link CommandSender sender} of the command - * @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. - */ - public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception; -} +package com.graywolf336.jail.command; + +import org.bukkit.command.CommandSender; + +import com.graywolf336.jail.JailManager; + +/** + * The base of all the commands. + * + * @author graywolf336 + * @since 3.0.0 + * @version 1.0.0 + */ +public interface Command { + /** + * Execute the command given the arguments, returning whether the command handled it or not. + * + *

+ * + * 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 + * something, then it should return true so that the sender of the command doesn't get the + * usage message. + * + * @param jm An instance of the {@link JailManager} + * @param sender The {@link CommandSender sender} of the command + * @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. + */ + public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception; +} diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailHelpCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailHelpCommand.java index d9d8eaf..932b787 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailHelpCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailHelpCommand.java @@ -1,24 +1,24 @@ -package com.graywolf336.jail.command.subcommands; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -import com.graywolf336.jail.JailManager; -import com.graywolf336.jail.command.Command; -import com.graywolf336.jail.command.CommandInfo; - -@CommandInfo( - maxArgs = 1, - minimumArgs = 0, - needsPlayer = false, - pattern = "help|h", - permission = "jail.command.jailhelp", - usage = "/jail help [page]" - ) -public class JailHelpCommand implements Command { - 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 + "https://github.com/graywolf336/Jail/wiki/Commands"); - return true; - } -} +package com.graywolf336.jail.command.subcommands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import com.graywolf336.jail.JailManager; +import com.graywolf336.jail.command.Command; +import com.graywolf336.jail.command.CommandInfo; + +@CommandInfo( + maxArgs = 1, + minimumArgs = 0, + needsPlayer = false, + pattern = "help|h", + permission = "jail.command.jailhelp", + usage = "/jail help [page]" + ) +public class JailHelpCommand implements Command { + 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 + "https://github.com/graywolf336/Jail/wiki/Commands"); + return true; + } +} diff --git a/src/main/java/com/graywolf336/jail/listeners/CellSignListener.java b/src/main/java/com/graywolf336/jail/listeners/CellSignListener.java index 3c8279d..26f3c0d 100644 --- a/src/main/java/com/graywolf336/jail/listeners/CellSignListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/CellSignListener.java @@ -1,156 +1,156 @@ -package com.graywolf336.jail.listeners; - -import java.util.HashSet; -import java.util.List; - -import org.bukkit.block.Sign; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -import com.graywolf336.jail.JailMain; -import com.graywolf336.jail.Util; -import com.graywolf336.jail.beans.SimpleLocation; -import com.graywolf336.jail.enums.Lang; -import com.graywolf336.jail.enums.Settings; -import com.graywolf336.jail.events.PrisonerJailedEvent; -import com.graywolf336.jail.events.PrisonerReleasedEvent; -import com.graywolf336.jail.events.PrisonerTimeChangeEvent; -import com.graywolf336.jail.events.PrisonerTransferredEvent; - -public class CellSignListener implements Listener { - private String lineOne, lineTwo, lineThree, lineFour; - private JailMain pl; - - public CellSignListener(JailMain plugin) { - pl = plugin; - List lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath()); - lineOne = lines.get(0); - lineTwo = lines.get(1); - lineThree = lines.get(2); - lineFour = lines.get(3); - } - - @EventHandler(ignoreCancelled=true, priority = EventPriority.MONITOR) - public void changeTheCellSigns(final PrisonerTimeChangeEvent event) { - pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() { - public void run() { - if (event.hasCell() && event.getCell().hasSigns()) { - HashSet signs = event.getCell().getSigns(); - String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); - String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); - String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); - String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); - - for (SimpleLocation s : signs) { - if (s.getLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) s.getLocation().getBlock().getState(); - sign.setLine(0, s1); - sign.setLine(1, s2); - sign.setLine(2, s3); - sign.setLine(3, s4); - sign.update(); - } else { - // Remove the sign from the cell since it isn't - // a valid sign - event.getCell().getSigns().remove(s); - } - } - } - } - }); - } - - @EventHandler - public void changeCellSignsOnJail(PrisonerJailedEvent event) { - if (event.hasCell() && event.getCell().hasSigns()) { - HashSet signs = event.getCell().getSigns(); - String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); - String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); - String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); - String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); - - for (SimpleLocation s : signs) { - if (s.getLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) s.getLocation().getBlock().getState(); - sign.setLine(0, s1); - sign.setLine(1, s2); - sign.setLine(2, s3); - sign.setLine(3, s4); - sign.update(); - } else { - // Remove the sign from the cell since it isn't - // a valid sign - event.getCell().getSigns().remove(s); - } - } - } - } - - @EventHandler - public void clearTheCellSigns(PrisonerReleasedEvent event) { - if (event.hasCell() && event.getCell().hasSigns()) { - HashSet signs = event.getCell().getSigns(); - - for (SimpleLocation s : signs) { - if (s.getLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) s.getLocation().getBlock().getState(); - sign.setLine(0, ""); - sign.setLine(1, Lang.CELLEMPTYSIGN.get()); - sign.setLine(2, ""); - sign.setLine(3, ""); - sign.update(); - } else { - // Remove the sign from the cell since it isn't - // a valid sign - event.getCell().getSigns().remove(s); - } - } - } - } - - @EventHandler - public void handleSignsOnTransfer(PrisonerTransferredEvent event) { - if (event.hasOriginalCell() && event.getOriginalCell().hasSigns()) { - HashSet signs = event.getOriginalCell().getSigns(); - - for (SimpleLocation s : signs) { - if (s.getLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) s.getLocation().getBlock().getState(); - sign.setLine(0, ""); - sign.setLine(1, Lang.CELLEMPTYSIGN.get()); - sign.setLine(2, ""); - sign.setLine(3, ""); - sign.update(); - } else { - // Remove the sign from the cell since it isn't - // a valid sign - event.getOriginalCell().getSigns().remove(s); - } - } - } - - if (event.hasTargetCell() && event.getTargetCell().hasSigns()) { - HashSet signs = event.getTargetCell().getSigns(); - String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); - String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); - String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); - String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); - - for (SimpleLocation s : signs) { - if (s.getLocation().getBlock().getState() instanceof Sign) { - Sign sign = (Sign) s.getLocation().getBlock().getState(); - sign.setLine(0, s1); - sign.setLine(1, s2); - sign.setLine(2, s3); - sign.setLine(3, s4); - sign.update(); - } else { - // Remove the sign from the cell since it isn't - // a valid sign - event.getTargetCell().getSigns().remove(s); - } - } - } - } -} +package com.graywolf336.jail.listeners; + +import java.util.HashSet; +import java.util.List; + +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.Util; +import com.graywolf336.jail.beans.SimpleLocation; +import com.graywolf336.jail.enums.Lang; +import com.graywolf336.jail.enums.Settings; +import com.graywolf336.jail.events.PrisonerJailedEvent; +import com.graywolf336.jail.events.PrisonerReleasedEvent; +import com.graywolf336.jail.events.PrisonerTimeChangeEvent; +import com.graywolf336.jail.events.PrisonerTransferredEvent; + +public class CellSignListener implements Listener { + private String lineOne, lineTwo, lineThree, lineFour; + private JailMain pl; + + public CellSignListener(JailMain plugin) { + pl = plugin; + List lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath()); + lineOne = lines.get(0); + lineTwo = lines.get(1); + lineThree = lines.get(2); + lineFour = lines.get(3); + } + + @EventHandler(ignoreCancelled=true, priority = EventPriority.MONITOR) + public void changeTheCellSigns(final PrisonerTimeChangeEvent event) { + pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() { + public void run() { + if (event.hasCell() && event.getCell().hasSigns()) { + HashSet signs = event.getCell().getSigns(); + String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); + String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); + String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); + String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); + + for (SimpleLocation s : signs) { + if (s.getLocation().getBlock().getState() instanceof Sign) { + Sign sign = (Sign) s.getLocation().getBlock().getState(); + sign.setLine(0, s1); + sign.setLine(1, s2); + sign.setLine(2, s3); + sign.setLine(3, s4); + sign.update(); + } else { + // Remove the sign from the cell since it isn't + // a valid sign + event.getCell().getSigns().remove(s); + } + } + } + } + }); + } + + @EventHandler + public void changeCellSignsOnJail(PrisonerJailedEvent event) { + if (event.hasCell() && event.getCell().hasSigns()) { + HashSet signs = event.getCell().getSigns(); + String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); + String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); + String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); + String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); + + for (SimpleLocation s : signs) { + if (s.getLocation().getBlock().getState() instanceof Sign) { + Sign sign = (Sign) s.getLocation().getBlock().getState(); + sign.setLine(0, s1); + sign.setLine(1, s2); + sign.setLine(2, s3); + sign.setLine(3, s4); + sign.update(); + } else { + // Remove the sign from the cell since it isn't + // a valid sign + event.getCell().getSigns().remove(s); + } + } + } + } + + @EventHandler + public void clearTheCellSigns(PrisonerReleasedEvent event) { + if (event.hasCell() && event.getCell().hasSigns()) { + HashSet signs = event.getCell().getSigns(); + + for (SimpleLocation s : signs) { + if (s.getLocation().getBlock().getState() instanceof Sign) { + Sign sign = (Sign) s.getLocation().getBlock().getState(); + sign.setLine(0, ""); + sign.setLine(1, Lang.CELLEMPTYSIGN.get()); + sign.setLine(2, ""); + sign.setLine(3, ""); + sign.update(); + } else { + // Remove the sign from the cell since it isn't + // a valid sign + event.getCell().getSigns().remove(s); + } + } + } + } + + @EventHandler + public void handleSignsOnTransfer(PrisonerTransferredEvent event) { + if (event.hasOriginalCell() && event.getOriginalCell().hasSigns()) { + HashSet signs = event.getOriginalCell().getSigns(); + + for (SimpleLocation s : signs) { + if (s.getLocation().getBlock().getState() instanceof Sign) { + Sign sign = (Sign) s.getLocation().getBlock().getState(); + sign.setLine(0, ""); + sign.setLine(1, Lang.CELLEMPTYSIGN.get()); + sign.setLine(2, ""); + sign.setLine(3, ""); + sign.update(); + } else { + // Remove the sign from the cell since it isn't + // a valid sign + event.getOriginalCell().getSigns().remove(s); + } + } + } + + if (event.hasTargetCell() && event.getTargetCell().hasSigns()) { + HashSet signs = event.getTargetCell().getSigns(); + String s1 = Util.replaceAllVariables(event.getPrisoner(), lineOne); + String s2 = Util.replaceAllVariables(event.getPrisoner(), lineTwo); + String s3 = Util.replaceAllVariables(event.getPrisoner(), lineThree); + String s4 = Util.replaceAllVariables(event.getPrisoner(), lineFour); + + for (SimpleLocation s : signs) { + if (s.getLocation().getBlock().getState() instanceof Sign) { + Sign sign = (Sign) s.getLocation().getBlock().getState(); + sign.setLine(0, s1); + sign.setLine(1, s2); + sign.setLine(2, s3); + sign.setLine(3, s4); + sign.update(); + } else { + // Remove the sign from the cell since it isn't + // a valid sign + event.getTargetCell().getSigns().remove(s); + } + } + } + } +} diff --git a/src/main/java/com/graywolf336/jail/listeners/EntityListener.java b/src/main/java/com/graywolf336/jail/listeners/EntityListener.java index dfd4851..e0f5109 100644 --- a/src/main/java/com/graywolf336/jail/listeners/EntityListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/EntityListener.java @@ -1,48 +1,48 @@ -package com.graywolf336.jail.listeners; - -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityExplodeEvent; - -import com.graywolf336.jail.JailMain; -import com.graywolf336.jail.enums.Settings; - -public class EntityListener implements Listener { - private JailMain pl; - - public EntityListener(JailMain plugin) { - this.pl = plugin; - } - - @EventHandler(ignoreCancelled=true) - public void onEntityExplode(EntityExplodeEvent event) { - //Only do the checking if plugin has it enabled - //otherwise let's not go through all the blocks - if(pl.getConfig().getBoolean(Settings.EXPLOSIONPROTECTION.getPath())) { - //Loop through the blocklist and do stuff - for(Block b : event.blockList()) { - //Check the current block and if it is inside a jail, - //then let's do something else - if(pl.getJailManager().getJailFromLocation(b.getLocation()) != null) { - //Clear the blocklist, this way the explosion effect still happens - event.blockList().clear(); - return; - } - } - } - } - - @EventHandler(ignoreCancelled=true) - public void protectFromEndermen(EntityChangeBlockEvent event) { - //If we are protecting the jails from endermen protection - if(pl.getConfig().getBoolean(Settings.ENDERMENPROTECTION.getPath())) { - //Check if there are any jails where the block's location is - if(pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) != null) { - //Let's cancel the event so it doesn't happen - event.setCancelled(true); - } - } - } -} +package com.graywolf336.jail.listeners; + +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityExplodeEvent; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.enums.Settings; + +public class EntityListener implements Listener { + private JailMain pl; + + public EntityListener(JailMain plugin) { + this.pl = plugin; + } + + @EventHandler(ignoreCancelled=true) + public void onEntityExplode(EntityExplodeEvent event) { + //Only do the checking if plugin has it enabled + //otherwise let's not go through all the blocks + if(pl.getConfig().getBoolean(Settings.EXPLOSIONPROTECTION.getPath())) { + //Loop through the blocklist and do stuff + for(Block b : event.blockList()) { + //Check the current block and if it is inside a jail, + //then let's do something else + if(pl.getJailManager().getJailFromLocation(b.getLocation()) != null) { + //Clear the blocklist, this way the explosion effect still happens + event.blockList().clear(); + return; + } + } + } + } + + @EventHandler(ignoreCancelled=true) + public void protectFromEndermen(EntityChangeBlockEvent event) { + //If we are protecting the jails from endermen protection + if(pl.getConfig().getBoolean(Settings.ENDERMENPROTECTION.getPath())) { + //Check if there are any jails where the block's location is + if(pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) != null) { + //Let's cancel the event so it doesn't happen + event.setCancelled(true); + } + } + } +} diff --git a/src/main/java/com/graywolf336/jail/listeners/WorldListener.java b/src/main/java/com/graywolf336/jail/listeners/WorldListener.java index e6f11ec..a9b9aae 100644 --- a/src/main/java/com/graywolf336/jail/listeners/WorldListener.java +++ b/src/main/java/com/graywolf336/jail/listeners/WorldListener.java @@ -1,30 +1,30 @@ -package com.graywolf336.jail.listeners; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldLoadEvent; -import org.bukkit.event.world.WorldUnloadEvent; - -import com.graywolf336.jail.JailMain; -import com.graywolf336.jail.beans.Jail; - -public class WorldListener implements Listener { - private JailMain pl; - - public WorldListener(JailMain plugin) { - this.pl = plugin; - } - - @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) - public void worldLoaded(WorldLoadEvent event) { - for(Jail j : pl.getJailManager().getJails()) - if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true); - } - - @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) - public void worldUnload(WorldUnloadEvent event) { - for(Jail j : pl.getJailManager().getJails()) - if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false); - } -} +package com.graywolf336.jail.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldUnloadEvent; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.beans.Jail; + +public class WorldListener implements Listener { + private JailMain pl; + + public WorldListener(JailMain plugin) { + this.pl = plugin; + } + + @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) + public void worldLoaded(WorldLoadEvent event) { + for(Jail j : pl.getJailManager().getJails()) + if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true); + } + + @EventHandler(ignoreCancelled=true, priority = EventPriority.LOW) + public void worldUnload(WorldUnloadEvent event) { + for(Jail j : pl.getJailManager().getJails()) + if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false); + } +} diff --git a/src/test/java/test/java/com/graywolf336/jail/TestJailAPI.java b/src/test/java/test/java/com/graywolf336/jail/TestJailAPI.java index 886022d..d7a6f42 100644 --- a/src/test/java/test/java/com/graywolf336/jail/TestJailAPI.java +++ b/src/test/java/test/java/com/graywolf336/jail/TestJailAPI.java @@ -1,99 +1,99 @@ -package test.java.com.graywolf336.jail; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.UUID; - -import org.bukkit.Location; -import org.bukkit.plugin.PluginDescriptionFile; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import test.java.com.graywolf336.jail.util.TestInstanceCreator; - -import com.graywolf336.jail.JailMain; -import com.graywolf336.jail.JailsAPI; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) -public class TestJailAPI { - private static TestInstanceCreator creator; - private static JailMain main; - - @BeforeClass - public static void setUp() throws Exception { - creator = new TestInstanceCreator(); - assertNotNull("The instance creator is null.", creator); - assertTrue(creator.setup()); - main = creator.getMain(); - assertNotNull("The JailMain class is null.", main); - assertTrue("The adding of a jail failed.", creator.addJail("TestJailAPI")); - } - - @AfterClass - public static void tearDown() throws Exception { - creator.tearDown(); - main = null; - } - - @Test - public void testManagersAreThere() { - assertNotNull(main.getHandCuffManager()); - assertNotNull(main.getJailManager()); - assertNotNull(main.getPrisonerManager()); - assertNotNull(main.getJailVoteManager()); - } - - @Test - public void verifyManagersAreTheSame() { - 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 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 Vote Manager references are different.", JailsAPI.getJailVoteManager(), is(main.getJailVoteManager())); - } - - @Test - public void testHandCuffManagerAPI() { - 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")); - assertFalse("The test id of someone is already handcuffed.", JailsAPI.getHandCuffManager().isHandCuffed(id)); - - JailsAPI.getHandCuffManager().addHandCuffs(id, loc); - assertTrue(JailsAPI.getHandCuffManager().isHandCuffed(id)); - assertThat(JailsAPI.getHandCuffManager().getLocation(id), is(loc)); - - JailsAPI.getHandCuffManager().removeHandCuffs(id); - assertFalse(JailsAPI.getHandCuffManager().isHandCuffed(id)); - assertNull(JailsAPI.getHandCuffManager().getLocation(id)); - } - - @Test - public void testJailManagerAPI() { - 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()); - 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())); - 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")); - JailsAPI.getJailManager().removeJail("furtherTesting"); - assertFalse("The jail furtherTesting wasn't successfully removed.", JailsAPI.getJailManager().isValidJail("furtherTesting")); - assertNull("The jail furtherTesting is not null.", JailsAPI.getJailManager().getJail("furtherTesting")); - 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("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 cells object returned is null.", JailsAPI.getJailManager().getAllCells()); - assertTrue("There are some cells even though there shouldn't be.", JailsAPI.getJailManager().getAllCells().isEmpty()); - } -} +package test.java.com.graywolf336.jail; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.plugin.PluginDescriptionFile; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import test.java.com.graywolf336.jail.util.TestInstanceCreator; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.JailsAPI; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) +public class TestJailAPI { + private static TestInstanceCreator creator; + private static JailMain main; + + @BeforeClass + public static void setUp() throws Exception { + creator = new TestInstanceCreator(); + assertNotNull("The instance creator is null.", creator); + assertTrue(creator.setup()); + main = creator.getMain(); + assertNotNull("The JailMain class is null.", main); + assertTrue("The adding of a jail failed.", creator.addJail("TestJailAPI")); + } + + @AfterClass + public static void tearDown() throws Exception { + creator.tearDown(); + main = null; + } + + @Test + public void testManagersAreThere() { + assertNotNull(main.getHandCuffManager()); + assertNotNull(main.getJailManager()); + assertNotNull(main.getPrisonerManager()); + assertNotNull(main.getJailVoteManager()); + } + + @Test + public void verifyManagersAreTheSame() { + 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 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 Vote Manager references are different.", JailsAPI.getJailVoteManager(), is(main.getJailVoteManager())); + } + + @Test + public void testHandCuffManagerAPI() { + 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")); + assertFalse("The test id of someone is already handcuffed.", JailsAPI.getHandCuffManager().isHandCuffed(id)); + + JailsAPI.getHandCuffManager().addHandCuffs(id, loc); + assertTrue(JailsAPI.getHandCuffManager().isHandCuffed(id)); + assertThat(JailsAPI.getHandCuffManager().getLocation(id), is(loc)); + + JailsAPI.getHandCuffManager().removeHandCuffs(id); + assertFalse(JailsAPI.getHandCuffManager().isHandCuffed(id)); + assertNull(JailsAPI.getHandCuffManager().getLocation(id)); + } + + @Test + public void testJailManagerAPI() { + 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()); + 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())); + 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")); + JailsAPI.getJailManager().removeJail("furtherTesting"); + assertFalse("The jail furtherTesting wasn't successfully removed.", JailsAPI.getJailManager().isValidJail("furtherTesting")); + assertNull("The jail furtherTesting is not null.", JailsAPI.getJailManager().getJail("furtherTesting")); + 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("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 cells object returned is null.", JailsAPI.getJailManager().getAllCells()); + assertTrue("There are some cells even though there shouldn't be.", JailsAPI.getJailManager().getAllCells().isEmpty()); + } +} diff --git a/src/test/java/test/java/com/graywolf336/jail/TestJailCommands.java b/src/test/java/test/java/com/graywolf336/jail/TestJailCommands.java index 333ac5f..3fade87 100644 --- a/src/test/java/test/java/com/graywolf336/jail/TestJailCommands.java +++ b/src/test/java/test/java/com/graywolf336/jail/TestJailCommands.java @@ -1,73 +1,73 @@ -package test.java.com.graywolf336.jail; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.verify; - -import org.bukkit.ChatColor; -import org.bukkit.plugin.PluginDescriptionFile; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import test.java.com.graywolf336.jail.util.TestInstanceCreator; - -import com.graywolf336.jail.JailMain; -import com.graywolf336.jail.Util; -import com.graywolf336.jail.beans.Prisoner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) -public class TestJailCommands { - private static TestInstanceCreator creator; - private static JailMain main; - private static final String name = "TestJailCommands"; - - @BeforeClass - public static void setUp() throws Exception { - creator = new TestInstanceCreator(); - assertNotNull("The instance creator is null.", creator); - assertTrue(creator.setup()); - main = creator.getMain(); - assertNotNull("The JailMain class is null.", main); - assertTrue("The adding of a jail failed.", creator.addJail(name)); - assertTrue("The jail " + name + " is not a valid jail.", main.getJailManager().isValidJail(name)); - } - - @AfterClass - public static void tearDown() throws Exception { - creator.tearDown(); - main = null; - } - - @Test - public void testJailTimeCommand() throws Exception { - Long time = Util.getTime("30m"); - 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."); - 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 username.", main.getJailManager().isPlayerJailedByLastKnownUsername(creator.getPlayer().getName())); - - //jail time show graywolf336 - 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."); - - //jail time add graywolf336 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."); - - //jail time remove graywolf336 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."); - - //jail time set graywolf336 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."); - } -} +package test.java.com.graywolf336.jail; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.verify; + +import org.bukkit.ChatColor; +import org.bukkit.plugin.PluginDescriptionFile; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import test.java.com.graywolf336.jail.util.TestInstanceCreator; + +import com.graywolf336.jail.JailMain; +import com.graywolf336.jail.Util; +import com.graywolf336.jail.beans.Prisoner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ JailMain.class, PluginDescriptionFile.class }) +public class TestJailCommands { + private static TestInstanceCreator creator; + private static JailMain main; + private static final String name = "TestJailCommands"; + + @BeforeClass + public static void setUp() throws Exception { + creator = new TestInstanceCreator(); + assertNotNull("The instance creator is null.", creator); + assertTrue(creator.setup()); + main = creator.getMain(); + assertNotNull("The JailMain class is null.", main); + assertTrue("The adding of a jail failed.", creator.addJail(name)); + assertTrue("The jail " + name + " is not a valid jail.", main.getJailManager().isValidJail(name)); + } + + @AfterClass + public static void tearDown() throws Exception { + creator.tearDown(); + main = null; + } + + @Test + public void testJailTimeCommand() throws Exception { + Long time = Util.getTime("30m"); + 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."); + 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 username.", main.getJailManager().isPlayerJailedByLastKnownUsername(creator.getPlayer().getName())); + + //jail time show graywolf336 + 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."); + + //jail time add graywolf336 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."); + + //jail time remove graywolf336 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."); + + //jail time set graywolf336 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."); + } +} diff --git a/src/test/java/test/java/com/graywolf336/jail/util/TestLogFormatter.java b/src/test/java/test/java/com/graywolf336/jail/util/TestLogFormatter.java index e92a33b..021892a 100644 --- a/src/test/java/test/java/com/graywolf336/jail/util/TestLogFormatter.java +++ b/src/test/java/test/java/com/graywolf336/jail/util/TestLogFormatter.java @@ -1,32 +1,32 @@ -package test.java.com.graywolf336.jail.util; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -/** Formatter to format log-messages in tests */ -public class TestLogFormatter extends Formatter { - private static final DateFormat df = new SimpleDateFormat("HH:mm:ss"); - - public String format(LogRecord record) { - StringBuilder ret = new StringBuilder(); - - ret.append("[").append(df.format(record.getMillis())).append("] [") - .append(record.getLoggerName()).append("] [") - .append(record.getLevel().getLocalizedName()).append("] "); - ret.append(record.getMessage()); - ret.append('\n'); - - if (record.getThrown() != null) { - // An Exception was thrown! Let's print the StackTrace! - StringWriter writer = new StringWriter(); - record.getThrown().printStackTrace(new PrintWriter(writer)); - ret.append(writer); - } - - return ret.toString(); - } -} +package test.java.com.graywolf336.jail.util; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +/** Formatter to format log-messages in tests */ +public class TestLogFormatter extends Formatter { + private static final DateFormat df = new SimpleDateFormat("HH:mm:ss"); + + public String format(LogRecord record) { + StringBuilder ret = new StringBuilder(); + + ret.append("[").append(df.format(record.getMillis())).append("] [") + .append(record.getLoggerName()).append("] [") + .append(record.getLevel().getLocalizedName()).append("] "); + ret.append(record.getMessage()); + ret.append('\n'); + + if (record.getThrown() != null) { + // An Exception was thrown! Let's print the StackTrace! + StringWriter writer = new StringWriter(); + record.getThrown().printStackTrace(new PrintWriter(writer)); + ret.append(writer); + } + + return ret.toString(); + } +}