Search in sources :

Example 1 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class CheckMessageKeyUsages method execute.

@Override
public void execute(Scanner scanner) {
    System.out.println("Enter a message key to find the files where it is used");
    System.out.println("Enter empty line to search for all unused message keys");
    String key = scanner.nextLine();
    if (key.trim().isEmpty()) {
        List<MessageKey> unusedKeys = findUnusedKeys();
        if (unusedKeys.isEmpty()) {
            System.out.println("No unused MessageKey entries found :)");
        } else {
            System.out.println("Did not find usages for keys:\n- " + String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name)));
        }
    } else {
        MessageKey messageKey = MessageKey.valueOf(key);
        List<File> filesUsingKey = findUsagesOfKey(messageKey);
        System.out.println("The following files use '" + key + "':\n- " + filesUsingKey.stream().map(File::getName).collect(Collectors.joining("\n- ")));
    }
}
Also used : MessageKey(fr.xephi.authme.message.MessageKey) File(java.io.File)

Example 2 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class CheckMessageKeyUsages method findUsagesOfKey.

private List<File> findUsagesOfKey(MessageKey key) {
    List<File> filesUsingKey = new ArrayList<>();
    File sourceFolder = new File(ToolsConstants.MAIN_SOURCE_ROOT);
    Consumer<File> usagesCollector = file -> {
        String source = FileIoUtils.readFromFile(file.toPath());
        if (source.contains(key.name())) {
            filesUsingKey.add(file);
        }
    };
    walkJavaFileTree(sourceFolder, usagesCollector);
    return filesUsingKey;
}
Also used : ToolTask(tools.utils.ToolTask) Predicate(java.util.function.Predicate) Scanner(java.util.Scanner) ToolsConstants(tools.utils.ToolsConstants) MessageKey(fr.xephi.authme.message.MessageKey) FileIoUtils(tools.utils.FileIoUtils) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Lists(com.google.common.collect.Lists) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManager method registerMessageTask.

/**
     * Registers a {@link MessageTask} for the given player name.
     *
     * @param player the player
     * @param limbo the associated limbo player of the player
     * @param isRegistered whether the player is registered or not
     *                     (false shows "please register", true shows "please log in")
     */
void registerMessageTask(Player player, LimboPlayer limbo, boolean isRegistered) {
    int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
    MessageKey key = getMessageKey(isRegistered);
    if (interval > 0) {
        MessageTask messageTask = new MessageTask(player, messages.retrieve(key));
        bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND);
        limbo.setMessageTask(messageTask);
    }
}
Also used : MessageTask(fr.xephi.authme.task.MessageTask) MessageKey(fr.xephi.authme.message.MessageKey)

Example 4 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class CaptchaCommand method runCommand.

@Override
public void runCommand(Player player, List<String> arguments) {
    final String name = player.getName();
    if (playerCache.isAuthenticated(name)) {
        // No captcha is relevant if the player is logged in
        commonService.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
        return;
    }
    if (loginCaptchaManager.isCaptchaRequired(name)) {
        checkLoginCaptcha(player, arguments.get(0));
    } else {
        final boolean isPlayerRegistered = dataSource.isAuthAvailable(name);
        if (!isPlayerRegistered && registrationCaptchaManager.isCaptchaRequired(name)) {
            checkRegisterCaptcha(player, arguments.get(0));
        } else {
            MessageKey errorMessage = isPlayerRegistered ? MessageKey.USAGE_LOGIN : MessageKey.USAGE_REGISTER;
            commonService.send(player, errorMessage);
        }
    }
}
Also used : MessageKey(fr.xephi.authme.message.MessageKey)

Example 5 with MessageKey

use of fr.xephi.authme.message.MessageKey in project AuthMeReloaded by AuthMe.

the class CommandHandler method sendImproperArgumentsMessage.

private void sendImproperArgumentsMessage(CommandSender sender, FoundCommandResult result) {
    CommandDescription command = result.getCommandDescription();
    if (!permissionsManager.hasPermission(sender, command.getPermission())) {
        messages.send(sender, MessageKey.NO_PERMISSION);
        return;
    }
    ExecutableCommand executableCommand = commands.get(command.getExecutableCommand());
    MessageKey usageMessage = executableCommand.getArgumentsMismatchMessage();
    if (usageMessage == null) {
        showHelpForCommand(sender, result);
    } else {
        messages.send(sender, usageMessage);
    }
}
Also used : MessageKey(fr.xephi.authme.message.MessageKey)

Aggregations

MessageKey (fr.xephi.authme.message.MessageKey)14 File (java.io.File)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 List (java.util.List)3 PropertyReader (ch.jalu.configme.resource.PropertyReader)2 Lists (com.google.common.collect.Lists)2 MessageTask (fr.xephi.authme.task.MessageTask)2 Arrays.asList (java.util.Arrays.asList)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 FileIoUtils (tools.utils.FileIoUtils)2 ToolsConstants (tools.utils.ToolsConstants)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 PropertyListBuilder (ch.jalu.configme.configurationdata.PropertyListBuilder)1 Property (ch.jalu.configme.properties.Property)1 StringProperty (ch.jalu.configme.properties.StringProperty)1