Run non-thread-safe addPotionEffect sync on unregister (Fixes #828)

This commit is contained in:
games647 2016-07-07 11:02:09 +02:00
parent 42ef99cf15
commit 6be58ee2e2
2 changed files with 17 additions and 6 deletions

View File

@ -14,7 +14,9 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager; import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService; import fr.xephi.authme.util.TeleportationService;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -37,6 +39,9 @@ public class AsynchronousUnregister implements AsynchronousProcess {
@Inject @Inject
private PlayerCache playerCache; private PlayerCache playerCache;
@Inject
private BukkitService bukktiService;
@Inject @Inject
private LimboCache limboCache; private LimboCache limboCache;
@ -49,7 +54,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
AsynchronousUnregister() { } 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(); final String name = player.getName().toLowerCase();
PlayerAuth cachedAuth = playerCache.getAuth(name); PlayerAuth cachedAuth = playerCache.getAuth(name);
if (force || passwordSecurity.comparePassword(password, cachedAuth.getPassword(), player.getName())) { if (force || passwordSecurity.comparePassword(password, cachedAuth.getPassword(), player.getName())) {
@ -80,10 +85,16 @@ public class AsynchronousUnregister implements AsynchronousProcess {
playerCache.removePlayer(name); playerCache.removePlayer(name);
// Apply blind effect // Apply blind effect
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; final int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { bukktiService.runTask(new Runnable() {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); @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); service.send(player, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(player.getName() + " unregistered himself"); ConsoleLogger.info(player.getName() + " unregistered himself");
} else { } else {