Search in sources :

Example 11 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class ChannelManagementListener method onPlayerQuit.

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = chat.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(event.getPlayer().getUniqueId());
    List<String> savedChannels = user.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
    List<String> channels = savedChannels.stream().filter(channelName -> {
        Channel channel = chat.getChannels().get(channelName);
        if (channel == null) {
            return false;
        }
        channel.getMembers().remove(user.getUniqueId());
        return true;
    }).collect(Collectors.toList());
    if (channels.size() != savedChannels.size()) {
        user.getStorage().set(EasterlynChat.USER_CHANNELS, channels);
        if (!channels.contains(user.getStorage().getString(EasterlynChat.USER_CURRENT))) {
            user.getStorage().set(EasterlynChat.USER_CURRENT, null);
        }
    }
}
Also used : UserChatEvent(com.easterlyn.chat.event.UserChatEvent) Date(java.util.Date) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) UserCreationEvent(com.easterlyn.event.UserCreationEvent) TextComponent(net.md_5.bungee.api.chat.TextComponent) EventHandler(org.bukkit.event.EventHandler) AutoUser(com.easterlyn.user.AutoUser) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) StringUtil(com.easterlyn.util.StringUtil) Map(java.util.Map) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) Listener(org.bukkit.event.Listener) User(com.easterlyn.user.User) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) EasterlynCore(com.easterlyn.EasterlynCore) Collection(java.util.Collection) Channel(com.easterlyn.chat.channel.Channel) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) StringJoiner(java.util.StringJoiner) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) EasterlynChat(com.easterlyn.EasterlynChat) AutoUser(com.easterlyn.user.AutoUser) User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore) Channel(com.easterlyn.chat.channel.Channel) EventHandler(org.bukkit.event.EventHandler)

Example 12 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class MuteListener method cancelIfMute.

private void cancelIfMute(Player player, Cancellable cancellable) {
    RegisteredServiceProvider<EasterlynCore> easterlynProvider = Bukkit.getServer().getServicesManager().getRegistration(EasterlynCore.class);
    if (easterlynProvider == null) {
        return;
    }
    User user = easterlynProvider.getProvider().getUserManager().getUser(player.getUniqueId());
    if (user.getStorage().getLong(EasterlynChat.USER_MUTE, 0L) > System.currentTimeMillis()) {
        cancellable.setCancelled(true);
    }
}
Also used : User(com.easterlyn.user.User) EasterlynCore(com.easterlyn.EasterlynCore)

Example 13 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class EasterlynChat method register.

