Skip to content

Commit

Permalink
Run non-thread-safe addPotionEffect sync on unregister (Fixes #828)
Browse files Browse the repository at this point in the history
  • Loading branch information
games647 committed Jul 7, 2016
1 parent 42ef99c commit 6be58ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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;
Expand All @@ -37,6 +39,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
@Inject
private PlayerCache playerCache;

@Inject
private BukkitService bukktiService;

@Inject
private LimboCache limboCache;

Expand All @@ -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())) {
Expand Down Expand Up @@ -80,10 +85,16 @@ public void unregister(Player player, String password, boolean force) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages/messages_fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down

0 comments on commit 6be58ee

Please sign in to comment.