Add lore content guard (#12116)

* add content guard

* use preconditions for null check
This commit is contained in:
Epic 2025-02-15 22:30:32 +00:00 committed by GitHub
parent 9b9de82706
commit c62252e19f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1250,8 +1250,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
@Override @Override
public void lore(final List<? extends net.kyori.adventure.text.Component> lore) { public void lore(final List<? extends net.kyori.adventure.text.Component> lore) {
Preconditions.checkArgument(lore == null || lore.size() <= ItemLore.MAX_LINES, "lore cannot have more than %s lines", ItemLore.MAX_LINES); // Paper - limit lore lines if (lore == null) {
this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(lore) : null; this.lore = null;
return;
}
Preconditions.checkArgument(lore.size() <= ItemLore.MAX_LINES, "lore cannot have more than %s lines", ItemLore.MAX_LINES); // Paper - limit lore lines
for (int i = 0; i < lore.size(); i++) {
Preconditions.checkArgument(lore.get(i) != null, "lore contains null entry at index: %s", i);
}
this.lore = io.papermc.paper.adventure.PaperAdventure.asVanilla(lore);
} }
// Paper end // Paper end