diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 8f87d1fa..71fa2fc1 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -7,6 +7,7 @@ import fr.xephi.authme.message.Messages; import fr.xephi.authme.process.Management; import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.service.JoinMessageService; import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.settings.Settings; @@ -54,8 +55,6 @@ import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAU */ public class PlayerListener implements Listener { - public static final Map joinMessage = new ConcurrentHashMap<>(); - @Inject private Settings settings; @Inject @@ -78,6 +77,8 @@ public class PlayerListener implements Listener { private TeleportationService teleportationService; @Inject private ValidationService validationService; + @Inject + private JoinMessageService joinMessageService; @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { @@ -188,7 +189,7 @@ public class PlayerListener implements Listener { // Remove the join message while the player isn't logging in if (joinMsg != null) { event.setJoinMessage(null); - joinMessage.put(name, joinMsg); + joinMessageService.putMessage(name, joinMsg); } } 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 206a55fa..1e4965d5 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -12,6 +12,7 @@ import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.BungeeService; import fr.xephi.authme.service.CommonService; +import fr.xephi.authme.service.JoinMessageService; import fr.xephi.authme.service.TeleportationService; import fr.xephi.authme.settings.WelcomeMessageConfiguration; import fr.xephi.authme.settings.commandconfig.CommandManager; @@ -51,6 +52,9 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { @Inject private WelcomeMessageConfiguration welcomeMessageConfiguration; + @Inject + private JoinMessageService joinMessageService; + ProcessSyncPlayerLogin() { } @@ -80,14 +84,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess { teleportationService.teleportOnLogin(player, auth, limbo); // We can now display the join message (if delayed) - String joinMessage = PlayerListener.joinMessage.remove(name); - if (!StringUtils.isEmpty(joinMessage)) { - for (Player p : bukkitService.getOnlinePlayers()) { - if (p.isOnline()) { - p.sendMessage(joinMessage); - } - } - } + joinMessageService.sendMessage(name); if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { player.removePotionEffect(PotionEffectType.BLINDNESS); diff --git a/src/main/java/fr/xephi/authme/service/JoinMessageService.java b/src/main/java/fr/xephi/authme/service/JoinMessageService.java new file mode 100644 index 00000000..2fa5766c --- /dev/null +++ b/src/main/java/fr/xephi/authme/service/JoinMessageService.java @@ -0,0 +1,46 @@ +package fr.xephi.authme.service; + +import fr.xephi.authme.util.StringUtils; + +import javax.inject.Inject; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The JoinMessageService class. + */ +public class JoinMessageService { + + private BukkitService bukkitService; + + private Map joinMessages; + + @Inject + JoinMessageService(BukkitService bukkitService) { + this.bukkitService = bukkitService; + joinMessages = new ConcurrentHashMap<>(); + } + + /** + * Store a join message. + * + * @param playerName the player name + * @param string the join message + */ + public void putMessage(String playerName, String string) { + joinMessages.put(playerName, string); + } + + /** + * Broadcast the join message of the specified player. + * + * @param playerName the player name + */ + public void sendMessage(String playerName) { + String joinMessage = joinMessages.remove(playerName); + if (StringUtils.isEmpty(joinMessage)) { + return; + } + bukkitService.broadcastMessage(joinMessage); + } +}