Fix the blacklist not working or sometimes erroring out.

This commit is contained in:
graywolf336 2014-07-14 23:47:36 -05:00
parent 9e0722c218
commit c9b0fc8480
2 changed files with 33 additions and 22 deletions

View File

@ -198,19 +198,23 @@ public class PrisonerManager {
ItemStack[] armor = player.getInventory().getArmorContents(); ItemStack[] armor = player.getInventory().getArmorContents();
for(ItemStack item : inventory) { for(ItemStack item : inventory) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) { if(item != null) {
int i = chest.firstEmpty(); if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
if(i != -1) {//Check that we have got a free spot, should never happen but just in case int i = chest.firstEmpty();
chest.setItem(i, item); if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item);
}
} }
} }
} }
for(ItemStack item : armor) { for(ItemStack item : armor) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) { if(item != null) {
int i = chest.firstEmpty(); if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
if(i != -1) {//Check that we have got a free spot, should never happen but just in case int i = chest.firstEmpty();
chest.setItem(i, item); if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item);
}
} }
} }
} }
@ -222,19 +226,15 @@ public class PrisonerManager {
//Updates the cell's signs //Updates the cell's signs
cell.update(); cell.update();
}else { }else {
for(ItemStack item : player.getInventory().getContents()) { for(ItemStack item : player.getInventory().getContents())
if(Util.isStringInsideList(blacklist, item.getType().toString())) { if(item != null)
pl.debug("Removing " + item.getType() + " from " + player.getName() + "'s (" + player.getUniqueId().toString() + ") inventory."); if(Util.isStringInsideList(blacklist, item.getType().toString()))
player.getInventory().remove(item.getType()); player.getInventory().remove(item);
}
}
for(ItemStack item : player.getInventory().getArmorContents()) { for(ItemStack item : player.getInventory().getArmorContents())
if(Util.isStringInsideList(blacklist, item.getType().toString())) { if(item != null)
pl.debug("Removing " + item.getType() + " from " + player.getName() + "'s (" + player.getUniqueId().toString() + ") inventory."); if(Util.isStringInsideList(blacklist, item.getType().toString()))
player.getInventory().remove(item.getType()); player.getInventory().remove(item);
}
}
String[] inv = Util.playerInventoryToBase64(player.getInventory()); String[] inv = Util.playerInventoryToBase64(player.getInventory());
prisoner.setInventory(inv[0]); prisoner.setInventory(inv[0]);
@ -252,6 +252,18 @@ public class PrisonerManager {
}else { }else {
//There is no cell we're jailing them to, so stick them in the jail //There is no cell we're jailing them to, so stick them in the jail
if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) { if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) {
List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
for(ItemStack item : player.getInventory().getContents())
if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString()))
player.getInventory().remove(item);
for(ItemStack item : player.getInventory().getArmorContents())
if(item != null)
if(Util.isStringInsideList(blacklist, item.getType().toString()))
player.getInventory().remove(item);
String[] inv = Util.playerInventoryToBase64(player.getInventory()); String[] inv = Util.playerInventoryToBase64(player.getInventory());
prisoner.setInventory(inv[0]); prisoner.setInventory(inv[0]);
prisoner.setArmor(inv[1]); prisoner.setArmor(inv[1]);

View File

@ -84,12 +84,11 @@ public class Util {
* @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(List<String> list, String value) {
boolean r = false;
for(String s : list) for(String s : list)
if(s.equalsIgnoreCase(value)) if(s.equalsIgnoreCase(value))
return true; return true;
return r; return false;
} }
/** Returns a colorful message from the color codes. */ /** Returns a colorful message from the color codes. */