Merge current FAWE master (227d6d91) into new-vector-system

Signed-off-by: Byron Marohn <combustible@live.com>
This commit is contained in:
Byron Marohn
2019-01-09 22:35:26 -08:00
215 changed files with 1876 additions and 2065 deletions

View File

@ -1,6 +1,24 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.jnbt;
import com.sk89q.worldedit.function.entity.ExtentEntityCopy;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -12,6 +30,7 @@ import java.util.Map;
public final class CompoundTag extends Tag {
private final Map<String, Tag> value;
/**
* Creates the tag with an empty name.
*
@ -425,5 +444,4 @@ public final class CompoundTag extends Tag {
return bldr.toString();
}
}

View File

@ -19,11 +19,11 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.HashMap;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create compound tags.
*/
@ -145,14 +145,14 @@ public class CompoundTagBuilder {
return put(key, new LongArrayTag(value));
}
/**
* Put the given key and value into the compound tag as a
* {@code LongTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
/**
* Put the given key and value into the compound tag as a
* {@code LongTag}.
*
* @param key they key
* @param value the value
* @return this object
*/
public CompoundTagBuilder putLong(String key, long value) {
return put(key, new LongTag(value));
}
@ -213,5 +213,4 @@ public class CompoundTagBuilder {
return new CompoundTagBuilder();
}
}

View File

@ -1,12 +1,13 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* The {@code TAG_List} tag.
@ -64,7 +65,7 @@ public final class ListTag<T extends Tag> extends Tag {
/**
* Get the tag if it exists at the given index.
*
*
* @param index the index
* @return the tag or null
*/
@ -419,6 +420,4 @@ public final class ListTag<T extends Tag> extends Tag {
return bldr.toString();
}
}

View File

@ -19,13 +19,13 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helps create list tags.
*/

View File