@Override
protected void register(EasterlynCore plugin) {
    StringUtil.addQuoteConsumer(new StaticQuoteConsumer(CHANNEL_PATTERN) {

        @Override
        public void addComponents(@NotNull ParsedText components, @NotNull Supplier<Matcher> matcherSupplier) {
            Matcher matcher = matcherSupplier.get();
            String channelName = matcher.group(1);
            Channel channel = getChannels().get(channelName.toLowerCase().substring(1));
            TextComponent component;
            if (channel != null) {
                component = channel.getMention();
            } else {
                int end = matcher.end(1);
                component = new TextComponent(matcher.group().substring(0, end));
                component.setColor(Colors.CHANNEL);
                component.setUnderlined(true);
                component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(Colors.COMMAND + "/join " + Colors.CHANNEL + channelName))));
                component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + channelName));
            }
            components.addComponent(component);
            String trailingPunctuation = matcher.group(2);
            if (trailingPunctuation != null && !trailingPunctuation.isEmpty()) {
                components.addText(trailingPunctuation, component.getHoverEvent(), component.getClickEvent());
            }
        }
    });
    IssuerAwareContextResolver<Channel, BukkitCommandExecutionContext> channelContext = context -> {
        String firstArg = context.getFirstArg();
        // Current channel or unspecified, defaulting to current
        if (context.hasFlag(ChannelFlag.CURRENT) || (context.hasFlag(ChannelFlag.LISTENING_OR_CURRENT) || context.hasFlag(ChannelFlag.VISIBLE_OR_CURRENT)) && (firstArg == null || firstArg.indexOf('#') != 0)) {
            if (!context.getIssuer().isPlayer()) {
                // Console never has a current channel
                throw new InvalidCommandArgument(CoreLang.NO_CONSOLE);
            }
            String channelName = plugin.getUserManager().getUser(context.getPlayer().getUniqueId()).getStorage().getString(USER_CURRENT);
            Channel channel = channels.get(channelName);
            if (channel == null) {
                throw new InvalidCommandArgument(MessageKey.of("chat.common.no_current_channel"));
            }
            return channel;
        }
        // Channel name must be specified for anything beyond this point, pop argument
        context.popFirstArg();
        if (firstArg == null) {
            throw new InvalidCommandArgument(MessageKey.of("chat.common.no_specified_channel"));
        }
        if (firstArg.length() == 0 || firstArg.charAt(0) != '#') {
            throw new InvalidCommandArgument(MessageKey.of("chat.commands.channel.create.error.naming_conventions"));
        }
        Channel channel = channels.get(firstArg.substring(1).toLowerCase());
        if (channel == null) {
            throw new InvalidCommandArgument(MessageKey.of("chat.common.no_matching_channel"), "{value}", firstArg);
        }
        User user;
        if (context.getIssuer().isPlayer()) {
            user = getCore().getUserManager().getUser(context.getIssuer().getUniqueId());
        } else {
            user = null;
        }
        if (context.hasFlag(ChannelFlag.VISIBLE) || context.hasFlag(ChannelFlag.VISIBLE_OR_CURRENT)) {
            if (user == null || !channel.isPrivate() || channel.isWhitelisted(user)) {
                return channel;
            }
            throw new InvalidCommandArgument(MessageKey.of("chat.common.no_channel_access"), "{value}", channel.getDisplayName());
        }
        if (context.hasFlag(ChannelFlag.LISTENING) || context.hasFlag(ChannelFlag.LISTENING_OR_CURRENT)) {
            if (user == null) {
                return channel;
            }
            List<String> channels = user.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
            if (!channels.contains(channel.getName())) {
                throw new InvalidCommandArgument(MessageKey.of("chat.common.not_listening_to_channel"), "{value}", channel.getDisplayName());
            }
            return channel;
        }
        if (user == null) {
            throw new InvalidCommandArgument(CoreLang.NO_CONSOLE);
        }
        if (context.hasFlag(ChannelFlag.NOT_LISTENING)) {
            List<String> channels = user.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
            if (channels.contains(channel.getName())) {
                throw new InvalidCommandArgument(MessageKey.of("chat.common.listening_to_channel"), "{value}", channel.getDisplayName());
            }
            return channel;
        }
        ReportableEvent.call("Missing Channel context flag!", 10);
        throw new InvalidCommandArgument(CoreLang.ERROR_LOGGED);
    };
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(Channel.class, channelContext);
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(NormalChannel.class, context -> {
        Channel channel = channelContext.getContext(context);
        if (!(channel instanceof NormalChannel)) {
            throw new InvalidCommandArgument(MessageKey.of("chat.common.channel_not_modifiable"));
        }
        return (NormalChannel) channel;
    });
    // TODO ACF is removing leading # from channel display names in completions
    plugin.getCommandManager().getCommandCompletions().registerCompletion("channels", getUserHandler(user -> channels.values().stream().distinct().filter(channel -> channel.isWhitelisted(user)).map(Channel::getDisplayName).collect(Collectors.toSet())));
    plugin.getCommandManager().getCommandCompletions().setDefaultCompletion("channels", Channel.class, NormalChannel.class);
    plugin.getCommandManager().getCommandCompletions().registerCompletion("channelsJoinable", getUserHandler(user -> {
        List<String> channelsJoined = user.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
        return channels.values().stream().distinct().filter(channel -> !channelsJoined.contains(channel.getName()) && channel.isWhitelisted(user)).map(Channel::getDisplayName).collect(Collectors.toSet());
    }));
    plugin.getCommandManager().getCommandCompletions().registerCompletion("channelsListening", getUserHandler(user -> user.getStorage().getStringList(EasterlynChat.USER_CHANNELS)));
    plugin.getCommandManager().getCommandCompletions().registerCompletion("channelsModerated", getUserHandler(user -> channels.values().stream().distinct().filter(channel -> channel.isModerator(user)).map(Channel::getDisplayName).collect(Collectors.toSet())));
    plugin.getCommandManager().getCommandCompletions().registerCompletion("channelsOwned", getUserHandler(user -> channels.values().stream().distinct().filter(channel -> channel.isOwner(user)).map(Channel::getDisplayName).collect(Collectors.toSet())));
    plugin.getLocaleManager().addLocaleSupplier(this);
    plugin.registerCommands(this, getClassLoader(), "com.easterlyn.chat.command");
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) EasterlynPlugin(com.easterlyn.plugin.EasterlynPlugin) MessageKey(co.aikar.locales.MessageKey) Text(net.md_5.bungee.api.chat.hover.content.Text) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) NormalChannel(com.easterlyn.chat.channel.NormalChannel) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) PermissionUtil(com.easterlyn.util.PermissionUtil) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) Supplier(java.util.function.Supplier) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext) HashSet(java.util.HashSet) TextComponent(net.md_5.bungee.api.chat.TextComponent) IssuerAwareContextResolver(co.aikar.commands.contexts.IssuerAwareContextResolver) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Matcher(java.util.regex.Matcher) ChannelFlag(com.easterlyn.chat.command.ChannelFlag) BukkitCommandCompletionContext(co.aikar.commands.BukkitCommandCompletionContext) StringUtil(com.easterlyn.util.StringUtil) StaticQuoteConsumer(com.easterlyn.util.text.StaticQuoteConsumer) Map(java.util.Map) ParsedText(com.easterlyn.util.text.ParsedText) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) User(com.easterlyn.user.User) MuteListener(com.easterlyn.chat.listener.MuteListener) Collection(java.util.Collection) PermissionDefault(org.bukkit.permissions.PermissionDefault) Channel(com.easterlyn.chat.channel.Channel) ReportableEvent(com.easterlyn.event.ReportableEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) SecretChannel(com.easterlyn.chat.channel.SecretChannel) Collectors(java.util.stream.Collectors) ChannelManagementListener(com.easterlyn.chat.listener.ChannelManagementListener) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) UserRank(com.easterlyn.user.UserRank) ChatColor(org.bukkit.ChatColor) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) CommandCompletions(co.aikar.commands.CommandCompletions) CoreLang(com.easterlyn.command.CoreLang) Colors(com.easterlyn.util.Colors) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) User(com.easterlyn.user.User) Matcher(java.util.regex.Matcher) NormalChannel(com.easterlyn.chat.channel.NormalChannel) Channel(com.easterlyn.chat.channel.Channel) SecretChannel(com.easterlyn.chat.channel.SecretChannel) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ParsedText(com.easterlyn.util.text.ParsedText) Text(net.md_5.bungee.api.chat.hover.content.Text) ParsedText(com.easterlyn.util.text.ParsedText) StaticQuoteConsumer(com.easterlyn.util.text.StaticQuoteConsumer) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) List(java.util.List) NormalChannel(com.easterlyn.chat.channel.NormalChannel) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext)

Example 14 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class ChannelCommand method delete.

@Subcommand("delete")
@Description("{@@chat.commands.channel.delete.description}")
@Syntax("<#channel>")
@CommandCompletion("@channelsOwned")
public void delete(@Flags(CoreContexts.SELF) User user, @Flags(ChannelFlag.VISIBLE_OR_CURRENT) NormalChannel channel, @Optional String name) {
    if (!channel.isOwner(user)) {
        core.getLocaleManager().sendMessage(user.getPlayer(), "chat.common.requires_owner");
        return;
    }
    if (!channel.getDisplayName().equals(name)) {
        core.getLocaleManager().sendMessage(user.getPlayer(), "chat.commands.channel.delete.error.confirm");
        return;
    }
    chat.getChannels().remove(channel.getName());
    channel.getMembers().stream().map(uuid -> core.getUserManager().getUser(uuid)).forEach(member -> {
        List<String> channels = member.getStorage().getStringList(EasterlynChat.USER_CHANNELS);
        channels.remove(channel.getName());
        member.getStorage().set(EasterlynChat.USER_CHANNELS, channels);
        String currentChannelName = member.getStorage().getString(EasterlynChat.USER_CURRENT);
        if (channel.getName().equals(currentChannelName) || currentChannelName == null) {
            if (channels.contains(EasterlynChat.DEFAULT.getName())) {
                member.getStorage().set(EasterlynChat.USER_CURRENT, EasterlynChat.DEFAULT.getName());
            }
        }
        Player player = member.getPlayer();
        if (player == null) {
            return;
        }
        BaseComponent component = new TextComponent();
        component.addExtra(channel.getMention());
        String locale = core.getLocaleManager().getLocale(player);
        for (TextComponent textComponent : StringUtil.toJSON(core.getLocaleManager().getValue("chat.commands.channel.delete.success", locale))) {
            component.addExtra(textComponent);
        }
        player.spigot().sendMessage(component);
    });
}
Also used : CommandAlias(co.aikar.commands.annotation.CommandAlias) Date(java.util.Date) NormalChannel(com.easterlyn.chat.channel.NormalChannel) CoreContexts(com.easterlyn.command.CoreContexts) SimpleDateFormat(java.text.SimpleDateFormat) Optional(co.aikar.commands.annotation.Optional) Player(org.bukkit.entity.Player) TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Private(co.aikar.commands.annotation.Private) StringUtil(com.easterlyn.util.StringUtil) AddRemove(com.easterlyn.util.command.AddRemove) CommandPermission(co.aikar.commands.annotation.CommandPermission) Description(co.aikar.commands.annotation.Description) Flags(co.aikar.commands.annotation.Flags) Bukkit(org.bukkit.Bukkit) Subcommand(co.aikar.commands.annotation.Subcommand) User(com.easterlyn.user.User) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) BaseCommand(co.aikar.commands.BaseCommand) EasterlynCore(com.easterlyn.EasterlynCore) Channel(com.easterlyn.chat.channel.Channel) Single(co.aikar.commands.annotation.Single) List(java.util.List) Dependency(co.aikar.commands.annotation.Dependency) Syntax(co.aikar.commands.annotation.Syntax) EasterlynChat(com.easterlyn.EasterlynChat) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax)

