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"));
}
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;
}
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);
}
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;
}
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;
}
Aggregations