Search in sources :

Example 1 with Environments

use of gg.projecteden.annotations.Environments 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;
}
Also used : Cooldown(gg.projecteden.nexus.framework.commands.models.annotations.Cooldown) CommandCooldownException(gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException) Nullables(gg.projecteden.nexus.utils.Nullables) Arrays(java.util.Arrays) StringUtils(gg.projecteden.nexus.utils.StringUtils) SneakyThrows(lombok.SneakyThrows) ReflectionUtils.withAnnotation(org.reflections.ReflectionUtils.withAnnotation) Commands(gg.projecteden.nexus.framework.commands.Commands) Player(org.bukkit.entity.Player) CommandRunEvent(gg.projecteden.nexus.framework.commands.models.events.CommandRunEvent) CommandTabEvent(gg.projecteden.nexus.framework.commands.models.events.CommandTabEvent) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) StringUtils.asParsableDecimal(gg.projecteden.nexus.utils.StringUtils.asParsableDecimal) Map(java.util.Map) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) NexusException(gg.projecteden.nexus.framework.exceptions.NexusException) Utils.getDefaultPrimitiveValue(gg.projecteden.nexus.utils.Utils.getDefaultPrimitiveValue) Method(java.lang.reflect.Method) Nexus(gg.projecteden.nexus.Nexus) ObjenesisStd(org.objenesis.ObjenesisStd) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) CommandSender(org.bukkit.command.CommandSender) NoPermissionException(gg.projecteden.nexus.framework.exceptions.preconfigured.NoPermissionException) StringUtils.camelCase(gg.projecteden.nexus.utils.StringUtils.camelCase) Collection(java.util.Collection) Tasks(gg.projecteden.nexus.utils.Tasks) UUID(java.util.UUID) PlayerNotFoundException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotFoundException) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) Switch(gg.projecteden.nexus.framework.commands.models.annotations.Switch) List(java.util.List) CustomCommand.getSwitchPattern(gg.projecteden.nexus.framework.commands.models.CustomCommand.getSwitchPattern) Modifier(java.lang.reflect.Modifier) Fallback(gg.projecteden.nexus.framework.commands.models.annotations.Fallback) Annotation(java.lang.annotation.Annotation) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) PlayerOwnedObject(gg.projecteden.interfaces.PlayerOwnedObject) Confirm(gg.projecteden.nexus.framework.commands.models.annotations.Confirm) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) Utils.isBoolean(gg.projecteden.nexus.utils.Utils.isBoolean) UUID0(gg.projecteden.utils.UUIDUtils.UUID0) Parameter(java.lang.reflect.Parameter) Environments(gg.projecteden.annotations.Environments) PathParser.getLiteralWords(gg.projecteden.nexus.framework.commands.models.PathParser.getLiteralWords) ReflectionUtils.getAllMethods(org.reflections.ReflectionUtils.getAllMethods) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Iterator(java.util.Iterator) DecimalFormat(java.text.DecimalFormat) CooldownService(gg.projecteden.nexus.models.cooldown.CooldownService) COMMA_SPLIT_REGEX(gg.projecteden.nexus.utils.StringUtils.COMMA_SPLIT_REGEX) MissingArgumentException(gg.projecteden.nexus.framework.exceptions.preconfigured.MissingArgumentException) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) Utils.getMaxValue(gg.projecteden.nexus.utils.Utils.getMaxValue) PlayerNotOnlineException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotOnlineException) PathParser.getPathString(gg.projecteden.nexus.framework.commands.models.PathParser.getPathString) Comparator(java.util.Comparator) Utils.getMinValue(gg.projecteden.nexus.utils.Utils.getMinValue) Disabled(gg.projecteden.annotations.Disabled) ArrayUtils(org.apache.commons.lang.ArrayUtils) Environments(gg.projecteden.annotations.Environments) HashMap(java.util.HashMap) Nullables(gg.projecteden.nexus.utils.Nullables) NoPermissionException(gg.projecteden.nexus.framework.exceptions.preconfigured.NoPermissionException) Method(java.lang.reflect.Method) PathParser.getPathString(gg.projecteden.nexus.framework.commands.models.PathParser.getPathString) Disabled(gg.projecteden.annotations.Disabled)

Aggregations

Async (gg.projecteden.annotations.Async)1 Disabled (gg.projecteden.annotations.Disabled)1 Environments (gg.projecteden.annotations.Environments)1 PlayerOwnedObject (gg.projecteden.interfaces.PlayerOwnedObject)1 Nexus (gg.projecteden.nexus.Nexus)1 ConfirmationMenu (gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu)1 Commands (gg.projecteden.nexus.framework.commands.Commands)1 CustomCommand.getSwitchPattern (gg.projecteden.nexus.framework.commands.models.CustomCommand.getSwitchPattern)1 PathParser.getLiteralWords (gg.projecteden.nexus.framework.commands.models.PathParser.getLiteralWords)1 PathParser.getPathString (gg.projecteden.nexus.framework.commands.models.PathParser.getPathString)1 Aliases (gg.projecteden.nexus.framework.commands.models.annotations.Aliases)1 Arg (gg.projecteden.nexus.framework.commands.models.annotations.Arg)1 Confirm (gg.projecteden.nexus.framework.commands.models.annotations.Confirm)1 Cooldown (gg.projecteden.nexus.framework.commands.models.annotations.Cooldown)1 Fallback (gg.projecteden.nexus.framework.commands.models.annotations.Fallback)1 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)1 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)1 Switch (gg.projecteden.nexus.framework.commands.models.annotations.Switch)1 CommandEvent (gg.projecteden.nexus.framework.commands.models.events.CommandEvent)1 CommandRunEvent (gg.projecteden.nexus.framework.commands.models.events.CommandRunEvent)1