mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
Don't throw error on invalid data in CraftMetaItem.
This commit is contained in:
parent
65bb2d0f7d
commit
fc10dec5f3
1 changed files with 23 additions and 7 deletions
|
@ -384,22 +384,34 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
net.minecraft.server.AttributeModifier nmsModifier = GenericAttributes.a(entry);
|
net.minecraft.server.AttributeModifier nmsModifier = GenericAttributes.a(entry);
|
||||||
Preconditions.checkNotNull(nmsModifier, "Could not create AttributeModifier. %s", entry.toString());
|
if (nmsModifier == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
AttributeModifier attribMod = CraftAttributeInstance.convert(nmsModifier);
|
AttributeModifier attribMod = CraftAttributeInstance.convert(nmsModifier);
|
||||||
|
|
||||||
String attributeName = entry.getString(ATTRIBUTES_IDENTIFIER.NBT);
|
String attributeName = entry.getString(ATTRIBUTES_IDENTIFIER.NBT);
|
||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(attributeName), "Missing Attribute for AttributeModifier. %s", entry.toString());
|
if (attributeName == null || attributeName.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Attribute attribute = CraftAttributeMap.fromMinecraft(attributeName);
|
Attribute attribute = CraftAttributeMap.fromMinecraft(attributeName);
|
||||||
Preconditions.checkNotNull(attribute, "Could not convert to Bukkit Attribute. %s", attributeName);
|
if (attribute == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.hasKeyOfType(ATTRIBUTES_SLOT.NBT, CraftMagicNumbers.NBT.TAG_STRING)) {
|
if (entry.hasKeyOfType(ATTRIBUTES_SLOT.NBT, CraftMagicNumbers.NBT.TAG_STRING)) {
|
||||||
String slotName = entry.getString(ATTRIBUTES_SLOT.NBT);
|
String slotName = entry.getString(ATTRIBUTES_SLOT.NBT);
|
||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(slotName), "Missing Slot when Slot is specified. %s", entry.toString());
|
if (slotName == null || slotName.isEmpty()) {
|
||||||
|
modifiers.put(attribute, attribMod);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
EquipmentSlot slot = CraftEquipmentSlot.getSlot(EnumItemSlot.a(slotName.toLowerCase(Locale.ROOT))); // PAIL rename fromName
|
EquipmentSlot slot = CraftEquipmentSlot.getSlot(EnumItemSlot.a(slotName.toLowerCase(Locale.ROOT))); // PAIL rename fromName
|
||||||
Preconditions.checkNotNull(slot, "No Slot found when Slot was specified. %s", entry.toString());
|
if (slot == null) {
|
||||||
|
modifiers.put(attribute, attribMod);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
attribMod = new AttributeModifier(attribMod.getUniqueId(), attribMod.getName(), attribMod.getAmount(), attribMod.getOperation(), slot);
|
attribMod = new AttributeModifier(attribMod.getUniqueId(), attribMod.getName(), attribMod.getAmount(), attribMod.getOperation(), slot);
|
||||||
}
|
}
|
||||||
|
@ -609,10 +621,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||||
}
|
}
|
||||||
net.minecraft.server.AttributeModifier nmsModifier = CraftAttributeInstance.convert(entry.getValue());
|
net.minecraft.server.AttributeModifier nmsModifier = CraftAttributeInstance.convert(entry.getValue());
|
||||||
NBTTagCompound sub = GenericAttributes.a(nmsModifier);
|
NBTTagCompound sub = GenericAttributes.a(nmsModifier);
|
||||||
Preconditions.checkState(!sub.isEmpty(), "Could not convert AttributeModifier. It was supplied in an invalid format. The following was supplied: %s", sub.toString());
|
if (sub.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String name = CraftAttributeMap.toMinecraft(entry.getKey());
|
String name = CraftAttributeMap.toMinecraft(entry.getKey());
|
||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Could not convert to Bukkit Attribute. %s", entry.getKey().name());
|
if (name == null || name.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sub.setString(ATTRIBUTES_IDENTIFIER.NBT, name); // Attribute Name
|
sub.setString(ATTRIBUTES_IDENTIFIER.NBT, name); // Attribute Name
|
||||||
if (entry.getValue().getSlot() != null) {
|
if (entry.getValue().getSlot() != null) {
|
||||||
|
|
Loading…
Reference in a new issue