- Abstract Messages into two layers: the top layer 'Messages' is how Messages can be retrieved and sent as before. In the background, package-private, MessagesManager actually does the file read and worries about I/O while Messages takes care of higher-level things (such as joining two lines or checking the current language).
121 lines
4.8 KiB
Java
121 lines
4.8 KiB
Java
package fr.xephi.authme.process.unregister;
|
|
|
|
import fr.xephi.authme.AuthMe;
|
|
import fr.xephi.authme.ConsoleLogger;
|
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
|
import fr.xephi.authme.cache.backup.JsonCache;
|
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
|
import fr.xephi.authme.security.PasswordSecurity;
|
|
import fr.xephi.authme.output.MessageKey;
|
|
import fr.xephi.authme.output.Messages;
|
|
import fr.xephi.authme.settings.Settings;
|
|
import fr.xephi.authme.task.MessageTask;
|
|
import fr.xephi.authme.task.TimeoutTask;
|
|
import fr.xephi.authme.util.Utils;
|
|
import fr.xephi.authme.util.Utils.GroupType;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.potion.PotionEffect;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
import org.bukkit.scheduler.BukkitScheduler;
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
/**
|
|
*/
|
|
public class AsynchronousUnregister {
|
|
|
|
protected final Player player;
|
|
protected final String name;
|
|
protected final String password;
|
|
protected final boolean force;
|
|
private final AuthMe plugin;
|
|
private final Messages m;
|
|
private final JsonCache playerCache;
|
|
|
|
/**
|
|
* Constructor for AsynchronousUnregister.
|
|
*
|
|
* @param player Player
|
|
* @param password String
|
|
* @param force boolean
|
|
* @param plugin AuthMe
|
|
*/
|
|
public AsynchronousUnregister(Player player, String password, boolean force, AuthMe plugin) {
|
|
this.m = plugin.getMessages();
|
|
this.player = player;
|
|
this.name = player.getName().toLowerCase();
|
|
this.password = password;
|
|
this.force = force;
|
|
this.plugin = plugin;
|
|
this.playerCache = new JsonCache();
|
|
}
|
|
|
|
/**
|
|
* Method getIp.
|
|
*
|
|
* @return String
|
|
*/
|
|
protected String getIp() {
|
|
return plugin.getIP(player);
|
|
}
|
|
|
|
public void process() {
|
|
try {
|
|
if (force || PasswordSecurity.comparePasswordWithHash(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) {
|
|
if (!plugin.database.removeAuth(name)) {
|
|
m.send(player, MessageKey.ERROR);
|
|
return;
|
|
}
|
|
int timeOut = Settings.getRegistrationTimeout * 20;
|
|
if (Settings.isForcedRegistrationEnabled) {
|
|
Utils.teleportToSpawn(player);
|
|
player.saveData();
|
|
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
|
|
if (!Settings.getRegisteredGroup.isEmpty()) {
|
|
Utils.setGroup(player, GroupType.UNREGISTERED);
|
|
}
|
|
LimboCache.getInstance().addLimboPlayer(player);
|
|
LimboPlayer limboPlayer = LimboCache.getInstance().getLimboPlayer(name);
|
|
int interval = Settings.getWarnMessageInterval;
|
|
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
|
if (timeOut != 0) {
|
|
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin,
|
|
new TimeoutTask(plugin, name, player), timeOut);
|
|
limboPlayer.setTimeoutTaskId(id);
|
|
}
|
|
limboPlayer.setMessageTaskId(scheduler.runTaskAsynchronously(plugin,
|
|
new MessageTask(plugin, name, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
|
|
m.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
|
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
|
return;
|
|
}
|
|
if (!Settings.unRegisteredGroup.isEmpty()) {
|
|
Utils.setGroup(player, Utils.GroupType.UNREGISTERED);
|
|
}
|
|
PlayerCache.getInstance().removePlayer(name);
|
|
// check if Player cache File Exist and delete it, preventing
|
|
// duplication of items
|
|
if (playerCache.doesCacheExist(player)) {
|
|
playerCache.removeCache(player);
|
|
}
|
|
// Apply blind effect
|
|
if (Settings.applyBlindEffect) {
|
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
|
}
|
|
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
|
player.setWalkSpeed(0.0f);
|
|
player.setFlySpeed(0.0f);
|
|
}
|
|
m.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
|
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
|
Utils.teleportToSpawn(player);
|
|
} else {
|
|
m.send(player, MessageKey.WRONG_PASSWORD);
|
|
}
|
|
} catch (NoSuchAlgorithmException ignored) {
|
|
}
|
|
}
|
|
}
|