@ -16,13 +16,18 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The {@code TAG_Long_Array} tag.
*/
public class LongArrayTag extends Tag {
private final long[] value;
/**
* Creates the tag with an empty name.
*
@ -33,10 +38,12 @@ public class LongArrayTag extends Tag {
checkNotNull(value);
this.value = value;
}
@Override
public long[] getValue() {
return value;
}
@Override
public String toString() {
StringBuilder hex = new StringBuilder();
@ -49,4 +56,5 @@ public class LongArrayTag extends Tag {
}
return "TAG_Long_Array(" + hex + ")";
}
}
}

View File

@ -37,7 +37,7 @@ import java.util.function.Function;
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* streams, and produces an object graph of subclasses of the {@code Tag}
* object.
* <p>
*
* <p>The NBT format was created by Markus Persson, and the specification may be
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
@ -49,7 +49,7 @@ public final class NBTInputStream implements Closeable {
/**
* Creates a new {@code NBTInputStream}, which will source its data
* from the specified input stream.
*
*
* @param is the input stream
* @throws IOException if an I/O error occurs
*/
@ -67,7 +67,7 @@ public final class NBTInputStream implements Closeable {
/**
* Reads an NBT tag from the stream.
*
*
* @return The tag that was read.
* @throws IOException if an I/O error occurs.
*/
@ -87,7 +87,7 @@ public final class NBTInputStream implements Closeable {
/**
* Reads an NBT from the stream.
*
*
* @param depth the depth of this tag
* @return The tag that was read.
* @throws IOException if an I/O error occurs.
@ -519,8 +519,8 @@ public final class NBTInputStream implements Closeable {
/**
* Reads the payload of a tag given the type.
*
* @param type the type
*
* @param type the type
* @param depth the depth
* @return the tag
* @throws IOException if an I/O error occurs.
@ -617,5 +617,4 @@ public final class NBTInputStream implements Closeable {
}
}
}

View File

@ -19,6 +19,8 @@
package com.sk89q.jnbt;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.object.io.LittleEndianOutputStream;
import java.io.Closeable;
import java.io.DataOutput;
@ -29,13 +31,10 @@ import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* {@code Tag} objects to an underlying {@code OutputStream}.
* <p>
*
* <p>The NBT format was created by Markus Persson, and the specification may be
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
@ -50,9 +49,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Creates a new {@code NBTOutputStream}, which will write data to the
* specified underlying output stream.
*
* @param os The output stream.
* @throws IOException if an I/O error occurs.
*
* @param os
* The output stream.
* @throws IOException
* if an I/O error occurs.
*/
public NBTOutputStream(OutputStream os) throws IOException {
this.os = new DataOutputStream(os);
@ -74,13 +75,16 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a tag.
*
* @param tag The tag to write.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag to write.
* @throws IOException
* if an I/O error occurs.
*/
public void writeNamedTag(String name, Tag tag) throws IOException {
checkNotNull(name);
checkNotNull(tag);
int type = NBTUtils.getTypeCode(tag.getClass());
writeNamedTagName(name, type);
if (type == NBTConstants.TYPE_END) {
@ -197,62 +201,66 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes tag payload.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
public void writeTagPayload(Tag tag) throws IOException {
int type = NBTUtils.getTypeCode(tag.getClass());
switch (type) {
case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag);
break;
case NBTConstants.TYPE_BYTE:
writeByteTagPayload((ByteTag) tag);
break;
case NBTConstants.TYPE_SHORT:
writeShortTagPayload((ShortTag) tag);
break;
case NBTConstants.TYPE_INT:
writeIntTagPayload((IntTag) tag);
break;
case NBTConstants.TYPE_LONG:
writeLongTagPayload((LongTag) tag);
break;
case NBTConstants.TYPE_FLOAT:
writeFloatTagPayload((FloatTag) tag);
break;
case NBTConstants.TYPE_DOUBLE:
writeDoubleTagPayload((DoubleTag) tag);
break;
case NBTConstants.TYPE_BYTE_ARRAY:
writeByteArrayTagPayload((ByteArrayTag) tag);
break;
case NBTConstants.TYPE_STRING:
writeStringTagPayload((StringTag) tag);
break;
case NBTConstants.TYPE_LIST:
writeListTagPayload((ListTag) tag);
break;
case NBTConstants.TYPE_COMPOUND:
writeCompoundTagPayload((CompoundTag) tag);
break;
case NBTConstants.TYPE_INT_ARRAY:
writeIntArrayTagPayload((IntArrayTag) tag);
break;
case NBTConstants.TYPE_LONG_ARRAY:
writeLongArrayTagPayload((LongArrayTag) tag);
break;
default:
throw new IOException("Invalid tag type: " + type + ".");
case NBTConstants.TYPE_END:
writeEndTagPayload((EndTag) tag);
break;
case NBTConstants.TYPE_BYTE:
writeByteTagPayload((ByteTag) tag);
break;
case NBTConstants.TYPE_SHORT:
writeShortTagPayload((ShortTag) tag);
break;
case NBTConstants.TYPE_INT:
writeIntTagPayload((IntTag) tag);
break;
case NBTConstants.TYPE_LONG:
writeLongTagPayload((LongTag) tag);
break;
case NBTConstants.TYPE_FLOAT:
writeFloatTagPayload((FloatTag) tag);
break;
case NBTConstants.TYPE_DOUBLE:
writeDoubleTagPayload((DoubleTag) tag);
break;
case NBTConstants.TYPE_BYTE_ARRAY:
writeByteArrayTagPayload((ByteArrayTag) tag);
break;
case NBTConstants.TYPE_STRING:
writeStringTagPayload((StringTag) tag);
break;
case NBTConstants.TYPE_LIST:
writeListTagPayload((ListTag) tag);
break;
case NBTConstants.TYPE_COMPOUND:
writeCompoundTagPayload((CompoundTag) tag);
break;
case NBTConstants.TYPE_INT_ARRAY:
writeIntArrayTagPayload((IntArrayTag) tag);
break;
case NBTConstants.TYPE_LONG_ARRAY:
writeLongArrayTagPayload((LongArrayTag) tag);
break;
default:
throw new IOException("Invalid tag type: " + type + ".");
}
}
/**
* Writes a {@code TAG_Byte} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeByteTagPayload(ByteTag tag) throws IOException {
os.writeByte(tag.getValue());
@ -260,9 +268,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Byte_Array} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
byte[] bytes = tag.getValue();
@ -272,9 +282,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Compound} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) {
@ -285,9 +297,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_List} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeListTagPayload(ListTag tag) throws IOException {
Class<? extends Tag> clazz = tag.getType();
@ -310,9 +324,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_String} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeStringTagPayload(StringTag tag) throws IOException {
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
@ -322,9 +338,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Double} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
os.writeDouble(tag.getValue());
@ -332,9 +350,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Float} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeFloatTagPayload(FloatTag tag) throws IOException {
os.writeFloat(tag.getValue());
@ -342,9 +362,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Long} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeLongTagPayload(LongTag tag) throws IOException {
os.writeLong(tag.getValue());
@ -352,9 +374,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Int} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeIntTagPayload(IntTag tag) throws IOException {
os.writeInt(tag.getValue());
@ -362,9 +386,11 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Short} tag.
*
* @param tag The tag.
* @throws IOException if an I/O error occurs.
*
* @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/
private void writeShortTagPayload(ShortTag tag) throws IOException {
os.writeShort(tag.getValue());
@ -372,19 +398,19 @@ public final class NBTOutputStream implements Closeable {
/**
* Writes a {@code TAG_Empty} tag.
*
*
* @param tag the tag
*/
private void writeEndTagPayload(EndTag tag) {
/* empty */
}
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
int[] data = tag.getValue();
os.writeInt(data.length);
for (int aData : data) {
os.writeInt(aData);
}
}
}
private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {

View File

@ -26,8 +26,6 @@ import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A class which contains NBT-related utility methods.
*

View File

@ -26,7 +26,7 @@ public abstract class Tag {
/**
* Gets the value of this tag.
*
*
* @return the value
*/
public abstract Object getValue();
@ -34,8 +34,4 @@ public abstract class Tag {
public Object getRaw() {
return getValue();
}
}