9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

fix: quickfix suggested by paper for Item Flags not properly working on lower versions

This commit is contained in:
LoJoSho
2025-04-19 18:24:44 -05:00
parent 7bd2a58b64
commit 739362fc37

View File

@@ -88,8 +88,11 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
if (itemMeta == null) return item; if (itemMeta == null) return item;
if (!nameNode.virtual()) { if (!nameNode.virtual()) {
if (HibiscusCommonsPlugin.isOnPaper()) itemMeta.displayName(AdventureUtils.MINI_MESSAGE.deserialize(nameNode.getString(""))); if (HibiscusCommonsPlugin.isOnPaper()) {
else itemMeta.setDisplayName(StringUtils.parseStringToString(nameNode.getString(""))); itemMeta.displayName(AdventureUtils.MINI_MESSAGE.deserialize(nameNode.getString("")));
} else {
itemMeta.setDisplayName(StringUtils.parseStringToString(nameNode.getString("")));
}
} }
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean()); if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
if (!glowingNode.virtual()) { if (!glowingNode.virtual()) {
@@ -97,11 +100,13 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
itemMeta.addEnchant(Enchantment.UNBREAKING, 1, true); itemMeta.addEnchant(Enchantment.UNBREAKING, 1, true);
} }
if (!loreNode.virtual()) { if (!loreNode.virtual()) {
if (HibiscusCommonsPlugin.isOnPaper()) if (HibiscusCommonsPlugin.isOnPaper()) {
itemMeta.lore(loreNode.getList(String.class, new ArrayList<>()). itemMeta.lore(loreNode.getList(String.class, new ArrayList<>()).
stream().map(AdventureUtils.MINI_MESSAGE::deserialize).collect(Collectors.toList())); stream().map(AdventureUtils.MINI_MESSAGE::deserialize).collect(Collectors.toList()));
else itemMeta.setLore(loreNode.getList(String.class, new ArrayList<>()). } else {
itemMeta.setLore(loreNode.getList(String.class, new ArrayList<>()).
stream().map(StringUtils::parseStringToString).collect(Collectors.toList())); stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
}
} }
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt()); if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
@@ -144,13 +149,14 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
} }
if (!itemFlagsNode.virtual()) { if (!itemFlagsNode.virtual()) {
for (String itemFlag : itemFlagsNode.getList(String.class)) { itemMeta.setAttributeModifiers(item.getType().getDefaultAttributeModifiers());
if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue; for (String itemFlag : itemFlagsNode.getList(String.class)) {
//MessagesUtil.sendDebugMessages("Added " + itemFlag + " to the item!"); if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue;
itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag)); //MessagesUtil.sendDebugMessages("Added " + itemFlag + " to the item!");
} itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag));
} }
}
if (item.getType() == Material.PLAYER_HEAD) { if (item.getType() == Material.PLAYER_HEAD) {
SkullMeta skullMeta = (SkullMeta) itemMeta; SkullMeta skullMeta = (SkullMeta) itemMeta;