Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 347-config-rewrite

This commit is contained in:
ljacqu 2016-01-07 21:51:20 +01:00
commit 7d749801f9
10 changed files with 220 additions and 637 deletions

View File

@ -32,7 +32,6 @@ import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.listener.AuthMePlayerListener16;
import fr.xephi.authme.listener.AuthMePlayerListener18;
import fr.xephi.authme.listener.AuthMeServerListener;
import fr.xephi.authme.listener.AuthMeServerStop;
import fr.xephi.authme.listener.AuthMeTabCompletePacketAdapter;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.modules.ModuleManager;
@ -307,13 +306,6 @@ public class AuthMe extends JavaPlugin {
// Show settings warnings
showSettingsWarnings();
// Register a server shutdown hook
try {
Runtime.getRuntime().addShutdownHook(new AuthMeServerStop(this));
} catch (Exception e) {
e.printStackTrace();
}
// Sponsor messages
ConsoleLogger.info("AuthMe hooks perfectly with the VeryGames server hosting!");
ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt.");
@ -521,10 +513,10 @@ public class AuthMe extends JavaPlugin {
public void onDisable() {
// Save player data
Collection<? extends Player> players = Utils.getOnlinePlayers();
if (players != null) {
for (Player player : players) {
this.savePlayer(player);
}
for (Player player : players) {
savePlayer(player);
// TODO: add a MessageKey
player.kickPlayer("Server is restarting or AuthMe plugin was disabled.");
}
// Do backup on stop if enabled

View File

@ -1,11 +1,5 @@
package fr.xephi.authme.datasource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@ -13,10 +7,16 @@ import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalListeners;
import com.google.common.cache.RemovalNotification;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
*/
public class CacheDataSource implements DataSource {
@ -52,44 +52,17 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method isAuthAvailable.
*
* @param user String
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
*/
@Override
public synchronized boolean isAuthAvailable(String user) {
return getAuth(user) != null;
}
/**
* Method getAuth.
*
* @param user String
*
* @return PlayerAuth
*
* @see fr.xephi.authme.datasource.DataSource#getAuth(String)
*/
@Override
public synchronized PlayerAuth getAuth(String user) {
user = user.toLowerCase();
return cachedAuths.getUnchecked(user).orNull();
}
/**
* Method saveAuth.
*
* @param auth PlayerAuth
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
*/
@Override
public synchronized boolean saveAuth(PlayerAuth auth) {
boolean result = source.saveAuth(auth);
@ -99,15 +72,6 @@ public class CacheDataSource implements DataSource {
return result;
}
/**
* Method updatePassword.
*
* @param auth PlayerAuth
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
*/
@Override
public synchronized boolean updatePassword(PlayerAuth auth) {
boolean result = source.updatePassword(auth);
@ -117,15 +81,6 @@ public class CacheDataSource implements DataSource {
return result;
}
/**
* Method updateSession.
*
* @param auth PlayerAuth
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
*/
@Override
public boolean updateSession(PlayerAuth auth) {
boolean result = source.updateSession(auth);
@ -135,47 +90,20 @@ public class CacheDataSource implements DataSource {
return result;
}
/**
* Method updateQuitLoc.
*
* @param auth PlayerAuth
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
*/
@Override
public boolean updateQuitLoc(final PlayerAuth auth) {
boolean result = source.updateSession(auth);
boolean result = source.updateQuitLoc(auth);
if (result) {
cachedAuths.refresh(auth.getNickname());
}
return result;
}
/**
* Method getIps.
*
* @param ip String
*
* @return int
*
* @see fr.xephi.authme.datasource.DataSource#getIps(String)
*/
@Override
public int getIps(String ip) {
return source.getIps(ip);
}
/**
* Method purgeDatabase.
*
* @param until long
*
* @return int
*
* @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
*/
@Override
public int purgeDatabase(long until) {
int cleared = source.purgeDatabase(until);
@ -189,15 +117,6 @@ public class CacheDataSource implements DataSource {
return cleared;
}
/**
* Method autoPurgeDatabase.
*
* @param until long
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
*/
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
@ -207,15 +126,6 @@ public class CacheDataSource implements DataSource {
return cleared;
}
/**
* Method removeAuth.
*
* @param name String
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
*/
@Override
public synchronized boolean removeAuth(String name) {
name = name.toLowerCase();
@ -226,22 +136,17 @@ public class CacheDataSource implements DataSource {
return result;
}
/**
* Method close.
*
* @see fr.xephi.authme.datasource.DataSource#close()
*/
@Override
public synchronized void close() {
exec.shutdown();
try {
exec.shutdown();
exec.awaitTermination(8, TimeUnit.SECONDS);
} catch (InterruptedException e) {
ConsoleLogger.writeStackTrace(e);
}
source.close();
}
/**
* Method reload.
*
* @see fr.xephi.authme.datasource.DataSource#reload()
*/
@Override
public void reload() { // unused method
exec.execute(new Runnable() {
@ -253,15 +158,6 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method updateEmail.
*
* @param auth PlayerAuth
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
*/
@Override
public synchronized boolean updateEmail(final PlayerAuth auth) {
boolean result = source.updateEmail(auth);
@ -271,55 +167,21 @@ public class CacheDataSource implements DataSource {
return result;
}
/**
* Method getAllAuthsByName.
*
* @param auth PlayerAuth
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
*/
@Override
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
return source.getAllAuthsByName(auth);
}
/**
* Method getAllAuthsByIp.
*
* @param ip String
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
*/
@Override
public synchronized List<String> getAllAuthsByIp(final String ip) {
return source.getAllAuthsByIp(ip);
}
/**
* Method getAllAuthsByEmail.
*
* @param email String
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
*/
@Override
public synchronized List<String> getAllAuthsByEmail(final String email) {
return source.getAllAuthsByEmail(email);
}
/**
* Method purgeBanned.
*
* @param banned List of String
*
* @see fr.xephi.authme.datasource.DataSource#purgeBanned(List)
*/
@Override
public synchronized void purgeBanned(final List<String> banned) {
exec.execute(new Runnable() {
@ -331,39 +193,16 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method getType.
*
* @return DataSourceType
*
* @see fr.xephi.authme.datasource.DataSource#getType()
*/
@Override
public DataSourceType getType() {
return source.getType();
}
/**
* Method isLogged.
*
* @param user String
*
* @return boolean
*
* @see fr.xephi.authme.datasource.DataSource#isLogged(String)
*/
@Override
public boolean isLogged(String user) {
return PlayerCache.getInstance().isAuthenticated(user);
}
/**
* Method setLogged.
*
* @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setLogged(String)
*/
@Override
public void setLogged(final String user) {
exec.execute(new Runnable() {
@ -374,13 +213,6 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method setUnlogged.
*
* @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
*/
@Override
public void setUnlogged(final String user) {
exec.execute(new Runnable() {
@ -391,11 +223,6 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method purgeLogged.
*
* @see fr.xephi.authme.datasource.DataSource#purgeLogged()
*/
@Override
public void purgeLogged() {
exec.execute(new Runnable() {
@ -407,26 +234,11 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method getAccountsRegistered.
*
* @return int
*
* @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
*/
@Override
public int getAccountsRegistered() {
return source.getAccountsRegistered();
}
/**
* Method updateName.
*
* @param oldOne String
* @param newOne String
*
* @see fr.xephi.authme.datasource.DataSource#updateName(String, String)
*/
@Override
public void updateName(final String oldOne, final String newOne) {
exec.execute(new Runnable() {
@ -438,25 +250,11 @@ public class CacheDataSource implements DataSource {
});
}
/**
* Method getAllAuths.
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#getAllAuths()
*/
@Override
public List<PlayerAuth> getAllAuths() {
return source.getAllAuths();
}
/**
* Method getLoggedPlayers.
*
* @return List
*
* @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers()
*/
@Override
public List<PlayerAuth> getLoggedPlayers() {
return new ArrayList<>(PlayerCache.getInstance().getCache().values());

View File

@ -70,12 +70,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method connect.
*
* @throws ClassNotFoundException
* @throws SQLException
*/
private synchronized void connect() throws ClassNotFoundException, SQLException {
Class.forName("org.sqlite.JDBC");
ConsoleLogger.info("SQLite driver loaded");
@ -83,11 +77,6 @@ public class SQLite implements DataSource {
}
/**
* Method setup.
*
* @throws SQLException
*/
private synchronized void setup() throws SQLException {
Statement st = null;
ResultSet rs = null;
@ -149,14 +138,6 @@ public class SQLite implements DataSource {
ConsoleLogger.info("SQLite Setup finished");
}
/**
* Method isAuthAvailable.
*
* @param user String
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String)
*/
@Override
public synchronized boolean isAuthAvailable(String user) {
PreparedStatement pst = null;
@ -175,14 +156,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAuth.
*
* @param user String
*
* @return PlayerAuth
* @see fr.xephi.authme.datasource.DataSource#getAuth(String)
*/
@Override
public synchronized PlayerAuth getAuth(String user) {
PreparedStatement pst = null;
@ -205,14 +178,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method saveAuth.
*
* @param auth PlayerAuth
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth)
*/
@Override
public synchronized boolean saveAuth(PlayerAuth auth) {
PreparedStatement pst = null;
@ -252,14 +217,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method updatePassword.
*
* @param auth PlayerAuth
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth)
*/
@Override
public synchronized boolean updatePassword(PlayerAuth auth) {
PreparedStatement pst = null;
@ -287,14 +244,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method updateSession.
*
* @param auth PlayerAuth
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth)
*/
@Override
public boolean updateSession(PlayerAuth auth) {
PreparedStatement pst = null;
@ -314,14 +263,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method purgeDatabase.
*
* @param until long
*
* @return int
* @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long)
*/
@Override
public int purgeDatabase(long until) {
PreparedStatement pst = null;
@ -338,14 +279,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method autoPurgeDatabase.
*
* @param until long
*
* @return List of String
* @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long)
*/
@Override
public List<String> autoPurgeDatabase(long until) {
PreparedStatement pst = null;
@ -368,14 +301,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method removeAuth.
*
* @param user String
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#removeAuth(String)
*/
@Override
public synchronized boolean removeAuth(String user) {
PreparedStatement pst = null;
@ -392,14 +317,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method updateQuitLoc.
*
* @param auth PlayerAuth
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth)
*/
@Override
public boolean updateQuitLoc(PlayerAuth auth) {
PreparedStatement pst = null;
@ -420,14 +337,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method getIps.
*
* @param ip String
*
* @return int
* @see fr.xephi.authme.datasource.DataSource#getIps(String)
*/
@Override
public int getIps(String ip) {
PreparedStatement pst = null;
@ -451,14 +360,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method updateEmail.
*
* @param auth PlayerAuth
*
* @return boolean
* @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth)
*/
@Override
public boolean updateEmail(PlayerAuth auth) {
PreparedStatement pst = null;
@ -476,11 +377,6 @@ public class SQLite implements DataSource {
return true;
}
/**
* Method close.
*
* @see fr.xephi.authme.datasource.DataSource#close()
*/
@Override
public synchronized void close() {
try {
@ -490,20 +386,10 @@ public class SQLite implements DataSource {
}
}
/**
* Method reload.
*
* @see fr.xephi.authme.datasource.DataSource#reload()
*/
@Override
public void reload() {
}
/**
* Method close.
*
* @param st Statement
*/
private void close(Statement st) {
if (st != null) {
try {
@ -514,11 +400,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method close.
*
* @param rs ResultSet
*/
private void close(ResultSet rs) {
if (rs != null) {
try {
@ -529,14 +410,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAllAuthsByName.
*
* @param auth PlayerAuth
*
* @return List of String
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth)
*/
@Override
public List<String> getAllAuthsByName(PlayerAuth auth) {
PreparedStatement pst = null;
@ -561,14 +434,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAllAuthsByIp.
*
* @param ip String
*
* @return List of String
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String)
*/
@Override
public List<String> getAllAuthsByIp(String ip) {
PreparedStatement pst = null;
@ -593,14 +458,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAllAuthsByEmail.
*
* @param email String
*
* @return List of String
* @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String)
*/
@Override
public List<String> getAllAuthsByEmail(String email) {
PreparedStatement pst = null;
@ -641,24 +498,11 @@ public class SQLite implements DataSource {
}
}
/**
* Method getType.
*
* @return DataSourceType
* @see fr.xephi.authme.datasource.DataSource#getType()
*/
@Override
public DataSourceType getType() {
return DataSourceType.SQLITE;
}
/**
* Method isLogged.
*
* @param user String
*
* @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String)
*/
@Override
public boolean isLogged(String user) {
PreparedStatement pst = null;
@ -679,13 +523,6 @@ public class SQLite implements DataSource {
return false;
}
/**
* Method setLogged.
*
* @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setLogged(String)
*/
@Override
public void setLogged(String user) {
PreparedStatement pst = null;
@ -701,13 +538,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method setUnlogged.
*
* @param user String
*
* @see fr.xephi.authme.datasource.DataSource#setUnlogged(String)
*/
@Override
public void setUnlogged(String user) {
PreparedStatement pst = null;
@ -724,11 +554,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method purgeLogged.
*
* @see fr.xephi.authme.datasource.DataSource#purgeLogged()
*/
@Override
public void purgeLogged() {
PreparedStatement pst = null;
@ -744,12 +569,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAccountsRegistered.
*
* @return int
* @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered()
*/
@Override
public int getAccountsRegistered() {
int result = 0;
@ -785,11 +604,6 @@ public class SQLite implements DataSource {
}
}
/**
* Method getAllAuths.
*
* @return List of PlayerAuth
*/
@Override
public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>();
@ -811,11 +625,6 @@ public class SQLite implements DataSource {
return auths;
}
/**
* Method getLoggedPlayers.
*
* @return List of PlayerAuth
*/
@Override
public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<>();

View File

@ -193,7 +193,7 @@ public class AuthMePlayerListener implements Listener {
}
if (Settings.isForceSurvivalModeEnabled
&& !player.hasPermission(PlayerPermission.BYPASS_FORCE_SURVIVAL.getNode())) {
&& !player.hasPermission(PlayerPermission.BYPASS_FORCE_SURVIVAL.getNode())) {
player.setGameMode(GameMode.SURVIVAL);
}
@ -221,7 +221,7 @@ public class AuthMePlayerListener implements Listener {
PlayerAuth auth = plugin.getDataSource().getAuth(event.getName());
if (Settings.preventOtherCase && auth != null && auth.getRealName() != null) {
String realName = auth.getRealName();
if(!realName.isEmpty() && !realName.equals("Player") && !realName.equals(event.getName())) {
if (!realName.isEmpty() && !realName.equals("Player") && !realName.equals(event.getName())) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
// TODO: Add a message like : MessageKey.INVALID_NAME_CASE
event.setKickMessage("You should join using username: " + ChatColor.AQUA + realName +
@ -274,21 +274,26 @@ public class AuthMePlayerListener implements Listener {
// Get the permissions manager
PermissionsManager permsMan = plugin.getPermissionsManager();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL
&& permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
int playersOnline = Utils.getOnlinePlayers().size();
if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow();
} else {
Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
if (pl != null) {
pl.kickPlayer(m.retrieveSingle(MessageKey.KICK_FOR_VIP));
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
if (permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
int playersOnline = Utils.getOnlinePlayers().size();
if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow();
} else {
ConsoleLogger.info("The player " + event.getPlayer().getName() + " tried to join, but the server was full");
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
if (pl != null) {
pl.kickPlayer(m.retrieveSingle(MessageKey.KICK_FOR_VIP));
event.allow();
} else {
ConsoleLogger.info("The player " + event.getPlayer().getName() + " tried to join, but the server was full");
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
}
}
} else {
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
}
}
@ -296,12 +301,6 @@ public class AuthMePlayerListener implements Listener {
return;
}
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
}
final String name = player.getName().toLowerCase();
boolean isAuthAvailable = plugin.getDataSource().isAuthAvailable(name);

View File

@ -1,30 +0,0 @@
package fr.xephi.authme.listener;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.settings.Settings;
public class AuthMeServerStop extends Thread {
private AuthMe plugin;
public AuthMeServerStop(AuthMe plugin) {
this.plugin = plugin;
}
public void run() {
// TODO: add a MessageKey
if (Settings.kickPlayersBeforeStopping) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
{
@Override
public void run() {
for (Player p : plugin.getServer().getOnlinePlayers()) {
p.kickPlayer("Server is restarting");
}
}
});
}
}
}

View File

@ -97,6 +97,8 @@ public enum MessageKey {
USAGE_ADD_EMAIL("usage_email_add"),
USAGE_CHANGE_EMAIL("usage_email_change"),
USAGE_RECOVER_EMAIL("usage_email_recovery"),
INVALID_NEW_EMAIL("new_email_invalid"),

View File

@ -298,8 +298,8 @@ public class PermissionsManager implements PermissionsService {
}
Player player = (Player) sender;
return hasPermission(player, permissionNode.getNode(), def)
|| hasPermission(player, permissionNode.getWildcardNode().getNode(), def);
return hasPermission(player, permissionNode.getNode(), def);
// || hasPermission(player, permissionNode.getWildcardNode().getNode(), def);
}
public boolean hasPermission(Player player, Iterable<PermissionNode> nodes, boolean def) {

View File

@ -1,13 +1,12 @@
package fr.xephi.authme.process.email;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.entity.Player;
/**
@ -35,66 +34,57 @@ public class AsyncChangeEmail {
}
public void process() {
try {
String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& plugin.getDataSource().getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
String playerName = player.getName().toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
if (!newEmail.equals(newEmailVerify)) {
m.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
return;
}
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
if (!newEmail.equals(newEmailVerify)) {
m.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
String currentEmail = auth.getEmail();
if (oldEmail != null) {
if (StringUtils.isEmpty(currentEmail) || currentEmail.equals("your@email.com")) {
m.send(player, MessageKey.USAGE_ADD_EMAIL);
return;
}
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
if (oldEmail != null) {
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
m.send(player, MessageKey.USAGE_ADD_EMAIL);
return;
}
if (!oldEmail.equals(auth.getEmail())) {
m.send(player, MessageKey.INVALID_OLD_EMAIL);
return;
}
}
if (!Settings.isEmailCorrect(newEmail)) {
m.send(player, MessageKey.INVALID_NEW_EMAIL);
if (!oldEmail.equals(currentEmail)) {
m.send(player, MessageKey.INVALID_OLD_EMAIL);
return;
}
String old = auth.getEmail();
auth.setEmail(newEmail);
if (!plugin.getDataSource().updateEmail(auth)) {
m.send(player, MessageKey.ERROR);
auth.setEmail(old);
return;
}
PlayerCache.getInstance().updatePlayer(auth);
if (oldEmail == null) {
m.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
player.sendMessage(auth.getEmail());
return;
}
m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
} else {
if (plugin.getDataSource().isAuthAvailable(playerName)) {
m.send(player, MessageKey.LOGIN_MESSAGE);
} else {
if (Settings.emailRegistration) {
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else {
m.send(player, MessageKey.REGISTER_MESSAGE);
}
if (!StringUtils.isEmpty(currentEmail) && !currentEmail.equals("your@email.com")) {
m.send(player, MessageKey.USAGE_CHANGE_EMAIL);
return;
}
}
if (!Settings.isEmailCorrect(newEmail)) {
m.send(player, MessageKey.INVALID_NEW_EMAIL);
return;
}
auth.setEmail(newEmail);
if (!plugin.getDataSource().updateEmail(auth)) {
m.send(player, MessageKey.ERROR);
auth.setEmail(currentEmail);
return;
}
PlayerCache.getInstance().updatePlayer(auth);
if (oldEmail == null) {
m.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
player.sendMessage(auth.getEmail());
return;
}
m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
} else {
if (plugin.getDataSource().isAuthAvailable(playerName)) {
m.send(player, MessageKey.LOGIN_MESSAGE);
} else {
if (Settings.emailRegistration) {
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else {
m.send(player, MessageKey.REGISTER_MESSAGE);
}
}
} catch (Exception e) {
ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e);
m.send(player, MessageKey.ERROR);
}
}
}

View File

@ -235,8 +235,7 @@ public final class Utils {
}
public static Player getPlayer(String name) {
name = name.toLowerCase();
return wrapper.getServer().getPlayer(name);
return wrapper.getServer().getPlayerExact(name);
}
public static boolean isNPC(Player player) {

View File

@ -45,120 +45,144 @@ commands:
usage: /converter <datatype>
permissions:
authme.admin.*:
description: Gives access to all authme admin commands
children:
authme.admin.reload: true
authme.admin.register: true
authme.admin.changepassword: true
authme.admin.unregister: true
authme.admin.purge: true
authme.seeOtherAccounts: true # This isn't a child of the admin section! Probably doesn't work.
authme.admin.lastlogin: true
authme.admin.getemail: true
authme.admin.chgemail: true
authme.admin.purgelastpos: true
authme.admin.switchantibot: true
authme.bypassantibot: true # This isn't a child of the admin section! Probably doesn't work.
authme.admin.getip: true
authme.admin.converter: true
authme.admin.resetposition: true
authme.admin.forcelogin: true
authme.register:
description: Register an account
default: true
authme.login:
description: Login into a account
default: true
authme.changepassword:
description: Change password of a account
default: true
authme.logout:
description: Logout
default: true
authme.email:
description: Email
default: true
authme.allow2accounts:
description: allow more accounts for same ip
default: false
authme.seeOtherAccounts:
description: display other accounts about a player when he logs in
default: false
authme.unregister:
description: unregister your account
default: true
authme.admin.reload:
description: AuthMe reload commands
default: op
description: Give access to all admin commands.
children:
authme.admin.accounts: true
authme.admin.changemail: true
authme.admin.changepassword: true
authme.admin.converter: true
authme.admin.firstspawn: true
authme.admin.forcelogin: true
authme.admin.getemail: true
authme.admin.getip: true
authme.admin.lastlogin: true
authme.admin.purge: true
authme.admin.purgebannedplayers: true
authme.admin.purgelastpos: true
authme.admin.register: true
authme.admin.reload: true
authme.admin.setfirstspawn: true
authme.admin.setspawn: true
authme.admin.spawn: true
authme.admin.switchantibot: true
authme.admin.unregister: true
authme.admin.register:
description: AuthMe register command
default: op
authme.admin.changepassword:
description: AuthMe changepassword command
description: Administrator command to register a new user.
default: op
authme.admin.unregister:
description: AuthMe unregister command
default: op
authme.admin.purge:
description: AuthMe unregister command
default: op
authme.admin.lastlogin:
description: Get last login date about a player
default: op
authme.admin.getemail:
description: Get last email about a player
default: op
authme.admin.chgemail:
description: Change a player email
default: op
authme.admin.accounts:
description: Display Players Accounts
default: op
authme.captcha:
description: Captcha
default: true
authme.admin.setspawn:
description: Set the AuthMe spawn point
default: op
authme.admin.spawn:
description: Teleport to AuthMe spawn point
default: op
authme.vip:
description: Allow vip slot when the server is full
default: op
authme.admin.purgebannedplayers:
description: Purge banned players
default: op
authme.bypassforcesurvival:
description: Bypass all ForceSurvival features
default: false
authme.admin.purgelastpos:
description: Purge last pos of players
default: op
authme.admin.switchantibot:
description: Switch AntiBot mode on/off
default: op
authme.bypassantibot:
description: Bypass the AntiBot check
default: op
authme.admin.setfirstspawn:
description: Set the AuthMe First Spawn Point
default: op
authme.admin.firstspawn:
description: Teleport to AuthMe First Spawn Point
default: op
authme.admin.getip:
description: Get IP from a player ( fake and real )
default: op
authme.admin.converter:
description: Allow /converter command
default: op
authme.admin.resetposition:
description: Reset last position for a player
description: Administrator command to unregister an existing user.
default: op
authme.admin.forcelogin:
description: Force login for that player
description: Administrator command to force-login an existing user.
default: op
authme.canbeforced:
description: Can this player be forced to login
authme.admin.changepassword:
description: Administrator command to change the password of a user.
default: op
authme.admin.lastlogin:
description: Administrator command to see the last login date and time of a user.
default: op
authme.admin.accounts:
description: Administrator command to see all accounts associated with a user.
default: op
authme.admin.getemail:
description: Administrator command to get the email address of a user, if set.
default: op
authme.admin.changemail:
description: Administrator command to set or change the email address of a user.
default: op
authme.admin.getip:
description: Administrator command to get the last known IP of a user.
default: op
authme.admin.spawn:
description: Administrator command to teleport to the AuthMe spawn.
default: op
authme.admin.setspawn:
description: Administrator command to set the AuthMe spawn.
default: op
authme.admin.firstspawn:
description: Administrator command to teleport to the first AuthMe spawn.
default: op
authme.admin.setfirstspawn:
description: Administrator command to set the first AuthMe spawn.
default: op
authme.admin.purge:
description: Administrator command to purge old user data.
default: op
authme.admin.purgelastpos:
description: Administrator command to purge the last position of a user.
default: op
authme.admin.purgebannedplayers:
description: Administrator command to purge all data associated with banned players.
default: op
authme.admin.switchantibot:
description: Administrator command to toggle the AntiBot protection status.
default: op
authme.admin.converter:
description: Administrator command to convert old or other data to AuthMe data.
default: op
authme.admin.reload:
description: Administrator command to reload the plugin configuration.
default: op
authme.player.*:
description: Permission to use all player (non-admin) commands.
children:
authme.player.allow2accounts: true
authme.player.bypassantibot: true
authme.player.bypassforcesurvival: true
authme.player.canbeforced: true
authme.player.captcha: true
authme.player.changepassword: true
authme.player.email.add: true
authme.player.email.change: true
authme.player.email.recover: true
authme.player.login: true
authme.player.logout: true
authme.player.register: true
authme.player.seeotheraccounts: true
authme.player.unregister: true
authme.player.vip: true
authme.player.bypassantibot:
description: Permission node to bypass AntiBot protection.
default: false
authme.player.vip:
description: Permission node to identify VIP users.
default: false
authme.player.login:
description: Command permission to login.
default: true
authme.player.logout:
description: Command permission to logout.
default: true
authme.player.register:
description: Command permission to register.
default: true
authme.player.unregister:
description: Command permission to unregister.
default: true
authme.player.changepassword:
description: Command permission to change the password.
default: true
authme.player.email.add:
description: Command permission to add an email address.
default: false
authme.player.email.change:
description: Command permission to change the email address.
default: false
authme.player.email.recover:
description: Command permission to recover an account using it's email address.
default: false
authme.player.captcha:
description: Command permission to use captcha.
default: false
authme.player.canbeforced:
description: Permission for users a login can be forced to.
default: false
authme.player.bypassforcesurvival:
description: Permission for users to bypass force-survival mode.
default: false
authme.player.allow2accounts:
description: Permission for users to allow two accounts.
default: false
authme.player.seeotheraccounts:
description: Permission for user to see other accounts.
default: false