diff --git a/src/main/java/fr/xephi/authme/command/CommandInitializer.java b/src/main/java/fr/xephi/authme/command/CommandInitializer.java index 948582fe1..d5a1e1caa 100644 --- a/src/main/java/fr/xephi/authme/command/CommandInitializer.java +++ b/src/main/java/fr/xephi/authme/command/CommandInitializer.java @@ -456,6 +456,7 @@ public class CommandInitializer { .labels("show", "myemail") .description("Show Email") .detailedDescription("Show your current email address.") + .permission(PlayerPermission.SEE_EMAIL) .executableCommand(ShowEmailCommand.class) .register(); diff --git a/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java index 64ddad117..770904445 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/ShowEmailCommand.java @@ -26,9 +26,18 @@ public class ShowEmailCommand extends PlayerCommand { public void runCommand(Player player, List arguments) { PlayerAuth auth = playerCache.getAuth(player.getName()); if (auth != null && !Utils.isEmailEmpty(auth.getEmail())) { - commonService.send(player, MessageKey.EMAIL_SHOW, auth.getEmail()); + commonService.send(player, MessageKey.EMAIL_SHOW, emailMask(auth.getEmail())); } else { commonService.send(player, MessageKey.SHOW_NO_EMAIL); } } + + private String emailMask(String email){ + String[] frag = email.split("@"); //Split id and domain + int sid = frag[0].length() / 3 + 1; //Define the id view + int sdomain = frag[1].length() / 3 + 1; //Define the domain view + String id = frag[0].substring(0, sid) + "*****"; //Build the id + String domain = "***" + frag[1].substring(sdomain, frag[1].length()); //Build the domain + return id + "@" + domain; + } } diff --git a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java index a42c9c9c8..5b3fcb569 100644 --- a/src/main/java/fr/xephi/authme/permission/PlayerPermission.java +++ b/src/main/java/fr/xephi/authme/permission/PlayerPermission.java @@ -30,6 +30,11 @@ public enum PlayerPermission implements PermissionNode { */ CHANGE_PASSWORD("authme.player.changepassword"), + /** + * Command permission to see the own email address. + */ + SEE_EMAIL("authme.player.email.see"), + /** * Command permission to add an email address. */ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9822005f1..05f718c35 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -18,6 +18,9 @@ commands: authme: description: AuthMe op commands usage: /authme register|unregister|forcelogin|password|lastlogin|accounts|email|setemail|getip|spawn|setspawn|firstspawn|setfirstspawn|purge|purgeplayer|backup|resetpos|purgebannedplayers|switchantibot|reload|version|converter|messages|debug + email: + description: Add email or recover password + usage: /email show|add|change|recover|code|setpassword login: description: Login command usage: /login @@ -43,9 +46,6 @@ commands: aliases: - changepass - cp - email: - description: Add email or recover password - usage: /email show|add|change|recover|code|setpassword captcha: description: Captcha Command usage: /captcha @@ -213,6 +213,7 @@ permissions: authme.player.email.add: true authme.player.email.change: true authme.player.email.recover: true + authme.player.email.see: true authme.player.login: true authme.player.logout: true authme.player.register: true @@ -233,6 +234,7 @@ permissions: authme.player.email.add: true authme.player.email.change: true authme.player.email.recover: true + authme.player.email.see: true authme.player.email.add: description: Command permission to add an email address. default: true @@ -242,6 +244,9 @@ permissions: authme.player.email.recover: description: Command permission to recover an account using its email address. default: true + authme.player.email.see: + description: Command permission to see the own email address. + default: true authme.player.login: description: Command permission to login. default: true @@ -258,5 +263,6 @@ permissions: description: Command permission to unregister. default: true authme.vip: - description: When the server is full and someone with this permission joins the server, someone will be kicked. + description: When the server is full and someone with this permission joins the + server, someone will be kicked. default: op diff --git a/src/test/java/fr/xephi/authme/command/executable/email/ShowEmailCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/email/ShowEmailCommandTest.java index 2825728a3..5ee031c48 100644 --- a/src/test/java/fr/xephi/authme/command/executable/email/ShowEmailCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/email/ShowEmailCommandTest.java @@ -46,7 +46,7 @@ public class ShowEmailCommandTest { command.executeCommand(sender, Collections.emptyList()); // then - verify(commandService).send(sender, MessageKey.EMAIL_SHOW, CURRENT_EMAIL); + verify(commandService).send(sender, MessageKey.EMAIL_SHOW, "my.*****@***ple.com"); } @Test