Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor

Conflicts:
	src/main/java/fr/xephi/authme/command/CommandDescription.java
	src/main/java/fr/xephi/authme/command/CommandInitializer.java
This commit is contained in:
ljacqu 2015-12-01 20:43:49 +01:00
commit c4df2589b7
21 changed files with 357 additions and 216 deletions

View File

@ -1,6 +1,6 @@
package fr.xephi.authme; package fr.xephi.authme;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
@ -73,7 +73,7 @@ public class AntiBot {
if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) { if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) {
return; return;
} }
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_ANTIBOT)) { if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) {
return; return;
} }

View File

@ -18,7 +18,7 @@ import fr.xephi.authme.hooks.EssSpawn;
import fr.xephi.authme.listener.*; import fr.xephi.authme.listener.*;
import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.modules.ModuleManager;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.process.Management; import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.*; import fr.xephi.authme.settings.*;
import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.GeoLiteAPI;
@ -736,7 +736,7 @@ public class AuthMe extends JavaPlugin {
public Player generateKickPlayer(Collection<? extends Player> collection) { public Player generateKickPlayer(Collection<? extends Player> collection) {
Player player = null; Player player = null;
for (Player p : collection) { for (Player p : collection) {
if (!getPermissionsManager().hasPermission(p, UserPermission.IS_VIP)) { if (!getPermissionsManager().hasPermission(p, PlayerPermission.IS_VIP)) {
player = p; player = p;
break; break;
} }

View File

@ -590,14 +590,14 @@ public class CommandDescription {
this.permissions = new CommandPermissions(permissionNode, defaultPermission); this.permissions = new CommandPermissions(permissionNode, defaultPermission);
} }
public static Builder builder() { public static CommandBuilder builder() {
return new Builder(); return new CommandBuilder();
} }
/** /**
* Builder for initializing CommandDescription objects. * Builder for initializing CommandDescription objects.
*/ */
public static final class Builder { public static final class CommandBuilder {
private List<String> labels; private List<String> labels;
private String description; private String description;
private String detailedDescription; private String detailedDescription;
@ -626,31 +626,31 @@ public class CommandDescription {
); );
} }
public Builder labels(List<String> labels) { public CommandBuilder labels(List<String> labels) {
this.labels = labels; this.labels = labels;
return this; return this;
} }
public Builder labels(String... labels) { public CommandBuilder labels(String... labels) {
return labels(asMutableList(labels)); return labels(asMutableList(labels));
} }
public Builder description(String description) { public CommandBuilder description(String description) {
this.description = description; this.description = description;
return this; return this;
} }
public Builder detailedDescription(String detailedDescription) { public CommandBuilder detailedDescription(String detailedDescription) {
this.detailedDescription = detailedDescription; this.detailedDescription = detailedDescription;
return this; return this;
} }
public Builder executableCommand(ExecutableCommand executableCommand) { public CommandBuilder executableCommand(ExecutableCommand executableCommand) {
this.executableCommand = executableCommand; this.executableCommand = executableCommand;
return this; return this;
} }
public Builder parent(CommandDescription parent) { public CommandBuilder parent(CommandDescription parent) {
this.parent = parent; this.parent = parent;
return this; return this;
} }
@ -665,18 +665,18 @@ public class CommandDescription {
* *
* @return The builder * @return The builder
*/ */
public Builder withArgument(String label, String description, boolean isOptional) { public CommandBuilder withArgument(String label, String description, boolean isOptional) {
arguments.add(new CommandArgumentDescription(label, description, isOptional)); arguments.add(new CommandArgumentDescription(label, description, isOptional));
return this; return this;
} }
public Builder noArgumentMaximum(boolean noArgumentMaximum) { public CommandBuilder noArgumentMaximum(boolean noArgumentMaximum) {
this.noArgumentMaximum = noArgumentMaximum; this.noArgumentMaximum = noArgumentMaximum;
return this; return this;
} }
public Builder permissions(CommandPermissions.DefaultPermission defaultPermission, public CommandBuilder permissions(CommandPermissions.DefaultPermission defaultPermission,
PermissionNode... permissionNodes) { PermissionNode... permissionNodes) {
this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission); this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission);
return this; return this;
} }

View File

@ -29,7 +29,7 @@ import fr.xephi.authme.command.executable.email.RecoverEmailCommand;
import fr.xephi.authme.command.executable.login.LoginCommand; import fr.xephi.authme.command.executable.login.LoginCommand;
import fr.xephi.authme.command.executable.logout.LogoutCommand; import fr.xephi.authme.command.executable.logout.LogoutCommand;
import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.util.Wrapper; import fr.xephi.authme.util.Wrapper;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,6 +87,8 @@ public final class CommandInitializer {
.labels("register", "reg", "r") .labels("register", "reg", "r")
.description("Register a player") .description("Register a player")
.detailedDescription("Register the specified player with the specified password.") .detailedDescription("Register the specified player with the specified password.")
.parent(authMeBaseCommand)
.permissions(OP_ONLY, PlayerPermission.REGISTER)
.withArgument("player", "Player name", false) .withArgument("player", "Player name", false)
.withArgument("password", "Password", false) .withArgument("password", "Password", false)
.permissions(OP_ONLY, UserPermission.REGISTER) .permissions(OP_ONLY, UserPermission.REGISTER)
@ -99,6 +101,8 @@ public final class CommandInitializer {
.labels("unregister", "unreg", "unr") .labels("unregister", "unreg", "unr")
.description("Unregister a player") .description("Unregister a player")
.detailedDescription("Unregister the specified player.") .detailedDescription("Unregister the specified player.")
.parent(authMeBaseCommand)
.permissions(OP_ONLY, PlayerPermission.UNREGISTER)
.withArgument("player", "Player name", false) .withArgument("player", "Player name", false)
.permissions(OP_ONLY, UserPermission.UNREGISTER) .permissions(OP_ONLY, UserPermission.UNREGISTER)
.executableCommand(new UnregisterCommand()) .executableCommand(new UnregisterCommand())
@ -110,6 +114,8 @@ public final class CommandInitializer {
.labels("forcelogin", "login") .labels("forcelogin", "login")
.description("Enforce login player") .description("Enforce login player")
.detailedDescription("Enforce the specified player to login.") .detailedDescription("Enforce the specified player to login.")
.parent(authMeBaseCommand)
.permissions(OP_ONLY, PlayerPermission.CAN_LOGIN_BE_FORCED)
.withArgument("player", "Online player name", true) .withArgument("player", "Online player name", true)
.permissions(OP_ONLY, UserPermission.CAN_LOGIN_BE_FORCED) .permissions(OP_ONLY, UserPermission.CAN_LOGIN_BE_FORCED)
.executableCommand(new ForceLoginCommand()) .executableCommand(new ForceLoginCommand())
@ -121,6 +127,8 @@ public final class CommandInitializer {
.labels("password", "changepassword", "changepass", "cp") .labels("password", "changepassword", "changepass", "cp")
.description("Change a player's password") .description("Change a player's password")
.detailedDescription("Change the password of a player.") .detailedDescription("Change the password of a player.")
.parent(authMeBaseCommand)
.permissions(OP_ONLY, PlayerPermission.CHANGE_PASSWORD)
.withArgument("player", "Player name", false) .withArgument("player", "Player name", false)
.withArgument("pwd", "New password", false) .withArgument("pwd", "New password", false)
.permissions(OP_ONLY, UserPermission.CHANGE_PASSWORD) .permissions(OP_ONLY, UserPermission.CHANGE_PASSWORD)
@ -150,33 +158,30 @@ public final class CommandInitializer {
.build(); .build();
// Register the getemail command // Register the getemail command
CommandDescription.builder() CommandDescription getEmailCommand = CommandDescription.builder()
.parent(AUTHME_BASE) .executableCommand(new GetEmailCommand())
.labels("getemail", "getmail", "email", "mail") .labels("getemail", "getmail", "email", "mail")
.description("Display player's email") .description("Display player's email")
.detailedDescription("Display the email address of the specified player if set.") .detailedDescription("Display the email address of the specified player if set.")
.withArgument("player", "Player name", true) .parent(authMeBaseCommand)
.permissions(OP_ONLY, AdminPermission.GET_EMAIL) .permissions(OP_ONLY, AdminPermission.GET_EMAIL)
.executableCommand(new GetEmailCommand()) .withArgument("player", "Player name", true)
.build(); .build();
// Register the setemail command // Register the setemail command
CommandDescription setEmailCommand = new CommandDescription(new SetEmailCommand(), new ArrayList<String>() { CommandDescription setEmailCommand = CommandDescription.builder()
.executableCommand(new SetEmailCommand())
{ .labels("chgemail", "chgmail", "setemail", "setmail")
add("chgemail"); .description("Change player's email")
add("chgmail"); .detailedDescription("Change the email address of the specified player.")
add("setemail"); .parent(authMeBaseCommand)
add("setmail"); .permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
} .withArgument("player", "Player name", false)
}, "Change player's email", "Change the email address of the specified player.", AUTHME_BASE); .withArgument("email", "Player email", false)
setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, OP_ONLY); .build();
setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false));
setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false));
// Register the getip command // Register the getip command
CommandDescription getIpCommand = new CommandDescription(new GetIpCommand(), new ArrayList<String>() { CommandDescription getIpCommand = new CommandDescription(new GetIpCommand(), new ArrayList<String>() {
{ {
add("getip"); add("getip");
add("ip"); add("ip");
@ -187,7 +192,6 @@ public final class CommandInitializer {
// Register the spawn command // Register the spawn command
CommandDescription spawnCommand = new CommandDescription(new SpawnCommand(), new ArrayList<String>() { CommandDescription spawnCommand = new CommandDescription(new SpawnCommand(), new ArrayList<String>() {
{ {
add("spawn"); add("spawn");
add("home"); add("home");
@ -197,7 +201,6 @@ public final class CommandInitializer {
// Register the setspawn command // Register the setspawn command
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() { CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
{ {
add("setspawn"); add("setspawn");
add("chgspawn"); add("chgspawn");
@ -207,7 +210,6 @@ public final class CommandInitializer {
// Register the firstspawn command // Register the firstspawn command
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() { CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
{ {
add("firstspawn"); add("firstspawn");
add("firsthome"); add("firsthome");
@ -217,7 +219,6 @@ public final class CommandInitializer {
// Register the setfirstspawn command // Register the setfirstspawn command
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() { CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
{ {
add("setfirstspawn"); add("setfirstspawn");
add("chgfirstspawn"); add("chgfirstspawn");
@ -227,7 +228,6 @@ public final class CommandInitializer {
// Register the purge command // Register the purge command
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() { CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
{ {
add("purge"); add("purge");
add("delete"); add("delete");
@ -238,7 +238,6 @@ public final class CommandInitializer {
// Register the purgelastposition command // Register the purgelastposition command
CommandDescription purgeLastPositionCommand = new CommandDescription(new PurgeLastPositionCommand(), new ArrayList<String>() { CommandDescription purgeLastPositionCommand = new CommandDescription(new PurgeLastPositionCommand(), new ArrayList<String>() {
{ {
add("resetpos"); add("resetpos");
add("purgelastposition"); add("purgelastposition");
@ -253,7 +252,6 @@ public final class CommandInitializer {
// Register the purgebannedplayers command // Register the purgebannedplayers command
CommandDescription purgeBannedPlayersCommand = new CommandDescription(new PurgeBannedPlayersCommand(), new ArrayList<String>() { CommandDescription purgeBannedPlayersCommand = new CommandDescription(new PurgeBannedPlayersCommand(), new ArrayList<String>() {
{ {
add("purgebannedplayers"); add("purgebannedplayers");
add("purgebannedplayer"); add("purgebannedplayer");
@ -265,7 +263,6 @@ public final class CommandInitializer {
// Register the switchantibot command // Register the switchantibot command
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() { CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
{ {
add("switchantibot"); add("switchantibot");
add("toggleantibot"); add("toggleantibot");
@ -290,7 +287,6 @@ public final class CommandInitializer {
// Register the reload command // Register the reload command
CommandDescription reloadCommand = new CommandDescription(new ReloadCommand(), new ArrayList<String>() { CommandDescription reloadCommand = new CommandDescription(new ReloadCommand(), new ArrayList<String>() {
{ {
add("reload"); add("reload");
add("rld"); add("rld");
@ -315,7 +311,7 @@ public final class CommandInitializer {
.description("Login command") .description("Login command")
.detailedDescription("Command to log in using AuthMeReloaded.") .detailedDescription("Command to log in using AuthMeReloaded.")
.parent(null) .parent(null)
.permissions(ALLOWED, UserPermission.LOGIN) .permissions(ALLOWED, PlayerPermission.LOGIN)
.withArgument("password", "Login password", false) .withArgument("password", "Login password", false)
.build(); .build();
@ -326,12 +322,11 @@ public final class CommandInitializer {
// Register the base logout command // Register the base logout command
CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() { CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
{ {
add("logout"); add("logout");
} }
}, "Logout command", "Command to logout using AuthMeReloaded.", null); }, "Logout command", "Command to logout using AuthMeReloaded.", null);
logoutBaseCommand.setCommandPermissions(UserPermission.LOGOUT, CommandPermissions.DefaultPermission.ALLOWED); logoutBaseCommand.setCommandPermissions(PlayerPermission.LOGOUT, CommandPermissions.DefaultPermission.ALLOWED);
// Register the help command // Register the help command
CommandDescription logoutHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels, CommandDescription logoutHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
@ -340,13 +335,12 @@ public final class CommandInitializer {
// Register the base register command // Register the base register command
CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() { CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList<String>() {
{ {
add("register"); add("register");
add("reg"); add("reg");
} }
}, "Registration command", "Command to register using AuthMeReloaded.", null); }, "Registration command", "Command to register using AuthMeReloaded.", null);
registerBaseCommand.setCommandPermissions(UserPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED); registerBaseCommand.setCommandPermissions(PlayerPermission.REGISTER, CommandPermissions.DefaultPermission.ALLOWED);
registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false)); registerBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false)); registerBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
@ -357,13 +351,12 @@ public final class CommandInitializer {
// Register the base unregister command // Register the base unregister command
CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() { CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList<String>() {
{ {
add("unregister"); add("unregister");
add("unreg"); add("unreg");
} }
}, "Unregistration command", "Command to unregister using AuthMeReloaded.", null); }, "Unregistration command", "Command to unregister using AuthMeReloaded.", null);
unregisterBaseCommand.setCommandPermissions(UserPermission.UNREGISTER, CommandPermissions.DefaultPermission.ALLOWED); unregisterBaseCommand.setCommandPermissions(PlayerPermission.UNREGISTER, CommandPermissions.DefaultPermission.ALLOWED);
unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false)); unregisterBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
// Register the help command // Register the help command
@ -372,13 +365,12 @@ public final class CommandInitializer {
// Register the base changepassword command // Register the base changepassword command
CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() { CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList<String>() {
{ {
add("changepassword"); add("changepassword");
add("changepass"); add("changepass");
} }
}, "Change password command", "Command to change your password using AuthMeReloaded.", null); }, "Change password command", "Command to change your password using AuthMeReloaded.", null);
changePasswordBaseCommand.setCommandPermissions(UserPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED); changePasswordBaseCommand.setCommandPermissions(PlayerPermission.CHANGE_PASSWORD, CommandPermissions.DefaultPermission.ALLOWED);
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false)); changePasswordBaseCommand.addArgument(new CommandArgumentDescription("password", "Password", false));
changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false)); changePasswordBaseCommand.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
@ -389,7 +381,6 @@ public final class CommandInitializer {
// Register the base Dungeon Maze command // Register the base Dungeon Maze command
CommandDescription emailBaseCommand = new CommandDescription(helpCommandExecutable, new ArrayList<String>() { CommandDescription emailBaseCommand = new CommandDescription(helpCommandExecutable, new ArrayList<String>() {
{ {
add("email"); add("email");
add("mail"); add("mail");
@ -403,33 +394,30 @@ public final class CommandInitializer {
// Register the add command // Register the add command
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() { CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
{ {
add("add"); add("add");
add("addemail"); add("addemail");
add("addmail"); add("addmail");
} }
}, "Add E-mail", "Add an new E-Mail address to your account.", emailBaseCommand); }, "Add E-mail", "Add an new E-Mail address to your account.", emailBaseCommand);
addEmailCommand.setCommandPermissions(UserPermission.ADD_EMAIL, CommandPermissions.DefaultPermission.ALLOWED); addEmailCommand.setCommandPermissions(PlayerPermission.ADD_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false)); addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false)); addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
// Register the change command // Register the change command
CommandDescription changeEmailCommand = new CommandDescription(new ChangeEmailCommand(), new ArrayList<String>() { CommandDescription changeEmailCommand = new CommandDescription(new ChangeEmailCommand(), new ArrayList<String>() {
{ {
add("change"); add("change");
add("changeemail"); add("changeemail");
add("changemail"); add("changemail");
} }
}, "Change E-mail", "Change an E-Mail address of your account.", emailBaseCommand); }, "Change E-mail", "Change an E-Mail address of your account.", emailBaseCommand);
changeEmailCommand.setCommandPermissions(UserPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.ALLOWED); changeEmailCommand.setCommandPermissions(PlayerPermission.CHANGE_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false)); changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false)); changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
// Register the recover command // Register the recover command
CommandDescription recoverEmailCommand = new CommandDescription(new RecoverEmailCommand(), new ArrayList<String>() { CommandDescription recoverEmailCommand = new CommandDescription(new RecoverEmailCommand(), new ArrayList<String>() {
{ {
add("recover"); add("recover");
add("recovery"); add("recovery");
@ -437,18 +425,17 @@ public final class CommandInitializer {
add("recovermail"); add("recovermail");
} }
}, "Recover using E-mail", "Recover your account using an E-mail address.", emailBaseCommand); }, "Recover using E-mail", "Recover your account using an E-mail address.", emailBaseCommand);
recoverEmailCommand.setCommandPermissions(UserPermission.RECOVER_EMAIL, CommandPermissions.DefaultPermission.ALLOWED); recoverEmailCommand.setCommandPermissions(PlayerPermission.RECOVER_EMAIL, CommandPermissions.DefaultPermission.ALLOWED);
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false)); recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
// Register the base captcha command // Register the base captcha command
CommandDescription captchaBaseCommand = new CommandDescription(new CaptchaCommand(), new ArrayList<String>() { CommandDescription captchaBaseCommand = new CommandDescription(new CaptchaCommand(), new ArrayList<String>() {
{ {
add("captcha"); add("captcha");
add("capt"); add("capt");
} }
}, "Captcha command", "Captcha command for AuthMeReloaded.", null); }, "Captcha command", "Captcha command for AuthMeReloaded.", null);
captchaBaseCommand.setCommandPermissions(UserPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED); captchaBaseCommand.setCommandPermissions(PlayerPermission.CAPTCHA, CommandPermissions.DefaultPermission.ALLOWED);
captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false)); captchaBaseCommand.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
// Register the help command // Register the help command
@ -458,14 +445,13 @@ public final class CommandInitializer {
// Register the base converter command // Register the base converter command
CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() { CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
{ {
add("converter"); add("converter");
add("convert"); add("convert");
add("conv"); add("conv");
} }
}, "Convert command", "Convert command for AuthMeReloaded.", null); }, "Convert command", "Convert command for AuthMeReloaded.", null);
converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, OP_ONLY); converterBaseCommand.setCommandPermissions(AdminPermission.CONVERTER, OP_ONLY);
converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false)); converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
// Register the help command // Register the help command

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -30,7 +30,7 @@ public class ForceLoginCommand extends ExecutableCommand {
sender.sendMessage("Player needs to be online!"); sender.sendMessage("Player needs to be online!");
return true; return true;
} }
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.CAN_LOGIN_BE_FORCED)) { if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)) {
sender.sendMessage("You cannot force login for the player " + playerName + "!"); sender.sendMessage("You cannot force login for the player " + playerName + "!");
return true; return true;
} }

View File

@ -10,7 +10,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
@ -254,7 +254,7 @@ public class AuthMePlayerListener implements Listener {
PermissionsManager permsMan = plugin.getPermissionsManager(); PermissionsManager permsMan = plugin.getPermissionsManager();
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, UserPermission.IS_VIP)) { if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER)); event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL); event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return; return;
@ -267,7 +267,7 @@ public class AuthMePlayerListener implements Listener {
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
boolean isAuthAvailable = plugin.database.isAuthAvailable(name); boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, UserPermission.BYPASS_ANTIBOT)) { if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (Settings.countriesBlacklist.contains(code)) { if (Settings.countriesBlacklist.contains(code)) {
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
@ -276,7 +276,7 @@ public class AuthMePlayerListener implements Listener {
} }
} }
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, UserPermission.BYPASS_ANTIBOT)) { if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (!Settings.countries.contains(code)) { if (!Settings.countries.contains(code)) {
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
@ -288,7 +288,7 @@ public class AuthMePlayerListener implements Listener {
// TODO: Add message to the messages file!!! // TODO: Add message to the messages file!!!
if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) { if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) {
if (Settings.antiBotInAction) { if (Settings.antiBotInAction) {
event.setKickMessage("AntiBot service in action! You actually need to be registered!"); event.setKickMessage(m.retrieveSingle(MessageKey.KICK_ANTIBOT));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
} else { } else {
@ -464,7 +464,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player == null) if (player == null)
return; return;
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)) if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL))
return; return;
if (Utils.checkAuth(player)) if (Utils.checkAuth(player))
return; return;

View File

@ -1,55 +1,125 @@
package fr.xephi.authme.permission; package fr.xephi.authme.permission;
/** /**
* AuthMe admin permissions. * AuthMe admin command permissions.
*/ */
public enum AdminPermission implements PermissionNode { public enum AdminPermission implements PermissionNode {
REGISTER("authme.admin.register"), /**
* Administrator command to register a new user.
*/
REGISTER("authme.command.admin.register"),
UNREGISTER("authme.admin.unregister"), /**
* Administrator command to unregister an existing user.
*/
UNREGISTER("authme.command.admin.unregister"),
FORCE_LOGIN("authme.admin.forcelogin"), /**
* Administrator command to force-login an existing user.
*/
FORCE_LOGIN("authme.command.admin.forcelogin"),
CHANGE_PASSWORD("authme.admin.changepassword"), /**
* Administrator command to change the password of a user.
*/
CHANGE_PASSWORD("authme.command.admin.changepassword"),
LAST_LOGIN("authme.admin.lastlogin"), /**
* Administrator command to see the last login date and time of an user.
*/
LAST_LOGIN("authme.command.admin.lastlogin"),
ACCOUNTS("authme.admin.accounts"), /**
* Administrator command to see all accounts associated with an user.
*/
ACCOUNTS("authme.command.admin.accounts"),
GET_EMAIL("authme.admin.getemail"), /**
* Administrator command to get the email address of an user, if set.
*/
GET_EMAIL("authme.command.admin.getemail"),
CHANGE_EMAIL("authme.admin.chgemail"), /**
* Administrator command to set or change the email adress of an user.
*/
CHANGE_EMAIL("authme.command.admin.changemail"),
GET_IP("authme.admin.getip"), /**
* Administrator command to get the last known IP of an user.
*/
GET_IP("authme.command.admin.getip"),
SPAWN("authme.admin.spawn"), /**
* Administrator command to teleport to the AuthMe spawn.
*/
SPAWN("authme.command.admin.spawn"),
SET_SPAWN("authme.admin.setspawn"), /**
* Administrator command to set the AuthMe spawn.
*/
SET_SPAWN("authme.command.admin.setspawn"),
FIRST_SPAWN("authme.admin.firstspawn"), /**
* Administrator command to teleport to the first AuthMe spawn.
*/
FIRST_SPAWN("authme.command.admin.firstspawn"),
SET_FIRST_SPAWN("authme.admin.setfirstspawn"), /**
* Administrator command to set the first AuthMe spawn.
*/
SET_FIRST_SPAWN("authme.command.admin.setfirstspawn"),
PURGE("authme.admin.purge"), /**
* Administrator command to purge old user data.
*/
PURGE("authme.command.admin.purge"),
PURGE_LAST_POSITION("authme.admin.purgelastpos"), /**
* Administrator command to purge the last position of an user.
*/
PURGE_LAST_POSITION("authme.command.admin.purgelastpos"),
PURGE_BANNED_PLAYERS("authme.admin.purgebannedplayers"), /**
* Administrator command to purge all data associated with banned players.
*/
PURGE_BANNED_PLAYERS("authme.command.admin.purgebannedplayers"),
SWITCH_ANTIBOT("authme.admin.switchantibot"), /**
* Administrator command to toggle the AntiBot protection status.
*/
SWITCH_ANTIBOT("authme.command.admin.switchantibot"),
RELOAD("authme.admin.reload"); /**
* Administrator command to convert old or other data to AuthMe data.
*/
CONVERTER("authme.command.admin.converter"),
/**
* Administrator command to reload the plugin configuration.
*/
RELOAD("authme.command.admin.reload");
/**
* Permission node.
*/
private String node; private String node;
/**
* Get the permission node.
* @return
*/
@Override @Override
public String getNode() { public String getNode() {
return node; return node;
} }
/**
* Constructor.
*
* @param node Permission node.
*/
AdminPermission(String node) { AdminPermission(String node) {
this.node = node; this.node = node;
} }
} }

View File

@ -0,0 +1,106 @@
package fr.xephi.authme.permission;
/**
* AuthMe player permission nodes, for regular players.
*/
public enum PlayerPermission implements PermissionNode {
/**
* Permission node to bypass AntiBot protection.
*/
BYPASS_ANTIBOT("authme.player.bypassantibot"),
/**
* Permission node to identify VIP users.
*/
IS_VIP("authme.player.vip"),
/**
* Command permission to login.
*/
LOGIN("authme.command.player.login"),
/**
* Command permission to logout.
*/
LOGOUT("authme.command.player.logout"),
/**
* Command permission to register.
*/
REGISTER("authme.command.player.register"),
/**
* Command permission to unregister.
*/
UNREGISTER("authme.command.player.unregister"),
/**
* Command permission to change the password.
*/
CHANGE_PASSWORD("authme.command.player.changepassword"),
/**
* Command permission to add an email address.
*/
ADD_EMAIL("authme.command.player.email.add"),
/**
* Command permission to change the email address.
*/
CHANGE_EMAIL("authme.command.player.email.change"),
/**
* Command permission to recover an account using it's email address.
*/
RECOVER_EMAIL("authme.command.player.email.recover"),
/**
* Command permission to use captcha.
*/
CAPTCHA("authme.command.player.captcha"),
/**
* Permission for users a login can be forced to.
*/
CAN_LOGIN_BE_FORCED("authme.player.canbeforced"),
/**
* Permission for users to bypass force-survival mode.
*/
BYPASS_FORCE_SURVIVAL("authme.command.player.bypassforcesurvival"),
/**
* Permission for users to allow two accounts.
*/
ALLOW_MULTIPLE_ACCOUNTS("authme.command.player.allow2accounts"),
/**
* Permission for user to see other accounts.
*/
SEE_OTHER_ACCOUNTS("authme.command.player.seeotheraccounts");
/**
* Permission node.
*/
private String node;
/**
* Get the permission node.
*
* @return Permission node.
*/
@Override
public String getNode() {
return node;
}
/**
* Constructor.
*
* @param node Permission node.
*/
PlayerPermission(String node) {
this.node = node;
}
}

View File

@ -1,52 +0,0 @@
package fr.xephi.authme.permission;
/**
* AuthMe user permission nodes.
*/
public enum UserPermission implements PermissionNode {
BYPASS_ANTIBOT("authme.bypassantibot"),
IS_VIP("authme.vip"),
LOGIN("authme.login"),
LOGOUT("authme.logout"),
REGISTER("authme.register"),
UNREGISTER("authme.unregister"),
CHANGE_PASSWORD("authme.changepassword"),
ADD_EMAIL("authme.email.add"),
CHANGE_EMAIL("authme.email.change"),
RECOVER_EMAIL("authme.email.recover"),
CAPTCHA("authme.captcha"),
CONVERTER("authme.converter"),
CAN_LOGIN_BE_FORCED("authme.canbeforced"),
BYPASS_FORCE_SURVIVAL("authme.bypassforcesurvival"),
ALLOW_MULTIPLE_ACCOUNTS("authme.allow2accounts"),
SEE_OTHER_ACCOUNTS("authme.seeOtherAccounts");
private String node;
@Override
public String getNode() {
return node;
}
UserPermission(String node) {
this.node = node;
}
}

View File

@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
@ -39,7 +39,7 @@ public class AsyncChangeEmail {
String playerName = player.getName().toLowerCase(); String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) { if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) { && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return; return;

View File

@ -10,7 +10,7 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
@ -95,7 +95,7 @@ public class AsynchronousJoin {
return; return;
} }
if (Settings.getMaxJoinPerIp > 0 if (Settings.getMaxJoinPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("127.0.0.1")
&& !ip.equalsIgnoreCase("localhost")) { && !ip.equalsIgnoreCase("localhost")) {
if (plugin.hasJoinedIp(player.getName(), ip)) { if (plugin.hasJoinedIp(player.getName(), ip)) {

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
@ -120,7 +120,7 @@ public class AsynchronousLogin {
} }
return null; return null;
} }
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) { if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS) && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
if (plugin.isLoggedIp(name, getIP())) { if (plugin.isLoggedIp(name, getIP())) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null; return null;
@ -268,7 +268,7 @@ public class AsynchronousLogin {
* uuidaccounts + "."; } } * uuidaccounts + "."; } }
*/ */
for (Player player : Utils.getOnlinePlayers()) { for (Player player : Utils.getOnlinePlayers()) {
if (plugin.getPermissionsManager().hasPermission(player, UserPermission.SEE_OTHER_ACCOUNTS)) { if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.SEE_OTHER_ACCOUNTS)) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts"); player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + auths.size() + " accounts");
player.sendMessage(message.toString()); player.sendMessage(message.toString());
// player.sendMessage(uuidaccounts.replace("%size%", // player.sendMessage(uuidaccounts.replace("%size%",

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
@ -65,7 +65,7 @@ public class AsyncRegister {
m.send(player, MessageKey.NAME_ALREADY_REGISTERED); m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
return false; return false;
} else if (Settings.getmaxRegPerIp > 0 } else if (Settings.getmaxRegPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
&& !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("127.0.0.1")
&& !getIp().equalsIgnoreCase("localhost")) { && !getIp().equalsIgnoreCase("localhost")) {
@ -82,7 +82,7 @@ public class AsyncRegister {
} }
if (!email.isEmpty() && !email.equals("")) { if (!email.isEmpty() && !email.equals("")) {
if (Settings.getmaxRegPerEmail > 0 if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return; return;
@ -100,7 +100,7 @@ public class AsyncRegister {
protected void emailRegister() throws Exception { protected void emailRegister() throws Exception {
if (Settings.getmaxRegPerEmail > 0 if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS) && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return; return;

View File

@ -5,6 +5,8 @@ package fr.xephi.authme.settings;
*/ */
public enum MessageKey { public enum MessageKey {
KICK_ANTIBOT("kick_antibot"),
UNKNOWN_USER("unknown_user"), UNKNOWN_USER("unknown_user"),
UNSAFE_QUIT_LOCATION("unsafe_spawn"), UNSAFE_QUIT_LOCATION("unsafe_spawn"),

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -201,7 +201,7 @@ public final class Utils {
* @param player the player to modify. * @param player the player to modify.
*/ */
public static void forceGM(Player player) { public static void forceGM(Player player) {
if (!plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)) { if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)) {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
} }
} }

View File

@ -1,3 +1,4 @@
kick_antibot: 'AntiBot protection mode is enabled! You have to wait some minutes before joining the server.'
unknown_user: '&cCan''t find the requested user in the database!' unknown_user: '&cCan''t find the requested user in the database!'
unsafe_spawn: '&cYour quit location was unsafe, you have been teleported to the world''s spawnpoint.' unsafe_spawn: '&cYour quit location was unsafe, you have been teleported to the world''s spawnpoint.'
not_logged_in: '&cYou''re not logged in!' not_logged_in: '&cYou''re not logged in!'

View File

@ -131,7 +131,7 @@ public class HelpSyntaxHelperTest {
} }
private static CommandDescription.Builder getDescriptionBuilder() { private static CommandDescription.CommandBuilder getDescriptionBuilder() {
CommandDescription base = CommandDescription.builder() CommandDescription base = CommandDescription.builder()
.labels("authme") .labels("authme")
.description("Base command") .description("Base command")

View File

@ -13,14 +13,27 @@ import static org.junit.Assert.fail;
public class AdminPermissionTest { public class AdminPermissionTest {
@Test @Test
public void shouldStartWithAuthMeAdminPrefix() { public void shouldStartWithAuthMePrefix() {
// given // given
String requiredPrefix = "authme.admin."; String requiredPrefix = "authme.";
// when/then // when/then
for (AdminPermission perm : AdminPermission.values()) { for (AdminPermission permission : AdminPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) { if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'"); fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
}
}
}
@Test
public void shouldContainAdminBranch() {
// given
String requiredBranch = ".admin.";
// when/then
for (AdminPermission permission : AdminPermission.values()) {
if (!permission.getNode().contains(requiredBranch)) {
fail("The permission '" + permission + "' does not contain with the required branch '" + requiredBranch + "'");
} }
} }
} }
@ -31,11 +44,11 @@ public class AdminPermissionTest {
Set<String> nodes = new HashSet<>(); Set<String> nodes = new HashSet<>();
// when/then // when/then
for (AdminPermission perm : AdminPermission.values()) { for (AdminPermission permission : AdminPermission.values()) {
if (nodes.contains(perm.getNode())) { if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'"); fail("More than one enum value defines the node '" + permission.getNode() + "'");
} }
nodes.add(perm.getNode()); nodes.add(permission.getNode());
} }
} }

View File

@ -0,0 +1,60 @@
package fr.xephi.authme.permission;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
/**
* Test for {@link PlayerPermission}.
*/
public class PlayerPermissionTest {
@Test
public void shouldStartWithAuthMePrefix() {
// given
String requiredPrefix = "authme.";
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (!permission.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
}
}
}
@Test
public void shouldContainPlayerBranch() {
// given
String playerBranch = ".player.";
String adminBranch = ".admin.";
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (permission.getNode().contains(adminBranch)) {
fail("The permission '" + permission + "' should not use a node with the admin-specific branch '"
+ adminBranch + "'");
} else if (!permission.getNode().contains(playerBranch)) {
fail("The permission '" + permission + "' should use a node with the player-specific branch '"
+ playerBranch + "'");
}
}
}
@Test
public void shouldHaveUniqueNodes() {
// given
Set<String> nodes = new HashSet<>();
// when/then
for (PlayerPermission permission : PlayerPermission.values()) {
if (nodes.contains(permission.getNode())) {
fail("More than one enum value defines the node '" + permission.getNode() + "'");
}
nodes.add(permission.getNode());
}
}
}

View File

@ -1,45 +0,0 @@
package fr.xephi.authme.permission;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
/**
* Test for {@link UserPermission}.
*/
public class UserPermissionTest {
@Test
public void shouldStartWithRegularAuthMePrefix() {
// given
String requiredPrefix = "authme.";
String adminPrefix = "authme.admin";
// when/then
for (UserPermission perm : UserPermission.values()) {
if (!perm.getNode().startsWith(requiredPrefix)) {
fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'");
} else if (perm.getNode().startsWith(adminPrefix)) {
fail("The permission '" + perm + "' should not use a node with the admin-specific prefix '"
+ adminPrefix + "'");
}
}
}
@Test
public void shouldHaveUniqueNodes() {
// given
Set<String> nodes = new HashSet<>();
// when/then
for (UserPermission perm : UserPermission.values()) {
if (nodes.contains(perm.getNode())) {
fail("More than one enum value defines the node '" + perm.getNode() + "'");
}
nodes.add(perm.getNode());
}
}
}

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.UserPermission; import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -54,7 +54,7 @@ public class UtilsTest {
public void shouldForceSurvivalGameMode() { public void shouldForceSurvivalGameMode() {
// given // given
Player player = mock(Player.class); Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(false); given(permissionsManagerMock.hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)).willReturn(false);
// when // when
Utils.forceGM(player); Utils.forceGM(player);
@ -68,14 +68,14 @@ public class UtilsTest {
public void shouldNotForceGameModeForUserWithBypassPermission() { public void shouldNotForceGameModeForUserWithBypassPermission() {
// given // given
Player player = mock(Player.class); Player player = mock(Player.class);
given(permissionsManagerMock.hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)).willReturn(true); given(permissionsManagerMock.hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)).willReturn(true);
// when // when
Utils.forceGM(player); Utils.forceGM(player);
// then // then
verify(authMeMock).getPermissionsManager(); verify(authMeMock).getPermissionsManager();
verify(permissionsManagerMock).hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL); verify(permissionsManagerMock).hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL);
verify(player, never()).setGameMode(any(GameMode.class)); verify(player, never()).setGameMode(any(GameMode.class));
} }