Remap CraftBukkit to Mojang+Yarn Mappings
By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
@@ -7,8 +7,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.CraftNBTTagConfigSerializer;
|
||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
||||
@@ -18,11 +18,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
|
||||
private final Map<String, NBTBase> customDataTags = new HashMap<>();
|
||||
private final Map<String, Tag> customDataTags = new HashMap<>();
|
||||
private final CraftPersistentDataTypeRegistry registry;
|
||||
private final CraftPersistentDataAdapterContext adapterContext;
|
||||
|
||||
public CraftPersistentDataContainer(Map<String, NBTBase> customTags, CraftPersistentDataTypeRegistry registry) {
|
||||
public CraftPersistentDataContainer(Map<String, Tag> customTags, CraftPersistentDataTypeRegistry registry) {
|
||||
this(registry);
|
||||
this.customDataTags.putAll(customTags);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
Preconditions.checkArgument(type != null, "The provided type cannot be null");
|
||||
Preconditions.checkArgument(value != null, "The provided value cannot be null");
|
||||
|
||||
this.customDataTags.put(key.toString(), this.registry.wrap(type, type.toPrimitive(value, adapterContext)));
|
||||
this.customDataTags.put(key.toString(), this.registry.wrap(type, type.toPrimitive(value, this.adapterContext)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,7 +47,7 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
Preconditions.checkArgument(key != null, "The NamespacedKey key cannot be null");
|
||||
Preconditions.checkArgument(type != null, "The provided type cannot be null");
|
||||
|
||||
NBTBase value = this.customDataTags.get(key.toString());
|
||||
Tag value = this.customDataTags.get(key.toString());
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -65,12 +65,12 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
Preconditions.checkArgument(key != null, "The NamespacedKey key cannot be null");
|
||||
Preconditions.checkArgument(type != null, "The provided type cannot be null");
|
||||
|
||||
NBTBase value = this.customDataTags.get(key.toString());
|
||||
Tag value = this.customDataTags.get(key.toString());
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return type.fromPrimitive(this.registry.extract(type, value), adapterContext);
|
||||
return type.fromPrimitive(this.registry.extract(type, value), this.adapterContext);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -114,9 +114,9 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
|
||||
CraftPersistentDataContainer target = (CraftPersistentDataContainer) other;
|
||||
if (replace) {
|
||||
target.customDataTags.putAll(customDataTags);
|
||||
target.customDataTags.putAll(this.customDataTags);
|
||||
} else {
|
||||
customDataTags.forEach(target.customDataTags::putIfAbsent);
|
||||
this.customDataTags.forEach(target.customDataTags::putIfAbsent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,35 +131,35 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<String, NBTBase> myRawMap = this.getRaw();
|
||||
Map<String, NBTBase> theirRawMap = ((CraftPersistentDataContainer) obj).getRaw();
|
||||
Map<String, Tag> myRawMap = this.getRaw();
|
||||
Map<String, Tag> theirRawMap = ((CraftPersistentDataContainer) obj).getRaw();
|
||||
|
||||
return Objects.equals(myRawMap, theirRawMap);
|
||||
}
|
||||
|
||||
public NBTTagCompound toTagCompound() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
for (Entry<String, NBTBase> entry : this.customDataTags.entrySet()) {
|
||||
public CompoundTag toTagCompound() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
for (Entry<String, Tag> entry : this.customDataTags.entrySet()) {
|
||||
tag.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void put(String key, NBTBase base) {
|
||||
public void put(String key, Tag base) {
|
||||
this.customDataTags.put(key, base);
|
||||
}
|
||||
|
||||
public void putAll(Map<String, NBTBase> map) {
|
||||
public void putAll(Map<String, Tag> map) {
|
||||
this.customDataTags.putAll(map);
|
||||
}
|
||||
|
||||
public void putAll(NBTTagCompound compound) {
|
||||
public void putAll(CompoundTag compound) {
|
||||
for (String key : compound.getAllKeys()) {
|
||||
this.customDataTags.put(key, compound.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, NBTBase> getRaw() {
|
||||
public Map<String, Tag> getRaw() {
|
||||
return this.customDataTags;
|
||||
}
|
||||
|
||||
@@ -175,6 +175,6 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
||||
}
|
||||
|
||||
public String serialize() {
|
||||
return CraftNBTTagConfigSerializer.serialize(toTagCompound());
|
||||
return CraftNBTTagConfigSerializer.serialize(this.toTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagByteArray;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
import net.minecraft.nbt.NBTTagLongArray;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.nbt.ByteArrayTag;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.FloatTag;
|
||||
import net.minecraft.nbt.IntArrayTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.LongArrayTag;
|
||||
import net.minecraft.nbt.LongTag;
|
||||
import net.minecraft.nbt.ShortTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import org.bukkit.persistence.ListPersistentDataType;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@@ -33,11 +33,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* The craft persistent data type registry, at its core, is responsible for the
|
||||
* conversion process between a {@link PersistentDataType} and a respective
|
||||
* {@link NBTBase} instance.
|
||||
* {@link Tag} instance.
|
||||
* <p>
|
||||
* It does so by creating {@link TagAdapter} instances that are capable of
|
||||
* mappings the supported "primitive types" of {@link PersistentDataType}s to
|
||||
* their respective {@link NBTBase} instances.
|
||||
* their respective {@link Tag} instances.
|
||||
* <p>
|
||||
* To accomplish this, the class makes <b>heavy</b> use of raw arguments. Their
|
||||
* validity is enforced by the mapping of class to {@link TagAdapter}
|
||||
@@ -50,39 +50,39 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
|
||||
/**
|
||||
* A tag adapter is a closely related type to a specific implementation of
|
||||
* the {@link NBTBase} interface. It exists to convert from and to the
|
||||
* respective value of a {@link NBTBase} to a "primitive type" for later
|
||||
* the {@link Tag} interface. It exists to convert from and to the
|
||||
* respective value of a {@link Tag} to a "primitive type" for later
|
||||
* usage in {@link PersistentDataType}.
|
||||
*
|
||||
* @param primitiveType the class of the primitive type, e.g.
|
||||
* {@link String}.
|
||||
* @param nbtBaseType the class of the tag implementation that is used to
|
||||
* store this primitive type, e.g {@link NBTTagString}.
|
||||
* store this primitive type, e.g {@link StringTag}.
|
||||
* @param nmsTypeByte the byte identifier of the tag as defined by
|
||||
* {@link NBTBase#getId()}.
|
||||
* {@link Tag#getId()}.
|
||||
* @param builder a bi function that is responsible for mapping a "primitive
|
||||
* type" and its respective {@link PersistentDataType} to a {@link NBTBase}.
|
||||
* type" and its respective {@link PersistentDataType} to a {@link Tag}.
|
||||
* @param extractor a bi function that is responsible for extracting a
|
||||
* "primitive type" from a {@link NBTBase} given a
|
||||
* "primitive type" from a {@link Tag} given a
|
||||
* {@link PersistentDataType}.
|
||||
* @param matcher a bi predicate that is responsible for computing if the
|
||||
* passed {@link NBTBase} holds a value that the {@link PersistentDataType}
|
||||
* passed {@link Tag} holds a value that the {@link PersistentDataType}
|
||||
* can extract.
|
||||
* @param <P> the generic type of the primitive the persistent data type
|
||||
* expects.
|
||||
* @param <T> the generic type of the concrete {@link NBTBase}
|
||||
* @param <T> the generic type of the concrete {@link Tag}
|
||||
* implementation that the primitive type is mapped into.
|
||||
*/
|
||||
private record TagAdapter<P, T extends NBTBase>(
|
||||
private record TagAdapter<P, T extends Tag>(
|
||||
Class<P> primitiveType,
|
||||
Class<T> nbtBaseType,
|
||||
byte nmsTypeByte,
|
||||
BiFunction<PersistentDataType<P, ?>, P, T> builder,
|
||||
BiFunction<PersistentDataType<P, ?>, T, P> extractor,
|
||||
BiPredicate<PersistentDataType<P, ?>, NBTBase> matcher) {
|
||||
BiPredicate<PersistentDataType<P, ?>, Tag> matcher) {
|
||||
|
||||
/**
|
||||
* Extract the primitive value from the {@link NBTBase}.
|
||||
* Extract the primitive value from the {@link Tag}.
|
||||
*
|
||||
* @param base the base to extract from
|
||||
* @return the value stored inside the tag
|
||||
@@ -90,7 +90,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* the defined base type and therefore is not applicable to the
|
||||
* extractor function.
|
||||
*/
|
||||
private P extract(final PersistentDataType<P, ?> dataType, final NBTBase base) {
|
||||
private P extract(final PersistentDataType<P, ?> dataType, final Tag base) {
|
||||
Preconditions.checkArgument(this.nbtBaseType.isInstance(base), "The provided NBTBase was of the type %s. Expected type %s", base.getClass().getSimpleName(), this.nbtBaseType.getSimpleName());
|
||||
return this.extractor.apply(dataType, this.nbtBaseType.cast(base));
|
||||
}
|
||||
@@ -111,12 +111,12 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
|
||||
/**
|
||||
* Computes if the provided persistent data type's primitive type is a
|
||||
* representation of the {@link NBTBase}.
|
||||
* representation of the {@link Tag}.
|
||||
*
|
||||
* @param base the base tag instance to check against
|
||||
* @return if the tag was an instance of the set type
|
||||
*/
|
||||
private boolean isInstance(final PersistentDataType<P, ?> persistentDataType, final NBTBase base) {
|
||||
private boolean isInstance(final PersistentDataType<P, ?> persistentDataType, final Tag base) {
|
||||
return this.matcher.test(persistentDataType, base);
|
||||
}
|
||||
}
|
||||
@@ -140,63 +140,63 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
// Primitives
|
||||
if (Objects.equals(Byte.class, type)) {
|
||||
return this.createAdapter(
|
||||
Byte.class, NBTTagByte.class, NBTBase.TAG_BYTE,
|
||||
NBTTagByte::valueOf, NBTTagByte::getAsByte
|
||||
Byte.class, ByteTag.class, Tag.TAG_BYTE,
|
||||
ByteTag::valueOf, ByteTag::getAsByte
|
||||
);
|
||||
}
|
||||
if (Objects.equals(Short.class, type)) {
|
||||
return this.createAdapter(
|
||||
Short.class, NBTTagShort.class, NBTBase.TAG_SHORT, NBTTagShort::valueOf, NBTTagShort::getAsShort
|
||||
Short.class, ShortTag.class, Tag.TAG_SHORT, ShortTag::valueOf, ShortTag::getAsShort
|
||||
);
|
||||
}
|
||||
if (Objects.equals(Integer.class, type)) {
|
||||
return this.createAdapter(
|
||||
Integer.class, NBTTagInt.class, NBTBase.TAG_INT, NBTTagInt::valueOf, NBTTagInt::getAsInt
|
||||
Integer.class, IntTag.class, Tag.TAG_INT, IntTag::valueOf, IntTag::getAsInt
|
||||
);
|
||||
}
|
||||
if (Objects.equals(Long.class, type)) {
|
||||
return this.createAdapter(
|
||||
Long.class, NBTTagLong.class, NBTBase.TAG_LONG, NBTTagLong::valueOf, NBTTagLong::getAsLong
|
||||
Long.class, LongTag.class, Tag.TAG_LONG, LongTag::valueOf, LongTag::getAsLong
|
||||
);
|
||||
}
|
||||
if (Objects.equals(Float.class, type)) {
|
||||
return this.createAdapter(
|
||||
Float.class, NBTTagFloat.class, NBTBase.TAG_FLOAT,
|
||||
NBTTagFloat::valueOf, NBTTagFloat::getAsFloat
|
||||
Float.class, FloatTag.class, Tag.TAG_FLOAT,
|
||||
FloatTag::valueOf, FloatTag::getAsFloat
|
||||
);
|
||||
}
|
||||
if (Objects.equals(Double.class, type)) {
|
||||
return this.createAdapter(
|
||||
Double.class, NBTTagDouble.class, NBTBase.TAG_DOUBLE,
|
||||
NBTTagDouble::valueOf, NBTTagDouble::getAsDouble
|
||||
Double.class, DoubleTag.class, Tag.TAG_DOUBLE,
|
||||
DoubleTag::valueOf, DoubleTag::getAsDouble
|
||||
);
|
||||
}
|
||||
if (Objects.equals(String.class, type)) {
|
||||
return this.createAdapter(
|
||||
String.class, NBTTagString.class, NBTBase.TAG_STRING,
|
||||
NBTTagString::valueOf, NBTTagString::getAsString
|
||||
String.class, StringTag.class, Tag.TAG_STRING,
|
||||
StringTag::valueOf, StringTag::getAsString
|
||||
);
|
||||
}
|
||||
|
||||
// Primitive non-list arrays
|
||||
if (Objects.equals(byte[].class, type)) {
|
||||
return this.createAdapter(
|
||||
byte[].class, NBTTagByteArray.class, NBTBase.TAG_BYTE_ARRAY,
|
||||
array -> new NBTTagByteArray(Arrays.copyOf(array, array.length)),
|
||||
byte[].class, ByteArrayTag.class, Tag.TAG_BYTE_ARRAY,
|
||||
array -> new ByteArrayTag(Arrays.copyOf(array, array.length)),
|
||||
n -> Arrays.copyOf(n.getAsByteArray(), n.size())
|
||||
);
|
||||
}
|
||||
if (Objects.equals(int[].class, type)) {
|
||||
return this.createAdapter(
|
||||
int[].class, NBTTagIntArray.class, NBTBase.TAG_INT_ARRAY,
|
||||
array -> new NBTTagIntArray(Arrays.copyOf(array, array.length)),
|
||||
int[].class, IntArrayTag.class, Tag.TAG_INT_ARRAY,
|
||||
array -> new IntArrayTag(Arrays.copyOf(array, array.length)),
|
||||
n -> Arrays.copyOf(n.getAsIntArray(), n.size())
|
||||
);
|
||||
}
|
||||
if (Objects.equals(long[].class, type)) {
|
||||
return this.createAdapter(
|
||||
long[].class, NBTTagLongArray.class, NBTBase.TAG_LONG_ARRAY,
|
||||
array -> new NBTTagLongArray(Arrays.copyOf(array, array.length)),
|
||||
long[].class, LongArrayTag.class, Tag.TAG_LONG_ARRAY,
|
||||
array -> new LongArrayTag(Arrays.copyOf(array, array.length)),
|
||||
n -> Arrays.copyOf(n.getAsLongArray(), n.size())
|
||||
);
|
||||
}
|
||||
@@ -204,9 +204,9 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
// Previously "emulated" compound lists, now useless as a proper list type exists.
|
||||
if (Objects.equals(PersistentDataContainer[].class, type)) {
|
||||
return this.createAdapter(
|
||||
PersistentDataContainer[].class, NBTTagList.class, NBTBase.TAG_LIST,
|
||||
PersistentDataContainer[].class, ListTag.class, Tag.TAG_LIST,
|
||||
(containerArray) -> {
|
||||
final NBTTagList list = new NBTTagList();
|
||||
final ListTag list = new ListTag();
|
||||
for (final PersistentDataContainer persistentDataContainer : containerArray) {
|
||||
list.add(((CraftPersistentDataContainer) persistentDataContainer).toTagCompound());
|
||||
}
|
||||
@@ -216,7 +216,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
final PersistentDataContainer[] containerArray = new CraftPersistentDataContainer[tag.size()];
|
||||
for (int i = 0; i < tag.size(); i++) {
|
||||
final CraftPersistentDataContainer container = new CraftPersistentDataContainer(this);
|
||||
final NBTTagCompound compound = tag.getCompound(i);
|
||||
final CompoundTag compound = tag.getCompound(i);
|
||||
for (final String key : compound.getAllKeys()) {
|
||||
container.put(key, compound.get(key));
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
// as defined in TagAdapter#build.
|
||||
if (Objects.equals(PersistentDataContainer.class, type)) {
|
||||
return this.createAdapter(
|
||||
CraftPersistentDataContainer.class, NBTTagCompound.class, NBTBase.TAG_COMPOUND,
|
||||
CraftPersistentDataContainer.class, CompoundTag.class, Tag.TAG_COMPOUND,
|
||||
CraftPersistentDataContainer::toTagCompound,
|
||||
tag -> {
|
||||
final CraftPersistentDataContainer container = new CraftPersistentDataContainer(this);
|
||||
@@ -244,10 +244,10 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
}
|
||||
|
||||
if (Objects.equals(List.class, type)) {
|
||||
return createAdapter(
|
||||
return this.createAdapter(
|
||||
List.class,
|
||||
net.minecraft.nbt.NBTTagList.class,
|
||||
NBTBase.TAG_LIST,
|
||||
net.minecraft.nbt.ListTag.class,
|
||||
Tag.TAG_LIST,
|
||||
this::constructList,
|
||||
this::extractList,
|
||||
this::matchesListTag
|
||||
@@ -258,11 +258,11 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
}
|
||||
|
||||
// Plain constructor helper method.
|
||||
private <T, Z extends NBTBase> TagAdapter<T, Z> createAdapter(
|
||||
private <T, Z extends Tag> TagAdapter<T, Z> createAdapter(
|
||||
final Class<T> primitiveType, final Class<Z> nbtBaseType, final byte nmsTypeByte,
|
||||
final Function<T, Z> builder, final Function<Z, T> extractor
|
||||
) {
|
||||
return createAdapter(
|
||||
return this.createAdapter(
|
||||
primitiveType,
|
||||
nbtBaseType,
|
||||
nmsTypeByte,
|
||||
@@ -273,11 +273,11 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
}
|
||||
|
||||
// Plain constructor helper method.
|
||||
private <T, Z extends NBTBase> TagAdapter<T, Z> createAdapter(
|
||||
private <T, Z extends Tag> TagAdapter<T, Z> createAdapter(
|
||||
final Class<T> primitiveType, final Class<Z> nbtBaseType, final byte nmsTypeByte,
|
||||
final BiFunction<PersistentDataType<T, ?>, T, Z> builder,
|
||||
final BiFunction<PersistentDataType<T, ?>, Z, T> extractor,
|
||||
final BiPredicate<PersistentDataType<T, ?>, NBTBase> matcher
|
||||
final BiPredicate<PersistentDataType<T, ?>, Tag> matcher
|
||||
) {
|
||||
return new TagAdapter<>(primitiveType, nbtBaseType, nmsTypeByte, builder, extractor, matcher);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* @throws IllegalArgumentException if no suitable tag type adapter for this
|
||||
* type was found.
|
||||
*/
|
||||
public <T> NBTBase wrap(final PersistentDataType<T, ?> type, final T value) {
|
||||
public <T> Tag wrap(final PersistentDataType<T, ?> type, final T value) {
|
||||
return this.getOrCreateAdapter(type).build(type, value);
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* @throws IllegalArgumentException if no suitable tag type adapter for this
|
||||
* type was found.
|
||||
*/
|
||||
public <T> boolean isInstanceOf(final PersistentDataType<T, ?> type, final NBTBase base) {
|
||||
public <T> boolean isInstanceOf(final PersistentDataType<T, ?> type, final Tag base) {
|
||||
return this.getOrCreateAdapter(type).isInstance(type, base);
|
||||
}
|
||||
|
||||
@@ -323,8 +323,8 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* persistent data type.
|
||||
*/
|
||||
@NotNull
|
||||
private <T, Z extends NBTBase> TagAdapter<T, Z> getOrCreateAdapter(@NotNull final PersistentDataType<T, ?> type) {
|
||||
return this.adapters.computeIfAbsent(type.getPrimitiveType(), CREATE_ADAPTER);
|
||||
private <T, Z extends Tag> TagAdapter<T, Z> getOrCreateAdapter(@NotNull final PersistentDataType<T, ?> type) {
|
||||
return this.adapters.computeIfAbsent(type.getPrimitiveType(), this.CREATE_ADAPTER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,7 +342,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* @throws IllegalArgumentException if no suitable tag type adapter for this
|
||||
* type was found.
|
||||
*/
|
||||
public <T, Z extends NBTBase> T extract(final PersistentDataType<T, ?> type, final NBTBase tag) throws ClassCastException, IllegalArgumentException {
|
||||
public <T, Z extends Tag> T extract(final PersistentDataType<T, ?> type, final Tag tag) throws ClassCastException, IllegalArgumentException {
|
||||
final Class<T> primitiveType = type.getPrimitiveType();
|
||||
final TagAdapter<T, Z> adapter = this.getOrCreateAdapter(type);
|
||||
Preconditions.checkArgument(adapter.isInstance(type, tag), "The found tag instance (%s) cannot store %s", tag.getClass().getSimpleName(), primitiveType.getSimpleName());
|
||||
@@ -353,30 +353,30 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link NBTTagList} from a {@link List} instance by using the
|
||||
* Constructs a {@link ListTag} from a {@link List} instance by using the
|
||||
* passed persistent data type.
|
||||
*
|
||||
* @param type the persistent data type of the list.
|
||||
* @param list the list or primitive values.
|
||||
* @param <P> the generic type of the primitive values in the list.
|
||||
* @return the constructed {@link NBTTagList}.
|
||||
* @return the constructed {@link ListTag}.
|
||||
*/
|
||||
private <P, T extends List<P>> NBTTagList constructList(@NotNull final PersistentDataType<T, ?> type, @NotNull final List<P> list) {
|
||||
private <P, T extends List<P>> ListTag constructList(@NotNull final PersistentDataType<T, ?> type, @NotNull final List<P> list) {
|
||||
Preconditions.checkArgument(type instanceof ListPersistentDataType<?, ?>, "The passed list cannot be written to the PDC with a %s (expected a list data type)", type.getClass().getSimpleName());
|
||||
final ListPersistentDataType<P, ?> listPersistentDataType = (ListPersistentDataType<P, ?>) type;
|
||||
|
||||
final TagAdapter<P, NBTBase> elementAdapter = this.getOrCreateAdapter(listPersistentDataType.elementType());
|
||||
final TagAdapter<P, Tag> elementAdapter = this.getOrCreateAdapter(listPersistentDataType.elementType());
|
||||
|
||||
final List<NBTBase> values = Lists.newArrayListWithCapacity(list.size());
|
||||
final List<Tag> values = Lists.newArrayListWithCapacity(list.size());
|
||||
for (final P primitiveValue : list) {
|
||||
values.add(this.wrap(listPersistentDataType.elementType(), primitiveValue));
|
||||
}
|
||||
|
||||
return new NBTTagList(values, values.isEmpty() ? NBTTagList.TAG_END : elementAdapter.nmsTypeByte());
|
||||
return new ListTag(values, values.isEmpty() ? ListTag.TAG_END : elementAdapter.nmsTypeByte());
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a {@link List} from a {@link NBTTagList} and a respective
|
||||
* Extracts a {@link List} from a {@link ListTag} and a respective
|
||||
* {@link PersistentDataType}.
|
||||
*
|
||||
* @param type the persistent data type of the list.
|
||||
@@ -389,12 +389,12 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* extract a {@link List}.
|
||||
*/
|
||||
private <P> List<P> extractList(@NotNull final PersistentDataType<P, ?> type,
|
||||
@NotNull final NBTTagList listTag) {
|
||||
@NotNull final ListTag listTag) {
|
||||
Preconditions.checkArgument(type instanceof ListPersistentDataType<?, ?>, "The found list tag cannot be read with a %s (expected a list data type)", type.getClass().getSimpleName());
|
||||
final ListPersistentDataType<P, ?> listPersistentDataType = (ListPersistentDataType<P, ?>) type;
|
||||
|
||||
final List<P> output = new ObjectArrayList<>(listTag.size());
|
||||
for (final NBTBase tag : listTag) {
|
||||
for (final Tag tag : listTag) {
|
||||
output.add(this.extract(listPersistentDataType.elementType(), tag));
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes if the passed {@link NBTBase} is a {@link NBTTagList} and it,
|
||||
* Computes if the passed {@link Tag} is a {@link ListTag} and it,
|
||||
* including its elements, can be read/written via the passed
|
||||
* {@link PersistentDataType}.
|
||||
* <p>
|
||||
@@ -416,17 +416,17 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
* @param tag the tag that is to be checked if it matches the data type.
|
||||
* @return whether the passed tag can be read/written via the passed type.
|
||||
*/
|
||||
private boolean matchesListTag(final PersistentDataType<List, ?> type, final NBTBase tag) {
|
||||
private boolean matchesListTag(final PersistentDataType<List, ?> type, final Tag tag) {
|
||||
if ((!(type instanceof final ListPersistentDataType listPersistentDataType))) {
|
||||
return false;
|
||||
}
|
||||
if (!(tag instanceof final NBTTagList listTag)) {
|
||||
if (!(tag instanceof final ListTag listTag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final byte elementType = listTag.getElementType();
|
||||
final TagAdapter elementAdapter = this.getOrCreateAdapter(listPersistentDataType.elementType());
|
||||
|
||||
return elementAdapter.nmsTypeByte() == elementType || elementType == NBTTagList.TAG_END;
|
||||
return elementAdapter.nmsTypeByte() == elementType || elementType == ListTag.TAG_END;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.bukkit.craftbukkit.persistence;
|
||||
|
||||
import java.util.Map;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -15,7 +15,7 @@ public final class DirtyCraftPersistentDataContainer extends CraftPersistentData
|
||||
|
||||
private boolean dirty;
|
||||
|
||||
public DirtyCraftPersistentDataContainer(Map<String, NBTBase> customTags, CraftPersistentDataTypeRegistry registry) {
|
||||
public DirtyCraftPersistentDataContainer(Map<String, Tag> customTags, CraftPersistentDataTypeRegistry registry) {
|
||||
super(customTags, registry);
|
||||
}
|
||||
|
||||
@@ -44,19 +44,19 @@ public final class DirtyCraftPersistentDataContainer extends CraftPersistentData
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, NBTBase base) {
|
||||
public void put(String key, Tag base) {
|
||||
super.put(key, base);
|
||||
this.dirty(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(NBTTagCompound compound) {
|
||||
public void putAll(CompoundTag compound) {
|
||||
super.putAll(compound);
|
||||
this.dirty(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<String, NBTBase> map) {
|
||||
public void putAll(Map<String, Tag> map) {
|
||||
super.putAll(map);
|
||||
this.dirty(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user