From 6be58ee2e2d467a1cb94148a3dff0ae91057af58 Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 7 Jul 2016 11:02:09 +0200 Subject: [PATCH] Run non-thread-safe addPotionEffect sync on unregister (Fixes #828) --- .../unregister/AsynchronousUnregister.java | 21 ++++++++++++++----- src/main/resources/messages/messages_fr.yml | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 7224fd751..9ace18449 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -14,7 +14,9 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.task.PlayerDataTaskManager; +import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.TeleportationService; + import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -37,6 +39,9 @@ public class AsynchronousUnregister implements AsynchronousProcess { @Inject private PlayerCache playerCache; + @Inject + private BukkitService bukktiService; + @Inject private LimboCache limboCache; @@ -49,7 +54,7 @@ public class AsynchronousUnregister implements AsynchronousProcess { AsynchronousUnregister() { } - public void unregister(Player player, String password, boolean force) { + public void unregister(final Player player, String password, boolean force) { final String name = player.getName().toLowerCase(); PlayerAuth cachedAuth = playerCache.getAuth(name); if (force || passwordSecurity.comparePassword(password, cachedAuth.getPassword(), player.getName())) { @@ -80,10 +85,16 @@ public class AsynchronousUnregister implements AsynchronousProcess { playerCache.removePlayer(name); // Apply blind effect - int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; - if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); - } + final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; + bukktiService.runTask(new Runnable() { + @Override + public void run() { + if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); + } + } + }); + service.send(player, MessageKey.UNREGISTERED_SUCCESS); ConsoleLogger.info(player.getName() + " unregistered himself"); } else { diff --git a/src/main/resources/messages/messages_fr.yml b/src/main/resources/messages/messages_fr.yml index 4c7c9cced..e5aae46c6 100644 --- a/src/main/resources/messages/messages_fr.yml +++ b/src/main/resources/messages/messages_fr.yml @@ -12,7 +12,7 @@ login: '&aConnexion effectuée !' vb_nonActiv: '&fCe compte n''est pas actif, consultez vos emails !' user_regged: '&cCe nom est déjà utilisé.' usage_reg: '&cUtilisez la commande /register motdepasse confirmermotdepasse' -# TODO max_reg: Missing tag %reg_count +# TODO max_reg: Missing tag %reg_count max_reg: '&cVous ne pouvez pas enregistrer plus de %max_acc compte(s). &o(Compte(s): %reg_names)' no_perm: '&cVous n''avez pas la permission.' password_error_nick: '&fTu ne peux pas utiliser ton pseudo comme mot de passe.'