use of gg.projecteden.nexus.framework.commands.models.events.CommandEvent in project Nexus by ProjectEdenGG.
the class ICustomCommand method getPathMethods.
List<Method> getPathMethods(CommandEvent event) {
List<Method> methods = getPathMethods();
Map<String, Method> overridden = new HashMap<>();
methods.forEach(method -> {
String key = method.getName() + "(" + Arrays.stream(method.getParameterTypes()).map(Class::getName).collect(Collectors.joining(",")) + ")";
if (!overridden.containsKey(key))
overridden.put(key, method);
else if (overridden.get(key).getDeclaringClass().isAssignableFrom(method.getDeclaringClass()))
overridden.put(key, method);
});
methods.clear();
methods.addAll(overridden.values());
methods.sort(Comparator.comparing(method -> Arrays.stream(getLiteralWords(getPathString((Method) method)).split(" ")).filter(Nullables::isNotNullOrEmpty).count()).thenComparing(method -> Arrays.stream(getPathString((Method) method).split(" ")).filter(Nullables::isNotNullOrEmpty).count()));
List<Method> filtered = methods.stream().filter(method -> method.getAnnotation(Disabled.class) == null).filter(method -> {
final Environments envs = method.getAnnotation(Environments.class);
return envs == null || ArrayUtils.contains(envs.value(), Nexus.getEnv());
}).filter(method -> hasPermission(event.getSender(), method)).collect(Collectors.toList());
if (methods.size() > 0 && filtered.size() == 0)
throw new NoPermissionException();
return filtered;
}
Aggregations