Search in sources :

Example 6 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class TypeContainer method getVisualMsonInner.

// -------------------------------------------- //
// WRITE VISUAL
// -------------------------------------------- //
@Override
public Mson getVisualMsonInner(C container, CommandSender sender) {
    // Empty
    if (ContainerUtil.isEmpty(container))
        return MSON_EMPTY;
    // Create
    List<Mson> parts = new MassiveList<>();
    // Fill
    List<E> elements = this.getContainerElementsOrdered(container);
    Type<E> innerType = this.getInnerType();
    int index = this.getIndexStart();
    for (E element : elements) {
        Mson part = innerType.getVisualMson(element, sender);
        if (this.isIndexVisible()) {
            part = Mson.mson(Mson.mson(String.valueOf(index)).color(ChatColor.WHITE), Mson.SPACE, part);
        }
        parts.add(part);
        index++;
    }
    // Return
    return Mson.implode(parts, Mson.mson("\n"));
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList)

Example 7 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList 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)

Example 8 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class InventoryUtil method setLore.

public static void setLore(ItemStack item, Collection<String> lore) {
    ItemMeta meta = createMeta(item);
    if (meta == null)
        return;
    meta.setLore(lore == null ? null : new MassiveList<>(lore));
    item.setItemMeta(meta);
}
Also used : MassiveList(com.massivecraft.massivecore.collections.MassiveList) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 9 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class ReflectionUtil method getPackageClasses.

// -------------------------------------------- //
// GET PACKAGE CLASSES
// -------------------------------------------- //
@SuppressWarnings("unchecked")
public static List<Class<?>> getPackageClasses(String packageName, ClassLoader classLoader, boolean recursive, Predicate<Class<?>>... predicates) {
    // Create ret
    List<Class<?>> ret = new MassiveList<>();
    try {
        // Get info
        ClassPath classPath = ClassPath.from(classLoader);
        Predicate<Class<?>> predicateCombined = PredicateAnd.get(predicates);
        Collection<ClassInfo> classInfos = recursive ? classPath.getTopLevelClassesRecursive(packageName) : classPath.getTopLevelClasses(packageName);
        for (ClassInfo classInfo : classInfos) {
            // Get name of class
            String className = classInfo.getName();
            // Apparently it found a "EngineMassiveCoreCollTick 3" which we don't want
            if (className.contains(" "))
                continue;
            // Try and load it
            Class<?> clazz;
            try {
                clazz = classInfo.load();
            } catch (NoClassDefFoundError ex) {
                // Just skip it
                continue;
            }
            // And it must not be ignored
            if (!predicateCombined.apply(clazz))
                continue;
            ret.add(clazz);
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    Collections.sort(ret, new Comparator<Class<?>>() {

        @Override
        public int compare(Class<?> class1, Class<?> class2) {
            return ComparatorNaturalOrder.get().compare(class1.getName(), class2.getName());
        }
    });
    return ret;
}
Also used : ClassPath(com.massivecraft.massivecore.xlib.guava.reflect.ClassPath) MassiveList(com.massivecraft.massivecore.collections.MassiveList) IOException(java.io.IOException) ClassInfo(com.massivecraft.massivecore.xlib.guava.reflect.ClassPath.ClassInfo)

Example 10 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class Button method render.

// -------------------------------------------- //
// RENDER
// -------------------------------------------- //
public Mson render() {
    // Create
    Mson ret = mson("[", Mson.parse(this.getName()), "]");
    // Error and Enabled
    String error = this.getError();
    if (error == null) {
        // Get Requirements
        List<Requirement> requirements = new MassiveList<>();
        requirements.add(RequirementIsPlayer.get());
        requirements.addAll(this.getRequirements());
        if (this.getCommand() != null)
            requirements.addAll(this.getCommand().getRequirements());
        // Check Requirements
        error = RequirementAbstract.getRequirementsError(requirements, this.getSender(), this.getCommand(), true);
    }
    boolean enabled = (error == null);
    // Check Verbose
    if (!enabled && !this.isVerbose())
        return null;
    // Colorize
    ChatColor color = (enabled ? COLOR_ENABLED : COLOR_DISABLED);
    ret = ret.color(color);
    // Empower
    if (enabled) {
        if (this.getCommand() != null) {
            // Create the command line
            String commandLine = this.getCommand().getCommandLine(this.getArgs());
            // Render the corresponding tooltip
            String tooltip = MsonEvent.command(commandLine).createTooltip();
            // Possibly make command line clicking
            if (this.isClicking())
                commandLine = CmdMassiveCore.get().cmdMassiveCoreClick.getCommandLine(commandLine);
            // Apply command
            ret = ret.command(commandLine);
            // Possibly set tooltip to hide the clicking clutter
            if (this.isClicking())
                ret = ret.tooltip(tooltip);
        } else if (this.getLink() != null) {
            ret = ret.link(this.getLink());
        } else {
            throw new RuntimeException();
        }
    } else {
        ret = ret.tooltip(error);
    }
    // Pad
    if (Boolean.TRUE.equals(this.isPaddingRight()))
        return mson(ret, " ");
    if (Boolean.FALSE.equals(this.isPaddingRight()))
        return mson(" ", ret);
    // Return
    return ret;
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) Requirement(com.massivecraft.massivecore.command.requirement.Requirement) MassiveList(com.massivecraft.massivecore.collections.MassiveList) ChatColor(org.bukkit.ChatColor)

Aggregations

MassiveList (com.massivecraft.massivecore.collections.MassiveList)22 Mson (com.massivecraft.massivecore.mson.Mson)7 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 Entry (java.util.Map.Entry)4 ItemStack (org.bukkit.inventory.ItemStack)3 ChatColor (org.bukkit.ChatColor)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 MassiveException (com.massivecraft.massivecore.MassiveException)1 EditorType (com.massivecraft.massivecore.command.editor.annotation.EditorType)1 EditorTypeInner (com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner)1 Requirement (com.massivecraft.massivecore.command.requirement.Requirement)1 Type (com.massivecraft.massivecore.command.type.Type)1 TypeEnchantment (com.massivecraft.massivecore.command.type.TypeEnchantment)1 TypeEntityType (com.massivecraft.massivecore.command.type.enumeration.TypeEntityType)1 TypeFireworkEffectType (com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType)1 TypeOcelotType (com.massivecraft.massivecore.command.type.enumeration.TypeOcelotType)1 TypeRabbitType (com.massivecraft.massivecore.command.type.enumeration.TypeRabbitType)1 TypeSkeletonType (com.massivecraft.massivecore.command.type.enumeration.TypeSkeletonType)1 TypeWorldType (com.massivecraft.massivecore.command.type.enumeration.TypeWorldType)1 EventMassiveCoreLorePriority (com.massivecraft.massivecore.event.EventMassiveCoreLorePriority)1