This commit is contained in:
Gabriele C 2017-03-26 16:51:34 +02:00
parent fc47a0a74f
commit 49aeb4308d
3 changed files with 55 additions and 11 deletions

View File

@ -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<String, String> 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);
}
}

View File

@ -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);

View File

@ -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<String, String> 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);
}
}