From 00c6b17f3e5a88570f459a831c813eecb1ac34c5 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 1 Dec 2015 15:42:02 +0100 Subject: [PATCH 01/14] Add customizable anto bot message --- .../java/fr/xephi/authme/listener/AuthMePlayerListener.java | 2 +- src/main/java/fr/xephi/authme/settings/MessageKey.java | 2 ++ src/main/resources/messages/messages_en.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 8400d572..03c3f70f 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -288,7 +288,7 @@ public class AuthMePlayerListener implements Listener { // TODO: Add message to the messages file!!! if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) { 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); return; } else { diff --git a/src/main/java/fr/xephi/authme/settings/MessageKey.java b/src/main/java/fr/xephi/authme/settings/MessageKey.java index 2fc1520a..72e71b63 100644 --- a/src/main/java/fr/xephi/authme/settings/MessageKey.java +++ b/src/main/java/fr/xephi/authme/settings/MessageKey.java @@ -5,6 +5,8 @@ package fr.xephi.authme.settings; */ public enum MessageKey { + KICK_ANTIBOT("kick_antibot"), + UNKNOWN_USER("unknown_user"), UNSAFE_QUIT_LOCATION("unsafe_spawn"), diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index dd191d24..fdb361a3 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -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!' unsafe_spawn: '&cYour quit location was unsafe, you have been teleported to the world''s spawnpoint.' not_logged_in: '&cYou''re not logged in!' From 3b9b1b7b8a2416845cef7dd62f35214c84937972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:14:59 +0100 Subject: [PATCH 02/14] Refactored name of command builder, to specify it a little better --- .../authme/command/CommandDescription.java | 26 +++++++++---------- .../command/help/HelpSyntaxHelperTest.java | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java index 3a534246..44989a20 100644 --- a/src/main/java/fr/xephi/authme/command/CommandDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java @@ -735,11 +735,11 @@ public class CommandDescription { this.permissions = new CommandPermissions(permissionNode, defaultPermission); } - public static Builder builder() { - return new Builder(); + public static CommandBuilder builder() { + return new CommandBuilder(); } - public static final class Builder { + public static final class CommandBuilder { private List labels; private String description; private String detailedDescription; @@ -767,47 +767,47 @@ public class CommandDescription { ); } - public Builder labels(List labels) { + public CommandBuilder labels(List labels) { this.labels = labels; return this; } - public Builder labels(String... labels) { + public CommandBuilder labels(String... labels) { return labels(asMutableList(labels)); } - public Builder description(String description) { + public CommandBuilder description(String description) { this.description = description; return this; } - public Builder detailedDescription(String detailedDescription) { + public CommandBuilder detailedDescription(String detailedDescription) { this.detailedDescription = detailedDescription; return this; } - public Builder executableCommand(ExecutableCommand executableCommand) { + public CommandBuilder executableCommand(ExecutableCommand executableCommand) { this.executableCommand = executableCommand; return this; } - public Builder parent(CommandDescription parent) { + public CommandBuilder parent(CommandDescription parent) { this.parent = parent; return this; } - 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)); return this; } - public Builder noArgumentMaximum(boolean noArgumentMaximum) { + public CommandBuilder noArgumentMaximum(boolean noArgumentMaximum) { this.noArgumentMaximum = noArgumentMaximum; return this; } - public Builder permissions(CommandPermissions.DefaultPermission defaultPermission, - PermissionNode... permissionNodes) { + public CommandBuilder permissions(CommandPermissions.DefaultPermission defaultPermission, + PermissionNode... permissionNodes) { this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission); return this; } diff --git a/src/test/java/fr/xephi/authme/command/help/HelpSyntaxHelperTest.java b/src/test/java/fr/xephi/authme/command/help/HelpSyntaxHelperTest.java index 1c3b4514..496dd93f 100644 --- a/src/test/java/fr/xephi/authme/command/help/HelpSyntaxHelperTest.java +++ b/src/test/java/fr/xephi/authme/command/help/HelpSyntaxHelperTest.java @@ -131,7 +131,7 @@ public class HelpSyntaxHelperTest { } - private static CommandDescription.Builder getDescriptionBuilder() { + private static CommandDescription.CommandBuilder getDescriptionBuilder() { CommandDescription base = CommandDescription.builder() .labels("authme") .description("Base command") From 8bea153005b3d4ca8c365f6dc87fd83a59531731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:17:37 +0100 Subject: [PATCH 03/14] Rebased administration command permission nodes --- .../xephi/authme/command/CommandManager.java | 22 ----------- .../authme/permission/AdminPermission.java | 37 +++++++++---------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index cc335561..5769e055 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -136,7 +136,6 @@ public class CommandManager { // Register the getemail command CommandDescription getEmailCommand = new CommandDescription(new GetEmailCommand(), new ArrayList() { - { add("getemail"); add("getmail"); @@ -149,7 +148,6 @@ public class CommandManager { // Register the setemail command CommandDescription setEmailCommand = new CommandDescription(new SetEmailCommand(), new ArrayList() { - { add("chgemail"); add("chgmail"); @@ -163,7 +161,6 @@ public class CommandManager { // Register the getip command CommandDescription getIpCommand = new CommandDescription(new GetIpCommand(), new ArrayList() { - { add("getip"); add("ip"); @@ -174,7 +171,6 @@ public class CommandManager { // Register the spawn command CommandDescription spawnCommand = new CommandDescription(new SpawnCommand(), new ArrayList() { - { add("spawn"); add("home"); @@ -184,7 +180,6 @@ public class CommandManager { // Register the setspawn command CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList() { - { add("setspawn"); add("chgspawn"); @@ -194,7 +189,6 @@ public class CommandManager { // Register the firstspawn command CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList() { - { add("firstspawn"); add("firsthome"); @@ -204,7 +198,6 @@ public class CommandManager { // Register the setfirstspawn command CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList() { - { add("setfirstspawn"); add("chgfirstspawn"); @@ -214,7 +207,6 @@ public class CommandManager { // Register the purge command CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList() { - { add("purge"); add("delete"); @@ -225,7 +217,6 @@ public class CommandManager { // Register the purgelastposition command CommandDescription purgeLastPositionCommand = new CommandDescription(new PurgeLastPositionCommand(), new ArrayList() { - { add("resetpos"); add("purgelastposition"); @@ -240,7 +231,6 @@ public class CommandManager { // Register the purgebannedplayers command CommandDescription purgeBannedPlayersCommand = new CommandDescription(new PurgeBannedPlayersCommand(), new ArrayList() { - { add("purgebannedplayers"); add("purgebannedplayer"); @@ -252,7 +242,6 @@ public class CommandManager { // Register the switchantibot command CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList() { - { add("switchantibot"); add("toggleantibot"); @@ -277,7 +266,6 @@ public class CommandManager { // Register the reload command CommandDescription reloadCommand = new CommandDescription(new ReloadCommand(), new ArrayList() { - { add("reload"); add("rld"); @@ -313,7 +301,6 @@ public class CommandManager { // Register the base logout command CommandDescription logoutBaseCommand = new CommandDescription(new LogoutCommand(), new ArrayList() { - { add("logout"); } @@ -327,7 +314,6 @@ public class CommandManager { // Register the base register command CommandDescription registerBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.register.RegisterCommand(), new ArrayList() { - { add("register"); add("reg"); @@ -344,7 +330,6 @@ public class CommandManager { // Register the base unregister command CommandDescription unregisterBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.unregister.UnregisterCommand(), new ArrayList() { - { add("unregister"); add("unreg"); @@ -359,7 +344,6 @@ public class CommandManager { // Register the base changepassword command CommandDescription changePasswordBaseCommand = new CommandDescription(new fr.xephi.authme.command.executable.changepassword.ChangePasswordCommand(), new ArrayList() { - { add("changepassword"); add("changepass"); @@ -376,7 +360,6 @@ public class CommandManager { // Register the base Dungeon Maze command CommandDescription emailBaseCommand = new CommandDescription(helpCommandExecutable, new ArrayList() { - { add("email"); add("mail"); @@ -390,7 +373,6 @@ public class CommandManager { // Register the add command CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList() { - { add("add"); add("addemail"); @@ -403,7 +385,6 @@ public class CommandManager { // Register the change command CommandDescription changeEmailCommand = new CommandDescription(new ChangeEmailCommand(), new ArrayList() { - { add("change"); add("changeemail"); @@ -416,7 +397,6 @@ public class CommandManager { // Register the recover command CommandDescription recoverEmailCommand = new CommandDescription(new RecoverEmailCommand(), new ArrayList() { - { add("recover"); add("recovery"); @@ -429,7 +409,6 @@ public class CommandManager { // Register the base captcha command CommandDescription captchaBaseCommand = new CommandDescription(new CaptchaCommand(), new ArrayList() { - { add("captcha"); add("capt"); @@ -445,7 +424,6 @@ public class CommandManager { // Register the base converter command CommandDescription converterBaseCommand = new CommandDescription(new ConverterCommand(), new ArrayList() { - { add("converter"); add("convert"); diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index 846c8322..979328bd 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -5,41 +5,41 @@ package fr.xephi.authme.permission; */ public enum AdminPermission implements PermissionNode { - REGISTER("authme.admin.register"), + REGISTER("authme.command.admin.register"), - UNREGISTER("authme.admin.unregister"), + UNREGISTER("authme.command.admin.unregister"), - FORCE_LOGIN("authme.admin.forcelogin"), + FORCE_LOGIN("authme.command.admin.forcelogin"), - CHANGE_PASSWORD("authme.admin.changepassword"), + CHANGE_PASSWORD("authme.command.admin.changepassword"), - LAST_LOGIN("authme.admin.lastlogin"), + LAST_LOGIN("authme.command.admin.lastlogin"), - ACCOUNTS("authme.admin.accounts"), + ACCOUNTS("authme.command.admin.accounts"), - GET_EMAIL("authme.admin.getemail"), + GET_EMAIL("authme.command.admin.getemail"), - CHANGE_EMAIL("authme.admin.chgemail"), + CHANGE_EMAIL("authme.command.admin.chgemail"), - GET_IP("authme.admin.getip"), + GET_IP("authme.command.admin.getip"), - SPAWN("authme.admin.spawn"), + SPAWN("authme.command.admin.spawn"), - SET_SPAWN("authme.admin.setspawn"), + SET_SPAWN("authme.command.admin.setspawn"), - FIRST_SPAWN("authme.admin.firstspawn"), + FIRST_SPAWN("authme.command.admin.firstspawn"), - SET_FIRST_SPAWN("authme.admin.setfirstspawn"), + SET_FIRST_SPAWN("authme.command.admin.setfirstspawn"), - PURGE("authme.admin.purge"), + PURGE("authme.command.admin.purge"), - PURGE_LAST_POSITION("authme.admin.purgelastpos"), + PURGE_LAST_POSITION("authme.command.admin.purgelastpos"), - PURGE_BANNED_PLAYERS("authme.admin.purgebannedplayers"), + PURGE_BANNED_PLAYERS("authme.command.admin.purgebannedplayers"), - SWITCH_ANTIBOT("authme.admin.switchantibot"), + SWITCH_ANTIBOT("authme.command.admin.switchantibot"), - RELOAD("authme.admin.reload"); + RELOAD("authme.command.admin.reload"); private String node; @@ -51,5 +51,4 @@ public enum AdminPermission implements PermissionNode { AdminPermission(String node) { this.node = node; } - } From 7f54838ad4bc552de1cc1ca6b50e811170b10e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:18:16 +0100 Subject: [PATCH 04/14] Rebased player command permission nodes --- .../authme/permission/UserPermission.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/UserPermission.java b/src/main/java/fr/xephi/authme/permission/UserPermission.java index 30c3dc87..b0653e62 100644 --- a/src/main/java/fr/xephi/authme/permission/UserPermission.java +++ b/src/main/java/fr/xephi/authme/permission/UserPermission.java @@ -5,37 +5,37 @@ package fr.xephi.authme.permission; */ public enum UserPermission implements PermissionNode { - BYPASS_ANTIBOT("authme.bypassantibot"), + BYPASS_ANTIBOT("authme.command.player.bypassantibot"), - IS_VIP("authme.vip"), + IS_VIP("authme.command.player.vip"), - LOGIN("authme.login"), + LOGIN("authme.command.player.login"), - LOGOUT("authme.logout"), + LOGOUT("authme.command.player.logout"), - REGISTER("authme.register"), + REGISTER("authme.command.player.register"), - UNREGISTER("authme.unregister"), + UNREGISTER("authme.command.player.unregister"), - CHANGE_PASSWORD("authme.changepassword"), + CHANGE_PASSWORD("authme.command.player.changepassword"), - ADD_EMAIL("authme.email.add"), + ADD_EMAIL("authme.command.player.email.add"), - CHANGE_EMAIL("authme.email.change"), + CHANGE_EMAIL("authme.command.player.email.change"), - RECOVER_EMAIL("authme.email.recover"), + RECOVER_EMAIL("authme.command.player.email.recover"), - CAPTCHA("authme.captcha"), + CAPTCHA("authme.command.player.captcha"), - CONVERTER("authme.converter"), + CONVERTER("authme.command.player.converter"), - CAN_LOGIN_BE_FORCED("authme.canbeforced"), + CAN_LOGIN_BE_FORCED("authme.command.player.canbeforced"), - BYPASS_FORCE_SURVIVAL("authme.bypassforcesurvival"), + BYPASS_FORCE_SURVIVAL("authme.command.player.bypassforcesurvival"), - ALLOW_MULTIPLE_ACCOUNTS("authme.allow2accounts"), + ALLOW_MULTIPLE_ACCOUNTS("authme.command.player.allow2accounts"), - SEE_OTHER_ACCOUNTS("authme.seeOtherAccounts"); + SEE_OTHER_ACCOUNTS("authme.command.player.seeOtherAccounts"); private String node; @@ -47,6 +47,4 @@ public enum UserPermission implements PermissionNode { UserPermission(String node) { this.node = node; } - - } From fdc747d007bc60a425b46a9612b6a4be8c23d2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:19:05 +0100 Subject: [PATCH 05/14] Refactored player permissions enum, to make the name suit better --- src/main/java/fr/xephi/authme/AntiBot.java | 4 +-- src/main/java/fr/xephi/authme/AuthMe.java | 4 +-- .../xephi/authme/command/CommandManager.java | 30 +++++++++---------- .../executable/authme/ForceLoginCommand.java | 4 +-- .../authme/listener/AuthMePlayerListener.java | 10 +++---- ...rPermission.java => PlayerPermission.java} | 6 ++-- .../process/email/AsyncChangeEmail.java | 4 +-- .../authme/process/join/AsynchronousJoin.java | 4 +-- .../process/login/AsynchronousLogin.java | 6 ++-- .../process/register/AsyncRegister.java | 8 ++--- src/main/java/fr/xephi/authme/util/Utils.java | 4 +-- ...ionTest.java => PlayerPermissionTest.java} | 8 ++--- .../java/fr/xephi/authme/util/UtilsTest.java | 8 ++--- 13 files changed, 50 insertions(+), 50 deletions(-) rename src/main/java/fr/xephi/authme/permission/{UserPermission.java => PlayerPermission.java} (87%) rename src/test/java/fr/xephi/authme/permission/{UserPermissionTest.java => PlayerPermissionTest.java} (84%) diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index 194e4cdf..afe7e2b6 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -1,6 +1,6 @@ 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.Messages; import fr.xephi.authme.settings.Settings; @@ -73,7 +73,7 @@ public class AntiBot { if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) { return; } - if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_ANTIBOT)) { + if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) { return; } diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 4f1886fc..4b07701f 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -18,7 +18,7 @@ import fr.xephi.authme.hooks.EssSpawn; import fr.xephi.authme.listener.*; import fr.xephi.authme.modules.ModuleManager; 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.settings.*; import fr.xephi.authme.util.GeoLiteAPI; @@ -735,7 +735,7 @@ public class AuthMe extends JavaPlugin { public Player generateKickPlayer(Collection collection) { Player player = null; for (Player p : collection) { - if (!getPermissionsManager().hasPermission(p, UserPermission.IS_VIP)) { + if (!getPermissionsManager().hasPermission(p, PlayerPermission.IS_VIP)) { player = p; break; } diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 5769e055..4d4f3f5c 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -10,7 +10,7 @@ import fr.xephi.authme.command.executable.email.RecoverEmailCommand; import fr.xephi.authme.command.executable.login.LoginCommand; import fr.xephi.authme.command.executable.logout.LogoutCommand; import fr.xephi.authme.permission.AdminPermission; -import fr.xephi.authme.permission.UserPermission; +import fr.xephi.authme.permission.PlayerPermission; import java.util.ArrayList; import java.util.Arrays; @@ -73,7 +73,7 @@ public class CommandManager { .description("Register a player") .detailedDescription("Register the specified player with the specified password.") .parent(authMeBaseCommand) - .permissions(OP_ONLY, UserPermission.REGISTER) + .permissions(OP_ONLY, PlayerPermission.REGISTER) .withArgument("player", "Player name", false) .withArgument("password", "Password", false) .build(); @@ -85,7 +85,7 @@ public class CommandManager { .description("Unregister a player") .detailedDescription("Unregister the specified player.") .parent(authMeBaseCommand) - .permissions(OP_ONLY, UserPermission.UNREGISTER) + .permissions(OP_ONLY, PlayerPermission.UNREGISTER) .withArgument("player", "Player name", false) .build(); @@ -96,7 +96,7 @@ public class CommandManager { .description("Enforce login player") .detailedDescription("Enforce the specified player to login.") .parent(authMeBaseCommand) - .permissions(OP_ONLY, UserPermission.CAN_LOGIN_BE_FORCED) + .permissions(OP_ONLY, PlayerPermission.CAN_LOGIN_BE_FORCED) .withArgument("player", "Online player name", true) .build(); @@ -107,7 +107,7 @@ public class CommandManager { .description("Change a player's password") .detailedDescription("Change the password of a player.") .parent(authMeBaseCommand) - .permissions(OP_ONLY, UserPermission.CHANGE_PASSWORD) + .permissions(OP_ONLY, PlayerPermission.CHANGE_PASSWORD) .withArgument("player", "Player name", false) .withArgument("pwd", "New password", false) .build(); @@ -290,7 +290,7 @@ public class CommandManager { .description("Login command") .detailedDescription("Command to log in using AuthMeReloaded.") .parent(null) - .permissions(ALLOWED, UserPermission.LOGIN) + .permissions(ALLOWED, PlayerPermission.LOGIN) .withArgument("password", "Login password", false) .build(); @@ -305,7 +305,7 @@ public class CommandManager { add("logout"); } }, "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 CommandDescription logoutHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels, @@ -319,7 +319,7 @@ public class CommandManager { add("reg"); } }, "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("verifyPassword", "Verify password", false)); @@ -335,7 +335,7 @@ public class CommandManager { add("unreg"); } }, "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)); // Register the help command @@ -349,7 +349,7 @@ public class CommandManager { add("changepass"); } }, "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("verifyPassword", "Verify password", false)); @@ -379,7 +379,7 @@ public class CommandManager { add("addmail"); } }, "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("verifyEmail", "Email address verification", false)); @@ -391,7 +391,7 @@ public class CommandManager { add("changemail"); } }, "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("newEmail", "New email address", false)); @@ -404,7 +404,7 @@ public class CommandManager { add("recovermail"); } }, "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)); // Register the base captcha command @@ -414,7 +414,7 @@ public class CommandManager { add("capt"); } }, "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)); // Register the help command @@ -430,7 +430,7 @@ public class CommandManager { add("conv"); } }, "Convert command", "Convert command for AuthMeReloaded.", null); - converterBaseCommand.setCommandPermissions(UserPermission.CONVERTER, OP_ONLY); + converterBaseCommand.setCommandPermissions(PlayerPermission.CONVERTER, OP_ONLY); converterBaseCommand.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false)); // Register the help command diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java index 7d8c9979..b5fa337e 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ForceLoginCommand.java @@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.CommandParts; 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.command.CommandSender; import org.bukkit.entity.Player; @@ -30,7 +30,7 @@ public class ForceLoginCommand extends ExecutableCommand { sender.sendMessage("Player needs to be online!"); 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 + "!"); return true; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 03c3f70f..095484e5 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -10,7 +10,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; 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.Messages; import fr.xephi.authme.settings.Settings; @@ -254,7 +254,7 @@ public class AuthMePlayerListener implements Listener { PermissionsManager permsMan = plugin.getPermissionsManager(); 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.setResult(PlayerLoginEvent.Result.KICK_FULL); return; @@ -267,7 +267,7 @@ public class AuthMePlayerListener implements Listener { final String name = player.getName().toLowerCase(); 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()); if (Settings.countriesBlacklist.contains(code)) { 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()); if (!Settings.countries.contains(code)) { event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); @@ -464,7 +464,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); if (player == null) return; - if (plugin.getPermissionsManager().hasPermission(player, UserPermission.BYPASS_FORCE_SURVIVAL)) + if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)) return; if (Utils.checkAuth(player)) return; diff --git a/src/main/java/fr/xephi/authme/permission/UserPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java similarity index 87% rename from src/main/java/fr/xephi/authme/permission/UserPermission.java rename to src/main/java/fr/xephi/authme/permission/PlayerPermission.java index b0653e62..73984519 100644 --- a/src/main/java/fr/xephi/authme/permission/UserPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -1,9 +1,9 @@ package fr.xephi.authme.permission; /** - * AuthMe user permission nodes. + * AuthMe player permission nodes, for regular players. */ -public enum UserPermission implements PermissionNode { +public enum PlayerPermission implements PermissionNode { BYPASS_ANTIBOT("authme.command.player.bypassantibot"), @@ -44,7 +44,7 @@ public enum UserPermission implements PermissionNode { return node; } - UserPermission(String node) { + PlayerPermission(String node) { this.node = node; } } diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index be186598..b6cb623d 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -4,7 +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.permission.PlayerPermission; import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; @@ -39,7 +39,7 @@ public class AsyncChangeEmail { String playerName = player.getName().toLowerCase(); 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) { m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index aa49d3f2..cee3a687 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -10,7 +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.permission.PlayerPermission; import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; @@ -95,7 +95,7 @@ public class AsynchronousJoin { return; } 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("localhost")) { if (plugin.hasJoinedIp(player.getName(), ip)) { diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index aae9397f..1333fd98 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -8,7 +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.permission.PlayerPermission; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.RandomString; import fr.xephi.authme.settings.MessageKey; @@ -120,7 +120,7 @@ public class AsynchronousLogin { } 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())) { m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return null; @@ -268,7 +268,7 @@ public class AsynchronousLogin { * uuidaccounts + "."; } } */ 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(message.toString()); // player.sendMessage(uuidaccounts.replace("%size%", diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 0007ccf3..6aaac37f 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -5,7 +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.permission.PlayerPermission; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; @@ -65,7 +65,7 @@ public class AsyncRegister { m.send(player, MessageKey.NAME_ALREADY_REGISTERED); return false; } 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 && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) { @@ -82,7 +82,7 @@ public class AsyncRegister { } if (!email.isEmpty() && !email.equals("")) { 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) { m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; @@ -100,7 +100,7 @@ public class AsyncRegister { protected void emailRegister() throws Exception { 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) { m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index e3e298b9..5005b843 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -7,7 +7,7 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.events.AuthMeTeleportEvent; 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 org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -201,7 +201,7 @@ public final class Utils { * @param player the player to modify. */ 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); } } diff --git a/src/test/java/fr/xephi/authme/permission/UserPermissionTest.java b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java similarity index 84% rename from src/test/java/fr/xephi/authme/permission/UserPermissionTest.java rename to src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java index 48d4bbed..92b3c7d9 100644 --- a/src/test/java/fr/xephi/authme/permission/UserPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java @@ -8,9 +8,9 @@ import java.util.Set; import static org.junit.Assert.fail; /** - * Test for {@link UserPermission}. + * Test for {@link PlayerPermission}. */ -public class UserPermissionTest { +public class PlayerPermissionTest { @Test public void shouldStartWithRegularAuthMePrefix() { @@ -19,7 +19,7 @@ public class UserPermissionTest { String adminPrefix = "authme.admin"; // when/then - for (UserPermission perm : UserPermission.values()) { + for (PlayerPermission perm : PlayerPermission.values()) { if (!perm.getNode().startsWith(requiredPrefix)) { fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'"); } else if (perm.getNode().startsWith(adminPrefix)) { @@ -35,7 +35,7 @@ public class UserPermissionTest { Set nodes = new HashSet<>(); // when/then - for (UserPermission perm : UserPermission.values()) { + for (PlayerPermission perm : PlayerPermission.values()) { if (nodes.contains(perm.getNode())) { fail("More than one enum value defines the node '" + perm.getNode() + "'"); } diff --git a/src/test/java/fr/xephi/authme/util/UtilsTest.java b/src/test/java/fr/xephi/authme/util/UtilsTest.java index 4c632187..2b9df6ad 100644 --- a/src/test/java/fr/xephi/authme/util/UtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/UtilsTest.java @@ -3,7 +3,7 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ReflectionTestUtils; 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 org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -54,7 +54,7 @@ public class UtilsTest { public void shouldForceSurvivalGameMode() { // given 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 Utils.forceGM(player); @@ -68,14 +68,14 @@ public class UtilsTest { public void shouldNotForceGameModeForUserWithBypassPermission() { // given 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 Utils.forceGM(player); // then 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)); } From 369a7ccd65898db5eabdc8bfd476b3f5f51ae972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:19:39 +0100 Subject: [PATCH 06/14] Lowercase'd player permission node --- src/main/java/fr/xephi/authme/permission/PlayerPermission.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java index 73984519..3e8925b4 100644 --- a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -35,7 +35,7 @@ public enum PlayerPermission implements PermissionNode { ALLOW_MULTIPLE_ACCOUNTS("authme.command.player.allow2accounts"), - SEE_OTHER_ACCOUNTS("authme.command.player.seeOtherAccounts"); + SEE_OTHER_ACCOUNTS("authme.command.player.seeotheraccounts"); private String node; From 999c08956d134e98c637a2549b853a87ef642f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:20:21 +0100 Subject: [PATCH 07/14] Changed 'changemail' permission to keep the nodes consistent --- src/main/java/fr/xephi/authme/permission/AdminPermission.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index 979328bd..3af0c6bc 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -19,7 +19,7 @@ public enum AdminPermission implements PermissionNode { GET_EMAIL("authme.command.admin.getemail"), - CHANGE_EMAIL("authme.command.admin.chgemail"), + CHANGE_EMAIL("authme.command.admin.changemail"), GET_IP("authme.command.admin.getip"), From 4afef9714d0c853918e9c35cdc3ec94e988f347a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:24:24 +0100 Subject: [PATCH 08/14] Converted two commands to use the builder --- .../xephi/authme/command/CommandManager.java | 40 +++++++++---------- .../authme/permission/AdminPermission.java | 2 +- .../authme/permission/PlayerPermission.java | 2 +- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 4d4f3f5c..501a00b8 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -135,29 +135,27 @@ public class CommandManager { .build(); // Register the getemail command - CommandDescription getEmailCommand = new CommandDescription(new GetEmailCommand(), new ArrayList() { - { - add("getemail"); - add("getmail"); - add("email"); - add("mail"); - } - }, "Display player's email", "Display the email address of the specified player if set.", authMeBaseCommand); - getEmailCommand.setCommandPermissions(AdminPermission.GET_EMAIL, OP_ONLY); - getEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", true)); + CommandDescription getEmailCommand = CommandDescription.builder() + .executableCommand(new GetEmailCommand()) + .labels("getemail", "getmail", "email", "mail") + .description("Display player's email") + .detailedDescription("Display the email address of the specified player if set.") + .parent(authMeBaseCommand) + .permissions(OP_ONLY, AdminPermission.GET_EMAIL) + .withArgument("player", "Player name", true) + .build(); // Register the setemail command - CommandDescription setEmailCommand = new CommandDescription(new SetEmailCommand(), new ArrayList() { - { - add("chgemail"); - add("chgmail"); - add("setemail"); - add("setmail"); - } - }, "Change player's email", "Change the email address of the specified player.", authMeBaseCommand); - setEmailCommand.setCommandPermissions(AdminPermission.CHANGE_EMAIL, OP_ONLY); - setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false)); - setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false)); + CommandDescription setEmailCommand = CommandDescription.builder() + .executableCommand(new SetEmailCommand()) + .labels("chgemail", "chgmail", "setemail", "setmail") + .description("Change player's email") + .detailedDescription("Change the email address of the specified player.") + .parent(authMeBaseCommand) + .permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL) + .withArgument("player", "Player name", false) + .withArgument("email", "Player email", false) + .build(); // Register the getip command CommandDescription getIpCommand = new CommandDescription(new GetIpCommand(), new ArrayList() { diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index 3af0c6bc..a65a6321 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -1,7 +1,7 @@ package fr.xephi.authme.permission; /** - * AuthMe admin permissions. + * AuthMe admin command permissions. */ public enum AdminPermission implements PermissionNode { diff --git a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java index 3e8925b4..e44617f5 100644 --- a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -1,7 +1,7 @@ package fr.xephi.authme.permission; /** - * AuthMe player permission nodes, for regular players. + * AuthMe player command permission nodes, for regular players. */ public enum PlayerPermission implements PermissionNode { From 42cebacd60ad062f3f4b401a39dc23267f4d134e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:29:47 +0100 Subject: [PATCH 09/14] Added JavaDocs to AdminPermission class --- .../authme/permission/AdminPermission.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index a65a6321..cfc777a6 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -5,49 +5,115 @@ package fr.xephi.authme.permission; */ public enum AdminPermission implements PermissionNode { + /** + * Administrator command to register a new user. + */ REGISTER("authme.command.admin.register"), + /** + * Administrator command to unregister an existing user. + */ UNREGISTER("authme.command.admin.unregister"), + /** + * Administrator command to force-login an existing user. + */ FORCE_LOGIN("authme.command.admin.forcelogin"), + /** + * Administrator command to change the password of a user. + */ CHANGE_PASSWORD("authme.command.admin.changepassword"), + /** + * Administrator command to see the last login date and time of an user. + */ LAST_LOGIN("authme.command.admin.lastlogin"), + /** + * Administrator command to see all accounts associated with an user. + */ ACCOUNTS("authme.command.admin.accounts"), + /** + * Administrator command to get the email address of an user, if set. + */ GET_EMAIL("authme.command.admin.getemail"), + /** + * Administrator command to set or change the email adress of an user. + */ CHANGE_EMAIL("authme.command.admin.changemail"), + /** + * Administrator command to get the last known IP of an user. + */ GET_IP("authme.command.admin.getip"), + /** + * Administrator command to teleport to the AuthMe spawn. + */ SPAWN("authme.command.admin.spawn"), + /** + * Administrator command to set the AuthMe spawn. + */ SET_SPAWN("authme.command.admin.setspawn"), + /** + * Administrator command to teleport to the first AuthMe spawn. + */ FIRST_SPAWN("authme.command.admin.firstspawn"), + /** + * Administrator command to set the first AuthMe spawn. + */ SET_FIRST_SPAWN("authme.command.admin.setfirstspawn"), + /** + * Administrator command to purge old user data. + */ PURGE("authme.command.admin.purge"), + /** + * Administrator command to purge the last position of an user. + */ PURGE_LAST_POSITION("authme.command.admin.purgelastpos"), + /** + * Administrator command to purge all data associated with banned players. + */ PURGE_BANNED_PLAYERS("authme.command.admin.purgebannedplayers"), + /** + * Administrator command to toggle the AntiBot protection status. + */ SWITCH_ANTIBOT("authme.command.admin.switchantibot"), + /** + * Administrator command to reload the plugin configuration. + */ RELOAD("authme.command.admin.reload"); + /** + * Permission node. + */ private String node; + /** + * Get the permission node. + * @return + */ @Override public String getNode() { return node; } + /** + * Constructor. + * + * @param node Permission node. + */ AdminPermission(String node) { this.node = node; } From 3d0bf674bdc3e6e6f51363098c28ce88c1c9075a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:34:22 +0100 Subject: [PATCH 10/14] Added JavaDocs to PlayerPermission class, fixed various permission nodes --- .../authme/permission/PlayerPermission.java | 69 +++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java index e44617f5..a125014a 100644 --- a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -1,49 +1,110 @@ package fr.xephi.authme.permission; /** - * AuthMe player command permission nodes, for regular players. + * AuthMe player permission nodes, for regular players. */ public enum PlayerPermission implements PermissionNode { - BYPASS_ANTIBOT("authme.command.player.bypassantibot"), + /** + * Permission node to bypass AntiBot protection. + */ + BYPASS_ANTIBOT("authme.player.bypassantibot"), - IS_VIP("authme.command.player.vip"), + /** + * 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"), + /** + * Administrator command to convert old or other data to AuthMe data. + */ CONVERTER("authme.command.player.converter"), - CAN_LOGIN_BE_FORCED("authme.command.player.canbeforced"), + /** + * 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; } From a0ed5545143806cb18ab41c1bd35cdd5990fedc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:34:54 +0100 Subject: [PATCH 11/14] Moved permission from player to admin space --- .../java/fr/xephi/authme/permission/AdminPermission.java | 5 +++++ .../java/fr/xephi/authme/permission/PlayerPermission.java | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index cfc777a6..335875a8 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -90,6 +90,11 @@ public enum AdminPermission implements PermissionNode { */ SWITCH_ANTIBOT("authme.command.admin.switchantibot"), + /** + * Administrator command to convert old or other data to AuthMe data. + */ + CONVERTER("authme.command.admin.converter"), + /** * Administrator command to reload the plugin configuration. */ diff --git a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java index a125014a..0488a67a 100644 --- a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -60,11 +60,6 @@ public enum PlayerPermission implements PermissionNode { */ CAPTCHA("authme.command.player.captcha"), - /** - * Administrator command to convert old or other data to AuthMe data. - */ - CONVERTER("authme.command.player.converter"), - /** * Permission for users a login can be forced to. */ From ccb9e24ce5b1ee505b0e36605620886acd819ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:35:28 +0100 Subject: [PATCH 12/14] Fixed invalid permission reference. --- src/main/java/fr/xephi/authme/command/CommandManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 501a00b8..1faa7f91 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -428,7 +428,7 @@ public class CommandManager { add("conv"); } }, "Convert command", "Convert command for AuthMeReloaded.", null); - converterBaseCommand.setCommandPermissions(PlayerPermission.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)); // Register the help command From 7ac39d80fd6b308ef53b42f7aa9a986eae362795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:40:00 +0100 Subject: [PATCH 13/14] Fixed admin permission tests --- .../authme/permission/AdminPermissionTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java index 14bf58b5..34de95a7 100644 --- a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java @@ -13,9 +13,9 @@ import static org.junit.Assert.fail; public class AdminPermissionTest { @Test - public void shouldStartWithAuthMeAdminPrefix() { + public void shouldStartWithAuthMePrefix() { // given - String requiredPrefix = "authme.admin."; + String requiredPrefix = "authme."; // when/then for (AdminPermission perm : AdminPermission.values()) { @@ -25,6 +25,19 @@ public class AdminPermissionTest { } } + @Test + public void shouldContainAdminBranch() { + // given + String requiredBranch = ".admin."; + + // when/then + for (AdminPermission perm : AdminPermission.values()) { + if (!perm.getNode().contains(requiredBranch)) { + fail("The permission '" + perm + "' does not contain with the required branch '" + requiredBranch + "'"); + } + } + } + @Test public void shouldHaveUniqueNodes() { // given From 2550e041126a01557dcaf9e7498d5f5dac8b357d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Tue, 1 Dec 2015 16:44:49 +0100 Subject: [PATCH 14/14] Fixed player permission tests, improved test structure consistency --- .../permission/AdminPermissionTest.java | 20 +++++----- .../permission/PlayerPermissionTest.java | 39 +++++++++++++------ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java index 34de95a7..c3a89b72 100644 --- a/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/AdminPermissionTest.java @@ -18,9 +18,9 @@ public class AdminPermissionTest { String requiredPrefix = "authme."; // when/then - for (AdminPermission perm : AdminPermission.values()) { - if (!perm.getNode().startsWith(requiredPrefix)) { - fail("The permission '" + perm + "' does not start with the required prefix '" + requiredPrefix + "'"); + for (AdminPermission permission : AdminPermission.values()) { + if (!permission.getNode().startsWith(requiredPrefix)) { + fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'"); } } } @@ -31,9 +31,9 @@ public class AdminPermissionTest { String requiredBranch = ".admin."; // when/then - for (AdminPermission perm : AdminPermission.values()) { - if (!perm.getNode().contains(requiredBranch)) { - fail("The permission '" + perm + "' does not contain with the required branch '" + requiredBranch + "'"); + for (AdminPermission permission : AdminPermission.values()) { + if (!permission.getNode().contains(requiredBranch)) { + fail("The permission '" + permission + "' does not contain with the required branch '" + requiredBranch + "'"); } } } @@ -44,11 +44,11 @@ public class AdminPermissionTest { Set nodes = new HashSet<>(); // when/then - for (AdminPermission perm : AdminPermission.values()) { - if (nodes.contains(perm.getNode())) { - fail("More than one enum value defines the node '" + perm.getNode() + "'"); + for (AdminPermission permission : AdminPermission.values()) { + if (nodes.contains(permission.getNode())) { + fail("More than one enum value defines the node '" + permission.getNode() + "'"); } - nodes.add(perm.getNode()); + nodes.add(permission.getNode()); } } diff --git a/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java index 92b3c7d9..81893373 100644 --- a/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java +++ b/src/test/java/fr/xephi/authme/permission/PlayerPermissionTest.java @@ -13,18 +13,33 @@ import static org.junit.Assert.fail; public class PlayerPermissionTest { @Test - public void shouldStartWithRegularAuthMePrefix() { + public void shouldStartWithAuthMePrefix() { // given String requiredPrefix = "authme."; - String adminPrefix = "authme.admin"; // when/then - for (PlayerPermission perm : PlayerPermission.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 + "'"); + 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 + "'"); } } } @@ -35,11 +50,11 @@ public class PlayerPermissionTest { Set nodes = new HashSet<>(); // when/then - for (PlayerPermission perm : PlayerPermission.values()) { - if (nodes.contains(perm.getNode())) { - fail("More than one enum value defines the node '" + perm.getNode() + "'"); + for (PlayerPermission permission : PlayerPermission.values()) { + if (nodes.contains(permission.getNode())) { + fail("More than one enum value defines the node '" + permission.getNode() + "'"); } - nodes.add(perm.getNode()); + nodes.add(permission.getNode()); } } }