Example 15 with User

use of com.easterlyn.user.User in project Easterlyn by Easterlyn.

the class CoreContexts method register.

public static void register(EasterlynCore plugin) {
    ContextResolver<Long, BukkitCommandExecutionContext> longResolver = context -> {
        String firstArg = context.popFirstArg();
        Matcher matcher = INTEGER_PATTERN.matcher(firstArg);
        if (matcher.find()) {
            try {
                return Long.valueOf(matcher.group(1));
            } catch (NumberFormatException e) {
                throw new InvalidCommandArgument(CoreLang.WHOLE_NUMBER);
            }
        }
        firstArg = firstArg.toUpperCase();
        if (firstArg.matches("[IVXLCDM]+")) {
            return (long) NumberUtil.intFromRoman(firstArg);
        }
        throw new InvalidCommandArgument(CoreLang.WHOLE_NUMBER);
    };
    plugin.getCommandManager().getCommandContexts().registerContext(long.class, longResolver);
    plugin.getCommandManager().getCommandContexts().registerContext(Long.class, longResolver);
    ContextResolver<Integer, BukkitCommandExecutionContext> intResolver = context -> Math.toIntExact(longResolver.getContext(context));
    plugin.getCommandManager().getCommandContexts().registerContext(int.class, intResolver);
    plugin.getCommandManager().getCommandContexts().registerContext(Integer.class, intResolver);
    plugin.getCommandManager().getCommandContexts().registerContext(UUID.class, context -> {
        String firstArg = context.popFirstArg();
        if (firstArg == null) {
            // TODO lang
            throw new InvalidCommandArgument("UUID required");
        }
        try {
            return UUID.fromString(firstArg);
        } catch (IllegalArgumentException e) {
            throw new InvalidCommandArgument("UUID required");
        }
    // TODO allow fetching by player after
    });
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(BukkitCommandIssuer.class, CommandExecutionContext::getIssuer);
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(Player.class, new IssuerAwareContextResolver<>() {

        @Override
        public Player getContext(BukkitCommandExecutionContext context) throws InvalidCommandArgument {
            // noinspection unchecked
            if (context.hasFlag(SELF) || context.hasFlag(ONLINE_WITH_PERM) && context.getIssuer().isPlayer() && context.getCmd().getRequiredPermissions().stream().noneMatch(perm -> context.getIssuer().hasPermission(perm.toString().replace(".self", ".other")))) {
                return getSelf(context.getIssuer());
            }
            if (context.hasFlag(ONLINE)) {
                return getOnline(context.getIssuer(), context.popFirstArg());
            }
            if (context.hasFlag(OFFLINE)) {
                return getOffline(context.getIssuer(), context.popFirstArg());
            }
            // Default/ONLINE_WITH_PERM behavior: Attempt to match online, fall through to self.
            Player player = null;
            String firstArg = context.getFirstArg();
            if (firstArg != null && firstArg.length() > 3) {
                try {
                    player = getOnline(context.getIssuer(), firstArg);
                } catch (InvalidCommandArgument ignored) {
                // If user is not specified, fall through to self.
                }
            }
            if (player != null) {
                context.popFirstArg();
                return player;
            }
            return getSelf(context.getIssuer());
        }

        @NotNull
        private Player getSelf(@NotNull BukkitCommandIssuer issuer) throws InvalidCommandArgument {
            if (issuer.isPlayer()) {
                return issuer.getPlayer();
            }
            throw new InvalidCommandArgument(CoreLang.NO_CONSOLE);
        }

        @NotNull
        private Player getOnline(@NotNull BukkitCommandIssuer issuer, @Nullable String argument) throws InvalidCommandArgument {
            if (argument == null) {
                throw new InvalidCommandArgument(CoreLang.INVALID_PLAYER, "{value}", "null");
            }
            Player player = PlayerUtil.matchOnlinePlayer(issuer.getIssuer(), argument);
            if (player == null) {
                throw new InvalidCommandArgument(CoreLang.INVALID_PLAYER, "{value}", argument);
            }
            return player;
        }

        @NotNull
        private Player getOffline(@NotNull BukkitCommandIssuer issuer, @Nullable String argument) throws InvalidCommandArgument {
            if (argument == null) {
                throw new InvalidCommandArgument(CoreLang.INVALID_PLAYER, "{value}", "null");
            }
            Player player;
            try {
                player = PlayerUtil.matchPlayer(issuer.getIssuer(), argument, true, plugin);
            } catch (IllegalAccessException e) {
                ReportableEvent.call("Called PlayerUtil#matchPlayer on the main thread while executing!", e, 5);
                player = PlayerUtil.matchOnlinePlayer(issuer.getIssuer(), argument);
            }
            if (player == null) {
                throw new InvalidCommandArgument(CoreLang.INVALID_PLAYER, "{value}", argument);
            }
            return player;
        }
    });
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(ConsoleCommandSender.class, context -> {
        if (!(context.getIssuer().getIssuer() instanceof ConsoleCommandSender)) {
            throw new InvalidCommandArgument(CoreLang.ONLY_CONSOLE);
        }
        return (ConsoleCommandSender) context.getIssuer().getIssuer();
    });
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(User.class, context -> {
        Player player = (Player) plugin.getCommandManager().getCommandContexts().getResolver(Player.class).getContext(context);
        return plugin.getUserManager().getUser(player.getUniqueId());
    });
    plugin.getCommandManager().getCommandContexts().registerContext(Date.class, context -> {
        String firstArg = context.popFirstArg();
        long duration = NumberUtil.parseDuration(firstArg);
        return new Date(Math.addExact(System.currentTimeMillis(), duration));
    });
    plugin.getCommandManager().getCommandContexts().registerContext(ChatColor.class, new ContextResolver<>() {

        @Override
        public ChatColor getContext(BukkitCommandExecutionContext context1) throws InvalidCommandArgument {
            ChatColor matched = Colors.getOrDefault(context1.popFirstArg(), null);
            if (matched == null) {
                invalid(context1);
            }
            if (matched == ChatColor.RESET || !context1.hasFlag("colour") && !context1.hasFlag("format")) {
                // Reset is a special case - used to clear colour settings
                return matched;
            }
            boolean format = matched == ChatColor.BOLD || matched == ChatColor.UNDERLINE || matched == ChatColor.STRIKETHROUGH || matched == ChatColor.MAGIC;
            if (context1.hasFlag("colour") && format || context1.hasFlag("format") && !format) {
                invalid(context1);
            }
            return matched;
        }

        private void invalid(BukkitCommandExecutionContext context1) {
            throw new InvalidCommandArgument(MessageKeys.PLEASE_SPECIFY_ONE_OF, "{valid}", Arrays.stream(org.bukkit.ChatColor.values()).filter(chatColor -> context1.hasFlag("format") ? chatColor.isFormat() : !context1.hasFlag("colour") || chatColor.isColor()).map(Enum::name).collect(Collectors.joining(", ", "[", "]")));
        }
    });
    // TODO lang for invalid args
    plugin.getCommandManager().getCommandContexts().registerIssuerAwareContext(World.class, context -> {
        String worldName = context.getFirstArg();
        if (worldName == null) {
            if (context.isOptional() && context.getIssuer().isPlayer()) {
                return context.getIssuer().getPlayer().getWorld();
            }
            throw new InvalidCommandArgument("No world specified!");
        }
        World world = plugin.getServer().getWorld(worldName.toLowerCase());
        if (world == null) {
            if (context.isOptional() && context.getIssuer().isPlayer()) {
                return context.getIssuer().getPlayer().getWorld();
            }
            throw new InvalidCommandArgument("No world specified!");
        }
        context.popFirstArg();
        return world;
    });
}
Also used : Arrays(java.util.Arrays) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) Date(java.util.Date) ContextResolver(co.aikar.commands.contexts.ContextResolver) Player(org.bukkit.entity.Player) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext) IssuerAwareContextResolver(co.aikar.commands.contexts.IssuerAwareContextResolver) Matcher(java.util.regex.Matcher) PlayerUtil(com.easterlyn.util.PlayerUtil) World(org.bukkit.World) ChatColor(net.md_5.bungee.api.ChatColor) CommandExecutionContext(co.aikar.commands.CommandExecutionContext) User(com.easterlyn.user.User) NumberUtil(com.easterlyn.util.NumberUtil) MessageKeys(co.aikar.commands.MessageKeys) EasterlynCore(com.easterlyn.EasterlynCore) ReportableEvent(com.easterlyn.event.ReportableEvent) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) BukkitCommandIssuer(co.aikar.commands.BukkitCommandIssuer) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) Colors(com.easterlyn.util.Colors) Player(org.bukkit.entity.Player) Matcher(java.util.regex.Matcher) BukkitCommandIssuer(co.aikar.commands.BukkitCommandIssuer) World(org.bukkit.World) NotNull(org.jetbrains.annotations.NotNull) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Date(java.util.Date) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) ChatColor(net.md_5.bungee.api.ChatColor) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext) CommandExecutionContext(co.aikar.commands.CommandExecutionContext)

Aggregations

User (com.easterlyn.user.User)22 EasterlynCore (com.easterlyn.EasterlynCore)12 Player (org.bukkit.entity.Player)12 EventHandler (org.bukkit.event.EventHandler)11 Channel (com.easterlyn.chat.channel.Channel)7 AutoUser (com.easterlyn.user.AutoUser)7 TextComponent (net.md_5.bungee.api.chat.TextComponent)6 StringUtil (com.easterlyn.util.StringUtil)5 List (java.util.List)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)5 Nullable (org.jetbrains.annotations.Nullable)5 EasterlynChat (com.easterlyn.EasterlynChat)4 UserChatEvent (com.easterlyn.chat.event.UserChatEvent)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 NotNull (org.jetbrains.annotations.NotNull)4 CommandAlias (co.aikar.commands.annotation.CommandAlias)3