mirror of https://github.com/ViaVersion/ViaNBT.git
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:
commit
6859c36d9b
|
@ -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));
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue