Search in sources :

Example 1 with EventMassiveCoreLorePriority

use of com.massivecraft.massivecore.event.EventMassiveCoreLorePriority in project MassiveCore by MassiveCraft.

the class InventoryUtil method getSortedLore.

// -------------------------------------------- //
// SORT LORE
// -------------------------------------------- //
public static List<String> getSortedLore(ItemStack item) {
    if (!item.getItemMeta().hasLore())
        return Collections.emptyList();
    EventMassiveCoreLorePriority event = new EventMassiveCoreLorePriority(item);
    event.run();
    List<Entry<String, Integer>> entries = event.getLore();
    // Note: Comparator cast is necessary for Maven to compile, even if the IDE doesn't complain.
    Comparator<Entry<? super String, ? super Integer>> comparator = (Comparator) ComparatorEntryValue.get(ComparatorComparable.get());
    Collections.sort(entries, comparator);
    List<String> ret = new MassiveList<>();
    for (Entry<String, Integer> entry : entries) {
        ret.add(entry.getKey());
    }
    return ret;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) MassiveList(com.massivecraft.massivecore.collections.MassiveList) EventMassiveCoreLorePriority(com.massivecraft.massivecore.event.EventMassiveCoreLorePriority) Comparator(java.util.Comparator)

Aggregations

MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 EventMassiveCoreLorePriority (com.massivecraft.massivecore.event.EventMassiveCoreLorePriority)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Comparator (java.util.Comparator)1 Entry (java.util.Map.Entry)1