Skip to content

Commit

Permalink
Pre-Pend Enchant Lore
Browse files Browse the repository at this point in the history
When adding crazy-enchantments, add all new ones to the start of the list instead of the end.
  • Loading branch information
TrueDarkLord committed Mar 21, 2024
1 parent ba67c2f commit d45e11c
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,23 @@ public ItemMeta addEnchantments(ItemMeta meta, Map<CEnchantment, Integer> enchan
String data = meta.getPersistentDataContainer().get(DataKeys.enchantments.getNamespacedKey(), PersistentDataType.STRING);
Enchant enchantData = data != null ? gson.fromJson(data, Enchant.class) : new Enchant(new HashMap<>());

List<Component> lore = meta.lore();
if (lore == null) lore = new ArrayList<>();
List<Component> oldLore = meta.lore() != null ? meta.lore() : new ArrayList<>();
List<Component> newLore = new ArrayList<>();

for (Entry<CEnchantment, Integer> entry : enchantments.entrySet()) {
CEnchantment enchantment = entry.getKey();
int level = entry.getValue();

String loreString = enchantment.getCustomName() + " " + NumberUtils.convertLevelString(level);

lore.add(ColorUtils.legacyTranslateColourCodes(loreString));
newLore.add(ColorUtils.legacyTranslateColourCodes(loreString));

for (Entry<CEnchantment, Integer> x : enchantments.entrySet()) {
enchantData.addEnchantment(x.getKey().getName(), x.getValue());
}
}

meta.lore(lore);
newLore.addAll(oldLore);
meta.lore(newLore);
meta.getPersistentDataContainer().set(DataKeys.enchantments.getNamespacedKey(), PersistentDataType.STRING, gson.toJson(enchantData));

return meta;
Expand Down

0 comments on commit d45e11c

Please sign in to comment.