Java Code Examples for org.apache.commons.lang3.ArrayUtils.removeAll()

The following are Jave code examples for showing how to use removeAll() of the org.apache.commons.lang3.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pokeraidbot   File: EggHatchedCommand.java   View Source Code Vote up 5 votes
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final String[] args = commandEvent.getArgs().split(" ");
    if (args.length < 2) {
        throw new UserMessedUpException(userName,
                localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user),
                        "!raid hatch Ho-Oh solna platform"));
    }
    String pokemonName = args[0].trim().toLowerCase();
    final String[] gymArguments = ArrayUtils.removeAll(args, 0);
    String gymName = StringUtils.join(gymArguments, " ");
    final String region = config.getRegion();
    final Gym gym = gymRepository.search(user, gymName, region);
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);

    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    final PokemonRaidInfo existingRaidInfo = raidStrategyService.getRaidInfo(raid.getPokemon());
    final int newBossTier = raidStrategyService.getRaidInfo(pokemon).getBossTier();
    if (!raid.getPokemon().isEgg()) {
        throw new UserMessedUpException(user,
                localeService.getMessageFor(LocaleService.EGG_ALREADY_HATCHED,
                        localeService.getLocaleForUser(user), raid.getPokemon().toString()));
    }
    if (pokemon.isEgg() || newBossTier != existingRaidInfo.getBossTier()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_WRONG_TIER,
                localeService.getLocaleForUser(user)));
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to hatch raid " + raid + " into " + pokemonName);
    }
    AlterRaidCommand.changePokemon(this, gymRepository, localeService, pokemonRepository, raidRepository,
            commandEvent, config, user, userName, pokemonName,
            gymArguments);
}
 
Example 2
Project: pokeraidbot   File: UnsignWithMinusCommandListener.java   View Source Code Vote up 4 votes
private void attemptUnsignFromMinusCommand(GuildMessageReceivedEvent guildMessageReceivedEvent, String[] splitArguments) {
    final String numberOfPeopleArgument = splitArguments[0];
    final String[] gymArgument = ArrayUtils.removeAll(splitArguments, 0);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to remove " + numberOfPeopleArgument + " from raid, gym " +
                StringUtils.join(gymArgument, " "));
    }
    final String guild = guildMessageReceivedEvent.getGuild().getName().trim().toLowerCase();
    final Config configForServer = serverConfigRepository.getConfigForServer(guild);
    final User user = guildMessageReceivedEvent.getAuthor();
    String message;
    try {
        message = raidRepository.executeUnsignCommand(configForServer, user,
                localeService.getLocaleForUser(user),
                splitArguments, "signup");
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.OK).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    } catch (Throwable t) {
        LOGGER.debug("Unsign command failed: " + t.getMessage());
        message = t.getMessage() + "\n\n" +
        "Syntax: *-1 Solna Platform*";
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.ERROR).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    }
    if (!StringUtils.isEmpty(message)) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setAuthor(null, null, null);
        embedBuilder.setTitle(null);
        embedBuilder.setDescription(message);
        final String msgRemoveText =
                localeService.getMessageFor(LocaleService.KEEP_CHAT_CLEAN,
                        localeService.getLocaleForUser(user),
                        "15");
        embedBuilder.setFooter(msgRemoveText, null);
        guildMessageReceivedEvent.getMessage().getChannel().sendMessage(embedBuilder.build())
                .queue(msg -> {
                    msg.delete().queueAfter(15, TimeUnit.SECONDS); // Clean up feedback after x seconds
                }
        );
        LOGGER.debug("Removed signup.");
    }
}
 
Example 3
Project: pokeraidbot   File: SignupWithPlusCommandListener.java   View Source Code Vote up 4 votes
private void attemptSignUpFromPlusCommand(GuildMessageReceivedEvent guildMessageReceivedEvent, String[] splitArguments) {
    final String numberOfPeopleArgument = splitArguments[0];
    final String etaArgument = splitArguments[1];
    final String[] gymArgument = ArrayUtils.removeAll(splitArguments, 0, 1);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to add " + numberOfPeopleArgument + " to raid, ETA " + etaArgument + " to gym " +
                StringUtils.join(gymArgument, " "));
    }
    final String guild = guildMessageReceivedEvent.getGuild().getName().trim().toLowerCase();
    final Config configForServer = serverConfigRepository.getConfigForServer(guild);
    final User user = guildMessageReceivedEvent.getAuthor();
    String message;
    try {
        message = raidRepository.executeSignUpCommand(configForServer, user,
                localeService.getLocaleForUser(user),
                splitArguments, "signup");
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.OK).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    } catch (Throwable t) {
        LOGGER.debug("Signup plus command failed: " + t.getMessage());
        message = t.getMessage() + "\n\n" +
        "Syntax: *+1 09:45 Solna Platform*";
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.ERROR).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    }
    if (!StringUtils.isEmpty(message)) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setAuthor(null, null, null);
        embedBuilder.setTitle(null);
        embedBuilder.setDescription(message);
        final String msgRemoveText =
                localeService.getMessageFor(LocaleService.KEEP_CHAT_CLEAN,
                        localeService.getLocaleForUser(user), "15");
        embedBuilder.setFooter(msgRemoveText, null);
        guildMessageReceivedEvent.getMessage().getChannel().sendMessage(embedBuilder.build())
                .queue(msg -> {
                    msg.delete().queueAfter(15, TimeUnit.SECONDS); // Clean up feedback after x seconds
                }
        );
        LOGGER.debug("Added signup.");
    }
}