Merge pull request #12 from MylesIsCool/allow-empty-lists

Allow empty ListTag for conversion and adding elements to empty lists
This commit is contained in:
Steven Smith 2018-07-02 14:46:25 -07:00 committed by GitHub
commit 6859c36d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -25,10 +25,6 @@ public class ListTagConverter implements TagConverter<ListTag, List> {
@Override
public ListTag convert(String name, List value) {
if(value.isEmpty()) {
throw new IllegalArgumentException("Cannot convert ListTag with size of 0.");
}
List<Tag> tags = new ArrayList<Tag>();
for(Object o : value) {
tags.add(ConverterRegistry.convertToTag("", o));

View File

@ -94,12 +94,17 @@ public class ListTag extends Tag implements Iterable<Tag> {
}
/**
* Adds a tag to this list tag.
* Adds a tag to this list tag, if the list is empty it will use the element as the list type.
*
* @param tag Tag to add.
* @return If the list was changed as a result.
*/
public boolean add(Tag tag) {
// If empty list, use this as tag type
if(this.value.size() == 0) {
this.type = tag.getClass();
}
if(tag.getClass() != this.type) {
throw new IllegalArgumentException("Tag type cannot differ from ListTag type.");
}