use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.
the class RegistryType method getInnerTypes.
// -------------------------------------------- //
// GET INNER TYPES
// -------------------------------------------- //
public static List<Type<?>> getInnerTypes(Field field, java.lang.reflect.Type fieldType, int amountRequired) {
// Annotation
if (field != null) {
try {
EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class);
if (annotation != null) {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
Class<?>[] innerTypeClasses = annotation.value();
for (Class<?> innerTypeClass : innerTypeClasses) {
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass);
ret.add(innerType);
}
// Return
return ret;
}
} catch (Throwable t) {
// This has to do with backwards compatibility (Usually 1.7).
// The annotations may trigger creation of type class instances.
// Those type classes may refer to Bukkit classes not present.
// This issue was first encountered for TypeDataItemStack.
}
if (fieldType == null) {
fieldType = field.getGenericType();
}
}
// Reflection
if (fieldType != null) {
if (fieldType instanceof ParameterizedType) {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
ParameterizedType parameterizedType = (ParameterizedType) fieldType;
int count = 0;
for (java.lang.reflect.Type actualTypeArgument : parameterizedType.getActualTypeArguments()) {
boolean strictThrow = (amountRequired < 0 || count < amountRequired);
Type<?> innerType = getType(actualTypeArgument, strictThrow);
ret.add(innerType);
count++;
}
// Return
return ret;
}
throw new IllegalArgumentException("Not ParameterizedType: " + fieldType);
}
throw new IllegalArgumentException("Failure");
}
use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.
the class TypeAbstractChoice method read.
@Override
public T read(String arg, CommandSender sender) throws MassiveException {
// NPE Evade
if (arg == null)
return null;
// Exact
T exact = this.getExactMatch(arg);
if (exact != null)
return exact;
// Get All
Collection<T> all = this.getAll(sender);
// Get Options
Map<String, T> options = this.getOptions();
if (options == null)
options = this.createOptions(all);
// Get Matches
List<T> matches = this.getMatches(options, arg, false);
// Exact
if (matches.size() == 1)
return matches.get(0);
// Exception
MassiveException exception = new MassiveException();
// Suggestions
boolean suggestNone = false;
boolean suggestAmbiguous = false;
boolean suggestAll = false;
boolean suggestLevenshtein = false;
// Nothing Found
String message;
if (matches.isEmpty()) {
message = String.format(MESSAGE_MATCH_NOTHING, this.getName(), arg);
exception.addMessage(message);
suggestLevenshtein = true;
} else // Ambiguous
{
message = String.format(MESSAGE_MATCH_AMBIGUOUS, matches.size(), this.getName(), arg);
exception.addMessage(message);
suggestAmbiguous = true;
}
// Suggest
if (all.isEmpty())
suggestNone = true;
if (all.size() <= this.getListCountMax())
suggestAll = true;
if (!this.canList(sender)) {
} else if (suggestNone) {
message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getName());
exception.addMessage(message);
} else {
Collection<T> suggestions = null;
Mson format = SUGGEST_FORMAT;
Mson comma = SUGGEST_COMMMA;
Mson and = SUGGEST_AND;
Mson dot = SUGGEST_DOT;
if (suggestAmbiguous) {
suggestions = matches;
message = MESSAGE_COLON_AMBIGUOUS;
} else if (suggestAll) {
suggestions = all;
message = MESSAGE_COLON_ALL;
} else if (suggestLevenshtein) {
suggestions = this.getMatches(options, arg, true);
message = MESSAGE_COLON_SIMILAR;
}
if (suggestions.isEmpty()) {
exception.addMessage(MESSAGE_SUGGESTIONS_EMPTY);
} else if (suggestions.size() > this.getListCountMax()) {
message = String.format(MESSAGE_SUGGESTIONS_MUCH, this.getListCountMax());
exception.addMessage(message);
} else {
List<Mson> visuals = new MassiveList<>();
for (T value : suggestions) {
visuals.add(this.getVisualMson(value, sender));
}
exception.addMessage(Mson.mson(message, Mson.implodeCommaAndDot(visuals, format, comma, and, dot)));
}
}
// Help
String help = this.getHelp();
if (help != null)
exception.addMessage(help);
throw exception;
}
use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.
the class PropertyReflection method getAll.
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public static <O> List<PropertyReflection<O, ?>> getAll(Class<O> clazz, Type<O> typeObject) {
List<PropertyReflection<O, ?>> ret = new MassiveList<>();
// TODO: Something to consider coding in for the future.
for (Field field : clazz.getDeclaredFields()) {
if (!isVisible(field))
continue;
PropertyReflection<O, ?> property = get(field, typeObject);
ret.add(property);
}
return ret;
}
use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.
the class TypeCombined method getVisualMsonInner.
// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public Mson getVisualMsonInner(T value, CommandSender sender) {
// Create
List<Mson> parts = new MassiveList<>();
// Fill
for (Entry<Type<?>, Object> entry : this.splitEntriesUser(value)) {
Type<Object> type = (Type<Object>) entry.getKey();
Mson part = type.getVisualMson(entry.getValue(), sender);
if (!this.isVisualMsonNullIncluded() && part == null)
continue;
parts.add(part);
}
// Return
return Mson.implode(parts, this.getVisualMsonSeparator());
}
use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.
the class CommandEditAbstract method attemptSetPerform.
protected void attemptSetPerform(V after) {
String descProperty = this.getProperty().getDisplayName();
Mson descObject = this.getObjectVisual();
Mson descValue = this.getInheritedVisual();
// Create messages
List<Mson> messages = new MassiveList<>();
// Before
// We inform what the value was before.
messages.add(mson(mson("Before: ").color(ChatColor.AQUA), descValue));
// Apply
// We set the new property value.
this.setValue(after);
// After
// We inform what the value is after.
descValue = this.getInheritedVisual();
messages.add(mson(mson("After: ").color(ChatColor.AQUA), descValue));
// Startup
// We inform what property and object the edit is taking place on.
// The visual might change after modification, so this should be added after we have made the change.
descObject = this.getObjectVisual();
messages.add(0, mson(descProperty, " for ", descObject, " edited:").color(ChatColor.GRAY));
message(messages);
}
Aggregations