Change use of String permissions to the permission enums

This commit is contained in:
ljacqu
2015-11-28 21:59:29 +01:00
parent e519906dc5
commit 364583e7db
18 changed files with 108 additions and 257 deletions
@@ -4,6 +4,7 @@ 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.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@@ -38,7 +39,7 @@ public class AsyncChangeEmail {
String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts")
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
@@ -10,6 +10,7 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
@@ -93,7 +94,10 @@ public class AsynchronousJoin {
});
return;
}
if (Settings.getMaxJoinPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) {
if (Settings.getMaxJoinPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !ip.equalsIgnoreCase("127.0.0.1")
&& !ip.equalsIgnoreCase("localhost")) {
if (plugin.hasJoinedIp(player.getName(), ip)) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@@ -8,6 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.MessageKey;
@@ -119,7 +120,7 @@ public class AsynchronousLogin {
}
return null;
}
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
if (plugin.isLoggedIp(name, getIP())) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null;
@@ -267,7 +268,7 @@ public class AsynchronousLogin {
* uuidaccounts + "."; } }
*/
for (Player player : Utils.getOnlinePlayers()) {
if (plugin.getPermissionsManager().hasPermission(player, "authme.seeOtherAccounts")) {
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.SEE_OTHER_ACCOUNTS)) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
player.sendMessage(message.toString());
// player.sendMessage(uuidaccounts.replace("%size%",
@@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.UserPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages;
@@ -26,15 +27,6 @@ public class AsyncRegister {
private final DataSource database;
private final Messages m;
/**
* Constructor for AsyncRegister.
*
* @param player Player
* @param password String
* @param email String
* @param plugin AuthMe
* @param data DataSource
*/
public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data) {
this.m = plugin.getMessages();
this.player = player;
@@ -45,20 +37,10 @@ public class AsyncRegister {
this.database = data;
}
/**
* Method getIp.
*
* @return String
*/
protected String getIp() {
return plugin.getIP(player);
}
/**
* Method preRegisterCheck.
*
* @return boolean * @throws Exception
*/
protected boolean preRegisterCheck() throws Exception {
String passLow = password.toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(name)) {
@@ -82,25 +64,28 @@ public class AsyncRegister {
} else if (database.isAuthAvailable(name)) {
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
return false;
} else if (Settings.getmaxRegPerIp > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return false;
}
} else if (Settings.getmaxRegPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
&& !getIp().equalsIgnoreCase("127.0.0.1")
&& !getIp().equalsIgnoreCase("localhost")) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return false;
}
return true;
}
public void process() {
try {
if (!preRegisterCheck())
if (!preRegisterCheck()) {
return;
}
if (!email.isEmpty() && !email.equals("")) {
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
emailRegister();
return;
@@ -113,17 +98,12 @@ public class AsyncRegister {
}
}
/**
* Method emailRegister.
*
* @throws Exception
*/
protected void emailRegister() throws Exception {
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
PlayerAuth auth;
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);