geforkt von Mirrors/Paper
Create NBT TypeId helper class
Dieser Commit ist enthalten in:
Ursprung
7b044defc0
Commit
c19c2932bf
@ -12,6 +12,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
import org.bukkit.block.banner.PatternType;
|
import org.bukkit.block.banner.PatternType;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.BannerMeta;
|
import org.bukkit.inventory.meta.BannerMeta;
|
||||||
|
|
||||||
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
||||||
@ -49,7 +50,7 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
|
|||||||
base = entityTag.hasKey(BASE.NBT) ? DyeColor.getByDyeData((byte) entityTag.getInt(BASE.NBT)) : null;
|
base = entityTag.hasKey(BASE.NBT) ? DyeColor.getByDyeData((byte) entityTag.getInt(BASE.NBT)) : null;
|
||||||
|
|
||||||
if (entityTag.hasKey(PATTERNS.NBT)) {
|
if (entityTag.hasKey(PATTERNS.NBT)) {
|
||||||
NBTTagList patterns = entityTag.getList(PATTERNS.NBT, 10);
|
NBTTagList patterns = entityTag.getList(PATTERNS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
||||||
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
|
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
|
||||||
NBTTagCompound p = patterns.get(i);
|
NBTTagCompound p = patterns.get(i);
|
||||||
this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
|
this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
|
||||||
@ -190,13 +191,11 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
|
|||||||
return super.notUncommon(meta) && (meta instanceof CraftMetaBanner || (patterns.isEmpty() && base == null));
|
return super.notUncommon(meta) && (meta instanceof CraftMetaBanner || (patterns.isEmpty() && base == null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isEmpty() {
|
boolean isEmpty() {
|
||||||
return super.isEmpty() && patterns.isEmpty() && base == null;
|
return super.isEmpty() && patterns.isEmpty() && base == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean applicableTo(Material type) {
|
boolean applicableTo(Material type) {
|
||||||
return type == Material.BANNER;
|
return type == Material.BANNER;
|
||||||
|
@ -55,6 +55,7 @@ import org.bukkit.craftbukkit.block.CraftShulkerBox;
|
|||||||
import org.bukkit.craftbukkit.block.CraftSign;
|
import org.bukkit.craftbukkit.block.CraftSign;
|
||||||
import org.bukkit.craftbukkit.block.CraftSkull;
|
import org.bukkit.craftbukkit.block.CraftSkull;
|
||||||
import org.bukkit.craftbukkit.block.CraftStructureBlock;
|
import org.bukkit.craftbukkit.block.CraftStructureBlock;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
|
||||||
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
||||||
@ -84,7 +85,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
super(tag);
|
super(tag);
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
|
||||||
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
|
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||||
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
||||||
} else {
|
} else {
|
||||||
blockEntityTag = null;
|
blockEntityTag = null;
|
||||||
@ -113,7 +114,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void deserializeInternal(NBTTagCompound tag) {
|
void deserializeInternal(NBTTagCompound tag) {
|
||||||
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
|
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||||
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.apache.commons.lang.Validate;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
@ -75,7 +76,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag.hasKey(BOOK_PAGES.NBT) && handlePages) {
|
if (tag.hasKey(BOOK_PAGES.NBT) && handlePages) {
|
||||||
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);
|
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
||||||
|
|
||||||
for (int i = 0; i < pages.size(); i++) {
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
String page = pages.getString(i);
|
String page = pages.getString(i);
|
||||||
|
@ -10,6 +10,7 @@ import net.minecraft.server.NBTTagList;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap.Builder;
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
@ -34,7 +35,7 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag.hasKey(BOOK_PAGES.NBT)) {
|
if (tag.hasKey(BOOK_PAGES.NBT)) {
|
||||||
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, 8);
|
NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
||||||
|
|
||||||
for (int i = 0; i < pages.size(); i++) {
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
String page = pages.getString(i);
|
String page = pages.getString(i);
|
||||||
|
@ -17,6 +17,7 @@ import org.bukkit.configuration.serialization.DelegateDeserialization;
|
|||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific.To;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific.To;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@ -88,7 +89,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, 10);
|
NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
||||||
List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());
|
List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());
|
||||||
|
|
||||||
for (int i = 0; i < fireworkEffects.size(); i++) {
|
for (int i = 0; i < fireworkEffects.size(); i++) {
|
||||||
|
@ -25,6 +25,7 @@ import org.bukkit.configuration.serialization.DelegateDeserialization;
|
|||||||
import org.bukkit.configuration.serialization.SerializableAs;
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
import org.bukkit.craftbukkit.Overridden;
|
import org.bukkit.craftbukkit.Overridden;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -268,7 +269,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (display.hasKey(LORE.NBT)) {
|
if (display.hasKey(LORE.NBT)) {
|
||||||
NBTTagList list = display.getList(LORE.NBT, 8);
|
NBTTagList list = display.getList(LORE.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
||||||
lore = new ArrayList<String>(list.size());
|
lore = new ArrayList<String>(list.size());
|
||||||
|
|
||||||
for (int index = 0; index < list.size(); index++) {
|
for (int index = 0; index < list.size(); index++) {
|
||||||
@ -293,7 +294,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
|
|
||||||
if (tag.get(ATTRIBUTES.NBT) instanceof NBTTagList) {
|
if (tag.get(ATTRIBUTES.NBT) instanceof NBTTagList) {
|
||||||
NBTTagList save = null;
|
NBTTagList save = null;
|
||||||
NBTTagList nbttaglist = tag.getList(ATTRIBUTES.NBT, 10);
|
NBTTagList nbttaglist = tag.getList(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
||||||
|
|
||||||
for (int i = 0; i < nbttaglist.size(); ++i) {
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
||||||
if (!(nbttaglist.get(i) instanceof NBTTagCompound)) {
|
if (!(nbttaglist.get(i) instanceof NBTTagCompound)) {
|
||||||
@ -301,10 +302,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
}
|
}
|
||||||
NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.get(i);
|
NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.get(i);
|
||||||
|
|
||||||
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_UUID_HIGH.NBT, 99)) {
|
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_UUID_HIGH.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_UUID_LOW.NBT, 99)) {
|
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_UUID_LOW.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(nbttagcompound.get(ATTRIBUTES_IDENTIFIER.NBT) instanceof NBTTagString) || !CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES.contains(nbttagcompound.getString(ATTRIBUTES_IDENTIFIER.NBT))) {
|
if (!(nbttagcompound.get(ATTRIBUTES_IDENTIFIER.NBT) instanceof NBTTagString) || !CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES.contains(nbttagcompound.getString(ATTRIBUTES_IDENTIFIER.NBT))) {
|
||||||
@ -313,10 +314,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
if (!(nbttagcompound.get(ATTRIBUTES_NAME.NBT) instanceof NBTTagString) || nbttagcompound.getString(ATTRIBUTES_NAME.NBT).isEmpty()) {
|
if (!(nbttagcompound.get(ATTRIBUTES_NAME.NBT) instanceof NBTTagString) || nbttagcompound.getString(ATTRIBUTES_NAME.NBT).isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_VALUE.NBT, 99)) {
|
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_VALUE.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_TYPE.NBT, 99) || nbttagcompound.getInt(ATTRIBUTES_TYPE.NBT) < 0 || nbttagcompound.getInt(ATTRIBUTES_TYPE.NBT) > 2) {
|
if (!nbttagcompound.hasKeyOfType(ATTRIBUTES_TYPE.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER) || nbttagcompound.getInt(ATTRIBUTES_TYPE.NBT) < 0 || nbttagcompound.getInt(ATTRIBUTES_TYPE.NBT) > 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +351,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagList ench = tag.getList(key.NBT, 10);
|
NBTTagList ench = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
||||||
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());
|
Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());
|
||||||
|
|
||||||
for (int i = 0; i < ench.size(); i++) {
|
for (int i = 0; i < ench.size(); i++) {
|
||||||
|
@ -13,6 +13,7 @@ import org.apache.commons.lang.Validate;
|
|||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
import org.bukkit.potion.PotionData;
|
import org.bukkit.potion.PotionData;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -63,7 +64,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
|
color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
|
||||||
}
|
}
|
||||||
if (tag.hasKey(POTION_EFFECTS.NBT)) {
|
if (tag.hasKey(POTION_EFFECTS.NBT)) {
|
||||||
NBTTagList list = tag.getList(POTION_EFFECTS.NBT, 10);
|
NBTTagList list = tag.getList(POTION_EFFECTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
||||||
int length = list.size();
|
int length = list.size();
|
||||||
customEffects = new ArrayList<PotionEffect>(length);
|
customEffects = new ArrayList<PotionEffect>(length);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import net.minecraft.server.NBTTagCompound;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap.Builder;
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
@ -37,9 +38,9 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|||||||
CraftMetaSkull(NBTTagCompound tag) {
|
CraftMetaSkull(NBTTagCompound tag) {
|
||||||
super(tag);
|
super(tag);
|
||||||
|
|
||||||
if (tag.hasKeyOfType(SKULL_OWNER.NBT, 10)) {
|
if (tag.hasKeyOfType(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||||
profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_OWNER.NBT));
|
profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_OWNER.NBT));
|
||||||
} else if (tag.hasKeyOfType(SKULL_OWNER.NBT, 8) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) {
|
} else if (tag.hasKeyOfType(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_STRING) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) {
|
||||||
profile = new GameProfile(null, tag.getString(SKULL_OWNER.NBT));
|
profile = new GameProfile(null, tag.getString(SKULL_OWNER.NBT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void deserializeInternal(NBTTagCompound tag) {
|
void deserializeInternal(NBTTagCompound tag) {
|
||||||
if (tag.hasKeyOfType(SKULL_PROFILE.NBT, 10)) {
|
if (tag.hasKeyOfType(SKULL_PROFILE.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||||
profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT));
|
profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,4 +146,26 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||||||
}
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This helper class represents the different NBT Tags.
|
||||||
|
* <p>
|
||||||
|
* These should match NBTBase#getTypeId
|
||||||
|
*/
|
||||||
|
public static class NBT {
|
||||||
|
|
||||||
|
public static final int TAG_END = 0;
|
||||||
|
public static final int TAG_BYTE = 1;
|
||||||
|
public static final int TAG_SHORT = 2;
|
||||||
|
public static final int TAG_INT = 3;
|
||||||
|
public static final int TAG_LONG = 4;
|
||||||
|
public static final int TAG_FLOAT = 5;
|
||||||
|
public static final int TAG_DOUBLE = 6;
|
||||||
|
public static final int TAG_BYTE_ARRAY = 7;
|
||||||
|
public static final int TAG_STRING = 8;
|
||||||
|
public static final int TAG_LIST = 9;
|
||||||
|
public static final int TAG_COMPOUND = 10;
|
||||||
|
public static final int TAG_INT_ARRAY = 11;
|
||||||
|
public static final int TAG_ANY_NUMBER = 99;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren