Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 437-add-email

Conflicts:
	src/main/java/fr/xephi/authme/datasource/MySQL.java
	src/main/java/fr/xephi/authme/datasource/SQLite.java
	src/main/java/fr/xephi/authme/process/Management.java
	src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java
This commit is contained in:
ljacqu
2016-02-06 18:01:11 +01:00
96 changed files with 1674 additions and 1762 deletions
@@ -2,7 +2,6 @@ package fr.xephi.authme.process;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.process.email.AsyncAddEmail;
import fr.xephi.authme.process.email.AsyncChangeEmail;
import fr.xephi.authme.process.join.AsynchronousJoin;
import fr.xephi.authme.process.login.AsynchronousLogin;
@@ -10,6 +9,7 @@ import fr.xephi.authme.process.logout.AsynchronousLogout;
import fr.xephi.authme.process.quit.AsynchronousQuit;
import fr.xephi.authme.process.register.AsyncRegister;
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
import fr.xephi.authme.settings.NewSetting;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
@@ -19,15 +19,17 @@ public class Management {
private final AuthMe plugin;
private final BukkitScheduler sched;
private final NewSetting settings;
/**
* Constructor for Management.
*
* @param plugin AuthMe
*/
public Management(AuthMe plugin) {
public Management(AuthMe plugin, NewSetting settings) {
this.plugin = plugin;
this.sched = this.plugin.getServer().getScheduler();
this.settings = settings;
}
public void performLogin(final Player player, final String password, final boolean forceLogin) {
@@ -35,7 +37,8 @@ public class Management {
@Override
public void run() {
new AsynchronousLogin(player, password, forceLogin, plugin, plugin.getDataSource()).process();
new AsynchronousLogin(player, password, forceLogin, plugin, plugin.getDataSource(), settings)
.process();
}
});
}
@@ -55,7 +58,7 @@ public class Management {
@Override
public void run() {
new AsyncRegister(player, password, email, plugin, plugin.getDataSource()).process();
new AsyncRegister(player, password, email, plugin, plugin.getDataSource(), settings).process();
}
});
}
@@ -96,8 +99,7 @@ public class Management {
sched.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
new AsyncAddEmail(plugin, player, newEmail, plugin.getDataSource(), PlayerCache.getInstance())
.process();
new AsyncChangeEmail(player, plugin, null, newEmail, plugin.getDataSource(), PlayerCache.getInstance(), settings).process();
}
});
}
@@ -106,7 +108,7 @@ public class Management {
sched.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
new AsyncChangeEmail(player, plugin, oldEmail, newEmail, plugin.getDataSource(), PlayerCache.getInstance()).process();
new AsyncChangeEmail(player, plugin, oldEmail, newEmail, plugin.getDataSource(), PlayerCache.getInstance(), settings).process();
}
});
}
@@ -6,8 +6,10 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
/**
@@ -20,13 +22,16 @@ public class AsyncAddEmail {
private final Messages messages;
private final DataSource dataSource;
private final PlayerCache playerCache;
private final NewSetting settings;
public AsyncAddEmail(AuthMe plugin, Player player, String email, DataSource dataSource, PlayerCache playerCache) {
public AsyncAddEmail(AuthMe plugin, Player player, String email, DataSource dataSource,
PlayerCache playerCache, NewSetting settings) {
this.messages = plugin.getMessages();
this.player = player;
this.email = email;
this.dataSource = dataSource;
this.playerCache = playerCache;
this.settings = settings;
}
public void process() {
@@ -52,9 +57,9 @@ public class AsyncAddEmail {
}
}
private static boolean isEmailInvalid(String email) {
private boolean isEmailInvalid(String email) {
return StringUtils.isEmpty(email) || "your@email.com".equals(email)
|| !Settings.isEmailCorrect(email);
|| !Utils.isEmailCorrect(email, settings);
}
private void sendUnloggedMessage(DataSource dataSource) {
@@ -6,8 +6,10 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
/**
@@ -19,17 +21,19 @@ public class AsyncChangeEmail {
private final String oldEmail;
private final String newEmail;
private final Messages m;
private final NewSetting settings;
private final PlayerCache playerCache;
private final DataSource dataSource;
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail,
String newEmail, DataSource dataSource, PlayerCache playerCache) {
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, DataSource dataSource,
PlayerCache playerCache, NewSetting settings) {
this.m = plugin.getMessages();
this.player = player;
this.oldEmail = oldEmail;
this.newEmail = newEmail;
this.playerCache = playerCache;
this.dataSource = dataSource;
this.settings = settings;
}
public void process() {
@@ -54,9 +58,9 @@ public class AsyncChangeEmail {
}
}
private static boolean isEmailInvalid(String email) {
private boolean isEmailInvalid(String email) {
return StringUtils.isEmpty(email) || "your@email.com".equals(email)
|| !Settings.isEmailCorrect(email);
|| !Utils.isEmailCorrect(email, settings);
}
private void saveNewEmail(PlayerAuth auth) {
@@ -49,14 +49,14 @@ public class AsynchronousJoin {
}
public void process() {
if (Settings.checkVeryGames) {
plugin.getVerygamesIp(player);
}
if (Utils.isUnrestricted(player)) {
return;
}
if (Settings.checkVeryGames) {
plugin.getVerygamesIp(player);
}
if (plugin.ess != null && Settings.disableSocialSpy) {
plugin.ess.getUser(player).setSocialSpyEnabled(false);
}
@@ -64,13 +64,13 @@ public class AsynchronousJoin {
final String ip = plugin.getIP(player);
if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip, player.getAddress().getHostName())) {
if (Settings.isAllowRestrictedIp && !isNameRestricted(name, ip, player.getAddress().getHostName())) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
player.kickPlayer("You are not the Owner of this account, please try another name!");
player.kickPlayer("You are not the owner of this account. Please try another name!");
if (Settings.banUnsafeIp)
plugin.getServer().banIP(ip);
}
@@ -225,7 +225,7 @@ public class AsynchronousJoin {
? m.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE)
: m.retrieve(MessageKey.REGISTER_MESSAGE);
}
if (LimboCache.getInstance().getLimboPlayer(name) != null) {
if (msgInterval > 0 && LimboCache.getInstance().getLimboPlayer(name) != null) {
BukkitTask msgTask = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
}
@@ -282,4 +282,30 @@ public class AsynchronousJoin {
});
}
/**
* Return whether the name is restricted based on the restriction setting.
*
* @param name The name to check
* @param ip The IP address of the player
* @param domain The hostname of the IP address
* @return True if the name is restricted (IP/domain is not allowed for the given name),
* false if the restrictions are met or if the name has no restrictions to it
*/
private static boolean isNameRestricted(String name, String ip, String domain) {
boolean nameFound = false;
for (String entry : Settings.getRestrictedIp) {
String[] args = entry.split(";");
String testName = args[0];
String testIp = args[1];
if (testName.equalsIgnoreCase(name)) {
nameFound = true;
if ((ip != null && testIp.equals(ip))
|| (domain != null && testIp.equalsIgnoreCase(domain))) {
return false;
}
}
}
return nameFound;
}
}
@@ -11,8 +11,11 @@ import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -34,6 +37,7 @@ public class AsynchronousLogin {
private final DataSource database;
private final Messages m;
private final String ip;
private final NewSetting settings;
/**
* Constructor for AsynchronousLogin.
@@ -43,8 +47,10 @@ public class AsynchronousLogin {
* @param forceLogin boolean
* @param plugin AuthMe
* @param data DataSource
* @param settings The settings
*/
public AsynchronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data) {
public AsynchronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data,
NewSetting settings) {
this.m = plugin.getMessages();
this.player = player;
this.name = player.getName().toLowerCase();
@@ -54,6 +60,7 @@ public class AsynchronousLogin {
this.plugin = plugin;
this.database = data;
this.ip = plugin.getIP(player);
this.settings = settings;
}
protected boolean needsCaptcha() {
@@ -98,7 +105,7 @@ public class AsynchronousLogin {
msg = m.retrieve(MessageKey.REGISTER_MESSAGE);
}
BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin,
new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
new MessageTask(plugin, name, msg, settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
}
return null;
@@ -165,12 +172,10 @@ public class AsynchronousLogin {
if (!forceLogin)
m.send(player, MessageKey.LOGIN_SUCCESS);
displayOtherAccounts(auth, player);
displayOtherAccounts(auth);
if (Settings.recallEmail) {
if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) {
m.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
}
if (Settings.recallEmail && (StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email))) {
m.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
}
if (!Settings.noConsoleSpam) {
@@ -186,7 +191,7 @@ public class AsynchronousLogin {
// task, we schedule it in the end
// so that we can be sure, and have not to care if it might be
// processed in other order.
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database);
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database, settings);
if (syncPlayerLogin.getLimbo() != null) {
if (syncPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
syncPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
@@ -215,7 +220,7 @@ public class AsynchronousLogin {
}
}
public void displayOtherAccounts(PlayerAuth auth, Player p) {
public void displayOtherAccounts(PlayerAuth auth) {
if (!Settings.displayOtherAccounts) {
return;
}
@@ -223,30 +228,16 @@ public class AsynchronousLogin {
return;
}
List<String> auths = this.database.getAllAuthsByName(auth);
if (auths.isEmpty()) {
if (auths.isEmpty() || auths.size() == 1) {
return;
}
if (auths.size() == 1) {
return;
}
StringBuilder message = new StringBuilder("[AuthMe] ");
int i = 0;
for (String account : auths) {
i++;
message.append(account);
if (i != auths.size()) {
message.append(", ");
} else {
message.append('.');
}
}
String message = "[AuthMe] " + StringUtils.join(", ", auths) + ".";
for (Player player : Utils.getOnlinePlayers()) {
if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.SEE_OTHER_ACCOUNTS)
|| (player.getName().equals(this.player.getName())
&& plugin.getPermissionsManager().hasPermission(player, PlayerPermission.SEE_OWN_ACCOUNTS))) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
player.sendMessage(message.toString());
player.sendMessage(message);
}
}
}
@@ -1,5 +1,7 @@
package fr.xephi.authme.process.login;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.HooksSettings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -24,6 +26,8 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
/**
*/
public class ProcessSyncPlayerLogin implements Runnable {
@@ -36,24 +40,26 @@ public class ProcessSyncPlayerLogin implements Runnable {
private final DataSource database;
private final PluginManager pm;
private final JsonCache playerCache;
private final NewSetting settings;
/**
* Constructor for ProcessSyncPlayerLogin.
*
* @param player Player
* @param plugin AuthMe
* @param data DataSource
* @param database DataSource
*/
public ProcessSyncPlayerLogin(Player player, AuthMe plugin,
DataSource data) {
DataSource database, NewSetting settings) {
this.plugin = plugin;
this.database = data;
this.database = database;
this.pm = plugin.getServer().getPluginManager();
this.player = player;
this.name = player.getName().toLowerCase();
this.limbo = LimboCache.getInstance().getLimboPlayer(name);
this.auth = database.getAuth(name);
this.playerCache = new JsonCache();
this.settings = settings;
}
/**
@@ -152,7 +158,7 @@ public class ProcessSyncPlayerLogin implements Runnable {
}
}
if (Settings.protectInventoryBeforeLogInEnabled) {
if (settings.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
restoreInventory();
}
@@ -188,27 +194,27 @@ public class ProcessSyncPlayerLogin implements Runnable {
// Login is finish, display welcome message if we use email registration
if (Settings.useWelcomeMessage && Settings.emailRegistration)
if (Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
for (String s : settings.getWelcomeMessage()) {
Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
}
} else {
for (String s : Settings.welcomeMsg) {
for (String s : settings.getWelcomeMessage()) {
player.sendMessage(plugin.replaceAllInfo(s, player));
}
}
// Login is now finish , we can force all commands
// Login is now finished; we can force all commands
forceCommands();
sendTo();
}
private void sendTo() {
if (Settings.sendPlayerTo.isEmpty())
return;
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(Settings.sendPlayerTo);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
if (!settings.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(settings.getProperty(HooksSettings.BUNGEECORD_SERVER));
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
}
}
@@ -49,6 +49,13 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
protected void restoreSpeedEffect() {
if (Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.0F);
player.setFlySpeed(0.0F);
}
}
/**
* Method run.
*
@@ -77,6 +84,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
if (Settings.applyBlindEffect)
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
player.setOp(false);
restoreSpeedEffect();
// Player is now logout... Time to fire event !
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
if (Settings.bungee)
@@ -75,18 +75,21 @@ public class AsynchronousQuit {
}
if (Settings.isSessionsEnabled && !isKick) {
if (Settings.getSessionTimeout != 0) {
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
if (plugin.isEnabled()) {
BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
PlayerCache.getInstance().removePlayer(name);
if (database.isLogged(name))
database.setUnlogged(name);
plugin.sessions.remove(name);
}
@Override
public void run() {
postLogout();
}
}, Settings.getSessionTimeout * 20 * 60);
plugin.sessions.put(name, task);
}, Settings.getSessionTimeout * 20 * 60);
plugin.sessions.put(name, task);
} else {
//plugin is disable we canno schedule more tasks so run it directly here
postLogout();
}
}
} else {
PlayerCache.getInstance().removePlayer(name);
@@ -94,6 +97,15 @@ public class AsynchronousQuit {
}
plugin.realIp.remove(name);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange));
if (plugin.isEnabled()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange));
}
}
private void postLogout() {
PlayerCache.getInstance().removePlayer(name);
if (database.isLogged(name))
database.setUnlogged(name);
plugin.sessions.remove(name);
}
}
@@ -9,6 +9,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
@@ -24,8 +25,10 @@ public class AsyncRegister {
private final AuthMe plugin;
private final DataSource database;
private final Messages m;
private final NewSetting settings;
public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data) {
public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data,
NewSetting settings) {
this.m = plugin.getMessages();
this.player = player;
this.password = password;
@@ -34,6 +37,7 @@ public class AsyncRegister {
this.plugin = plugin;
this.database = data;
this.ip = plugin.getIP(player);
this.settings = settings;
}
private boolean preRegisterCheck() throws Exception {
@@ -75,14 +79,13 @@ public class AsyncRegister {
if (!preRegisterCheck()) {
return;
}
if (!email.isEmpty() && !email.equals("")) {
if (email != null && !email.isEmpty()) {
emailRegister();
} else {
passwordRegister();
}
} catch (Exception e) {
ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e);
ConsoleLogger.logException("Error during async register process", e);
m.send(player, MessageKey.ERROR);
}
}
@@ -137,7 +140,7 @@ public class AsyncRegister {
plugin.getManagement().performLogin(player, "dontneed", true);
}
plugin.otherAccounts.addPlayer(player.getUniqueId());
ProcessSyncPasswordRegister sync = new ProcessSyncPasswordRegister(player, plugin);
ProcessSyncPasswordRegister sync = new ProcessSyncPasswordRegister(player, plugin, settings);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, sync);
}
}
@@ -1,5 +1,7 @@
package fr.xephi.authme.process.register;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.HooksSettings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@@ -30,6 +32,7 @@ public class ProcessSyncPasswordRegister implements Runnable {
protected final String name;
private final AuthMe plugin;
private final Messages m;
private final NewSetting settings;
/**
* Constructor for ProcessSyncPasswordRegister.
@@ -37,11 +40,12 @@ public class ProcessSyncPasswordRegister implements Runnable {
* @param player Player
* @param plugin AuthMe
*/
public ProcessSyncPasswordRegister(Player player, AuthMe plugin) {
public ProcessSyncPasswordRegister(Player player, AuthMe plugin, NewSetting settings) {
this.m = plugin.getMessages();
this.player = player;
this.name = player.getName().toLowerCase();
this.plugin = plugin;
this.settings = settings;
}
private void sendBungeeMessage() {
@@ -63,11 +67,6 @@ public class ProcessSyncPasswordRegister implements Runnable {
}
}
/**
* Method forceLogin.
*
* @param player Player
*/
private void forceLogin(Player player) {
Utils.teleportToSpawn(player);
LimboCache cache = LimboCache.getInstance();
@@ -88,11 +87,6 @@ public class ProcessSyncPasswordRegister implements Runnable {
}
}
/**
* Method run.
*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
@@ -141,11 +135,11 @@ public class ProcessSyncPasswordRegister implements Runnable {
// Register is finish and player is logged, display welcome message
if (Settings.useWelcomeMessage) {
if (Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
for (String s : settings.getWelcomeMessage()) {
plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
}
} else {
for (String s : Settings.welcomeMsg) {
for (String s : settings.getWelcomeMessage()) {
player.sendMessage(plugin.replaceAllInfo(s, player));
}
}
@@ -161,18 +155,18 @@ public class ProcessSyncPasswordRegister implements Runnable {
sendBungeeMessage();
}
// Register is now finish , we can force all commands
// Register is now finished; we can force all commands
forceCommands();
sendTo();
}
private void sendTo() {
if (Settings.sendPlayerTo.isEmpty())
return;
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(Settings.sendPlayerTo);
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
if (!settings.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(settings.getProperty(HooksSettings.BUNGEECORD_SERVER));
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
}
}