diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index a1cdbc433..5deaf40cb 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -169,8 +169,10 @@ public class PlayerListener implements Listener { String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE); if (!customJoinMessage.isEmpty()) { - event.setJoinMessage(customJoinMessage.replace("{PLAYERNAME}", player.getName()) - .replace("{DISPLAYNAME}", player.getDisplayName())); + event.setJoinMessage(customJoinMessage + .replace("{PLAYERNAME}", player.getName()) + .replace("{DISPLAYNAME}", player.getDisplayName()) + .replace("{PLAYERLISTNAME}", player.getPlayerListName())); } if (!settings.getProperty(RegistrationSettings.DELAY_JOIN_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 5fcad5290..ebb1d43d1 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -15,6 +15,7 @@ import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.service.ValidationService; +import fr.xephi.authme.settings.WelcomeMessageConfiguration; import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; @@ -68,6 +69,9 @@ public class AsynchronousJoin implements AsynchronousProcess { @Inject private ValidationService validationService; + @Inject + private WelcomeMessageConfiguration welcomeMessageConfiguration; + AsynchronousJoin() { } @@ -126,6 +130,8 @@ public class AsynchronousJoin implements AsynchronousProcess { return; } } else if (!service.getProperty(RegistrationSettings.FORCE)) { + welcomeMessageConfiguration.sendWelcomeMessage(player); + // Skip if registration is optional return; } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index c4178a201..acfaef420 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -19,7 +19,6 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import javax.inject.Inject; -import java.util.List; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; @@ -91,14 +90,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { player.saveData(); // Login is done, display welcome message - List welcomeMessage = welcomeMessageConfiguration.getWelcomeMessage(player); - if (commonService.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { - if (commonService.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) { - welcomeMessage.forEach(bukkitService::broadcastMessage); - } else { - welcomeMessage.forEach(player::sendMessage); - } - } + welcomeMessageConfiguration.sendWelcomeMessage(player); // Login is now finished; we can force all commands commandManager.runCommandsOnLogin(player); diff --git a/src/main/java/fr/xephi/authme/settings/WelcomeMessageConfiguration.java b/src/main/java/fr/xephi/authme/settings/WelcomeMessageConfiguration.java index 9ff1f0a7d..2c8e0605e 100644 --- a/src/main/java/fr/xephi/authme/settings/WelcomeMessageConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/WelcomeMessageConfiguration.java @@ -5,7 +5,9 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.GeoIpService; +import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.util.PlayerUtils; import fr.xephi.authme.util.lazytags.Tag; import fr.xephi.authme.util.lazytags.TagReplacer; @@ -47,6 +49,9 @@ public class WelcomeMessageConfiguration implements Reloadable { @Inject private PlayerCache playerCache; + @Inject + private CommonService service; + /** List of all supported tags for the welcome message. */ private final List> availableTags = Arrays.asList( createTag("&", () -> String.valueOf(ChatColor.COLOR_CHAR)), @@ -79,6 +84,22 @@ public class WelcomeMessageConfiguration implements Reloadable { return messageSupplier.getAdaptedMessages(player); } + /** + * Sends the welcome message accordingly to the configuration + * + * @param player the player for whom the welcome message should be prepared + */ + public void sendWelcomeMessage(Player player) { + List welcomeMessage = getWelcomeMessage(player); + if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { + if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) { + welcomeMessage.forEach(bukkitService::broadcastMessage); + } else { + welcomeMessage.forEach(player::sendMessage); + } + } + } + /** * @return the lines of the welcome message file */ diff --git a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java index 7d87e77bd..a9fb7fc50 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RegistrationSettings.java @@ -80,7 +80,8 @@ public final class RegistrationSettings implements SettingsHolder { "keep empty to use the original one.", "Available variables:", "{PLAYERNAME}: the player name (no colors)", - "{DISPLAYNAME}: the player name (with colors)"}) + "{DISPLAYNAME}: the player display name (with colors)", + "{PLAYERLISTNAME}: the player list name (with colors)"}) public static final Property CUSTOM_JOIN_MESSAGE = newProperty("settings.customJoinMessage", "");