mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
clean: clean up ItemSerializer a bit
This commit is contained in:
@@ -81,11 +81,8 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
if (itemMeta == null) return item;
|
||||
|
||||
if (!nameNode.virtual()) {
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
itemMeta.displayName(AdventureUtils.MINI_MESSAGE.deserialize(nameNode.getString("")));
|
||||
} else {
|
||||
itemMeta.setDisplayName(StringUtils.parseStringToString(nameNode.getString("")));
|
||||
}
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) itemMeta.displayName(AdventureUtils.MINI_MESSAGE.deserialize(nameNode.getString("")));
|
||||
else itemMeta.setDisplayName(StringUtils.parseStringToString(nameNode.getString("")));
|
||||
}
|
||||
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
||||
if (!glowingNode.virtual()) {
|
||||
@@ -93,13 +90,12 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
}
|
||||
if (!loreNode.virtual()) {
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
if (HibiscusCommonsPlugin.isOnPaper())
|
||||
itemMeta.lore(loreNode.getList(String.class, new ArrayList<>()).
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
||||
|
||||
@@ -113,13 +109,13 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
|
||||
String enchantName = enchantNode.key().toString().toLowerCase();
|
||||
NamespacedKey key = NamespacedKey.minecraft(enchantName);
|
||||
Enchantment enchant = Enchantment.getByKey(key);
|
||||
Enchantment enchant = Registry.ENCHANTMENT.get(key);
|
||||
if (enchant == null) continue;
|
||||
itemMeta.addEnchant(enchant, enchantNode.getInt(1), true);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (!itemFlagsNode.virtual()) {
|
||||
for (String itemFlag : itemFlagsNode.getList(String.class)) {
|
||||
if (!EnumUtils.isValidEnum(ItemFlag.class, itemFlag)) continue;
|
||||
@@ -127,9 +123,6 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
itemMeta.addItemFlags(ItemFlag.valueOf(itemFlag));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemMeta;
|
||||
@@ -150,7 +143,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
skullMeta.getPersistentDataContainer().set(InventoryUtils.getSkullTexture(), PersistentDataType.STRING, textureString);
|
||||
}
|
||||
// Decodes the texture string and sets the texture url to the skull
|
||||
PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID());
|
||||
PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID());
|
||||
PlayerTextures textures = profile.getTextures();
|
||||
|
||||
String decoded = new String(Base64.getDecoder().decode(textureString));
|
||||
@@ -166,7 +159,6 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
skullMeta.setOwnerProfile(profile);
|
||||
}
|
||||
}
|
||||
itemMeta = skullMeta;
|
||||
}
|
||||
|
||||
if (!colorNode.virtual()) {
|
||||
@@ -186,6 +178,5 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user