Semantic update on the a util method

The name of the method(s) says the string we are checking goes first, so
make it that way.
This commit is contained in:
graywolf336 2015-06-04 17:18:22 -05:00
parent 176fde313e
commit 2e492ebe74
4 changed files with 39 additions and 22 deletions

View File

@ -268,7 +268,7 @@ public class PrisonerManager {
for(ItemStack item : inventory) { for(ItemStack item : inventory) {
if(item != null) { if(item != null) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) { if(!Util.isStringInsideList(item.getType().toString(), blacklist)) {
int i = chest.firstEmpty(); int i = chest.firstEmpty();
if(i != -1) {//Check that we have got a free spot, should never happen but just in case if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item); chest.setItem(i, item);
@ -279,7 +279,7 @@ public class PrisonerManager {
for(ItemStack item : armor) { for(ItemStack item : armor) {
if(item != null) { if(item != null) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) { if(!Util.isStringInsideList(item.getType().toString(), blacklist)) {
int i = chest.firstEmpty(); int i = chest.firstEmpty();
if(i != -1) {//Check that we have got a free spot, should never happen but just in case if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item); chest.setItem(i, item);
@ -293,12 +293,12 @@ public class PrisonerManager {
}else { }else {
for(ItemStack item : player.getInventory().getContents()) for(ItemStack item : player.getInventory().getContents())
if(item != null) if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString())) if(Util.isStringInsideList(item.getType().toString(), blacklist))
player.getInventory().remove(item); player.getInventory().remove(item);
for(ItemStack item : player.getInventory().getArmorContents()) for(ItemStack item : player.getInventory().getArmorContents())
if(item != null) if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString())) if(Util.isStringInsideList(item.getType().toString(), blacklist))
player.getInventory().remove(item); player.getInventory().remove(item);
String[] inv = Util.playerInventoryToBase64(player.getInventory()); String[] inv = Util.playerInventoryToBase64(player.getInventory());
@ -321,12 +321,12 @@ public class PrisonerManager {
for(ItemStack item : player.getInventory().getContents()) for(ItemStack item : player.getInventory().getContents())
if(item != null) if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString())) if(Util.isStringInsideList(item.getType().toString(), blacklist))
player.getInventory().remove(item); player.getInventory().remove(item);
for(ItemStack item : player.getInventory().getArmorContents()) for(ItemStack item : player.getInventory().getArmorContents())
if(item != null) if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString())) if(Util.isStringInsideList(item.getType().toString(), blacklist))
player.getInventory().remove(item); player.getInventory().remove(item);
String[] inv = Util.playerInventoryToBase64(player.getInventory()); String[] inv = Util.playerInventoryToBase64(player.getInventory());

View File

@ -75,16 +75,33 @@ public class Util {
return (point1 <= loc) && (loc <= point2); return (point1 <= loc) && (loc <= point2);
} }
/**
* Checks if the given string is inside the array, ignoring the casing.
*
* <p />
*
* @param value to check
* @param array of strings to check
* @return true if the array contains the provided value, false if it doesn't
*/
public static boolean isStringInsideArray(String value, String... array) {
for(String s : array)
if(s.equalsIgnoreCase(value))
return true;
return false;
}
/** /**
* Checks if the given string is inside the list, ignoring the casing. * Checks if the given string is inside the list, ignoring the casing.
* *
* <p /> * <p />
* *
* @param list of strings to check
* @param value to check * @param value to check
* @param list of strings to check
* @return true if the list contains the provided value, false if it doesn't * @return true if the list contains the provided value, false if it doesn't
*/ */
public static boolean isStringInsideList(List<String> list, String value) { public static boolean isStringInsideList(String value, List<String> list) {
for(String s : list) for(String s : list)
if(s.equalsIgnoreCase(value)) if(s.equalsIgnoreCase(value))
return true; return true;

View File

@ -32,8 +32,8 @@ public class ProtectionListener implements Listener {
//Let's check if the player is jailed //Let's check if the player is jailed
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) { if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
//Get the breaking whitelist, check if the current item is in there //Get the breaking whitelist, check if the current item is in there
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()), if(!Util.isStringInsideList(event.getBlock().getType().toString().toLowerCase(),
event.getBlock().getType().toString().toLowerCase())) { pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()))) {
//As our Util.getTime throws an exception when the time is in an //As our Util.getTime throws an exception when the time is in an
//incorrect format, we catch the exception and don't add any time //incorrect format, we catch the exception and don't add any time
//as a fail safe, don't want us to go crazy adding tons of time. //as a fail safe, don't want us to go crazy adding tons of time.
@ -84,8 +84,8 @@ public class ProtectionListener implements Listener {
//Let's check if the player is jailed //Let's check if the player is jailed
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) { if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
//Get the placing whitelist, check if the current item is in there //Get the placing whitelist, check if the current item is in there
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()), if(!Util.isStringInsideList(event.getBlock().getType().toString().toLowerCase(),
event.getBlock().getType().toString().toLowerCase())) { pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()))) {
//As our Util.getTime throws an exception when the time is in an //As our Util.getTime throws an exception when the time is in an
//incorrect format, we catch the exception and don't add any time //incorrect format, we catch the exception and don't add any time
//as a fail safe, don't want us to go crazy adding tons of time. //as a fail safe, don't want us to go crazy adding tons of time.
@ -264,8 +264,8 @@ public class ProtectionListener implements Listener {
if (event.getClickedBlock() != null) { if (event.getClickedBlock() != null) {
//Get the interaction blacklist, check if the current block is in there //Get the interaction blacklist, check if the current block is in there
//if it is, then let's take action //if it is, then let's take action
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()), if(Util.isStringInsideList(event.getClickedBlock().getType().toString().toLowerCase(),
event.getClickedBlock().getType().toString().toLowerCase())) { pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()))) {
try { try {
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath())); long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add); pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
@ -293,8 +293,8 @@ public class ProtectionListener implements Listener {
//Otherwise let's check if they have something in hand //Otherwise let's check if they have something in hand
//Get the interaction blacklist, check if the current item is in there //Get the interaction blacklist, check if the current item is in there
//if it is, then let's take action //if it is, then let's take action
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()), if(Util.isStringInsideList(event.getClickedBlock().getType().toString().toLowerCase(),
event.getClickedBlock().getType().toString().toLowerCase())) { pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()))) {
try { try {
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath())); long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath()));
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add); pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);

View File

@ -58,16 +58,16 @@ public class TestUtilClass {
@Test @Test
public void testInList() { public void testInList() {
assertTrue(Util.isStringInsideList(list, "seeds")); assertTrue(Util.isStringInsideList("seeds", list));
assertTrue(Util.isStringInsideList(list, Material.COAL_ORE.toString())); assertTrue(Util.isStringInsideList(Material.COAL_ORE.toString(), list));
assertTrue(Util.isStringInsideList(list, "tOrCh")); assertTrue(Util.isStringInsideList("tOrCh", list));
} }
@Test @Test
public void testNotInList() { public void testNotInList() {
assertFalse(Util.isStringInsideList(list, "dirt")); assertFalse(Util.isStringInsideList("dirt", list));
assertFalse(Util.isStringInsideList(list, "SAND")); assertFalse(Util.isStringInsideList("SAND", list));
assertFalse(Util.isStringInsideList(list, Material.BEDROCK.toString())); assertFalse(Util.isStringInsideList(Material.BEDROCK.toString(), list));
} }
@Test @Test