SPIGOT-5428: Better handling of some ItemMeta

This commit is contained in:
md_5 2019-12-14 10:54:12 +11:00
parent 16dc5758ae
commit 61d4b09023
4 changed files with 21 additions and 4 deletions

View file

@ -53,7 +53,12 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
NBTTagList patterns = entityTag.getList(PATTERNS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
NBTTagCompound p = patterns.getCompound(i);
this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
DyeColor color = DyeColor.getByWoolData((byte) p.getInt(COLOR.NBT));
PatternType pattern = PatternType.getByIdentifier(p.getString(PATTERN.NBT));
if (color != null && pattern != null) {
this.patterns.add(new Pattern(color, pattern));
}
}
}
}

View file

@ -33,7 +33,11 @@ class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta {
super(tag);
if (tag.hasKey(EXPLOSION.NBT)) {
effect = CraftMetaFirework.getEffect(tag.getCompound(EXPLOSION.NBT));
try {
effect = CraftMetaFirework.getEffect(tag.getCompound(EXPLOSION.NBT));
} catch (IllegalArgumentException ex) {
// Ignore invalid effects
}
}
}

View file

@ -63,7 +63,11 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
}
if (display.hasKey(MAP_COLOR.NBT)) {
color = Color.fromRGB(display.getInt(MAP_COLOR.NBT));
try {
color = Color.fromRGB(display.getInt(MAP_COLOR.NBT));
} catch (IllegalArgumentException ex) {
// Invalid colour
}
}
}
}

View file

@ -58,7 +58,11 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
type = CraftPotionUtil.toBukkit(tag.getString(DEFAULT_POTION.NBT));
}
if (tag.hasKey(POTION_COLOR.NBT)) {
color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
try {
color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
} catch (IllegalArgumentException ex) {
// Invalid colour
}
}
if (tag.hasKey(POTION_EFFECTS.NBT)) {
NBTTagList list = tag.getList(POTION_EFFECTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);