mirror of https://github.com/ViaVersion/ViaNBT.git
Code formatting
This commit is contained in:
parent
412b730811
commit
fe18bc74e7
|
@ -2,7 +2,6 @@ package com.github.steveice10.opennbt;
|
|||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
|
@ -131,8 +130,8 @@ public final class NBTIO {
|
|||
* @throws java.io.IOException If an I/O error occurs.
|
||||
*/
|
||||
public static void writeFile(CompoundTag tag, File file, boolean compressed, boolean littleEndian) throws IOException {
|
||||
if(!file.exists()) {
|
||||
if(file.getParentFile() != null && !file.getParentFile().exists()) {
|
||||
if (!file.exists()) {
|
||||
if (file.getParentFile() != null && !file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
@ -206,7 +205,7 @@ public final class NBTIO {
|
|||
*/
|
||||
public static CompoundTag readTag(DataInput in, TagLimiter tagLimiter) throws IOException {
|
||||
int id = in.readByte();
|
||||
if(id != CompoundTag.ID) {
|
||||
if (id != CompoundTag.ID) {
|
||||
throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", id));
|
||||
}
|
||||
|
||||
|
@ -278,13 +277,13 @@ public final class NBTIO {
|
|||
|
||||
@Override
|
||||
public void readFully(byte[] b, int off, int len) throws IOException {
|
||||
if(len < 0) {
|
||||
if (len < 0) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else {
|
||||
int read;
|
||||
for(int pos = 0; pos < len; pos += read) {
|
||||
for (int pos = 0; pos < len; pos += read) {
|
||||
read = this.in.read(b, off + pos, len - pos);
|
||||
if(read < 0) {
|
||||
if (read < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +294,7 @@ public final class NBTIO {
|
|||
public int skipBytes(int n) throws IOException {
|
||||
int total = 0;
|
||||
int skipped = 0;
|
||||
while(total < n && (skipped = (int) this.in.skip(n - total)) > 0) {
|
||||
while (total < n && (skipped = (int) this.in.skip(n - total)) > 0) {
|
||||
total += skipped;
|
||||
}
|
||||
|
||||
|
@ -305,7 +304,7 @@ public final class NBTIO {
|
|||
@Override
|
||||
public boolean readBoolean() throws IOException {
|
||||
int val = this.in.read();
|
||||
if(val < 0) {
|
||||
if (val < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -315,7 +314,7 @@ public final class NBTIO {
|
|||
@Override
|
||||
public byte readByte() throws IOException {
|
||||
int val = this.in.read();
|
||||
if(val < 0) {
|
||||
if (val < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -325,7 +324,7 @@ public final class NBTIO {
|
|||
@Override
|
||||
public int readUnsignedByte() throws IOException {
|
||||
int val = this.in.read();
|
||||
if(val < 0) {
|
||||
if (val < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -336,7 +335,7 @@ public final class NBTIO {
|
|||
public short readShort() throws IOException {
|
||||
int b1 = this.in.read();
|
||||
int b2 = this.in.read();
|
||||
if((b1 | b2) < 0) {
|
||||
if ((b1 | b2) < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -347,7 +346,7 @@ public final class NBTIO {
|
|||
public int readUnsignedShort() throws IOException {
|
||||
int b1 = this.in.read();
|
||||
int b2 = this.in.read();
|
||||
if((b1 | b2) < 0) {
|
||||
if ((b1 | b2) < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -358,7 +357,7 @@ public final class NBTIO {
|
|||
public char readChar() throws IOException {
|
||||
int b1 = this.in.read();
|
||||
int b2 = this.in.read();
|
||||
if((b1 | b2) < 0) {
|
||||
if ((b1 | b2) < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -371,7 +370,7 @@ public final class NBTIO {
|
|||
int b2 = this.in.read();
|
||||
int b3 = this.in.read();
|
||||
int b4 = this.in.read();
|
||||
if((b1 | b2 | b3 | b4) < 0) {
|
||||
if ((b1 | b2 | b3 | b4) < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -388,7 +387,7 @@ public final class NBTIO {
|
|||
long b6 = this.in.read();
|
||||
long b7 = this.in.read();
|
||||
long b8 = this.in.read();
|
||||
if((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) {
|
||||
if ((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
|
@ -495,7 +494,7 @@ public final class NBTIO {
|
|||
@Override
|
||||
public void writeBytes(String s) throws IOException {
|
||||
int len = s.length();
|
||||
for(int index = 0; index < len; index++) {
|
||||
for (int index = 0; index < len; index++) {
|
||||
this.out.write((byte) s.charAt(index));
|
||||
}
|
||||
}
|
||||
|
@ -503,7 +502,7 @@ public final class NBTIO {
|
|||
@Override
|
||||
public void writeChars(String s) throws IOException {
|
||||
int len = s.length();
|
||||
for(int index = 0; index < len; index++) {
|
||||
for (int index = 0; index < len; index++) {
|
||||
char c = s.charAt(index);
|
||||
this.out.write(c & 0xFF);
|
||||
this.out.write((c >>> 8) & 0xFF);
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
package com.github.steveice10.opennbt.conversion;
|
||||
|
||||
import com.github.steveice10.opennbt.conversion.builtin.*;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.ByteArrayTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.ByteTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.CompoundTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.DoubleTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.FloatTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.IntArrayTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.IntTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.ListTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.LongArrayTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.LongTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.ShortTagConverter;
|
||||
import com.github.steveice10.opennbt.conversion.builtin.StringTagConverter;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
|
@ -9,12 +20,11 @@ import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
|||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -56,11 +66,11 @@ public class ConverterRegistry {
|
|||
* @throws ConverterRegisterException If an error occurs while registering the converter.
|
||||
*/
|
||||
public static <T extends Tag, V> void register(Class<T> tag, Class<V> type, TagConverter<T, V> converter) throws ConverterRegisterException {
|
||||
if(tagToConverter.containsKey(tag)) {
|
||||
if (tagToConverter.containsKey(tag)) {
|
||||
throw new ConverterRegisterException("Type conversion to tag " + tag.getName() + " is already registered.");
|
||||
}
|
||||
|
||||
if(typeToConverter.containsKey(type)) {
|
||||
if (typeToConverter.containsKey(type)) {
|
||||
throw new ConverterRegisterException("Tag conversion to type " + type.getName() + " is already registered.");
|
||||
}
|
||||
|
||||
|
@ -91,11 +101,11 @@ public class ConverterRegistry {
|
|||
* @throws ConversionException If a suitable converter could not be found.
|
||||
*/
|
||||
public static <T extends Tag, V> V convertToValue(T tag) throws ConversionException {
|
||||
if(tag == null || tag.getValue() == null) {
|
||||
if (tag == null || tag.getValue() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!tagToConverter.containsKey(tag.getClass())) {
|
||||
if (!tagToConverter.containsKey(tag.getClass())) {
|
||||
throw new ConversionException("Tag type " + tag.getClass().getName() + " has no converter.");
|
||||
}
|
||||
|
||||
|
@ -113,24 +123,24 @@ public class ConverterRegistry {
|
|||
* @throws ConversionException If a suitable converter could not be found.
|
||||
*/
|
||||
public static <V, T extends Tag> T convertToTag(V value) throws ConversionException {
|
||||
if(value == null) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TagConverter<T, V> converter = (TagConverter<T, V>) typeToConverter.get(value.getClass());
|
||||
if(converter == null) {
|
||||
for(Class<?> clazz : getAllClasses(value.getClass())) {
|
||||
if(typeToConverter.containsKey(clazz)) {
|
||||
if (converter == null) {
|
||||
for (Class<?> clazz : getAllClasses(value.getClass())) {
|
||||
if (typeToConverter.containsKey(clazz)) {
|
||||
try {
|
||||
converter = (TagConverter<T, V>) typeToConverter.get(clazz);
|
||||
break;
|
||||
} catch(ClassCastException e) {
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(converter == null) {
|
||||
if (converter == null) {
|
||||
throw new ConversionException("Value type " + value.getClass().getName() + " has no converter.");
|
||||
}
|
||||
|
||||
|
@ -140,14 +150,14 @@ public class ConverterRegistry {
|
|||
private static Set<Class<?>> getAllClasses(Class<?> clazz) {
|
||||
Set<Class<?>> ret = new LinkedHashSet<Class<?>>();
|
||||
Class<?> c = clazz;
|
||||
while(c != null) {
|
||||
while (c != null) {
|
||||
ret.add(c);
|
||||
ret.addAll(getAllSuperInterfaces(c));
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
|
||||
// Make sure Serializable is at the end to avoid mix-ups.
|
||||
if(ret.contains(Serializable.class)) {
|
||||
if (ret.contains(Serializable.class)) {
|
||||
ret.remove(Serializable.class);
|
||||
ret.add(Serializable.class);
|
||||
}
|
||||
|
@ -157,7 +167,7 @@ public class ConverterRegistry {
|
|||
|
||||
private static Set<Class<?>> getAllSuperInterfaces(Class<?> clazz) {
|
||||
Set<Class<?>> ret = new HashSet<Class<?>>();
|
||||
for(Class<?> c : clazz.getInterfaces()) {
|
||||
for (Class<?> c : clazz.getInterfaces()) {
|
||||
ret.add(c);
|
||||
ret.addAll(getAllSuperInterfaces(c));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.conversion.ConverterRegistry;
|
|||
import com.github.steveice10.opennbt.conversion.TagConverter;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -16,7 +15,7 @@ public class CompoundTagConverter implements TagConverter<CompoundTag, Map> {
|
|||
public Map convert(CompoundTag tag) {
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
Map<String, Tag> tags = tag.getValue();
|
||||
for(Map.Entry<String, Tag> entry : tags.entrySet()) {
|
||||
for (Map.Entry<String, Tag> entry : tags.entrySet()) {
|
||||
ret.put(entry.getKey(), ConverterRegistry.convertToValue(entry.getValue()));
|
||||
}
|
||||
|
||||
|
@ -26,7 +25,7 @@ public class CompoundTagConverter implements TagConverter<CompoundTag, Map> {
|
|||
@Override
|
||||
public CompoundTag convert(Map value) {
|
||||
Map<String, Tag> tags = new HashMap<>();
|
||||
for(Object na : value.keySet()) {
|
||||
for (Object na : value.keySet()) {
|
||||
String n = (String) na;
|
||||
tags.put(n, ConverterRegistry.convertToTag(value.get(n)));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.conversion.ConverterRegistry;
|
|||
import com.github.steveice10.opennbt.conversion.TagConverter;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,7 +15,7 @@ public class ListTagConverter implements TagConverter<ListTag, List> {
|
|||
public List convert(ListTag tag) {
|
||||
List<Object> ret = new ArrayList<>();
|
||||
List<? extends Tag> tags = tag.getValue();
|
||||
for(Tag t : tags) {
|
||||
for (Tag t : tags) {
|
||||
ret.add(ConverterRegistry.convertToValue(t));
|
||||
}
|
||||
|
||||
|
@ -26,7 +25,7 @@ public class ListTagConverter implements TagConverter<ListTag, List> {
|
|||
@Override
|
||||
public ListTag convert(List value) {
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
for(Object o : value) {
|
||||
for (Object o : value) {
|
||||
tags.add(ConverterRegistry.convertToTag(o));
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,8 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A registry containing different tag classes.
|
||||
|
@ -53,13 +52,13 @@ public final class TagRegistry {
|
|||
* @throws TagRegisterException If an error occurs while registering the tag.
|
||||
*/
|
||||
public static void register(int id, Class<? extends Tag> tag, Supplier<? extends Tag> supplier) throws TagRegisterException {
|
||||
if(id < 0 || id > HIGHEST_ID) {
|
||||
if (id < 0 || id > HIGHEST_ID) {
|
||||
throw new TagRegisterException("Tag ID must be between 0 and " + HIGHEST_ID);
|
||||
}
|
||||
if(idToTag[id] != null) {
|
||||
if (idToTag[id] != null) {
|
||||
throw new TagRegisterException("Tag ID \"" + id + "\" is already in use.");
|
||||
}
|
||||
if(tagToId.containsKey(tag)) {
|
||||
if (tagToId.containsKey(tag)) {
|
||||
throw new TagRegisterException("Tag \"" + tag.getSimpleName() + "\" is already registered.");
|
||||
}
|
||||
|
||||
|
@ -109,7 +108,7 @@ public final class TagRegistry {
|
|||
*/
|
||||
public static Tag createInstance(int id) throws TagCreateException {
|
||||
Supplier<? extends Tag> supplier = id > 0 && id < instanceSuppliers.length ? instanceSuppliers[id] : null;
|
||||
if(supplier == null) {
|
||||
if (supplier == null) {
|
||||
throw new TagCreateException("Could not find tag with ID \"" + id + "\".");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
@ -42,7 +41,7 @@ public class ByteArrayTag extends Tag {
|
|||
* @param value New value of this tag.
|
||||
*/
|
||||
public void setValue(byte[] value) {
|
||||
if(value == null) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -3,8 +3,6 @@ package com.github.steveice10.opennbt.tag.builtin;
|
|||
import com.github.steveice10.opennbt.tag.TagCreateException;
|
||||
import com.github.steveice10.opennbt.tag.TagRegistry;
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.EOFException;
|
||||
|
@ -15,6 +13,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A compound tag containing other tags.
|
||||
|
@ -205,16 +204,16 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
|
|||
tag.read(in, tagLimiter, newNestingLevel);
|
||||
this.value.put(name, tag);
|
||||
}
|
||||
} catch(TagCreateException e) {
|
||||
} catch (TagCreateException e) {
|
||||
throw new IOException("Failed to create tag.", e);
|
||||
} catch(EOFException ignored) {
|
||||
} catch (EOFException ignored) {
|
||||
throw new IOException("Closing tag was not found!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput out) throws IOException {
|
||||
for(Entry<String, Tag> entry : this.value.entrySet()) {
|
||||
for (Entry<String, Tag> entry : this.value.entrySet()) {
|
||||
Tag tag = entry.getValue();
|
||||
out.writeByte(tag.getTagId());
|
||||
out.writeUTF(entry.getKey());
|
||||
|
@ -241,7 +240,7 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
|
|||
@Override
|
||||
public final CompoundTag clone() {
|
||||
LinkedHashMap<String, Tag> newMap = new LinkedHashMap<>();
|
||||
for(Entry<String, Tag> entry : this.value.entrySet()) {
|
||||
for (Entry<String, Tag> entry : this.value.entrySet()) {
|
||||
newMap.put(entry.getKey(), entry.getValue().clone());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
@ -85,7 +84,7 @@ public class IntArrayTag extends Tag {
|
|||
tagLimiter.countInt();
|
||||
this.value = new int[in.readInt()];
|
||||
tagLimiter.countBytes(4 * this.value.length);
|
||||
for(int index = 0; index < this.value.length; index++) {
|
||||
for (int index = 0; index < this.value.length; index++) {
|
||||
this.value[index] = in.readInt();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -3,8 +3,6 @@ package com.github.steveice10.opennbt.tag.builtin;
|
|||
import com.github.steveice10.opennbt.tag.TagCreateException;
|
||||
import com.github.steveice10.opennbt.tag.TagRegistry;
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
@ -12,6 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A tag containing a list of tags.
|
||||
|
@ -69,7 +68,7 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
this.type = null;
|
||||
this.value.clear();
|
||||
|
||||
for(Tag tag : value) {
|
||||
for (Tag tag : value) {
|
||||
this.add(tag);
|
||||
}
|
||||
}
|
||||
|
@ -97,9 +96,9 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
}
|
||||
|
||||
// If empty list, use this as tag type.
|
||||
if(this.type == null) {
|
||||
if (this.type == null) {
|
||||
this.type = tag.getClass();
|
||||
} else if(tag.getClass() != this.type) {
|
||||
} else if (tag.getClass() != this.type) {
|
||||
throw new IllegalArgumentException("Tag type " + tag.getClass().getSimpleName() + " differs from list type " + this.type.getSimpleName());
|
||||
}
|
||||
|
||||
|
@ -148,20 +147,20 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
tagLimiter.checkLevel(nestingLevel);
|
||||
tagLimiter.countBytes(1 + 4);
|
||||
int id = in.readByte();
|
||||
if(id != 0) {
|
||||
if (id != 0) {
|
||||
this.type = TagRegistry.getClassFor(id);
|
||||
if(this.type == null) {
|
||||
if (this.type == null) {
|
||||
throw new IOException("Unknown tag ID in ListTag: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
int count = in.readInt();
|
||||
int newNestingLevel = nestingLevel + 1;
|
||||
for(int index = 0; index < count; index++) {
|
||||
for (int index = 0; index < count; index++) {
|
||||
Tag tag;
|
||||
try {
|
||||
tag = TagRegistry.createInstance(id);
|
||||
} catch(TagCreateException e) {
|
||||
} catch (TagCreateException e) {
|
||||
throw new IOException("Failed to create tag.", e);
|
||||
}
|
||||
|
||||
|
@ -172,11 +171,11 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
|
||||
@Override
|
||||
public void write(DataOutput out) throws IOException {
|
||||
if(this.type == null) {
|
||||
if (this.type == null) {
|
||||
out.writeByte(0);
|
||||
} else {
|
||||
int id = TagRegistry.getIdFor(this.type);
|
||||
if(id == -1) {
|
||||
if (id == -1) {
|
||||
throw new IOException("ListTag contains unregistered tag class.");
|
||||
}
|
||||
|
||||
|
@ -184,7 +183,7 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
}
|
||||
|
||||
out.writeInt(this.value.size());
|
||||
for(Tag tag : this.value) {
|
||||
for (Tag tag : this.value) {
|
||||
tag.write(out);
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +191,7 @@ public class ListTag extends Tag implements Iterable<Tag> {
|
|||
@Override
|
||||
public final ListTag clone() {
|
||||
List<Tag> newList = new ArrayList<>();
|
||||
for(Tag value : this.value) {
|
||||
for (Tag value : this.value) {
|
||||
newList.add(value.clone());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
@ -85,7 +84,7 @@ public class LongArrayTag extends Tag {
|
|||
tagLimiter.countInt();
|
||||
this.value = new long[in.readInt()];
|
||||
tagLimiter.countBytes(8 * this.value.length);
|
||||
for(int index = 0; index < this.value.length; index++) {
|
||||
for (int index = 0; index < this.value.length; index++) {
|
||||
this.value[index] = in.readLong();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -73,13 +73,13 @@ public abstract class Tag implements Cloneable {
|
|||
public String toString() {
|
||||
//TODO cleanup/push down
|
||||
String value = "";
|
||||
if(this.getValue() != null) {
|
||||
if (this.getValue() != null) {
|
||||
value = this.getValue().toString();
|
||||
if(this.getValue().getClass().isArray()) {
|
||||
if (this.getValue().getClass().isArray()) {
|
||||
StringBuilder build = new StringBuilder();
|
||||
build.append("[");
|
||||
for(int index = 0; index < Array.getLength(this.getValue()); index++) {
|
||||
if(index > 0) {
|
||||
for (int index = 0; index < Array.getLength(this.getValue()); index++) {
|
||||
if (index > 0) {
|
||||
build.append(", ");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue