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();
for(ItemStack item : inventory) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
int i = chest.firstEmpty();
if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item);
if(item != null) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
int i = chest.firstEmpty();
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) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
int i = chest.firstEmpty();
if(i != -1) {//Check that we have got a free spot, should never happen but just in case
chest.setItem(i, item);
if(item != null) {
if(!Util.isStringInsideList(blacklist, item.getType().toString())) {
int i = chest.firstEmpty();
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
cell.update();
}else {
for(ItemStack item : player.getInventory().getContents()) {
if(Util.isStringInsideList(blacklist, item.getType().toString())) {
pl.debug("Removing " + item.getType() + " from " + player.getName() + "'s (" + player.getUniqueId().toString() + ") inventory.");
player.getInventory().remove(item.getType());
}
}
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(Util.isStringInsideList(blacklist, item.getType().toString())) {
pl.debug("Removing " + item.getType() + " from " + player.getName() + "'s (" + player.getUniqueId().toString() + ") inventory.");
player.getInventory().remove(item.getType());
}
}
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());
prisoner.setInventory(inv[0]);
@ -252,6 +252,18 @@ public class PrisonerManager {
}else {
//There is no cell we're jailing them to, so stick them in the jail
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());
prisoner.setInventory(inv[0]);
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
*/
public static boolean isStringInsideList(List<String> list, String value) {
boolean r = false;
for(String s : list)
if(s.equalsIgnoreCase(value))
return true;
return r;
return false;
}
/** Returns a colorful message from the color codes. */