You could do this:
String listOfItemsBanned = "";
for(int i = 0; i < itemsBanned.size(); i++){ //loop threw contents of itemsBanned (List<String>)
String s = itemsBanned.get(i); //get the string in itemsBanned (i)
listOfItemsBanned = listOfItemsBanned + "," + s; //add s to listOfItemsBanned
}
Now, if you would like to get all of the items that are banned from the string listOfItemsBanned
, you could do:
String[] s = listOfItemsBanned.split(",");
//start the for loop at 1 because when saved it will be ",TnT,Sand,Enderpearl", notice the extra , in the begining
for(int i = 1; i < s.size(); i++){ //loop threw all of the items banned.
String itmBanned = s[i];
}
You could now do anything with itmBanned
, like convert it to a Material
:
Material m = Material.getMaterial(itmBanned);
So, you could do something like this for a remove method:
public void remove(String type){
String listOfItemsBanned = "";
itemsBanned.remove(type); //remove 'type' from the array
for(int i = 0; i < itemsBanned.size(); i++){
String s = itemsBanned.get(i);
listOfItemsBanned = listOfItemsBanned + "," + s; //reset the string to the new list
}
}
and for adding:
public void remove(String type){
String listOfItemsBanned = "";
itemsBanned.add(type); //add 'type' to the array
for(int i = 0; i < itemsBanned.size(); i++){
String s = itemsBanned.get(i);
listOfItemsBanned = listOfItemsBanned + "," + s; //reset the string to the new list
}
}
then you could check if the player is using a banned item, and cancel the event if they do, an example if they're using a banned block, like sand or TnT would be:
@EventHandler
public void playerInteract(PlayerInteractEvent e){
if(e.getAction.equals(Action.RIGHT_CLICK_AIR) || e.getAction.equals(Action.RIGHT_CLICK_BLOCK){
//the user has right-clicked
Material m = e.getItemInHand().getType(); //get the item in the user's hand
if(m != null){ //check that it's not null
if(listOfItemsBanned.contains(m.getName()){ //if listOfItemsBanned has the name of the item in the player's hand in it
e.setCanceled(true); //cancel the block place
}
}
}
}