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- ")));
}
}
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;
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations