From 5abc9b9d452c2e39e407086e2b7931e3a2554889 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Sun, 4 Mar 2018 18:36:21 +0100 Subject: [PATCH 01/29] 'session expired' message spam fix --- .../xephi/authme/service/SessionService.java | 24 ++++++++++++------- .../fr/xephi/authme/service/SessionState.java | 13 ++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/service/SessionState.java diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index dd676cc87..87f1bfc7d 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -45,11 +45,12 @@ public class SessionService implements Reloadable { database.setUnlogged(name); database.revokeSession(name); PlayerAuth auth = database.getAuth(name); - if (hasValidSessionData(auth, player)) { + SessionState state = hasValidSessionData(auth, player); + if(state.equals(SessionState.VALID)) { RestoreSessionEvent event = bukkitService.createAndCallEvent( isAsync -> new RestoreSessionEvent(player, isAsync)); return !event.isCancelled(); - } else { + } else if(state.equals(SessionState.IP_CHANGED)) { service.send(player, MessageKey.SESSION_EXPIRED); } } @@ -64,17 +65,24 @@ public class SessionService implements Reloadable { * @param player the associated player * @return true if the player may resume his login session, false otherwise */ - private boolean hasValidSessionData(PlayerAuth auth, Player player) { + private SessionState hasValidSessionData(PlayerAuth auth, Player player) { if (auth == null) { ConsoleLogger.warning("No PlayerAuth in database for '" + player.getName() + "' during session check"); - return false; + return SessionState.NOT_VALID; } else if (auth.getLastLogin() == null) { - return false; + return SessionState.NOT_VALID; } long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin(); - return PlayerUtils.getPlayerIp(player).equals(auth.getLastIp()) - && timeSinceLastLogin > 0 - && timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE; + + if(timeSinceLastLogin > 0 + && timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE) { + if(PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())) { + return SessionState.VALID; + } else { + return SessionState.IP_CHANGED; + } + } + return SessionState.OUTDATED; } public void grantSession(String name) { diff --git a/src/main/java/fr/xephi/authme/service/SessionState.java b/src/main/java/fr/xephi/authme/service/SessionState.java new file mode 100644 index 000000000..801f36bc8 --- /dev/null +++ b/src/main/java/fr/xephi/authme/service/SessionState.java @@ -0,0 +1,13 @@ +package fr.xephi.authme.service; + +public enum SessionState { + + VALID, + + NOT_VALID, + + OUTDATED, + + IP_CHANGED + +} From 9db38a3bf4a840b5685015dd8e43fb12bc1194c3 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Sun, 4 Mar 2018 18:38:46 +0100 Subject: [PATCH 02/29] SessionService#hasValidSessionData description update --- src/main/java/fr/xephi/authme/service/SessionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index 87f1bfc7d..27f31b850 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -63,7 +63,7 @@ public class SessionService implements Reloadable { * * @param auth the player auth * @param player the associated player - * @return true if the player may resume his login session, false otherwise + * @return SessionState based on the state of the session (VALID, NOT_VALID, OUTDATED, IP_CHANGED) */ private SessionState hasValidSessionData(PlayerAuth auth, Player player) { if (auth == null) { From be2c6ae1162f209780ffd4b457d9a577aefb7d17 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Sun, 4 Mar 2018 19:23:08 +0100 Subject: [PATCH 03/29] Fixing tests --- src/main/java/fr/xephi/authme/service/SessionService.java | 1 + .../java/fr/xephi/authme/service/SessionServiceTest.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index 27f31b850..f9f43948e 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -45,6 +45,7 @@ public class SessionService implements Reloadable { database.setUnlogged(name); database.revokeSession(name); PlayerAuth auth = database.getAuth(name); + SessionState state = hasValidSessionData(auth, player); if(state.equals(SessionState.VALID)) { RestoreSessionEvent event = bukkitService.createAndCallEvent( diff --git a/src/test/java/fr/xephi/authme/service/SessionServiceTest.java b/src/test/java/fr/xephi/authme/service/SessionServiceTest.java index 754487c15..441b53561 100644 --- a/src/test/java/fr/xephi/authme/service/SessionServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/SessionServiceTest.java @@ -106,7 +106,6 @@ public class SessionServiceTest { // then assertThat(result, equalTo(false)); verify(commonService).getProperty(PluginSettings.SESSIONS_ENABLED); - verify(commonService).send(player, MessageKey.SESSION_EXPIRED); verify(dataSource).hasSession(name); verify(dataSource).setUnlogged(name); verify(dataSource).revokeSession(name); @@ -132,7 +131,6 @@ public class SessionServiceTest { // then assertThat(result, equalTo(false)); verify(commonService).getProperty(PluginSettings.SESSIONS_ENABLED); - verify(commonService).send(player, MessageKey.SESSION_EXPIRED); verify(dataSource).hasSession(name); verify(dataSource).setUnlogged(name); verify(dataSource).revokeSession(name); @@ -145,9 +143,10 @@ public class SessionServiceTest { String ip = "127.3.12.15"; Player player = mockPlayerWithNameAndIp(name, ip); given(dataSource.hasSession(name)).willReturn(true); + given(commonService.getProperty(PluginSettings.SESSIONS_TIMEOUT)).willReturn(8); PlayerAuth auth = PlayerAuth.builder() .name(name) - .lastLogin(System.currentTimeMillis()) + .lastLogin(System.currentTimeMillis() - 7 * 60 * 1000) .lastIp("8.8.8.8").build(); given(dataSource.getAuth(name)).willReturn(auth); From 57809194f32f0623c26fbd0ceca96d5886851aa8 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Sun, 4 Mar 2018 19:45:05 +0100 Subject: [PATCH 04/29] Renaming function hasValidSessionData -> fetchSessionStatus --- src/main/java/fr/xephi/authme/service/SessionService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index f9f43948e..d530f5855 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -46,7 +46,7 @@ public class SessionService implements Reloadable { database.revokeSession(name); PlayerAuth auth = database.getAuth(name); - SessionState state = hasValidSessionData(auth, player); + SessionState state = fetchSessionStatus(auth, player); if(state.equals(SessionState.VALID)) { RestoreSessionEvent event = bukkitService.createAndCallEvent( isAsync -> new RestoreSessionEvent(player, isAsync)); @@ -66,8 +66,9 @@ public class SessionService implements Reloadable { * @param player the associated player * @return SessionState based on the state of the session (VALID, NOT_VALID, OUTDATED, IP_CHANGED) */ - private SessionState hasValidSessionData(PlayerAuth auth, Player player) { + private SessionState fetchSessionStatus(PlayerAuth auth, Player player) { if (auth == null) { + ConsoleLogger.warning("No PlayerAuth in database for '" + player.getName() + "' during session check"); return SessionState.NOT_VALID; } else if (auth.getLastLogin() == null) { From 00de15016a1eeaba4349fc224c275b66f904b28f Mon Sep 17 00:00:00 2001 From: Maxetto Date: Mon, 5 Mar 2018 19:38:24 +0100 Subject: [PATCH 05/29] Follow remarks #1509 --- .../authme/RegisterAdminCommand.java | 2 +- .../fr/xephi/authme/data/TempbanManager.java | 2 +- .../data/limbo/LimboPlayerTaskManager.java | 4 +- .../xephi/authme/listener/OnJoinVerifier.java | 6 +- .../xephi/authme/listener/PlayerListener.java | 6 +- .../fr/xephi/authme/message/Messages.java | 70 ++++++++++++++----- .../authme/process/join/AsynchronousJoin.java | 4 +- .../process/login/AsynchronousLogin.java | 2 +- .../register/ProcessSyncPasswordRegister.java | 2 +- .../xephi/authme/service/CommonService.java | 4 +- .../authme/RegisterAdminCommandTest.java | 2 +- .../xephi/authme/data/TempbanManagerTest.java | 4 +- .../limbo/LimboPlayerTaskManagerTest.java | 16 ++--- .../authme/listener/OnJoinVerifierTest.java | 6 +- .../authme/listener/PlayerListenerTest.java | 2 +- .../message/MessagesIntegrationTest.java | 47 +++++++++++-- .../authme/service/CommonServiceTest.java | 7 +- .../fr/xephi/authme/message/messages_test.yml | 2 + 18 files changed, 132 insertions(+), 56 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index 0b88227a1..5c28fdc69 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -74,7 +74,7 @@ public class RegisterAdminCommand implements ExecutableCommand { final Player player = bukkitService.getPlayerExact(playerName); if (player != null) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> - player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER))); + player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER, player))); } }); } diff --git a/src/main/java/fr/xephi/authme/data/TempbanManager.java b/src/main/java/fr/xephi/authme/data/TempbanManager.java index a09212bde..288864376 100644 --- a/src/main/java/fr/xephi/authme/data/TempbanManager.java +++ b/src/main/java/fr/xephi/authme/data/TempbanManager.java @@ -97,7 +97,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup { if (isEnabled) { final String name = player.getName(); final String ip = PlayerUtils.getPlayerIp(player); - final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS); + final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player); final Date expires = new Date(); long newTime = expires.getTime() + (length * MILLIS_PER_MINUTE); diff --git a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java index 9b9373e61..2362b7736 100644 --- a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java +++ b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java @@ -51,7 +51,7 @@ class LimboPlayerTaskManager { int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); MessageResult messageResult = getMessageKey(player.getName(), isRegistered); if (interval > 0) { - String[] joinMessage = messages.retrieveSingle(messageResult.messageKey, messageResult.args).split("\n"); + String[] joinMessage = messages.retrieveSingle(messageResult.messageKey, player, messageResult.args).split("\n"); MessageTask messageTask = new MessageTask(player, joinMessage); bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND); limbo.setMessageTask(messageTask); @@ -67,7 +67,7 @@ class LimboPlayerTaskManager { void registerTimeoutTask(Player player, LimboPlayer limbo) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { - String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); + String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); limbo.setTimeoutTask(task); } diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index ffd008059..c10b8fcc5 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -123,7 +123,7 @@ public class OnJoinVerifier implements Reloadable { return false; } else if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) { // Server is full and player is NOT VIP; set kick message and proceed with kick - event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER)); + event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)); return true; } @@ -135,12 +135,12 @@ public class OnJoinVerifier implements Reloadable { } Player nonVipPlayer = generateKickPlayer(onlinePlayers); if (nonVipPlayer != null) { - nonVipPlayer.kickPlayer(messages.retrieveSingle(MessageKey.KICK_FOR_VIP)); + nonVipPlayer.kickPlayer(messages.retrieveSingle(MessageKey.KICK_FOR_VIP, player)); event.allow(); return false; } else { ConsoleLogger.info("VIP player " + player.getName() + " tried to join, but the server was full"); - event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER)); + event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)); return true; } } diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index b4709a564..4d906c58c 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -21,6 +21,8 @@ import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.Server; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -257,7 +259,7 @@ public class PlayerListener implements Listener { try { runOnJoinChecks(JoiningPlayer.fromName(name), event.getAddress().getHostAddress()); } catch (FailedVerificationException e) { - event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs())); + event.setKickMessage(m.retrieveSingle(e.getReason(), name, e.getArgs())); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); } } @@ -285,7 +287,7 @@ public class PlayerListener implements Listener { try { runOnJoinChecks(JoiningPlayer.fromPlayerObject(player), event.getAddress().getHostAddress()); } catch (FailedVerificationException e) { - event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs())); + event.setKickMessage(m.retrieveSingle(e.getReason(), player, e.getArgs())); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); } } diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 7cc0ac285..3d9041111 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -18,7 +18,7 @@ public class Messages { // Custom Authme tag replaced to new line private static final String NEWLINE_TAG = "%nl%"; - private static final String PLAYER_TAG = "%username%"; + private static final String USERNAME_TAG = "%username%"; /** Contains the keys of the singular messages for time units. */ private static final Map TIME_UNIT_SINGULARS = ImmutableMap.builder() @@ -51,9 +51,9 @@ public class Messages { * @param key The key of the message to send */ public void send(CommandSender sender, MessageKey key) { - String[] lines = retrieve(key); + String[] lines = retrieve(key, sender); for (String line : lines) { - sender.sendMessage(line.replaceAll(PLAYER_TAG, sender.getName())); + sender.sendMessage(line); } } @@ -67,7 +67,7 @@ public class Messages { * @param replacements The replacements to apply for the tags */ public void send(CommandSender sender, MessageKey key, String... replacements) { - String message = retrieveSingle(key, replacements).replaceAll(PLAYER_TAG, sender.getName()); + String message = retrieveSingle(key, sender, replacements); for (String line : message.split("\n")) { sender.sendMessage(line); } @@ -77,10 +77,11 @@ public class Messages { * Retrieve the message from the text file and return it split by new line as an array. * * @param key The message key to retrieve + * @param sender The entity to send the message to * @return The message split by new lines */ - public String[] retrieve(MessageKey key) { - String message = retrieveMessage(key); + public String[] retrieve(MessageKey key, CommandSender sender) { + String message = retrieveMessage(key, sender); if (message.isEmpty()) { // Return empty array instead of array with 1 empty string as entry return new String[0]; @@ -101,18 +102,37 @@ public class Messages { ? TIME_UNIT_SINGULARS.get(duration.getTimeUnit()) : TIME_UNIT_PLURALS.get(duration.getTimeUnit()); - return value + " " + retrieveMessage(timeUnitKey); + return value + " " + retrieveMessage(timeUnitKey, ""); } /** * Retrieve the message from the text file. * * @param key The message key to retrieve + * @param sender The entity to send the message to * @return The message from the file */ - private String retrieveMessage(MessageKey key) { - return formatMessage( - messagesFileHandler.getMessage(key.getKey())); + private String retrieveMessage(MessageKey key, CommandSender sender) { + String message = messagesFileHandler.getMessage(key.getKey()); + + return ChatColor.translateAlternateColorCodes('&', message) + .replace(NEWLINE_TAG, "\n") + .replace(USERNAME_TAG, sender.getName()); + } + + /** + * Retrieve the message from the text file. + * + * @param key The message key to retrieve + * @param name The name of the entity to send the message to + * @return The message from the file + */ + private String retrieveMessage(MessageKey key, String name) { + String message = messagesFileHandler.getMessage(key.getKey()); + + return ChatColor.translateAlternateColorCodes('&', message) + .replace(NEWLINE_TAG, "\n") + .replace(USERNAME_TAG, name); } /** @@ -121,11 +141,12 @@ public class Messages { * the message key contains. * * @param key The key of the message to send + * @param sender The entity to send the message to * @param replacements The replacements to apply for the tags * @return The message from the file with replacements */ - public String retrieveSingle(MessageKey key, String... replacements) { - String message = retrieveMessage(key); + public String retrieveSingle(MessageKey key, CommandSender sender, String... replacements) { + String message = retrieveMessage(key, sender); String[] tags = key.getTags(); if (replacements.length == tags.length) { for (int i = 0; i < tags.length; ++i) { @@ -137,9 +158,26 @@ public class Messages { return message; } - private static String formatMessage(String message) { - return ChatColor.translateAlternateColorCodes('&', message) - .replace(NEWLINE_TAG, "\n"); + /** + * Retrieve the given message code with the given tag replacements. Note that this method + * logs an error if the number of supplied replacements doesn't correspond to the number of tags + * the message key contains. + * + * @param key The key of the message to send + * @param name The name of the entity to send the message to + * @param replacements The replacements to apply for the tags + * @return The message from the file with replacements + */ + public String retrieveSingle(MessageKey key, String name, String... replacements) { + String message = retrieveMessage(key, name); + String[] tags = key.getTags(); + if (replacements.length == tags.length) { + for (int i = 0; i < tags.length; ++i) { + message = message.replace(tags[i], replacements[i]); + } + } else { + ConsoleLogger.warning("Invalid number of replacements for message key '" + key + "'"); + } + return message; } - } diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 6cb16a674..da9e5127d 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -138,7 +138,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private void handlePlayerWithUnmetNameRestriction(Player player, String ip) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> { - player.kickPlayer(service.retrieveSingleMessage(MessageKey.NOT_OWNER_ERROR)); + player.kickPlayer(service.retrieveSingleMessage(MessageKey.NOT_OWNER_ERROR, player)); if (service.getProperty(RestrictionSettings.BAN_UNKNOWN_IP)) { server.banIP(ip); } @@ -188,7 +188,7 @@ public class AsynchronousJoin implements AsynchronousProcess { && countOnlinePlayersByIp(ip) > service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask( - () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.SAME_IP_ONLINE))); + () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.SAME_IP_ONLINE, player))); return false; } return true; diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index c52202ef4..2731c59a1 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -197,7 +197,7 @@ public class AsynchronousLogin implements AsynchronousProcess { tempbanManager.tempbanPlayer(player); } else if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask( - () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD))); + () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD, player))); } else { service.send(player, MessageKey.WRONG_PASSWORD); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index 589c88aa2..f59bb28b1 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -58,7 +58,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { // Kick Player after Registration is enabled, kick the player if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) { - player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS)); + player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS, player)); return; } diff --git a/src/main/java/fr/xephi/authme/service/CommonService.java b/src/main/java/fr/xephi/authme/service/CommonService.java index 2422b1fa1..c95171b1c 100644 --- a/src/main/java/fr/xephi/authme/service/CommonService.java +++ b/src/main/java/fr/xephi/authme/service/CommonService.java @@ -66,8 +66,8 @@ public class CommonService { * @param key the key of the message * @return the message */ - public String retrieveSingleMessage(MessageKey key) { - return messages.retrieveSingle(key); + public String retrieveSingleMessage(MessageKey key, CommandSender sender) { + return messages.retrieveSingle(key, sender); } /** diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index ce52ece6b..162de38ac 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -160,7 +160,7 @@ public class RegisterAdminCommandTest { Player player = mock(Player.class); given(bukkitService.getPlayerExact(user)).willReturn(player); String kickForAdminRegister = "Admin registered you -- log in again"; - given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister); + given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER, player)).willReturn(kickForAdminRegister); CommandSender sender = mock(CommandSender.class); setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); setBukkitServiceToRunTaskOptionallyAsync(bukkitService); diff --git a/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java index e5fb70429..5b1da8c7a 100644 --- a/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java @@ -149,7 +149,7 @@ public class TempbanManagerTest { String ip = "123.45.67.89"; TestHelper.mockPlayerIp(player, ip); String banReason = "IP ban too many logins"; - given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason); + given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player)).willReturn(banReason); Settings settings = mockSettings(2, 100, ""); TempbanManager manager = new TempbanManager(bukkitService, messages, settings); setBukkitServiceToScheduleSyncDelayedTask(bukkitService); @@ -195,7 +195,7 @@ public class TempbanManagerTest { String ip = "22.44.66.88"; TestHelper.mockPlayerIp(player, ip); String banReason = "kick msg"; - given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason); + given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player)).willReturn(banReason); Settings settings = mockSettings(10, 60, ""); TempbanManager manager = new TempbanManager(bukkitService, messages, settings); manager.increaseCount(ip, "user"); diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java index 9a8d876ca..79fa4f4dc 100644 --- a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java @@ -71,7 +71,7 @@ public class LimboPlayerTaskManagerTest { Player player = mock(Player.class); LimboPlayer limboPlayer = mock(LimboPlayer.class); MessageKey key = MessageKey.REGISTER_MESSAGE; - given(messages.retrieveSingle(key)).willReturn("Please register!"); + given(messages.retrieveSingle(key, player)).willReturn("Please register!"); int interval = 12; given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(interval); @@ -80,7 +80,7 @@ public class LimboPlayerTaskManagerTest { // then verify(limboPlayer).setMessageTask(any(MessageTask.class)); - verify(messages).retrieveSingle(key); + verify(messages).retrieveSingle(key, player); verify(bukkitService).runTaskTimer( any(MessageTask.class), eq(2L * TICKS_PER_SECOND), eq((long) interval * TICKS_PER_SECOND)); } @@ -110,7 +110,7 @@ public class LimboPlayerTaskManagerTest { MessageTask existingMessageTask = mock(MessageTask.class); limboPlayer.setMessageTask(existingMessageTask); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8); - given(messages.retrieveSingle(MessageKey.REGISTER_MESSAGE)).willReturn("Please register!"); + given(messages.retrieveSingle(MessageKey.REGISTER_MESSAGE, player)).willReturn("Please register!"); // when limboPlayerTaskManager.registerMessageTask(player, limboPlayer, false); @@ -119,7 +119,7 @@ public class LimboPlayerTaskManagerTest { assertThat(limboPlayer.getMessageTask(), not(nullValue())); assertThat(limboPlayer.getMessageTask(), not(sameInstance(existingMessageTask))); verify(registrationCaptchaManager).isCaptchaRequired(name); - verify(messages).retrieveSingle(MessageKey.REGISTER_MESSAGE); + verify(messages).retrieveSingle(MessageKey.REGISTER_MESSAGE, player); verify(existingMessageTask).cancel(); } @@ -134,14 +134,14 @@ public class LimboPlayerTaskManagerTest { given(registrationCaptchaManager.isCaptchaRequired(name)).willReturn(true); String captcha = "M032"; given(registrationCaptchaManager.getCaptchaCodeOrGenerateNew(name)).willReturn(captcha); - given(messages.retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, captcha)).willReturn("Need to use captcha"); + given(messages.retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, player, captcha)).willReturn("Need to use captcha"); // when limboPlayerTaskManager.registerMessageTask(player, limboPlayer, false); // then assertThat(limboPlayer.getMessageTask(), not(nullValue())); - verify(messages).retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, captcha); + verify(messages).retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, player, captcha); } @Test @@ -159,7 +159,7 @@ public class LimboPlayerTaskManagerTest { // then verify(limboPlayer).setTimeoutTask(bukkitTask); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND - verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); + verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); } @Test @@ -194,7 +194,7 @@ public class LimboPlayerTaskManagerTest { verify(existingTask).cancel(); assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask)); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND - verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); + verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); } } diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 7ea3085a6..7d8c95176 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -101,7 +101,7 @@ public class OnJoinVerifierTest { event.setResult(PlayerLoginEvent.Result.KICK_FULL); given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(false); String serverFullMessage = "server is full"; - given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER)).willReturn(serverFullMessage); + given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)).willReturn(serverFullMessage); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); @@ -125,7 +125,7 @@ public class OnJoinVerifierTest { given(permissionsManager.hasPermission(onlinePlayers.get(1), PlayerStatePermission.IS_VIP)).willReturn(false); returnOnlineListFromBukkitServer(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); - given(messages.retrieveSingle(MessageKey.KICK_FOR_VIP)).willReturn("kick for vip"); + given(messages.retrieveSingle(MessageKey.KICK_FOR_VIP, player)).willReturn("kick for vip"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); @@ -149,7 +149,7 @@ public class OnJoinVerifierTest { given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true); returnOnlineListFromBukkitServer(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); - given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER)).willReturn("kick full server"); + given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)).willReturn("kick full server"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); diff --git a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java index d4204315c..9fd750ff7 100644 --- a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java @@ -596,7 +596,7 @@ public class PlayerListenerTest { MessageKey.INVALID_NAME_CHARACTERS, "[a-z]"); doThrow(exception).when(onJoinVerifier).checkIsValidName(name); String message = "Invalid characters!"; - given(messages.retrieveSingle(exception.getReason(), exception.getArgs())).willReturn(message); + given(messages.retrieveSingle(exception.getReason(), player, exception.getArgs())).willReturn(message); // when listener.onPlayerLogin(event); diff --git a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java index 30af10773..69bbfe5d2 100644 --- a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java @@ -81,9 +81,11 @@ public class MessagesIntegrationTest { public void shouldLoadMessageAndSplitAtNewLines() { // given MessageKey key = MessageKey.UNKNOWN_USER; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - String[] message = messages.retrieve(key); + String[] message = messages.retrieve(key, sender); // then String[] lines = new String[]{"We've got", "new lines", "and ' apostrophes"}; @@ -94,9 +96,11 @@ public class MessagesIntegrationTest { public void shouldLoadMessageAsStringWithNewLines() { // given MessageKey key = MessageKey.UNKNOWN_USER; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - String message = messages.retrieveSingle(key); + String message = messages.retrieveSingle(key, sender); // then assertThat(message, equalTo("We've got\nnew lines\nand ' apostrophes")); @@ -106,9 +110,11 @@ public class MessagesIntegrationTest { public void shouldFormatColorCodes() { // given MessageKey key = MessageKey.LOGIN_SUCCESS; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - String[] message = messages.retrieve(key); + String[] message = messages.retrieve(key, sender); // then assertThat(message, arrayWithSize(1)); @@ -120,6 +126,7 @@ public class MessagesIntegrationTest { // given MessageKey key = MessageKey.EMAIL_ALREADY_USED_ERROR; CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when messages.send(sender, key); @@ -133,6 +140,7 @@ public class MessagesIntegrationTest { // given MessageKey key = MessageKey.LOGIN_SUCCESS; Player player = Mockito.mock(Player.class); + given(player.getName()).willReturn("Tester"); // when messages.send(player, key); @@ -146,6 +154,7 @@ public class MessagesIntegrationTest { // given MessageKey key = MessageKey.UNKNOWN_USER; Player player = Mockito.mock(Player.class); + given(player.getName()).willReturn("Tester"); // when messages.send(player, key); @@ -157,11 +166,26 @@ public class MessagesIntegrationTest { assertThat(captor.getAllValues(), contains(lines)); } + @Test + public void shouldSendMessageToPlayerWithNameReplacement() { + // given + MessageKey key = MessageKey.REGISTER_MESSAGE; + Player player = Mockito.mock(Player.class); + given(player.getName()).willReturn("Tester"); + + // when + messages.send(player, key); + + // then + verify(player).sendMessage("§3Please Tester, register to the server with the command: /register "); + } + @Test public void shouldSendMessageToPlayerWithTagReplacement() { // given MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR; CommandSender sender = Mockito.mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when messages.send(sender, key, "1234"); @@ -175,6 +199,7 @@ public class MessagesIntegrationTest { // given MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR; CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when messages.send(sender, key); @@ -189,9 +214,11 @@ public class MessagesIntegrationTest { Logger logger = mock(Logger.class); ConsoleLogger.setLogger(logger); MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - messages.send(mock(CommandSender.class), key, "rep", "rep2"); + messages.send(sender, key, "rep", "rep2"); // then verify(logger).warning(argThat(containsString("Invalid number of replacements"))); @@ -203,9 +230,11 @@ public class MessagesIntegrationTest { Logger logger = mock(Logger.class); ConsoleLogger.setLogger(logger); MessageKey key = MessageKey.UNKNOWN_USER; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - messages.send(mock(CommandSender.class), key, "Replacement"); + messages.send(sender, key, "Replacement"); // then verify(logger).warning(argThat(containsString("Invalid number of replacements"))); @@ -216,9 +245,11 @@ public class MessagesIntegrationTest { // given // Key is present in both files MessageKey key = MessageKey.WRONG_PASSWORD; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - String message = messages.retrieveSingle(key); + String message = messages.retrieveSingle(key, sender); // then assertThat(message, equalTo("§cWrong password!")); @@ -228,9 +259,11 @@ public class MessagesIntegrationTest { public void shouldRetrieveMessageWithReplacements() { // given MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR; + CommandSender sender = mock(CommandSender.class); + given(sender.getName()).willReturn("Tester"); // when - String result = messages.retrieveSingle(key, "24680"); + String result = messages.retrieveSingle(key, sender.getName(), "24680"); // then assertThat(result, equalTo("Use /captcha 24680 to solve the captcha")); diff --git a/src/test/java/fr/xephi/authme/service/CommonServiceTest.java b/src/test/java/fr/xephi/authme/service/CommonServiceTest.java index 87cba2005..e4ff2817b 100644 --- a/src/test/java/fr/xephi/authme/service/CommonServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/CommonServiceTest.java @@ -83,15 +83,16 @@ public class CommonServiceTest { public void shouldRetrieveSingleMessage() { // given MessageKey key = MessageKey.ACCOUNT_NOT_ACTIVATED; + Player player = mock(Player.class); String text = "Test text"; - given(messages.retrieveSingle(key)).willReturn(text); + given(messages.retrieveSingle(key, player)).willReturn(text); // when - String result = commonService.retrieveSingleMessage(key); + String result = commonService.retrieveSingleMessage(key, player); // then assertThat(result, equalTo(text)); - verify(messages).retrieveSingle(key); + verify(messages).retrieveSingle(key, player); } @Test diff --git a/src/test/resources/fr/xephi/authme/message/messages_test.yml b/src/test/resources/fr/xephi/authme/message/messages_test.yml index b7670dc2d..86b38986e 100644 --- a/src/test/resources/fr/xephi/authme/message/messages_test.yml +++ b/src/test/resources/fr/xephi/authme/message/messages_test.yml @@ -2,6 +2,8 @@ error: unregistered_user: 'We''ve got%nl%new lines%nl%and '' apostrophes' +registration: + register_request: '&3Please %username%, register to the server with the command: /register ' login: success: '&cHere we have&bdefined some colors &dand some other <hings' wrong_password: '&cWrong password!' From f9d1a3aef2a144fce8c7c26b9f7146bca2a36414 Mon Sep 17 00:00:00 2001 From: Maxetto Date: Mon, 5 Mar 2018 19:42:43 +0100 Subject: [PATCH 06/29] Those were not meant to be there --- src/main/java/fr/xephi/authme/listener/PlayerListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 4d906c58c..6482cd637 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -21,8 +21,6 @@ import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.Server; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; From 11d039c818861d2bb3f83f188d0b464998051e23 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Mon, 5 Mar 2018 20:20:25 +0100 Subject: [PATCH 07/29] space after 'if'(s) --- .../java/fr/xephi/authme/service/SessionService.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/SessionService.java b/src/main/java/fr/xephi/authme/service/SessionService.java index d530f5855..f821a64b3 100644 --- a/src/main/java/fr/xephi/authme/service/SessionService.java +++ b/src/main/java/fr/xephi/authme/service/SessionService.java @@ -47,11 +47,11 @@ public class SessionService implements Reloadable { PlayerAuth auth = database.getAuth(name); SessionState state = fetchSessionStatus(auth, player); - if(state.equals(SessionState.VALID)) { + if (state.equals(SessionState.VALID)) { RestoreSessionEvent event = bukkitService.createAndCallEvent( isAsync -> new RestoreSessionEvent(player, isAsync)); return !event.isCancelled(); - } else if(state.equals(SessionState.IP_CHANGED)) { + } else if (state.equals(SessionState.IP_CHANGED)) { service.send(player, MessageKey.SESSION_EXPIRED); } } @@ -68,7 +68,6 @@ public class SessionService implements Reloadable { */ private SessionState fetchSessionStatus(PlayerAuth auth, Player player) { if (auth == null) { - ConsoleLogger.warning("No PlayerAuth in database for '" + player.getName() + "' during session check"); return SessionState.NOT_VALID; } else if (auth.getLastLogin() == null) { @@ -76,9 +75,9 @@ public class SessionService implements Reloadable { } long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin(); - if(timeSinceLastLogin > 0 + if (timeSinceLastLogin > 0 && timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE) { - if(PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())) { + if (PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())) { return SessionState.VALID; } else { return SessionState.IP_CHANGED; From 9b7139a17a0df1030f4cda32c8bf170d74ffb909 Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 7 Mar 2018 19:08:36 +0100 Subject: [PATCH 08/29] Add Display Name tag replacement too #1509 --- .../fr/xephi/authme/message/Messages.java | 13 +++++++-- src/main/resources/messages/messages_bg.yml | 5 ++++ src/main/resources/messages/messages_br.yml | 4 +++ src/main/resources/messages/messages_cz.yml | 5 ++++ src/main/resources/messages/messages_de.yml | 5 ++++ src/main/resources/messages/messages_en.yml | 5 ++++ src/main/resources/messages/messages_eo.yml | 5 ++++ src/main/resources/messages/messages_es.yml | 4 +++ src/main/resources/messages/messages_et.yml | 5 ++++ src/main/resources/messages/messages_eu.yml | 5 ++++ src/main/resources/messages/messages_fi.yml | 5 ++++ src/main/resources/messages/messages_fr.yml | 5 +++- src/main/resources/messages/messages_gl.yml | 5 ++++ src/main/resources/messages/messages_hu.yml | 5 ++++ src/main/resources/messages/messages_id.yml | 5 ++++ src/main/resources/messages/messages_it.yml | 28 +++++++++++-------- src/main/resources/messages/messages_ko.yml | 4 +++ src/main/resources/messages/messages_lt.yml | 5 ++++ src/main/resources/messages/messages_nl.yml | 5 ++++ src/main/resources/messages/messages_pl.yml | 5 ++++ src/main/resources/messages/messages_pt.yml | 5 ++++ src/main/resources/messages/messages_ro.yml | 5 ++++ src/main/resources/messages/messages_ru.yml | 5 ++++ src/main/resources/messages/messages_sk.yml | 4 +++ src/main/resources/messages/messages_tr.yml | 5 ++++ src/main/resources/messages/messages_uk.yml | 5 ++++ src/main/resources/messages/messages_vn.yml | 5 ++++ src/main/resources/messages/messages_zhcn.yml | 5 ++++ src/main/resources/messages/messages_zhhk.yml | 4 +++ src/main/resources/messages/messages_zhmc.yml | 5 ++++ src/main/resources/messages/messages_zhtw.yml | 4 +++ 31 files changed, 165 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 3d9041111..4439a1b7d 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.util.expiring.Duration; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import javax.inject.Inject; import java.util.Map; @@ -18,7 +19,9 @@ public class Messages { // Custom Authme tag replaced to new line private static final String NEWLINE_TAG = "%nl%"; + // Global tag replacements private static final String USERNAME_TAG = "%username%"; + private static final String DISPLAYNAME_TAG = "%displayname%"; /** Contains the keys of the singular messages for time units. */ private static final Map TIME_UNIT_SINGULARS = ImmutableMap.builder() @@ -114,10 +117,15 @@ public class Messages { */ private String retrieveMessage(MessageKey key, CommandSender sender) { String message = messagesFileHandler.getMessage(key.getKey()); + String displayName = sender.getName(); + if (sender instanceof Player) { + displayName = ((Player) sender).getDisplayName(); + } return ChatColor.translateAlternateColorCodes('&', message) .replace(NEWLINE_TAG, "\n") - .replace(USERNAME_TAG, sender.getName()); + .replace(USERNAME_TAG, sender.getName()) + .replace(DISPLAYNAME_TAG, displayName); } /** @@ -132,7 +140,8 @@ public class Messages { return ChatColor.translateAlternateColorCodes('&', message) .replace(NEWLINE_TAG, "\n") - .replace(USERNAME_TAG, name); + .replace(USERNAME_TAG, name) + .replace(DISPLAYNAME_TAG, name); } /** diff --git a/src/main/resources/messages/messages_bg.yml b/src/main/resources/messages/messages_bg.yml index ee21f3f57..c49e2cb00 100644 --- a/src/main/resources/messages/messages_bg.yml +++ b/src/main/resources/messages/messages_bg.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cРегистрациите са изключени!' diff --git a/src/main/resources/messages/messages_br.yml b/src/main/resources/messages/messages_br.yml index 05d8aa6f8..3000840bb 100644 --- a/src/main/resources/messages/messages_br.yml +++ b/src/main/resources/messages/messages_br.yml @@ -1,6 +1,10 @@ #Tradução pt/br Authme Reloaded #Feito por GabrielDev(DeathRush) e Frani (PotterCraft_) # http://gamersboard.com.br/ | www.magitechserver.com +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_cz.yml b/src/main/resources/messages/messages_cz.yml index 0b0e9e02a..3b97a5aec 100644 --- a/src/main/resources/messages/messages_cz.yml +++ b/src/main/resources/messages/messages_cz.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRegistrace je zakázána!' diff --git a/src/main/resources/messages/messages_de.yml b/src/main/resources/messages/messages_de.yml index 18693d476..108d7dad8 100644 --- a/src/main/resources/messages/messages_de.yml +++ b/src/main/resources/messages/messages_de.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRegistrierungen sind deaktiviert' diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index f2aa1d44a..e5e20055a 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: register_request: '&3Please, register to the server with the command: /register ' diff --git a/src/main/resources/messages/messages_eo.yml b/src/main/resources/messages/messages_eo.yml index f438b19da..dd1657728 100644 --- a/src/main/resources/messages/messages_eo.yml +++ b/src/main/resources/messages/messages_eo.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cEn-ludo registriĝo estas malebligita!' diff --git a/src/main/resources/messages/messages_es.yml b/src/main/resources/messages/messages_es.yml index 9a87984d2..ce0d8a369 100644 --- a/src/main/resources/messages/messages_es.yml +++ b/src/main/resources/messages/messages_es.yml @@ -1,4 +1,8 @@ # This file must be in ANSI if win, or UTF-8 if linux. +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_et.yml b/src/main/resources/messages/messages_et.yml index 3696593c1..df6bd053c 100644 --- a/src/main/resources/messages/messages_et.yml +++ b/src/main/resources/messages/messages_et.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cMängusisene registreerimine välja lülitatud!' diff --git a/src/main/resources/messages/messages_eu.yml b/src/main/resources/messages/messages_eu.yml index b7782ee3a..4eec94c34 100644 --- a/src/main/resources/messages/messages_eu.yml +++ b/src/main/resources/messages/messages_eu.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cErregistroa desgaitua' diff --git a/src/main/resources/messages/messages_fi.yml b/src/main/resources/messages/messages_fi.yml index 5e88b4c1e..9a6578bdd 100644 --- a/src/main/resources/messages/messages_fi.yml +++ b/src/main/resources/messages/messages_fi.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRekisteröinti on suljettu!' diff --git a/src/main/resources/messages/messages_fr.yml b/src/main/resources/messages/messages_fr.yml index 47e01f2db..93358b2e8 100644 --- a/src/main/resources/messages/messages_fr.yml +++ b/src/main/resources/messages/messages_fr.yml @@ -1,7 +1,10 @@ # Traduction par: André & Twonox # Pour afficher une apostrophe, vous devez en mettre deux consécutivement (ex: «J''ai» au lieu de «J'ai») -# Pour passer à la ligne, utilisez: %nl% +# List of global tags: +# %nl% - Pour passer à la ligne. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_gl.yml b/src/main/resources/messages/messages_gl.yml index 11210f4e9..9c47a222d 100644 --- a/src/main/resources/messages/messages_gl.yml +++ b/src/main/resources/messages/messages_gl.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cO rexistro está deshabilitado' diff --git a/src/main/resources/messages/messages_hu.yml b/src/main/resources/messages/messages_hu.yml index ea2837122..609545976 100644 --- a/src/main/resources/messages/messages_hu.yml +++ b/src/main/resources/messages/messages_hu.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cA regisztráció letiltva!' diff --git a/src/main/resources/messages/messages_id.yml b/src/main/resources/messages/messages_id.yml index 00899b1e3..9fda2668d 100644 --- a/src/main/resources/messages/messages_id.yml +++ b/src/main/resources/messages/messages_id.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRegister dalam game tidak diaktifkan!' diff --git a/src/main/resources/messages/messages_it.yml b/src/main/resources/messages/messages_it.yml index 570971f87..40b0059ec 100644 --- a/src/main/resources/messages/messages_it.yml +++ b/src/main/resources/messages/messages_it.yml @@ -1,6 +1,10 @@ -# Lingua Italiana creata da Maxetto e sgdc3. +# Lingua Italiana creata da Maxetto. +# Tag globali disponibili: +# %nl% - Vai a capo. +# %username% - Sostituisce il nome dell'utente che riceve il messaggio. +# %displayname% - Sostituisce il nickname (e i colori) dell'utente che riceve il messaggio. -# Registration +# Registrazione registration: disabled: '&cLa registrazione tramite i comandi di gioco è disabilitata.' name_taken: '&cHai già eseguito la registrazione, non puoi eseguirla nuovamente.' @@ -10,7 +14,7 @@ registration: success: '&2Registrato correttamente!' kicked_admin_registered: 'Un amministratore ti ha appena registrato, per favore rientra nel server' -# Password errors on registration +# Errori della password durante la registrazione password: match_error: '&cLe password non corrispondono!' name_in_password: '&cNon puoi usare il tuo nome utente come password, per favore scegline un''altra...' @@ -18,7 +22,7 @@ password: forbidden_characters: '&4La tua password contiene caratteri non consentiti. I caratteri consentiti sono: %valid_chars' wrong_length: '&cLa password che hai inserito è troppo corta o troppo lunga, per favore scegline un''altra...' -# Login +# Autenticazione login: command_usage: '&cUtilizzo: /login ' wrong_password: '&cPassword non corretta!' @@ -26,7 +30,7 @@ login: login_request: '&cPer favore, esegui l''autenticazione con il comando: /login ' timeout_error: '&4Tempo scaduto per eseguire l''autenticazione, sei stato espulso dal server, per favore riprova!' -# Errors +# Errori error: denied_command: '&cPer poter usare questo comando devi essere autenticato!' denied_chat: '&cPer poter scrivere messaggi in chat devi essere autenticato!' @@ -45,12 +49,12 @@ antibot: auto_enabled: '&4Il servizio di AntiBot è stato automaticamente abilitato a seguito delle numerose connessioni!' auto_disabled: '&2Il servizio di AntiBot è stato automaticamente disabilitato dopo %m minuti!' -# Unregister +# Rimozione dal Database unregister: success: '&2Sei stato correttamente rimosso dal database!' command_usage: '&cUtilizzo: /unregister ' -# Other messages +# Altri messaggi misc: account_not_activated: '&cIl tuo account non è stato ancora verificato, controlla fra le tue email per scoprire come attivarlo!' password_changed: '&2Password cambiata correttamente!' @@ -61,12 +65,12 @@ misc: accounts_owned_self: 'Possiedi %count account:' accounts_owned_other: 'Il giocatore %name possiede %count account:' -# Session messages +# Messaggi della sessione session: valid_session: '&2Autenticato automaticamente attraverso la precedente sessione!' invalid_session: '&cIl tuo indirizzo IP è cambiato e la tua sessione è stata terminata!' -# Error messages when joining +# Messaggi di errore durante l'accesso on_join_validation: same_ip_online: 'Un giocatore con il tuo stesso IP è già connesso sul server!' same_nick_online: '&4Un giocatore con il tuo stesso nome utente è già connesso sul server!' @@ -96,7 +100,7 @@ email: change_password_expired: 'Non puoi più cambiare la tua password con questo comando.' email_cooldown_error: '&cUna email di recupero ti è già stata inviata recentemente. Devi attendere %time prima di poterne richiedere una nuova.' -# Password recovery by email +# Recupero password via Email recovery: forgot_password_hint: '&3Hai dimenticato la tua password? Puoi recuperarla eseguendo il comando: /email recovery ' command_usage: '&cUtilizzo: /email recovery ' @@ -116,7 +120,7 @@ captcha: captcha_for_registration: 'Per poterti registrare devi prima risolvere un captcha, per favore scrivi: /captcha %captcha_code' register_captcha_valid: '&2Il captcha inserito è valido! Ora puoi eseguire la registrazione con: /register ' -# Verification code +# Codice di verifica verification: code_required: '&3Questo comando va a modificare dati sensibili e richiede una verifica tramite email! Controlla la tua posta in arrivo e segui le istruzioni nell''email.' command_usage: '&cUtilizzo: /verification ' @@ -126,7 +130,7 @@ verification: code_expired: '&3Il tuo codice è scaduto! Esegui nuovamente un comando che modifica dati sensibili per ricevere uno nuovo codice!' email_needed: '&3Per verificare la tua identità devi collegare un indirizzo email al tuo account!' -# Time units +# Unità di tempo time: second: 'secondo' seconds: 'secondi' diff --git a/src/main/resources/messages/messages_ko.yml b/src/main/resources/messages/messages_ko.yml index 0713fcb51..f934f4ccb 100644 --- a/src/main/resources/messages/messages_ko.yml +++ b/src/main/resources/messages/messages_ko.yml @@ -1,5 +1,9 @@ #Translated by Kirito (kds123321@naver.com), System32(me@syst32.com), Adeuran(adeuran@tistory.com) #14.05.2017 Thanks for use +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_lt.yml b/src/main/resources/messages/messages_lt.yml index 091903d88..2952d4497 100644 --- a/src/main/resources/messages/messages_lt.yml +++ b/src/main/resources/messages/messages_lt.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&6Registracija yra isjungta' diff --git a/src/main/resources/messages/messages_nl.yml b/src/main/resources/messages/messages_nl.yml index 634c92b1e..00b290de9 100644 --- a/src/main/resources/messages/messages_nl.yml +++ b/src/main/resources/messages/messages_nl.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRegistratie is uitgeschakeld!' diff --git a/src/main/resources/messages/messages_pl.yml b/src/main/resources/messages/messages_pl.yml index b5050fc87..427ad302b 100644 --- a/src/main/resources/messages/messages_pl.yml +++ b/src/main/resources/messages/messages_pl.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&4Rejestracja jest wyłączona.' diff --git a/src/main/resources/messages/messages_pt.yml b/src/main/resources/messages/messages_pt.yml index b0f707e28..fe41dd553 100644 --- a/src/main/resources/messages/messages_pt.yml +++ b/src/main/resources/messages/messages_pt.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cRegisto de novos utilizadores desactivado' diff --git a/src/main/resources/messages/messages_ro.yml b/src/main/resources/messages/messages_ro.yml index 874e70ee3..16b144497 100644 --- a/src/main/resources/messages/messages_ro.yml +++ b/src/main/resources/messages/messages_ro.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cInregistrarea in joc nu este activata!' diff --git a/src/main/resources/messages/messages_ru.yml b/src/main/resources/messages/messages_ru.yml index de31b258f..82d9d48e0 100644 --- a/src/main/resources/messages/messages_ru.yml +++ b/src/main/resources/messages/messages_ru.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cРегистрация отключена.' diff --git a/src/main/resources/messages/messages_sk.yml b/src/main/resources/messages/messages_sk.yml index deb03a8f7..030e721d7 100644 --- a/src/main/resources/messages/messages_sk.yml +++ b/src/main/resources/messages/messages_sk.yml @@ -4,6 +4,10 @@ # in future there can be more translators # # if they are not listed here # # check Translators on GitHub Wiki. # +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_tr.yml b/src/main/resources/messages/messages_tr.yml index 94ac23086..119f037e3 100644 --- a/src/main/resources/messages/messages_tr.yml +++ b/src/main/resources/messages/messages_tr.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cOyun icin kayit olma kapatildi!' diff --git a/src/main/resources/messages/messages_uk.yml b/src/main/resources/messages/messages_uk.yml index d5f448fb9..a1579c303 100644 --- a/src/main/resources/messages/messages_uk.yml +++ b/src/main/resources/messages/messages_uk.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cВнутрішньоігрову реєстрацію зараз вимкнено.' diff --git a/src/main/resources/messages/messages_vn.yml b/src/main/resources/messages/messages_vn.yml index 03190e9bb..61bbda945 100644 --- a/src/main/resources/messages/messages_vn.yml +++ b/src/main/resources/messages/messages_vn.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&cKhông cho phép đăng ký tài khoản trong máy chủ!' diff --git a/src/main/resources/messages/messages_zhcn.yml b/src/main/resources/messages/messages_zhcn.yml index c4032e30a..d53a44486 100644 --- a/src/main/resources/messages/messages_zhcn.yml +++ b/src/main/resources/messages/messages_zhcn.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&8[&6玩家系统&8] &c目前服务器暂时禁止注册,请到服务器论坛以得到更多资讯' diff --git a/src/main/resources/messages/messages_zhhk.yml b/src/main/resources/messages/messages_zhhk.yml index 002a52d5f..ae29c65b1 100644 --- a/src/main/resources/messages/messages_zhhk.yml +++ b/src/main/resources/messages/messages_zhhk.yml @@ -1,6 +1,10 @@ # Translator: lifehome # # Last modif: 1508689979 UTC # # -------------------------------------------- # +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: diff --git a/src/main/resources/messages/messages_zhmc.yml b/src/main/resources/messages/messages_zhmc.yml index 6d811c4eb..76fa6ccc4 100644 --- a/src/main/resources/messages/messages_zhmc.yml +++ b/src/main/resources/messages/messages_zhmc.yml @@ -1,3 +1,8 @@ +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. + # Registration registration: disabled: '&c遊戲內註冊已停用!' diff --git a/src/main/resources/messages/messages_zhtw.yml b/src/main/resources/messages/messages_zhtw.yml index 2cfff1379..91696b5d8 100644 --- a/src/main/resources/messages/messages_zhtw.yml +++ b/src/main/resources/messages/messages_zhtw.yml @@ -1,5 +1,9 @@ # Translators: MineWolf50, lifehome, haer0248 # # -------------------------------------------- # +# List of global tags: +# %nl% - Goes to new line. +# %username% - Replaces the username of the player receiving the message. +# %displayname% - Replaces the nickname (and colors) of the player receiving the message. # Registration registration: From bc4cb5046dcaa3537832aafc4cd15deb33ddea8e Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 7 Mar 2018 19:29:24 +0100 Subject: [PATCH 09/29] Fix yet another build --- .../fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java | 4 ++-- src/main/java/fr/xephi/authme/message/Messages.java | 2 +- src/main/java/fr/xephi/authme/service/CommonService.java | 1 + .../fr/xephi/authme/message/MessagesIntegrationTest.java | 5 ++++- src/test/resources/fr/xephi/authme/message/messages_test.yml | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java index 2362b7736..f8e2e7baf 100644 --- a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java +++ b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java @@ -49,9 +49,9 @@ class LimboPlayerTaskManager { */ void registerMessageTask(Player player, LimboPlayer limbo, boolean isRegistered) { int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); - MessageResult messageResult = getMessageKey(player.getName(), isRegistered); + MessageResult result = getMessageKey(player.getName(), isRegistered); if (interval > 0) { - String[] joinMessage = messages.retrieveSingle(messageResult.messageKey, player, messageResult.args).split("\n"); + String[] joinMessage = messages.retrieveSingle(result.messageKey, player, result.args).split("\n"); MessageTask messageTask = new MessageTask(player, joinMessage); bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND); limbo.setMessageTask(messageTask); diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 4439a1b7d..13017b3a8 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -116,7 +116,7 @@ public class Messages { * @return The message from the file */ private String retrieveMessage(MessageKey key, CommandSender sender) { - String message = messagesFileHandler.getMessage(key.getKey()); + String message = messagesFileHandler.getMessage(key.getKey()); String displayName = sender.getName(); if (sender instanceof Player) { displayName = ((Player) sender).getDisplayName(); diff --git a/src/main/java/fr/xephi/authme/service/CommonService.java b/src/main/java/fr/xephi/authme/service/CommonService.java index c95171b1c..ea63c58e1 100644 --- a/src/main/java/fr/xephi/authme/service/CommonService.java +++ b/src/main/java/fr/xephi/authme/service/CommonService.java @@ -64,6 +64,7 @@ public class CommonService { * Retrieves a message in one piece. * * @param key the key of the message + * @param sender The entity to send the message to * @return the message */ public String retrieveSingleMessage(MessageKey key, CommandSender sender) { diff --git a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java index 69bbfe5d2..125ad36af 100644 --- a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java @@ -141,6 +141,7 @@ public class MessagesIntegrationTest { MessageKey key = MessageKey.LOGIN_SUCCESS; Player player = Mockito.mock(Player.class); given(player.getName()).willReturn("Tester"); + given(player.getDisplayName()).willReturn("§cTesty"); // when messages.send(player, key); @@ -155,6 +156,7 @@ public class MessagesIntegrationTest { MessageKey key = MessageKey.UNKNOWN_USER; Player player = Mockito.mock(Player.class); given(player.getName()).willReturn("Tester"); + given(player.getDisplayName()).willReturn("§cTesty"); // when messages.send(player, key); @@ -172,12 +174,13 @@ public class MessagesIntegrationTest { MessageKey key = MessageKey.REGISTER_MESSAGE; Player player = Mockito.mock(Player.class); given(player.getName()).willReturn("Tester"); + given(player.getDisplayName()).willReturn("§cTesty"); // when messages.send(player, key); // then - verify(player).sendMessage("§3Please Tester, register to the server with the command: /register "); + verify(player).sendMessage("§3Please Tester, register to the §cTesty§3."); } @Test diff --git a/src/test/resources/fr/xephi/authme/message/messages_test.yml b/src/test/resources/fr/xephi/authme/message/messages_test.yml index 86b38986e..93287786a 100644 --- a/src/test/resources/fr/xephi/authme/message/messages_test.yml +++ b/src/test/resources/fr/xephi/authme/message/messages_test.yml @@ -3,7 +3,7 @@ error: unregistered_user: 'We''ve got%nl%new lines%nl%and '' apostrophes' registration: - register_request: '&3Please %username%, register to the server with the command: /register ' + register_request: '&3Please %username%, register to the %displayname%&3.' login: success: '&cHere we have&bdefined some colors &dand some other <hings' wrong_password: '&cWrong password!' From 7a3e2e9f71089147dfe8056838c5e33f49289169 Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 7 Mar 2018 19:37:20 +0100 Subject: [PATCH 10/29] Use spaces instead of tabs --- .../fr/xephi/authme/message/Messages.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 13017b3a8..69be2687e 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -117,15 +117,15 @@ public class Messages { */ private String retrieveMessage(MessageKey key, CommandSender sender) { String message = messagesFileHandler.getMessage(key.getKey()); - String displayName = sender.getName(); - if (sender instanceof Player) { - displayName = ((Player) sender).getDisplayName(); - } - - return ChatColor.translateAlternateColorCodes('&', message) - .replace(NEWLINE_TAG, "\n") - .replace(USERNAME_TAG, sender.getName()) - .replace(DISPLAYNAME_TAG, displayName); + String displayName = sender.getName(); + if (sender instanceof Player) { + displayName = ((Player) sender).getDisplayName(); + } + + return ChatColor.translateAlternateColorCodes('&', message) + .replace(NEWLINE_TAG, "\n") + .replace(USERNAME_TAG, sender.getName()) + .replace(DISPLAYNAME_TAG, displayName); } /** @@ -136,12 +136,12 @@ public class Messages { * @return The message from the file */ private String retrieveMessage(MessageKey key, String name) { - String message = messagesFileHandler.getMessage(key.getKey()); - - return ChatColor.translateAlternateColorCodes('&', message) - .replace(NEWLINE_TAG, "\n") - .replace(USERNAME_TAG, name) - .replace(DISPLAYNAME_TAG, name); + String message = messagesFileHandler.getMessage(key.getKey()); + + return ChatColor.translateAlternateColorCodes('&', message) + .replace(NEWLINE_TAG, "\n") + .replace(USERNAME_TAG, name) + .replace(DISPLAYNAME_TAG, name); } /** From 586b98f74ff2420dcd3b712998d3386797345b59 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 7 Mar 2018 23:19:27 +0100 Subject: [PATCH 11/29] Update CI and repository links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee54889dc..48ee415a1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - [Discord](https://discord.gg/Vn9eCyE) - CI Services: - - [Official Jenkins](http://ci.xephi.fr/job/AuthMeReloaded) (**DEVELOPMENT BUILDS**) +  - Jenkins: [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/AuthMeReloaded) (**DEVELOPMENT BUILDS**) - CircleCI: [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) - Project status: @@ -19,8 +19,8 @@ - Code climate: [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) - Development resources: - - JavaDocs - - Maven Repository +  - JavaDocs +  - Maven Repository - Statistics: - bStats: [AuthMe on bstats.org](https://bstats.org/plugin/bukkit/AuthMe) From d80a9b27cb915e4e7a27e8a4b6b454ffc8e15cf1 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 7 Mar 2018 23:41:28 +0100 Subject: [PATCH 12/29] Try to fix javadocs generation --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 56ef29401..3f0f4610c 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,7 @@ attach-javadocs - aggregate + javadoc jar From e67255c50562d8d7fb7d138731881f01d24a0456 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 7 Mar 2018 23:45:08 +0100 Subject: [PATCH 13/29] Fix link markdown --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 48ee415a1..5c60afb50 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - [Discord](https://discord.gg/Vn9eCyE) - CI Services: -  - Jenkins: [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/AuthMeReloaded) (**DEVELOPMENT BUILDS**) + - Jenkins: [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/AuthMeReloaded) (**DEVELOPMENT BUILDS**) - CircleCI: [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) - Project status: @@ -19,8 +19,8 @@ - Code climate: [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) - Development resources: -  - JavaDocs -  - Maven Repository + - JavaDocs + - Maven Repository - Statistics: - bStats: [AuthMe on bstats.org](https://bstats.org/plugin/bukkit/AuthMe) From 6ddfa3fd2bc5b547eedf31c741944d3c9ec36d73 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Thu, 8 Mar 2018 01:24:28 +0100 Subject: [PATCH 14/29] [CI-SKIP] Add bStats graph image --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5c60afb50..7d5a5f767 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ - Statistics: - bStats: [AuthMe on bstats.org](https://bstats.org/plugin/bukkit/AuthMe) + ![Graph](https://bstats.org/signatures/bukkit/AuthMe.svg)
From 1a53cd11b2caa770ebb47262ed804e575670156c Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 10 Mar 2018 16:58:30 +0100 Subject: [PATCH 15/29] #829 Move CommandSender / name to first argument to avoid confusion with varargs - Overloaded method with (String, String...) as args was problematic as it could be confusing on its own and also confusing with the (CommandSender, String...) flavor --- .../executable/authme/RegisterAdminCommand.java | 2 +- .../fr/xephi/authme/data/TempbanManager.java | 2 +- .../data/limbo/LimboPlayerTaskManager.java | 4 ++-- .../fr/xephi/authme/listener/OnJoinVerifier.java | 6 +++--- .../fr/xephi/authme/listener/PlayerListener.java | 4 ++-- .../java/fr/xephi/authme/message/Messages.java | 10 +++++----- .../authme/process/join/AsynchronousJoin.java | 4 ++-- .../authme/process/login/AsynchronousLogin.java | 2 +- .../register/ProcessSyncPasswordRegister.java | 2 +- .../fr/xephi/authme/service/CommonService.java | 6 +++--- .../authme/RegisterAdminCommandTest.java | 2 +- .../fr/xephi/authme/data/TempbanManagerTest.java | 4 ++-- .../data/limbo/LimboPlayerTaskManagerTest.java | 16 ++++++++-------- .../authme/listener/OnJoinVerifierTest.java | 6 +++--- .../authme/listener/PlayerListenerTest.java | 2 +- .../authme/message/MessagesIntegrationTest.java | 6 +++--- .../xephi/authme/service/CommonServiceTest.java | 6 +++--- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index 5c28fdc69..e05089da8 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -74,7 +74,7 @@ public class RegisterAdminCommand implements ExecutableCommand { final Player player = bukkitService.getPlayerExact(playerName); if (player != null) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> - player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER, player))); + player.kickPlayer(commonService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER))); } }); } diff --git a/src/main/java/fr/xephi/authme/data/TempbanManager.java b/src/main/java/fr/xephi/authme/data/TempbanManager.java index 288864376..e6b685aca 100644 --- a/src/main/java/fr/xephi/authme/data/TempbanManager.java +++ b/src/main/java/fr/xephi/authme/data/TempbanManager.java @@ -97,7 +97,7 @@ public class TempbanManager implements SettingsDependent, HasCleanup { if (isEnabled) { final String name = player.getName(); final String ip = PlayerUtils.getPlayerIp(player); - final String reason = messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player); + final String reason = messages.retrieveSingle(player, MessageKey.TEMPBAN_MAX_LOGINS); final Date expires = new Date(); long newTime = expires.getTime() + (length * MILLIS_PER_MINUTE); diff --git a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java index f8e2e7baf..e5f4f65d0 100644 --- a/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java +++ b/src/main/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManager.java @@ -51,7 +51,7 @@ class LimboPlayerTaskManager { int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); MessageResult result = getMessageKey(player.getName(), isRegistered); if (interval > 0) { - String[] joinMessage = messages.retrieveSingle(result.messageKey, player, result.args).split("\n"); + String[] joinMessage = messages.retrieveSingle(player, result.messageKey, result.args).split("\n"); MessageTask messageTask = new MessageTask(player, joinMessage); bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND); limbo.setMessageTask(messageTask); @@ -67,7 +67,7 @@ class LimboPlayerTaskManager { void registerTimeoutTask(Player player, LimboPlayer limbo) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { - String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); + String message = messages.retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); limbo.setTimeoutTask(task); } diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index c10b8fcc5..c1c30cf94 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -123,7 +123,7 @@ public class OnJoinVerifier implements Reloadable { return false; } else if (!permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)) { // Server is full and player is NOT VIP; set kick message and proceed with kick - event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)); + event.setKickMessage(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)); return true; } @@ -135,12 +135,12 @@ public class OnJoinVerifier implements Reloadable { } Player nonVipPlayer = generateKickPlayer(onlinePlayers); if (nonVipPlayer != null) { - nonVipPlayer.kickPlayer(messages.retrieveSingle(MessageKey.KICK_FOR_VIP, player)); + nonVipPlayer.kickPlayer(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP)); event.allow(); return false; } else { ConsoleLogger.info("VIP player " + player.getName() + " tried to join, but the server was full"); - event.setKickMessage(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)); + event.setKickMessage(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)); return true; } } diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 6482cd637..e48ff6be2 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -257,7 +257,7 @@ public class PlayerListener implements Listener { try { runOnJoinChecks(JoiningPlayer.fromName(name), event.getAddress().getHostAddress()); } catch (FailedVerificationException e) { - event.setKickMessage(m.retrieveSingle(e.getReason(), name, e.getArgs())); + event.setKickMessage(m.retrieveSingle(name, e.getReason(), e.getArgs())); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); } } @@ -285,7 +285,7 @@ public class PlayerListener implements Listener { try { runOnJoinChecks(JoiningPlayer.fromPlayerObject(player), event.getAddress().getHostAddress()); } catch (FailedVerificationException e) { - event.setKickMessage(m.retrieveSingle(e.getReason(), player, e.getArgs())); + event.setKickMessage(m.retrieveSingle(player, e.getReason(), e.getArgs())); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); } } diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 69be2687e..be887276f 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -70,7 +70,7 @@ public class Messages { * @param replacements The replacements to apply for the tags */ public void send(CommandSender sender, MessageKey key, String... replacements) { - String message = retrieveSingle(key, sender, replacements); + String message = retrieveSingle(sender, key, replacements); for (String line : message.split("\n")) { sender.sendMessage(line); } @@ -149,12 +149,12 @@ public class Messages { * logs an error if the number of supplied replacements doesn't correspond to the number of tags * the message key contains. * - * @param key The key of the message to send * @param sender The entity to send the message to + * @param key The key of the message to send * @param replacements The replacements to apply for the tags * @return The message from the file with replacements */ - public String retrieveSingle(MessageKey key, CommandSender sender, String... replacements) { + public String retrieveSingle(CommandSender sender, MessageKey key, String... replacements) { String message = retrieveMessage(key, sender); String[] tags = key.getTags(); if (replacements.length == tags.length) { @@ -172,12 +172,12 @@ public class Messages { * logs an error if the number of supplied replacements doesn't correspond to the number of tags * the message key contains. * - * @param key The key of the message to send * @param name The name of the entity to send the message to + * @param key The key of the message to send * @param replacements The replacements to apply for the tags * @return The message from the file with replacements */ - public String retrieveSingle(MessageKey key, String name, String... replacements) { + public String retrieveSingle(String name, MessageKey key, String... replacements) { String message = retrieveMessage(key, name); String[] tags = key.getTags(); if (replacements.length == tags.length) { diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index da9e5127d..7fb13bac6 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -138,7 +138,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private void handlePlayerWithUnmetNameRestriction(Player player, String ip) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> { - player.kickPlayer(service.retrieveSingleMessage(MessageKey.NOT_OWNER_ERROR, player)); + player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.NOT_OWNER_ERROR)); if (service.getProperty(RestrictionSettings.BAN_UNKNOWN_IP)) { server.banIP(ip); } @@ -188,7 +188,7 @@ public class AsynchronousJoin implements AsynchronousProcess { && countOnlinePlayersByIp(ip) > service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask( - () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.SAME_IP_ONLINE, player))); + () -> player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.SAME_IP_ONLINE))); return false; } return true; diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 2731c59a1..193332501 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -197,7 +197,7 @@ public class AsynchronousLogin implements AsynchronousProcess { tempbanManager.tempbanPlayer(player); } else if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) { bukkitService.scheduleSyncTaskFromOptionallyAsyncTask( - () -> player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD, player))); + () -> player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.WRONG_PASSWORD))); } else { service.send(player, MessageKey.WRONG_PASSWORD); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index f59bb28b1..ea5c028ef 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -58,7 +58,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { // Kick Player after Registration is enabled, kick the player if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) { - player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS, player)); + player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.REGISTER_SUCCESS)); return; } diff --git a/src/main/java/fr/xephi/authme/service/CommonService.java b/src/main/java/fr/xephi/authme/service/CommonService.java index ea63c58e1..92a49267b 100644 --- a/src/main/java/fr/xephi/authme/service/CommonService.java +++ b/src/main/java/fr/xephi/authme/service/CommonService.java @@ -63,12 +63,12 @@ public class CommonService { /** * Retrieves a message in one piece. * - * @param key the key of the message * @param sender The entity to send the message to + * @param key the key of the message * @return the message */ - public String retrieveSingleMessage(MessageKey key, CommandSender sender) { - return messages.retrieveSingle(key, sender); + public String retrieveSingleMessage(CommandSender sender, MessageKey key) { + return messages.retrieveSingle(sender, key); } /** diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index 162de38ac..92492b99f 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -160,7 +160,7 @@ public class RegisterAdminCommandTest { Player player = mock(Player.class); given(bukkitService.getPlayerExact(user)).willReturn(player); String kickForAdminRegister = "Admin registered you -- log in again"; - given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER, player)).willReturn(kickForAdminRegister); + given(commandService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister); CommandSender sender = mock(CommandSender.class); setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); setBukkitServiceToRunTaskOptionallyAsync(bukkitService); diff --git a/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java index 5b1da8c7a..154098e88 100644 --- a/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/TempbanManagerTest.java @@ -149,7 +149,7 @@ public class TempbanManagerTest { String ip = "123.45.67.89"; TestHelper.mockPlayerIp(player, ip); String banReason = "IP ban too many logins"; - given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player)).willReturn(banReason); + given(messages.retrieveSingle(player, MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason); Settings settings = mockSettings(2, 100, ""); TempbanManager manager = new TempbanManager(bukkitService, messages, settings); setBukkitServiceToScheduleSyncDelayedTask(bukkitService); @@ -195,7 +195,7 @@ public class TempbanManagerTest { String ip = "22.44.66.88"; TestHelper.mockPlayerIp(player, ip); String banReason = "kick msg"; - given(messages.retrieveSingle(MessageKey.TEMPBAN_MAX_LOGINS, player)).willReturn(banReason); + given(messages.retrieveSingle(player, MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason); Settings settings = mockSettings(10, 60, ""); TempbanManager manager = new TempbanManager(bukkitService, messages, settings); manager.increaseCount(ip, "user"); diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java index 79fa4f4dc..f1507a29e 100644 --- a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java +++ b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java @@ -71,7 +71,7 @@ public class LimboPlayerTaskManagerTest { Player player = mock(Player.class); LimboPlayer limboPlayer = mock(LimboPlayer.class); MessageKey key = MessageKey.REGISTER_MESSAGE; - given(messages.retrieveSingle(key, player)).willReturn("Please register!"); + given(messages.retrieveSingle(player, key)).willReturn("Please register!"); int interval = 12; given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(interval); @@ -80,7 +80,7 @@ public class LimboPlayerTaskManagerTest { // then verify(limboPlayer).setMessageTask(any(MessageTask.class)); - verify(messages).retrieveSingle(key, player); + verify(messages).retrieveSingle(player, key); verify(bukkitService).runTaskTimer( any(MessageTask.class), eq(2L * TICKS_PER_SECOND), eq((long) interval * TICKS_PER_SECOND)); } @@ -110,7 +110,7 @@ public class LimboPlayerTaskManagerTest { MessageTask existingMessageTask = mock(MessageTask.class); limboPlayer.setMessageTask(existingMessageTask); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8); - given(messages.retrieveSingle(MessageKey.REGISTER_MESSAGE, player)).willReturn("Please register!"); + given(messages.retrieveSingle(player, MessageKey.REGISTER_MESSAGE)).willReturn("Please register!"); // when limboPlayerTaskManager.registerMessageTask(player, limboPlayer, false); @@ -119,7 +119,7 @@ public class LimboPlayerTaskManagerTest { assertThat(limboPlayer.getMessageTask(), not(nullValue())); assertThat(limboPlayer.getMessageTask(), not(sameInstance(existingMessageTask))); verify(registrationCaptchaManager).isCaptchaRequired(name); - verify(messages).retrieveSingle(MessageKey.REGISTER_MESSAGE, player); + verify(messages).retrieveSingle(player, MessageKey.REGISTER_MESSAGE); verify(existingMessageTask).cancel(); } @@ -134,14 +134,14 @@ public class LimboPlayerTaskManagerTest { given(registrationCaptchaManager.isCaptchaRequired(name)).willReturn(true); String captcha = "M032"; given(registrationCaptchaManager.getCaptchaCodeOrGenerateNew(name)).willReturn(captcha); - given(messages.retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, player, captcha)).willReturn("Need to use captcha"); + given(messages.retrieveSingle(player, MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, captcha)).willReturn("Need to use captcha"); // when limboPlayerTaskManager.registerMessageTask(player, limboPlayer, false); // then assertThat(limboPlayer.getMessageTask(), not(nullValue())); - verify(messages).retrieveSingle(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, player, captcha); + verify(messages).retrieveSingle(player, MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, captcha); } @Test @@ -159,7 +159,7 @@ public class LimboPlayerTaskManagerTest { // then verify(limboPlayer).setTimeoutTask(bukkitTask); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L)); // 30 * TICKS_PER_SECOND - verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); + verify(messages).retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); } @Test @@ -194,7 +194,7 @@ public class LimboPlayerTaskManagerTest { verify(existingTask).cancel(); assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask)); verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L)); // 18 * TICKS_PER_SECOND - verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR, player); + verify(messages).retrieveSingle(player, MessageKey.LOGIN_TIMEOUT_ERROR); } } diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 7d8c95176..2f6121a90 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -101,7 +101,7 @@ public class OnJoinVerifierTest { event.setResult(PlayerLoginEvent.Result.KICK_FULL); given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(false); String serverFullMessage = "server is full"; - given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)).willReturn(serverFullMessage); + given(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)).willReturn(serverFullMessage); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); @@ -125,7 +125,7 @@ public class OnJoinVerifierTest { given(permissionsManager.hasPermission(onlinePlayers.get(1), PlayerStatePermission.IS_VIP)).willReturn(false); returnOnlineListFromBukkitServer(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); - given(messages.retrieveSingle(MessageKey.KICK_FOR_VIP, player)).willReturn("kick for vip"); + given(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP)).willReturn("kick for vip"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); @@ -149,7 +149,7 @@ public class OnJoinVerifierTest { given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true); returnOnlineListFromBukkitServer(onlinePlayers); given(server.getMaxPlayers()).willReturn(onlinePlayers.size()); - given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER, player)).willReturn("kick full server"); + given(messages.retrieveSingle(player, MessageKey.KICK_FULL_SERVER)).willReturn("kick full server"); // when boolean result = onJoinVerifier.refusePlayerForFullServer(event); diff --git a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java index 9fd750ff7..3d75e2c52 100644 --- a/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/PlayerListenerTest.java @@ -596,7 +596,7 @@ public class PlayerListenerTest { MessageKey.INVALID_NAME_CHARACTERS, "[a-z]"); doThrow(exception).when(onJoinVerifier).checkIsValidName(name); String message = "Invalid characters!"; - given(messages.retrieveSingle(exception.getReason(), player, exception.getArgs())).willReturn(message); + given(messages.retrieveSingle(player, exception.getReason(), exception.getArgs())).willReturn(message); // when listener.onPlayerLogin(event); diff --git a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java index 125ad36af..d8a2bd00b 100644 --- a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java @@ -100,7 +100,7 @@ public class MessagesIntegrationTest { given(sender.getName()).willReturn("Tester"); // when - String message = messages.retrieveSingle(key, sender); + String message = messages.retrieveSingle(sender, key); // then assertThat(message, equalTo("We've got\nnew lines\nand ' apostrophes")); @@ -252,7 +252,7 @@ public class MessagesIntegrationTest { given(sender.getName()).willReturn("Tester"); // when - String message = messages.retrieveSingle(key, sender); + String message = messages.retrieveSingle(sender, key); // then assertThat(message, equalTo("§cWrong password!")); @@ -266,7 +266,7 @@ public class MessagesIntegrationTest { given(sender.getName()).willReturn("Tester"); // when - String result = messages.retrieveSingle(key, sender.getName(), "24680"); + String result = messages.retrieveSingle(sender.getName(), key, "24680"); // then assertThat(result, equalTo("Use /captcha 24680 to solve the captcha")); diff --git a/src/test/java/fr/xephi/authme/service/CommonServiceTest.java b/src/test/java/fr/xephi/authme/service/CommonServiceTest.java index e4ff2817b..b74762dc2 100644 --- a/src/test/java/fr/xephi/authme/service/CommonServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/CommonServiceTest.java @@ -85,14 +85,14 @@ public class CommonServiceTest { MessageKey key = MessageKey.ACCOUNT_NOT_ACTIVATED; Player player = mock(Player.class); String text = "Test text"; - given(messages.retrieveSingle(key, player)).willReturn(text); + given(messages.retrieveSingle(player, key)).willReturn(text); // when - String result = commonService.retrieveSingleMessage(key, player); + String result = commonService.retrieveSingleMessage(player, key); // then assertThat(result, equalTo(text)); - verify(messages).retrieveSingle(key, player); + verify(messages).retrieveSingle(player, key); } @Test From de6b9cbff0b227582b1d73bf56d46f2a0f93fdc5 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 11 Mar 2018 01:20:29 +0100 Subject: [PATCH 16/29] Add LoC badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7d5a5f767..7705cb367 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ - CircleCI: [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) - Project status: + - Lines of code: [![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded)](https://github.com/AuthMe/AuthMeReloaded). - Test coverage: [![Coverage status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) - Code climate: [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) From 2219906e90c058a6ae580408919f21b5d3af2eb0 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 11 Mar 2018 01:22:02 +0100 Subject: [PATCH 17/29] Whoops... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7705cb367..1232c46b1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - CircleCI: [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) - Project status: - - Lines of code: [![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded)](https://github.com/AuthMe/AuthMeReloaded). + - Lines of code: [![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded)](https://github.com/AuthMe/AuthMeReloaded) - Test coverage: [![Coverage status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) - Code climate: [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) From ff0a7e1f89065dca0eeff0aecb0d3152fd863068 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 11 Mar 2018 16:34:25 +0100 Subject: [PATCH 18/29] Fix failing test --- src/test/java/fr/xephi/authme/service/SessionServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/fr/xephi/authme/service/SessionServiceTest.java b/src/test/java/fr/xephi/authme/service/SessionServiceTest.java index 441b53561..b631c67e5 100644 --- a/src/test/java/fr/xephi/authme/service/SessionServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/SessionServiceTest.java @@ -218,6 +218,7 @@ public class SessionServiceTest { String name = "Charles"; Player player = mockPlayerWithNameAndIp(name, "144.117.118.145"); given(dataSource.hasSession(name)).willReturn(true); + given(commonService.getProperty(PluginSettings.SESSIONS_TIMEOUT)).willReturn(8); PlayerAuth auth = PlayerAuth.builder() .name(name) .lastIp(null) From f391abe2a702ff161eef789bd6af4f3855cf6dc8 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 11 Mar 2018 18:44:52 +0100 Subject: [PATCH 19/29] New readme [WIP] (#1526) * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --- README.md | 110 ++++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 1232c46b1..2360f2d1d 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,15 @@ -

-

The most used authentication plugin for the Spigot and derivates!

-
+# AuthMeReloaded +**"The best authentication plugin for the Bukkit modding API!"** +AuthMeLogo -##### Links and Contacts: +| Type | Badges | +|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **General:** | ![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded?category=code) ![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded?category=files) | +| **Code quality:** | [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) [![Coverage status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) | +| **Jenkins CI:** | [![Jenkins Status](https://img.shields.io/website-up-down-green-red/http/shields.io.svg?label=ci.codemc.org)](https://ci.codemc.org/) [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/job/AuthMeReloaded) ![Build Tests](https://img.shields.io/jenkins/t/https/ci.codemc.org/job/AuthMe/job/AuthMeReloaded.svg) | +| **Other CIs:** | [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) | - - Support: - - [GitHub issue tracker](https://github.com/AuthMe/AuthMeReloaded/issues) - - [BukkitDev page](https://dev.bukkit.org/projects/authme-reloaded) - - [Spigot page](https://www.spigotmc.org/resources/authmereloaded.6269/) - - [Discord](https://discord.gg/Vn9eCyE) - -- CI Services: - - Jenkins: [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/AuthMeReloaded) (**DEVELOPMENT BUILDS**) - - CircleCI: [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) - -- Project status: - - Lines of code: [![](https://tokei.rs/b1/github/AuthMe/AuthMeReloaded)](https://github.com/AuthMe/AuthMeReloaded) - - Test coverage: [![Coverage status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) - - Code climate: [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) - -- Development resources: - - JavaDocs - - Maven Repository - -- Statistics: - - bStats: [AuthMe on bstats.org](https://bstats.org/plugin/bukkit/AuthMe) - ![Graph](https://bstats.org/signatures/bukkit/AuthMe.svg) - -
- -##### Compiling requirements: ->- JDK 1.8 ->- Maven ->- Git/Github (Optional) - -##### How to compile the project: ->- Clone the project with Git/Github ->- Execute command "mvn clean package" - -##### Running requirements: ->- Java 1.8 ->- TacoSpigot, PaperSpigot or Spigot (1.7.10, 1.8.X, 1.9.X, 1.10.X, 1.11.X, 1.12.X)
- (In case you use Thermos, Cauldron or similar, you have to update the SpecialSource library to support Java 8 plugins. - HowTo: https://github.com/games647/FastLogin/issues/111#issuecomment-272331347) ->- ProtocolLib (optional, required by some features) - -
- -### Plugin Description: - -##### "The best authentication plugin for the Bukkit/Spigot API!" +## Description Prevent username stealing on your server!
Use it to secure your Offline mode server or to increase your Online mode server's protection! @@ -118,15 +78,51 @@ You can also create your own translation file and, if you want, you can share it - [How to convert from Rakamak](https://dev.bukkit.org/projects/authme-reloaded/pages/how-to-import-database-from-rakamak) - Convert between database types (e.g. SQLite to MySQL): /authme converter -
-##### Sponsor +## Links and Contacts + + - **Support:** + - [GitHub issue tracker](https://github.com/AuthMe/AuthMeReloaded/issues) + - [BukkitDev page](https://dev.bukkit.org/projects/authme-reloaded) + - [Spigot page](https://www.spigotmc.org/resources/authmereloaded.6269/) + - [Discord](https://discord.gg/Vn9eCyE) + +- **Dev resources:** + - JavaDocs + - Maven Repository + +- **Statistics:** + ![Graph](https://bstats.org/signatures/bukkit/AuthMe.svg) + +## Requirements + +##### Compiling requirements: +>- JDK 1.8 +>- Maven +>- Git/Github (Optional) + +##### How to compile the project: +>- Clone the project with Git/Github +>- Execute command "mvn clean package" + +##### Running requirements: +>- Java 1.8 +>- TacoSpigot, PaperSpigot or Spigot (1.7.10, 1.8.X, 1.9.X, 1.10.X, 1.11.X, 1.12.X)
+ (In case you use Thermos, Cauldron or similar, you have to update the SpecialSource library to support Java 8 plugins. + HowTo: https://github.com/games647/FastLogin/issues/111#issuecomment-272331347) +>- ProtocolLib (optional, required by some features) + +## Credits + +##### Sponsor: [GameHosting.it](http://www.gamehosting.it) is leader in Italy as Game Server Provider. With its own DataCenter offers Anti-DDoS solutions at affordable prices. Game Server of Minecraft based on Multicraft are equipped with the latest technology in hardware. -##### Credits -

Contributors: developers, translators -

Credit for old version of the plugin to: d4rkwarriors, fabe1337, Whoami2 and pomo4ka

-

Thanks also to: AS1LV3RN1NJA, Hoeze and eprimex

+##### Contributors: +Team members: developers, translators -##### GeoIP License +Credits for the old version of the plugin: d4rkwarriors, fabe1337, Whoami2 and pomo4ka + +Thanks also to: AS1LV3RN1NJA, Hoeze and eprimex + +##### GeoIP License: This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com From 98bd0f7a6b9204a1eb7bc9be47be3ce086a1359e Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 11 Mar 2018 18:54:45 +0100 Subject: [PATCH 20/29] [ci-skip] Add gemnasium badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2360f2d1d..255f36cf9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ | **Code quality:** | [![Code Climate](https://codeclimate.com/github/AuthMe/AuthMeReloaded/badges/gpa.svg)](https://codeclimate.com/github/AuthMe/AuthMeReloaded) [![Coverage status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) | | **Jenkins CI:** | [![Jenkins Status](https://img.shields.io/website-up-down-green-red/http/shields.io.svg?label=ci.codemc.org)](https://ci.codemc.org/) [![Build Status](https://ci.codemc.org/buildStatus/icon?job=AuthMe/AuthMeReloaded)](https://ci.codemc.org/job/AuthMe/job/AuthMeReloaded) ![Build Tests](https://img.shields.io/jenkins/t/https/ci.codemc.org/job/AuthMe/job/AuthMeReloaded.svg) | | **Other CIs:** | [![CircleCI](https://circleci.com/gh/AuthMe/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/AuthMe/AuthMeReloaded) | +| **Dependencies:** | [![Dependency Status](https://gemnasium.com/badges/github.com/AuthMe/AuthMeReloaded.svg)](https://gemnasium.com/github.com/AuthMe/AuthMeReloaded) | ## Description From fddb3bf265dd0607e5e028bd20776e7670522ba3 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 11 Mar 2018 19:08:21 +0100 Subject: [PATCH 21/29] Fix minor Checkstyle violations - Mostly missing JavaDoc, some line lengths --- .../authme/debug/MySqlDefaultChanger.java | 5 +++ .../fr/xephi/authme/datasource/MySQL.java | 11 +++++++ .../fr/xephi/authme/datasource/SQLite.java | 1 + .../listener/PlayerListener19Spigot.java | 3 +- .../permission/handlers/LuckPermsHandler.java | 3 +- .../register/ProcessSyncEmailRegister.java | 9 +++++- .../register/ProcessSyncPasswordRegister.java | 6 ++++ .../xephi/authme/settings/SettingsWarner.java | 6 ++-- .../authme/task/purge/PurgeExecutor.java | 15 +++++++++ .../java/fr/xephi/authme/AuthMeMatchers.java | 1 + .../java/fr/xephi/authme/ClassCollector.java | 6 ++-- .../fr/xephi/authme/ReflectionTestUtils.java | 10 +++++- .../data/limbo/LimboPlayerMatchers.java | 4 ++- .../datasource/SqlDataSourceTestUtil.java | 9 ++++++ .../tools/dependencygraph/DrawDependency.java | 3 +- .../EncryptionMethodInfoGatherer.java | 6 ++++ .../permissions/PermissionNodesGatherer.java | 1 + .../permissions/PermissionsListWriter.java | 8 +++-- .../TranslationPageGenerator.java | 6 ++-- .../translations/TranslationsGatherer.java | 32 ++++++++++++------- .../filegeneration/GeneratePluginYml.java | 2 +- .../tools/messages/CheckMessageKeyUsages.java | 19 ++--------- src/test/java/tools/utils/FileIoUtils.java | 24 ++++++++++++++ 23 files changed, 142 insertions(+), 48 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java b/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java index 5fbd6993f..4f201fa5c 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/debug/MySqlDefaultChanger.java @@ -172,6 +172,11 @@ class MySqlDefaultChanger implements DebugSection { + sender.getName() + "'"); } + /** + * Outputs the current definitions of all {@link Columns} which can be migrated. + * + * @param sender command sender to output the data to + */ private void showColumnDetails(CommandSender sender) { sender.sendMessage(ChatColor.BLUE + "MySQL column details"); final String tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE); diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 01a240fe3..ce46baadd 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -28,6 +28,10 @@ import java.util.Set; import static fr.xephi.authme.datasource.SqlDataSourceUtils.getNullableLong; import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException; +/** + * MySQL data source. + */ +@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore public class MySQL implements DataSource { private boolean useSsl; @@ -728,6 +732,13 @@ public class MySQL implements DataSource { return players; } + /** + * Creates a {@link PlayerAuth} object with the data from the provided result set. + * + * @param row the result set to read from + * @return generated player auth object with the data from the result set + * @throws SQLException . + */ private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException { String salt = col.SALT.isEmpty() ? null : row.getString(col.SALT); int group = col.GROUP.isEmpty() ? -1 : row.getInt(col.GROUP); diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 422d57b17..ada94afbc 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -28,6 +28,7 @@ import static fr.xephi.authme.datasource.SqlDataSourceUtils.logSqlException; /** * SQLite data source. */ +@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) // Justification: Class name cannot be changed anymore public class SQLite implements DataSource { private final Settings settings; diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java b/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java index d5f46b305..1684887e6 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener19Spigot.java @@ -12,10 +12,11 @@ import javax.inject.Inject; public class PlayerListener19Spigot implements Listener { + private static boolean isPlayerSpawnLocationEventCalled = false; + @Inject private TeleportationService teleportationService; - private static boolean isPlayerSpawnLocationEventCalled = false; public static boolean isPlayerSpawnLocationEventCalled() { return isPlayerSpawnLocationEventCalled; diff --git a/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java index ad46a35ca..9e52746fc 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/LuckPermsHandler.java @@ -62,7 +62,8 @@ public class LuckPermsHandler implements PermissionHandler { return false; } - DataMutateResult result = user.setPermissionUnchecked(luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build()); + DataMutateResult result = user.setPermissionUnchecked( + luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build()); if (result == DataMutateResult.FAIL) { return false; } diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index b43a85639..6ab4a874a 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -10,7 +10,9 @@ import org.bukkit.entity.Player; import javax.inject.Inject; - +/** + * Performs synchronous tasks after a successful {@link RegistrationType#EMAIL email registration}. + */ public class ProcessSyncEmailRegister implements SynchronousProcess { @Inject @@ -22,6 +24,11 @@ public class ProcessSyncEmailRegister implements SynchronousProcess { ProcessSyncEmailRegister() { } + /** + * Performs sync tasks for a player which has just registered by email. + * + * @param player the recently registered player + */ public void processEmailRegister(Player player) { service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); limboService.replaceTasksAfterRegistration(player); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index ea5c028ef..30e7f59ae 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import javax.inject.Inject; /** + * Performs synchronous tasks after a successful {@link RegistrationType#PASSWORD password registration}. */ public class ProcessSyncPasswordRegister implements SynchronousProcess { @@ -46,6 +47,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess { } } + /** + * Processes a player having registered with a password. + * + * @param player the newly registered player + */ public void processPasswordRegister(Player player) { service.send(player, MessageKey.REGISTER_SUCCESS); diff --git a/src/main/java/fr/xephi/authme/settings/SettingsWarner.java b/src/main/java/fr/xephi/authme/settings/SettingsWarner.java index ca049d56b..c94b0455c 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsWarner.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsWarner.java @@ -56,9 +56,9 @@ public class SettingsWarner { // Warn if spigot.yml has settings.bungeecord set to true but config.yml has Hooks.bungeecord set to false if (Utils.isSpigot() && Bukkit.spigot().getConfig().getBoolean("settings.bungeecord") && !settings.getProperty(HooksSettings.BUNGEECORD)) { - ConsoleLogger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in" + - " bungeecord mode (see your spigot.yml). In order to allow the datasource caching and the AuthMeBungee" + - " add-on to work properly you have to enable this option!"); + ConsoleLogger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in" + + " bungeecord mode (see your spigot.yml). In order to allow the datasource caching and the" + + " AuthMeBungee add-on to work properly you have to enable this option!"); } // Check if argon2 library is present and can be loaded diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index 04b7f5cc6..a3e42f756 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -61,6 +61,11 @@ public class PurgeExecutor { purgePermissions(players); } + /** + * Purges data from the AntiXray plugin. + * + * @param cleared the players whose data should be cleared + */ synchronized void purgeAntiXray(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_ANTI_XRAY_FILE)) { return; @@ -95,6 +100,11 @@ public class PurgeExecutor { ConsoleLogger.info(ChatColor.GOLD + "Deleted " + names.size() + " user accounts"); } + /** + * Purges data from the LimitedCreative plugin. + * + * @param cleared the players whose data should be cleared + */ synchronized void purgeLimitedCreative(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_LIMITED_CREATIVE_INVENTORIES)) { return; @@ -191,6 +201,11 @@ public class PurgeExecutor { ConsoleLogger.info("AutoPurge: Removed " + deletedFiles + " EssentialsFiles"); } + /** + * Removes permission data (groups a user belongs to) for the given players. + * + * @param cleared the players to remove data for + */ synchronized void purgePermissions(Collection cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_PERMISSIONS)) { return; diff --git a/src/test/java/fr/xephi/authme/AuthMeMatchers.java b/src/test/java/fr/xephi/authme/AuthMeMatchers.java index 69f2ac27e..33768883d 100644 --- a/src/test/java/fr/xephi/authme/AuthMeMatchers.java +++ b/src/test/java/fr/xephi/authme/AuthMeMatchers.java @@ -11,6 +11,7 @@ import java.util.Objects; /** * Custom matchers for AuthMe entities. */ +@SuppressWarnings("checkstyle:JavadocMethod") // Justification: Javadoc would be huge because of the many parameters public final class AuthMeMatchers { private AuthMeMatchers() { diff --git a/src/test/java/fr/xephi/authme/ClassCollector.java b/src/test/java/fr/xephi/authme/ClassCollector.java index 886201b02..23c065e82 100644 --- a/src/test/java/fr/xephi/authme/ClassCollector.java +++ b/src/test/java/fr/xephi/authme/ClassCollector.java @@ -67,7 +67,7 @@ public class ClassCollector { public List> collectClasses(Predicate> filter) { File rootFolder = new File(root); List> collection = new ArrayList<>(); - collectClasses(rootFolder, filter, collection); + gatherClassesFromFile(rootFolder, filter, collection); return collection; } @@ -124,14 +124,14 @@ public class ClassCollector { * @param filter the class predicate * @param collection collection to add classes to */ - private void collectClasses(File folder, Predicate> filter, List> collection) { + private void gatherClassesFromFile(File folder, Predicate> filter, List> collection) { File[] files = folder.listFiles(); if (files == null) { throw new IllegalStateException("Could not read files from '" + folder + "'"); } for (File file : files) { if (file.isDirectory()) { - collectClasses(file, filter, collection); + gatherClassesFromFile(file, filter, collection); } else if (file.isFile()) { Class clazz = loadTaskClassFromFile(file); if (clazz != null && filter.test(clazz)) { diff --git a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java index 033bed276..963fbf71d 100644 --- a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java +++ b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java @@ -82,7 +82,6 @@ public final class ReflectionTestUtils { * @param clazz the class to retrieve a method from * @param methodName the name of the method * @param parameterTypes the parameter types the method to retrieve has - * * @return the method of the class, set to be accessible */ public static Method getMethod(Class clazz, String methodName, Class... parameterTypes) { @@ -96,6 +95,15 @@ public final class ReflectionTestUtils { } } + /** + * Invokes the given method on the provided instance with the given parameters. + * + * @param method the method to invoke + * @param instance the instance to invoke the method on (null for static methods) + * @param parameters the parameters to pass to the method + * @param return value of the method + * @return method return value + */ @SuppressWarnings("unchecked") public static V invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java index bb5a452e6..78386e2d3 100644 --- a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java +++ b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerMatchers.java @@ -14,6 +14,7 @@ import static org.hamcrest.collection.IsIterableContainingInOrder.contains; /** * Contains matchers for LimboPlayer. */ +@SuppressWarnings("checkstyle:JavadocMethod") // Justification: Javadoc would be huge because of the many parameters public final class LimboPlayerMatchers { private LimboPlayerMatchers() { @@ -45,7 +46,8 @@ public final class LimboPlayerMatchers { @Override public void describeMismatchSafely(LimboPlayer item, Description description) { description.appendText(format("Limbo with isOp=%s, groups={%s}, canFly=%s, walkSpeed=%f, flySpeed=%f", - item.isOperator(), String.join(" ,", item.getGroups()), item.isCanFly(), item.getWalkSpeed(), item.getFlySpeed())); + item.isOperator(), String.join(" ,", item.getGroups()), item.isCanFly(), + item.getWalkSpeed(), item.getFlySpeed())); } }; } diff --git a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java index 79a938f6f..dd54e39a4 100644 --- a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java +++ b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceTestUtil.java @@ -27,6 +27,15 @@ public final class SqlDataSourceTestUtil { return new MySQL(settings, hikariDataSource, extensionsFactory); } + /** + * Creates a SQLite implementation for testing purposes. Methods are overridden so the + * provided connection is never overridden. + * + * @param settings settings instance + * @param dataFolder data folder + * @param connection connection to use + * @return the created SQLite instance + */ public static SQLite createSqlite(Settings settings, File dataFolder, Connection connection) { return new SQLite(settings, dataFolder, connection) { // Override reload() so it doesn't run SQLite#connect, since we're given a specific Connection to use diff --git a/src/test/java/tools/dependencygraph/DrawDependency.java b/src/test/java/tools/dependencygraph/DrawDependency.java index 3f34197c4..40a3b6b23 100644 --- a/src/test/java/tools/dependencygraph/DrawDependency.java +++ b/src/test/java/tools/dependencygraph/DrawDependency.java @@ -131,7 +131,8 @@ public class DrawDependency implements ToolTask { private Class unwrapGenericClass(Type genericType) { if (genericType == Factory.class || genericType == SingletonStore.class) { Class parameterType = ReflectionUtils.getGenericType(genericType); - Objects.requireNonNull(parameterType, "Parameter type for '" + genericType + "' should be a concrete class"); + Objects.requireNonNull(parameterType, + "Parameter type for '" + genericType + "' should be a concrete class"); return parameterType; } return InjectorUtils.convertToClass(genericType); diff --git a/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java index 86f808386..0362e26ca 100644 --- a/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java +++ b/src/test/java/tools/docs/hashmethods/EncryptionMethodInfoGatherer.java @@ -56,6 +56,12 @@ public class EncryptionMethodInfoGatherer { } } + /** + * Creates a description of the given hash algorithm based on its annotations. + * + * @param algorithm the algorithm to describe + * @return description of the hash algorithm + */ private static MethodDescription createDescription(HashAlgorithm algorithm) { Class clazz = algorithm.getClazz(); EncryptionMethod method = createEncryptionMethod(clazz); diff --git a/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java index f177cbc67..0b17ebf61 100644 --- a/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java +++ b/src/test/java/tools/docs/permissions/PermissionNodesGatherer.java @@ -37,6 +37,7 @@ public class PermissionNodesGatherer { /** * Return a sorted collection of all permission nodes, including its JavaDoc description. * + * @param permission node enum type * @return Ordered map whose keys are the permission nodes and the values the associated JavaDoc */ @SuppressWarnings("unchecked") diff --git a/src/test/java/tools/docs/permissions/PermissionsListWriter.java b/src/test/java/tools/docs/permissions/PermissionsListWriter.java index 797e26e79..1e0e8abd6 100644 --- a/src/test/java/tools/docs/permissions/PermissionsListWriter.java +++ b/src/test/java/tools/docs/permissions/PermissionsListWriter.java @@ -4,18 +4,20 @@ import tools.utils.AutoToolTask; import tools.utils.FileIoUtils; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; -import tools.utils.ToolsConstants; import java.util.Map; +import static tools.utils.ToolsConstants.DOCS_FOLDER; +import static tools.utils.ToolsConstants.TOOLS_SOURCE_ROOT; + /** * Task responsible for formatting a permissions node list and * for writing it to a file if desired. */ public class PermissionsListWriter implements AutoToolTask { - private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; - private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md"; + private static final String TEMPLATE_FILE = TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; + private static final String PERMISSIONS_OUTPUT_FILE = DOCS_FOLDER + "permission_nodes.md"; @Override public String getTaskName() { diff --git a/src/test/java/tools/docs/translations/TranslationPageGenerator.java b/src/test/java/tools/docs/translations/TranslationPageGenerator.java index dc555292c..dd87973d3 100644 --- a/src/test/java/tools/docs/translations/TranslationPageGenerator.java +++ b/src/test/java/tools/docs/translations/TranslationPageGenerator.java @@ -45,10 +45,10 @@ public class TranslationPageGenerator implements AutoToolTask { NestedTagValue translationValuesHolder = new NestedTagValue(); for (TranslationInfo translation : gatherer.getTranslationInfo()) { - int percentage = (int) Math.round(translation.percentTranslated * 100); - String name = firstNonNull(LANGUAGE_NAMES.get(translation.code), "?"); + int percentage = (int) Math.round(translation.getPercentTranslated() * 100); + String name = firstNonNull(LANGUAGE_NAMES.get(translation.getCode()), "?"); TagValueHolder valueHolder = TagValueHolder.create() - .put("code", translation.code) + .put("code", translation.getCode()) .put("name", name) .put("percentage", Integer.toString(percentage)) .put("color", computeColor(percentage)); diff --git a/src/test/java/tools/docs/translations/TranslationsGatherer.java b/src/test/java/tools/docs/translations/TranslationsGatherer.java index f54843a9c..e42b266d1 100644 --- a/src/test/java/tools/docs/translations/TranslationsGatherer.java +++ b/src/test/java/tools/docs/translations/TranslationsGatherer.java @@ -25,7 +25,7 @@ public class TranslationsGatherer { public TranslationsGatherer() { gatherTranslations(); - translationInfo.sort((e1, e2) -> getCode(e1).compareTo(getCode(e2))); + translationInfo.sort((e1, e2) -> getSortCode(e1).compareTo(getSortCode(e2))); } public List getTranslationInfo() { @@ -61,16 +61,6 @@ public class TranslationsGatherer { return null; } - public static final class TranslationInfo { - public final String code; - public final double percentTranslated; - - TranslationInfo(String code, double percentTranslated) { - this.code = code; - this.percentTranslated = percentTranslated; - } - } - /** * Returns the language code from the translation info for sorting purposes. * Returns "a" for "en" language code to sort English on top. @@ -78,8 +68,26 @@ public class TranslationsGatherer { * @param info the translation info * @return the language code for sorting */ - private static String getCode(TranslationInfo info) { + private static String getSortCode(TranslationInfo info) { return "en".equals(info.code) ? "a" : info.code; } + public static final class TranslationInfo { + private final String code; + private final double percentTranslated; + + TranslationInfo(String code, double percentTranslated) { + this.code = code; + this.percentTranslated = percentTranslated; + } + + public String getCode() { + return code; + } + + public double getPercentTranslated() { + return percentTranslated; + } + } + } diff --git a/src/test/java/tools/filegeneration/GeneratePluginYml.java b/src/test/java/tools/filegeneration/GeneratePluginYml.java index 04dba91ef..cf833b007 100644 --- a/src/test/java/tools/filegeneration/GeneratePluginYml.java +++ b/src/test/java/tools/filegeneration/GeneratePluginYml.java @@ -67,7 +67,7 @@ public class GeneratePluginYml implements AutoToolTask { List pluginYmlLines = FileIoUtils.readLinesFromFile(Paths.get(PLUGIN_YML_FILE)); int lineNr = 0; for (String line : pluginYmlLines) { - if (line.equals("commands:")) { + if ("commands:".equals(line)) { break; } ++lineNr; diff --git a/src/test/java/tools/messages/CheckMessageKeyUsages.java b/src/test/java/tools/messages/CheckMessageKeyUsages.java index d43ad5d07..7387f0023 100644 --- a/src/test/java/tools/messages/CheckMessageKeyUsages.java +++ b/src/test/java/tools/messages/CheckMessageKeyUsages.java @@ -33,8 +33,8 @@ public class CheckMessageKeyUsages implements AutoToolTask { 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))); + System.out.println("Did not find usages for keys:\n- " + + String.join("\n- ", Lists.transform(unusedKeys, MessageKey::name))); } } @@ -51,21 +51,6 @@ public class CheckMessageKeyUsages implements AutoToolTask { return keys; } - private List findUsagesOfKey(MessageKey key) { - List filesUsingKey = new ArrayList<>(); - File sourceFolder = new File(ToolsConstants.MAIN_SOURCE_ROOT); - - Consumer usagesCollector = file -> { - String source = FileIoUtils.readFromFile(file.toPath()); - if (source.contains(key.name())) { - filesUsingKey.add(file); - } - }; - - walkJavaFileTree(sourceFolder, usagesCollector); - return filesUsingKey; - } - private static void walkJavaFileTree(File folder, Consumer javaFileConsumer) { for (File file : FileIoUtils.listFilesOrThrow(folder)) { if (file.isDirectory()) { diff --git a/src/test/java/tools/utils/FileIoUtils.java b/src/test/java/tools/utils/FileIoUtils.java index eadefd2d5..995c71a01 100644 --- a/src/test/java/tools/utils/FileIoUtils.java +++ b/src/test/java/tools/utils/FileIoUtils.java @@ -27,6 +27,12 @@ public final class FileIoUtils { writeToFile(Paths.get(outputFile), contents); } + /** + * Writes the given contents to the file, overriding any existing content. + * + * @param path the file to write to + * @param contents the contents to write + */ public static void writeToFile(Path path, String contents) { try { Files.write(path, contents.getBytes()); @@ -35,6 +41,12 @@ public final class FileIoUtils { } } + /** + * Adds the given contents to the file while keeping any existing content. + * + * @param outputFile the file to write to + * @param contents the contents to append + */ public static void appendToFile(String outputFile, String contents) { try { Files.write(Paths.get(outputFile), contents.getBytes(), StandardOpenOption.APPEND); @@ -47,6 +59,12 @@ public final class FileIoUtils { return readFromFile(Paths.get(file)); } + /** + * Returns the given file's contents as string. + * + * @param file the file to read + * @return the file's contents + */ public static String readFromFile(Path file) { try { return new String(Files.readAllBytes(file), StandardCharsets.UTF_8); @@ -55,6 +73,12 @@ public final class FileIoUtils { } } + /** + * Returns the lines of the given file. + * + * @param path the path of the file to read + * @return the lines of the file + */ public static List readLinesFromFile(Path path) { try { return Files.readAllLines(path, StandardCharsets.UTF_8); From 7f00e87e85e931a3c8af1b86983f657a5a47cb68 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 11:42:39 +0100 Subject: [PATCH 22/29] [CI-SKIP] Create Jenkinsfile --- Jenkinsfile | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..b3dc23d99 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,125 @@ +pipeline { + agent any + tools { + maven 'Maven 3' + jdk 'OracleJDK 8' + } + stages { + stage ('Clean') { + steps { + echo 'Cleaning the maven workspace...' + sh 'mvn clean' + } + } + stage ('Dependencies') { + steps { + echo 'Downloading dependencies...' + sh 'mvn dependency:go-offline' + } + post { + success { + junit 'target/surefire-reports/**/*.xml' + archiveArtifacts artifacts: 'target/nukkit-*-SNAPSHOT.jar', fingerprint: true + } + } + } + stage ('Validate') { + steps { + echo 'Validating the maven project...' + sh 'mvn -o validate' + } + } + stage ('Compile') { + steps { + echo 'Compiling source classes...' + sh 'mvn -o compile' + } + } + stage ('Compile-Test') { + steps { + echo 'Compiling test classes...' + sh 'mvn -o test-compile' + } + } + stage ('Test') { + steps { + echo 'Performing unit testing...' + sh 'mvn -o test' + } + post { + success { + echo 'Archiving test results...' + junit 'target/surefire-reports/**/*.xml' + } + } + } + stage ('Package') { + steps { + echo 'Preparing the final package...' + sh 'mvn -o package' + } + post { + success { + echo 'Archiving the final package...' + archiveArtifacts artifacts: 'target/*.jar', fingerprint: true + } + } + } + stage ('Sources') { + when { + branch "master" + } + steps { + echo 'Generating sources...' + sh 'mvn -o source:jar' + } + post { + success { + echo 'Archiving sources...' + archiveArtifacts artifacts: 'target/*-souces.jar', fingerprint: true + } + } + } + stage ('Javadoc') { + when { + branch "master" + } + steps { + echo 'Generaing javadocs...' + sh 'mvn -o javadoc:javadoc javadoc:jar' + } + post { + success { + echo 'Archiving javadocs...' + step([ + $class: 'JavadocArchiver', + javadocDir: 'target/site/apidocs', + keepAll: true + ]) + archiveArtifacts artifacts: 'target/*-javadoc.jar', fingerprint: true + } + } + } + stage ('Verify') { + steps { + echo 'Performing integration testing...' + sh 'mvn -o verify' + } + } + stage ('Install') { + steps { + echo 'Installing artifacts to the local repository...' + sh 'mvn -o install' + } + } + stage ('Deploy') { + when { + branch "master" + } + steps { + echo 'Deploying to repository...' + sh 'mvn -o deploy' + } + } + } +} From 8a66a92f812544dd948aa6f4b3f583fd8c6ab1bb Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 11:57:08 +0100 Subject: [PATCH 23/29] [CI-SKIP] Don't generate javadocs and sources by default --- pom.xml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/pom.xml b/pom.xml index 3f0f4610c..baf61d49b 100644 --- a/pom.xml +++ b/pom.xml @@ -187,15 +187,6 @@ org.apache.maven.plugins maven-javadoc-plugin 3.0.0 - - - attach-javadocs - - javadoc - jar - - - ${project.outputName}-${project.version} public @@ -206,14 +197,6 @@ org.apache.maven.plugins maven-source-plugin 3.0.1 - - - attach-sources - - jar - - - ${project.outputName}-${project.version} From d503d2c061080e9d967360050325ec8476a37833 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 12:44:54 +0100 Subject: [PATCH 24/29] [CI-SKIP] implement pipeline ci-skip --- Jenkinsfile | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b3dc23d99..57ff8cc95 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,43 +5,52 @@ pipeline { jdk 'OracleJDK 8' } stages { - stage ('Clean') { + stage ('prepare') { + steps { + env.CI_SKIP = "false" + result = sh (script: "git log -1 | grep '(?s).[CI[-\s]SKIP].*'", returnStatus: true) + if (result == 0) { + env.CI_SKIP = "true" + error "'[CI-SKIP]' found in git commit message. Aborting." + } + } + } + stage ('clean') { steps { echo 'Cleaning the maven workspace...' sh 'mvn clean' } } - stage ('Dependencies') { + stage ('dependencies') { steps { echo 'Downloading dependencies...' sh 'mvn dependency:go-offline' } post { success { - junit 'target/surefire-reports/**/*.xml' archiveArtifacts artifacts: 'target/nukkit-*-SNAPSHOT.jar', fingerprint: true } } } - stage ('Validate') { + stage ('validate') { steps { echo 'Validating the maven project...' sh 'mvn -o validate' } } - stage ('Compile') { + stage ('compile') { steps { echo 'Compiling source classes...' sh 'mvn -o compile' } } - stage ('Compile-Test') { + stage ('compile-test') { steps { echo 'Compiling test classes...' sh 'mvn -o test-compile' } } - stage ('Test') { + stage ('test') { steps { echo 'Performing unit testing...' sh 'mvn -o test' @@ -53,7 +62,7 @@ pipeline { } } } - stage ('Package') { + stage ('package') { steps { echo 'Preparing the final package...' sh 'mvn -o package' @@ -65,7 +74,7 @@ pipeline { } } } - stage ('Sources') { + stage ('sources') { when { branch "master" } @@ -80,7 +89,7 @@ pipeline { } } } - stage ('Javadoc') { + stage ('javadoc') { when { branch "master" } @@ -100,19 +109,19 @@ pipeline { } } } - stage ('Verify') { + stage ('verify') { steps { echo 'Performing integration testing...' sh 'mvn -o verify' } } - stage ('Install') { + stage ('install') { steps { echo 'Installing artifacts to the local repository...' sh 'mvn -o install' } } - stage ('Deploy') { + stage ('deploy') { when { branch "master" } @@ -121,5 +130,12 @@ pipeline { sh 'mvn -o deploy' } } + post { + always { + if (env.CI_SKIP == "true") { + currentBuild.result = 'NOT_BUILT' + } + } + } } } From 193e93e30ad38fed80b8891cd323375aa85b6c2e Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 12:46:23 +0100 Subject: [PATCH 25/29] Whoops, damn escape character --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 57ff8cc95..f2c117d7e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { stage ('prepare') { steps { env.CI_SKIP = "false" - result = sh (script: "git log -1 | grep '(?s).[CI[-\s]SKIP].*'", returnStatus: true) + result = sh (script: "git log -1 | grep '(?s).[CI[-\\s]SKIP].*'", returnStatus: true) if (result == 0) { env.CI_SKIP = "true" error "'[CI-SKIP]' found in git commit message. Aborting." From 18e4be8d5b6c9896924df9dd0456a026a55e7db6 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 22:14:55 +0100 Subject: [PATCH 26/29] [CI-SKIP] Remove Jenkinsfile from main branch --- Jenkinsfile | 141 ---------------------------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index f2c117d7e..000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,141 +0,0 @@ -pipeline { - agent any - tools { - maven 'Maven 3' - jdk 'OracleJDK 8' - } - stages { - stage ('prepare') { - steps { - env.CI_SKIP = "false" - result = sh (script: "git log -1 | grep '(?s).[CI[-\\s]SKIP].*'", returnStatus: true) - if (result == 0) { - env.CI_SKIP = "true" - error "'[CI-SKIP]' found in git commit message. Aborting." - } - } - } - stage ('clean') { - steps { - echo 'Cleaning the maven workspace...' - sh 'mvn clean' - } - } - stage ('dependencies') { - steps { - echo 'Downloading dependencies...' - sh 'mvn dependency:go-offline' - } - post { - success { - archiveArtifacts artifacts: 'target/nukkit-*-SNAPSHOT.jar', fingerprint: true - } - } - } - stage ('validate') { - steps { - echo 'Validating the maven project...' - sh 'mvn -o validate' - } - } - stage ('compile') { - steps { - echo 'Compiling source classes...' - sh 'mvn -o compile' - } - } - stage ('compile-test') { - steps { - echo 'Compiling test classes...' - sh 'mvn -o test-compile' - } - } - stage ('test') { - steps { - echo 'Performing unit testing...' - sh 'mvn -o test' - } - post { - success { - echo 'Archiving test results...' - junit 'target/surefire-reports/**/*.xml' - } - } - } - stage ('package') { - steps { - echo 'Preparing the final package...' - sh 'mvn -o package' - } - post { - success { - echo 'Archiving the final package...' - archiveArtifacts artifacts: 'target/*.jar', fingerprint: true - } - } - } - stage ('sources') { - when { - branch "master" - } - steps { - echo 'Generating sources...' - sh 'mvn -o source:jar' - } - post { - success { - echo 'Archiving sources...' - archiveArtifacts artifacts: 'target/*-souces.jar', fingerprint: true - } - } - } - stage ('javadoc') { - when { - branch "master" - } - steps { - echo 'Generaing javadocs...' - sh 'mvn -o javadoc:javadoc javadoc:jar' - } - post { - success { - echo 'Archiving javadocs...' - step([ - $class: 'JavadocArchiver', - javadocDir: 'target/site/apidocs', - keepAll: true - ]) - archiveArtifacts artifacts: 'target/*-javadoc.jar', fingerprint: true - } - } - } - stage ('verify') { - steps { - echo 'Performing integration testing...' - sh 'mvn -o verify' - } - } - stage ('install') { - steps { - echo 'Installing artifacts to the local repository...' - sh 'mvn -o install' - } - } - stage ('deploy') { - when { - branch "master" - } - steps { - echo 'Deploying to repository...' - sh 'mvn -o deploy' - } - } - post { - always { - if (env.CI_SKIP == "true") { - currentBuild.result = 'NOT_BUILT' - } - } - } - } -} From fe538a43410cbd1801ed4ae96380e4c3ed7705b1 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 22:23:43 +0100 Subject: [PATCH 27/29] Revert "[CI-SKIP] Don't generate javadocs and sources by default" This reverts commit 8a66a92f812544dd948aa6f4b3f583fd8c6ab1bb. --- pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pom.xml b/pom.xml index baf61d49b..3f0f4610c 100644 --- a/pom.xml +++ b/pom.xml @@ -187,6 +187,15 @@ org.apache.maven.plugins maven-javadoc-plugin 3.0.0 + + + attach-javadocs + + javadoc + jar + + + ${project.outputName}-${project.version} public @@ -197,6 +206,14 @@ org.apache.maven.plugins maven-source-plugin 3.0.1 + + + attach-sources + + jar + + + ${project.outputName}-${project.version} From c93bfae90cb36bd58827550ef6a1c7da65f2eeca Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 13 Mar 2018 23:58:24 +0100 Subject: [PATCH 28/29] Try to fix jenkins javadocs archive --- pom.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3f0f4610c..6386fabd3 100644 --- a/pom.xml +++ b/pom.xml @@ -189,12 +189,17 @@ 3.0.0 - attach-javadocs + attach-javadoc - javadoc jar + + aggregate-javadoc + + aggregate + + ${project.outputName}-${project.version} From 914b76ad120ad797b8ec68e67adad2981473a685 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 14 Mar 2018 00:31:43 +0100 Subject: [PATCH 29/29] Update dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6386fabd3..b518d97af 100644 --- a/pom.xml +++ b/pom.xml @@ -461,7 +461,7 @@ de.mkammerer argon2-jvm-nolibs - 2.3 + 2.4 compile true @@ -544,7 +544,7 @@ me.lucko.luckperms luckperms-api - 4.0 + 4.1 provided