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

This commit is contained in:
ljacqu 2015-12-06 00:52:34 +01:00
commit 22ad305506
38 changed files with 1002 additions and 381 deletions

View File

@ -5,6 +5,8 @@
<value>
<option name="AUTODETECT_INDENTS" value="false" />
<option name="LINE_SEPARATOR" value="&#10;" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
<XML>

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.command;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils;
@ -558,16 +559,6 @@ public class CommandDescription {
return this.permissions;
}
/**
* Set the command permissions.
*
* @param permissionNode The permission node required.
* @param defaultPermission The default permission.
*/
public void setCommandPermissions(PermissionNode permissionNode, CommandPermissions.DefaultPermission defaultPermission) {
this.permissions = new CommandPermissions(permissionNode, defaultPermission);
}
public static CommandBuilder builder() {
return new CommandBuilder();
}
@ -646,7 +637,7 @@ public class CommandDescription {
return this;
}
public CommandBuilder permissions(CommandPermissions.DefaultPermission defaultPermission,
public CommandBuilder permissions(DefaultPermission defaultPermission,
PermissionNode... permissionNodes) {
this.permissions = new CommandPermissions(asMutableList(permissionNodes), defaultPermission);
return this;

View File

@ -37,8 +37,8 @@ import fr.xephi.authme.util.Wrapper;
import java.util.*;
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.ALLOWED;
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.OP_ONLY;
import static fr.xephi.authme.permission.DefaultPermission.ALLOWED;
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
/**
* Initializes all available AuthMe commands.
@ -162,7 +162,7 @@ public final class CommandInitializer {
.build();
// Register the setemail command
CommandDescription setEmailCommand = CommandDescription.builder()
CommandDescription.builder()
.executableCommand(new SetEmailCommand())
.parent(AUTHME_BASE)
.labels("chgemail", "chgmail", "setemail", "setmail")
@ -174,96 +174,101 @@ public final class CommandInitializer {
.build();
// Register the getip command
CommandDescription getIpCommand = new CommandDescription(new GetIpCommand(), new ArrayList<String>() {
{
add("getip");
add("ip");
}
}, "Get player's IP", "Get the IP address of the specified online player.", AUTHME_BASE);
getIpCommand.setCommandPermissions(AdminPermission.GET_IP, OP_ONLY);
getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", true));
CommandDescription.builder()
.executableCommand(new GetIpCommand())
.parent(AUTHME_BASE)
.labels("getip", "ip")
.description("Get player's IP")
.detailedDescription("Get the IP address of the specified online player.")
.permissions(OP_ONLY, AdminPermission.GET_IP)
.withArgument("player", "Player Name", false)
.build();
// Register the spawn command
CommandDescription spawnCommand = new CommandDescription(new SpawnCommand(), new ArrayList<String>() {
{
add("spawn");
add("home");
}
}, "Teleport to spawn", "Teleport to the spawn.", AUTHME_BASE);
spawnCommand.setCommandPermissions(AdminPermission.SPAWN, OP_ONLY);
CommandDescription.builder()
.executableCommand(new SpawnCommand())
.parent(AUTHME_BASE)
.labels("spawn", "home")
.description("Teleport to spawn")
.detailedDescription("Teleport to the spawn.")
.permissions(OP_ONLY, AdminPermission.SPAWN)
.withArgument("player", "Player Name", false)
.build();
// Register the setspawn command
CommandDescription setSpawnCommand = new CommandDescription(new SetSpawnCommand(), new ArrayList<String>() {
{
add("setspawn");
add("chgspawn");
}
}, "Change the spawn", "Change the player's spawn to your current position.", AUTHME_BASE);
setSpawnCommand.setCommandPermissions(AdminPermission.SET_SPAWN, OP_ONLY);
CommandDescription.builder()
.executableCommand(new SetSpawnCommand())
.parent(AUTHME_BASE)
.labels("setspawn", "chgspawn")
.description("Change the spawn")
.detailedDescription("Change the player's spawn to your current position.")
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
.build();
// Register the firstspawn command
CommandDescription firstSpawnCommand = new CommandDescription(new FirstSpawnCommand(), new ArrayList<String>() {
{
add("firstspawn");
add("firsthome");
}
}, "Teleport to first spawn", "Teleport to the first spawn.", AUTHME_BASE);
firstSpawnCommand.setCommandPermissions(AdminPermission.FIRST_SPAWN, OP_ONLY);
CommandDescription.builder()
.executableCommand(new FirstSpawnCommand())
.parent(AUTHME_BASE)
.labels("firstspawn", "firsthome")
.description("Teleport to first spawn")
.detailedDescription("Teleport to the first spawn.")
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
.build();
// Register the setfirstspawn command
CommandDescription setFirstSpawnCommand = new CommandDescription(new SetFirstSpawnCommand(), new ArrayList<String>() {
{
add("setfirstspawn");
add("chgfirstspawn");
}
}, "Change the first spawn", "Change the first player's spawn to your current position.", AUTHME_BASE);
setFirstSpawnCommand.setCommandPermissions(AdminPermission.SET_FIRST_SPAWN, OP_ONLY);
CommandDescription.builder()
.executableCommand(new SetFirstSpawnCommand())
.parent(AUTHME_BASE)
.labels("setfirstspawn", "chgfirstspawn")
.description("Change the first spawn")
.detailedDescription("Change the first player's spawn to your current position.")
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
.build();
// Register the purge command
CommandDescription purgeCommand = new CommandDescription(new PurgeCommand(), new ArrayList<String>() {
{
add("purge");
add("delete");
}
}, "Purge old data", "Purge old AuthMeReloaded data longer than the specified amount of days ago.", AUTHME_BASE);
purgeCommand.setCommandPermissions(AdminPermission.PURGE, OP_ONLY);
purgeCommand.addArgument(new CommandArgumentDescription("days", "Number of days", false));
CommandDescription.builder()
.executableCommand(new PurgeCommand())
.parent(AUTHME_BASE)
.labels("purge", "delete")
.description("Purge old data")
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
.permissions(OP_ONLY, AdminPermission.PURGE)
.withArgument("days", "Number of days", false)
.build();
// Register the purgelastposition command
CommandDescription purgeLastPositionCommand = new CommandDescription(new PurgeLastPositionCommand(), new ArrayList<String>() {
{
add("resetpos");
add("purgelastposition");
add("purgelastpos");
add("resetposition");
add("resetlastposition");
add("resetlastpos");
}
}, "Purge player's last position", "Purge the last know position of the specified player.", AUTHME_BASE);
purgeLastPositionCommand.setCommandPermissions(AdminPermission.PURGE_LAST_POSITION, OP_ONLY);
purgeLastPositionCommand.addArgument(new CommandArgumentDescription("player", "Player name", true));
CommandDescription.builder()
.executableCommand(new PurgeLastPositionCommand())
.parent(AUTHME_BASE)
.labels("resetpos", "purgelastposition", "purgelastpos", "resetposition", "resetlastposition", "resetlastpos")
.description("Purge player's last position")
.detailedDescription("Purge the last know position of the specified player.")
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
.withArgument("player", "Player name", false)
.build();
// Register the purgebannedplayers command
CommandDescription purgeBannedPlayersCommand = new CommandDescription(new PurgeBannedPlayersCommand(), new ArrayList<String>() {
{
add("purgebannedplayers");
add("purgebannedplayer");
add("deletebannedplayers");
add("deletebannedplayer");
}
}, "Purge banned palyers data", "Purge all AuthMeReloaded data for banned players.", AUTHME_BASE);
purgeBannedPlayersCommand.setCommandPermissions(AdminPermission.PURGE_BANNED_PLAYERS, OP_ONLY);
CommandDescription purgeBannedPlayersCommand = CommandDescription.builder()
.executableCommand(new PurgeBannedPlayersCommand())
.parent(AUTHME_BASE)
.labels("purgebannedplayers", "purgebannedplayer", "deletebannedplayers", "deletebannedplayer")
.description("Purge banned players data")
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
.build();
// Register the switchantibot command
CommandDescription switchAntiBotCommand = new CommandDescription(new SwitchAntiBotCommand(), new ArrayList<String>() {
{
add("switchantibot");
add("toggleantibot");
add("antibot");
}
}, "Switch AntiBot mode", "Switch or toggle the AntiBot mode to the specified state.", AUTHME_BASE);
switchAntiBotCommand.setCommandPermissions(AdminPermission.SWITCH_ANTIBOT, OP_ONLY);
switchAntiBotCommand.addArgument(new CommandArgumentDescription("mode", "ON / OFF", true));
CommandDescription switchAntiBotCommand = CommandDescription.builder()
.executableCommand(new SwitchAntiBotCommand())
.parent(AUTHME_BASE)
.labels("switchantibot", "toggleantibot", "antibot")
.description("Switch AntiBot mode")
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
.withArgument("mode", "ON / OFF", true)
.build();
// // Register the resetname command
// CommandDescription resetNameCommand = new CommandDescription(
@ -279,13 +284,14 @@ public final class CommandInitializer {
// CommandPermissions.DefaultPermission.OP_ONLY);
// Register the reload command
CommandDescription reloadCommand = new CommandDescription(new ReloadCommand(), new ArrayList<String>() {
{
add("reload");
add("rld");
}
}, "Reload plugin", "Reload the AuthMeReloaded plugin.", AUTHME_BASE);
reloadCommand.setCommandPermissions(AdminPermission.RELOAD, OP_ONLY);
CommandDescription reloadCommand = CommandDescription.builder()
.executableCommand(new PurgeLastPositionCommand())
.parent(AUTHME_BASE)
.labels("reload", "reload")
.description("Reload plugin")
.detailedDescription("Reload the AutheMeReloaded plugin.")
.permissions(OP_ONLY, AdminPermission.RELOAD)
.build();
// Register the version command
CommandDescription.builder()
@ -309,22 +315,36 @@ public final class CommandInitializer {
.build();
// Register the help command
CommandDescription loginHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded login commands.", LOGIN_BASE);
loginHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription loginHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(LOGIN_BASE)
.labels(helpCommandLabels)
.description("View Help")
.detailedDescription("View detailed help pages about AuthMeReloaded login commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base logout command
CommandDescription LOGOUT_BASE = new CommandDescription(new LogoutCommand(), new ArrayList<String>() {
{
add("logout");
}
}, "Logout command", "Command to logout using AuthMeReloaded.", null);
LOGOUT_BASE.setCommandPermissions(PlayerPermission.LOGOUT, ALLOWED);
CommandDescription LOGOUT_BASE = CommandDescription.builder()
.executableCommand(new LogoutCommand())
.parent(null)
.labels("logout")
.description("Logout command")
.detailedDescription("Command to logout using AuthMeReloaded.")
.permissions(ALLOWED, PlayerPermission.LOGOUT)
.build();
// Register the help command
CommandDescription logoutHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded logout commands.", LOGOUT_BASE);
logoutHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription logoutHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(LOGOUT_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded logout commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base register command
final CommandDescription REGISTER_BASE = CommandDescription.builder()
@ -339,120 +359,161 @@ public final class CommandInitializer {
.build();
// Register the help command
CommandDescription registerHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded register commands.", REGISTER_BASE);
registerHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription registerHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(REGISTER_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded register commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base unregister command
CommandDescription UNREGISTER_BASE = new CommandDescription(new UnregisterCommand(), new ArrayList<String>() {
{
add("unregister");
add("unreg");
}
}, "Unregistration command", "Command to unregister using AuthMeReloaded.", null);
UNREGISTER_BASE.setCommandPermissions(PlayerPermission.UNREGISTER, ALLOWED);
UNREGISTER_BASE.addArgument(new CommandArgumentDescription("password", "Password", false));
CommandDescription UNREGISTER_BASE = CommandDescription.builder()
.executableCommand(new UnregisterCommand())
.parent(null)
.labels("unreg", "unregister")
.description("Unregistration Command")
.detailedDescription("Command to unregister using AuthMeReloaded.")
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
.withArgument("password", "Password", false)
.build();
// Register the help command
CommandDescription unregisterHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels, "View help", "View detailed help pages about AuthMeReloaded unregister commands.", UNREGISTER_BASE);
unregisterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription unregisterHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(UNREGISTER_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded unregister commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base changepassword command
final CommandDescription CHANGE_PASSWORD_BASE = new CommandDescription(
new ChangePasswordCommand(), new ArrayList<String>() {
{
add("changepassword");
add("changepass");
}
}, "Change password command", "Command to change your password using AuthMeReloaded.", null);
CHANGE_PASSWORD_BASE.setCommandPermissions(PlayerPermission.CHANGE_PASSWORD, ALLOWED);
CHANGE_PASSWORD_BASE.addArgument(new CommandArgumentDescription("password", "Password", false));
CHANGE_PASSWORD_BASE.addArgument(new CommandArgumentDescription("verifyPassword", "Verify password", false));
final CommandDescription CHANGE_PASSWORD_BASE = CommandDescription.builder()
.executableCommand(new ChangePasswordCommand())
.parent(null)
.labels("changepassword", "changepass", "cp")
.description("Change password Command")
.detailedDescription("Command to change your password using AuthMeReloaded.")
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
.withArgument("password", "Password", false)
.withArgument("verifyPassword", "Verify password.", false)
.build();
// Register the help command
CommandDescription changePasswordHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change password commands.", CHANGE_PASSWORD_BASE);
changePasswordHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription changePasswordHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(CHANGE_PASSWORD_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded changepassword commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base Dungeon Maze command
CommandDescription EMAIL_BASE = new CommandDescription(helpCommandExecutable, new ArrayList<String>() {
{
add("email");
add("mail");
}
}, "E-mail command", "The AuthMe Reloaded E-mail command. The root for all E-mail commands.", null);
// Register the base Email command
CommandDescription EMAIL_BASE = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(null)
.labels("email", "mail")
.description("Email command")
.detailedDescription("The AuthMeReloaded Email command base.")
.permissions(ALLOWED)
.build();
// Register the help command
CommandDescription emailHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded help commands.", EMAIL_BASE);
emailHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription emailHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(EMAIL_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded email commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the add command
CommandDescription addEmailCommand = new CommandDescription(new AddEmailCommand(), new ArrayList<String>() {
{
add("add");
add("addemail");
add("addmail");
}
}, "Add E-mail", "Add an new E-Mail address to your account.", EMAIL_BASE);
addEmailCommand.setCommandPermissions(PlayerPermission.ADD_EMAIL, ALLOWED);
addEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
addEmailCommand.addArgument(new CommandArgumentDescription("verifyEmail", "Email address verification", false));
CommandDescription addEmailCommand = CommandDescription.builder()
.executableCommand(new AddEmailCommand())
.parent(EMAIL_BASE)
.labels("add", "addemail", "addmail")
.description("Add Email")
.detailedDescription("Add a new Email address to your account.")
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
.withArgument("email", "Email address", false)
.withArgument("verifyEmail", "Email address verification", false)
.build();
// Register the change command
CommandDescription changeEmailCommand = new CommandDescription(new ChangeEmailCommand(), new ArrayList<String>() {
{
add("change");
add("changeemail");
add("changemail");
}
}, "Change E-mail", "Change an E-Mail address of your account.", EMAIL_BASE);
changeEmailCommand.setCommandPermissions(PlayerPermission.CHANGE_EMAIL, ALLOWED);
changeEmailCommand.addArgument(new CommandArgumentDescription("oldEmail", "Old email address", false));
changeEmailCommand.addArgument(new CommandArgumentDescription("newEmail", "New email address", false));
CommandDescription changeEmailCommand = CommandDescription.builder()
.executableCommand(new ChangeEmailCommand())
.parent(EMAIL_BASE)
.labels("change", "changeemail", "changemail")
.description("Change Email")
.detailedDescription("Change an Email address of your account.")
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
.withArgument("oldEmail", "Old email address", false)
.withArgument("newEmail", "New email address", false)
.build();
// Register the recover command
CommandDescription recoverEmailCommand = new CommandDescription(new RecoverEmailCommand(), new ArrayList<String>() {
{
add("recover");
add("recovery");
add("recoveremail");
add("recovermail");
}
}, "Recover using E-mail", "Recover your account using an E-mail address.", EMAIL_BASE);
recoverEmailCommand.setCommandPermissions(PlayerPermission.RECOVER_EMAIL, ALLOWED);
recoverEmailCommand.addArgument(new CommandArgumentDescription("email", "Email address", false));
CommandDescription recoverEmailCommand = CommandDescription.builder()
.executableCommand(new RecoverEmailCommand())
.parent(EMAIL_BASE)
.labels("recover", "recovery", "recoveremail", "recovermail")
.description("Recover password using Email")
.detailedDescription("Recover your account using an Email address by sending a mail containing a new password.")
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
.withArgument("email", "Email address", false)
.build();
// Register the base captcha command
CommandDescription CAPTCHA_BASE = new CommandDescription(new CaptchaCommand(), new ArrayList<String>() {
{
add("captcha");
add("capt");
}
}, "Captcha command", "Captcha command for AuthMeReloaded.", null);
CAPTCHA_BASE.setCommandPermissions(PlayerPermission.CAPTCHA, ALLOWED);
CAPTCHA_BASE.addArgument(new CommandArgumentDescription("captcha", "The captcha", false));
CommandDescription CAPTCHA_BASE = CommandDescription.builder()
.executableCommand(new CaptchaCommand())
.parent(null)
.labels("captcha", "capt")
.description("Captcha Command")
.detailedDescription("Captcha command for AuthMeRelaoded.")
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
.withArgument("captcha", "The Captcha", false)
.build();
// Register the help command
CommandDescription captchaHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", CAPTCHA_BASE);
captchaHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription captchaHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(CAPTCHA_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded captcha commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Register the base converter command
CommandDescription CONVERTER_BASE = new CommandDescription(new ConverterCommand(), new ArrayList<String>() {
{
add("converter");
add("convert");
add("conv");
}
}, "Convert command", "Convert command for AuthMeReloaded.", null);
CONVERTER_BASE.setCommandPermissions(AdminPermission.CONVERTER, OP_ONLY);
CONVERTER_BASE.addArgument(new CommandArgumentDescription("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false));
CommandDescription CONVERTER_BASE = CommandDescription.builder()
.executableCommand(new ConverterCommand())
.parent(null)
.labels("converter", "convert", "conv")
.description("Converter Command")
.detailedDescription("Converter command for AuthMeRelaoded.")
.permissions(OP_ONLY, AdminPermission.CONVERTER)
.withArgument("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false)
.build();
// Register the help command
CommandDescription converterHelpCommand = new CommandDescription(helpCommandExecutable, helpCommandLabels,
"View help", "View detailed help pages about AuthMeReloaded change captcha commands.", CONVERTER_BASE);
converterHelpCommand.addArgument(new CommandArgumentDescription("query", "The command or query to view help for.", true));
CommandDescription converterHelpCommand = CommandDescription.builder()
.executableCommand(helpCommandExecutable)
.parent(CONVERTER_BASE)
.labels(helpCommandLabels)
.description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded converter commands.")
.permissions(OP_ONLY)
.withArgument("query", "The command or query to view help for.", true)
.build();
// Add the base commands to the commands array
baseCommands = new HashSet<>(Arrays.asList(

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.command;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PermissionNode;
import org.bukkit.command.CommandSender;
@ -22,18 +23,6 @@ public class CommandPermissions {
*/
private DefaultPermission defaultPermission;
/**
* Constructor.
*
* @param permissionNode The permission node required to execute a command.
* @param defaultPermission The default permission if the permission nodes couldn't be used.
*/
public CommandPermissions(PermissionNode permissionNode, DefaultPermission defaultPermission) {
this.permissionNodes = new ArrayList<>();
this.permissionNodes.add(permissionNode);
this.defaultPermission = defaultPermission;
}
/**
* Constructor.
*
@ -54,16 +43,6 @@ public class CommandPermissions {
return this.permissionNodes;
}
/**
* Get the number of permission nodes set.
*
* @return Permission node count.
*/
public int getPermissionNodeCount() {
return this.permissionNodes.size();
}
/**
* Check whether this command requires any permission to be executed. This is based on the getPermission() method.
*
@ -73,31 +52,28 @@ public class CommandPermissions {
*/
public boolean hasPermission(CommandSender sender) {
// Make sure any permission node is set
if (getPermissionNodeCount() == 0)
if (permissionNodes.isEmpty()) {
return true;
}
// Get the default permission
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
final boolean defaultPermission = getDefaultPermissionCommandSender(sender);
// Make sure the command sender is a player, if not use the default
if (!(sender instanceof Player))
if (!(sender instanceof Player)) {
return defaultPermission;
}
// Get the player instance
Player player = (Player) sender;
// Get the permissions manager, and make sure it's instance is valid
PermissionsManager permissionsManager = AuthMe.getInstance().getPermissionsManager();
if (permissionsManager == null)
return false;
// Check whether the player has permission, return the result
for (PermissionNode node : this.permissionNodes) {
if (!permissionsManager.hasPermission(player, node, defaultPermission)) {
return false;
}
}
return true;
return permissionsManager.hasPermission(player, this.permissionNodes, defaultPermission);
}
/**
@ -109,14 +85,6 @@ public class CommandPermissions {
return this.defaultPermission;
}
/**
* Set the default permission used if the permission nodes couldn't be used.
*
* @param defaultPermission The default permission.
*/
public void setDefaultPermission(DefaultPermission defaultPermission) {
this.defaultPermission = defaultPermission;
}
/**
* Get the default permission for a specified command sender.
@ -138,12 +106,4 @@ public class CommandPermissions {
return false;
}
}
/**
*/
public enum DefaultPermission {
NOT_ALLOWED,
OP_ONLY,
ALLOWED
}
}

View File

@ -43,8 +43,12 @@ public class RegisterAdminCommand extends ExecutableCommand {
final String playerPassLowerCase = playerPass.toLowerCase();
// Command logic
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR);
if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where")
|| playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify")
|| playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select")
|| playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null")
|| !playerPassLowerCase.matches(Settings.getPassRegex)) {
m.send(sender, MessageKey.PASSWORD_MATCH_ERROR);
return true;
}
if (playerPassLowerCase.equalsIgnoreCase(playerName)) {

View File

@ -6,12 +6,14 @@ import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.CommandPermissions;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -85,14 +87,11 @@ public class HelpPrinter {
* @param command The command to print the permissions help for.
*/
public static void printPermissions(CommandSender sender, CommandDescription command) {
// Get the permissions and make sure it isn't null
// Get the permissions and make sure they aren't missing
CommandPermissions permissions = command.getCommandPermissions();
if (permissions == null)
return;
// Make sure any permission node is set
if (permissions.getPermissionNodeCount() <= 0)
if (permissions == null || CollectionUtils.isEmpty(permissions.getPermissionNodes())) {
return;
}
// Print the header
sender.sendMessage(ChatColor.GOLD + "Permissions:");
@ -107,13 +106,16 @@ public class HelpPrinter {
}
// Print the default permission
// TODO ljacqu 20151205: This is duplicating the logic in PermissionsManager#evaluateDefaultPermission
// Either use the command manager here, or if that's too heavy, look into moving certain permissions logic
// into a Utils class
switch (permissions.getDefaultPermission()) {
case ALLOWED:
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.GRAY + ChatColor.ITALIC + "Permission!");
break;
case OP_ONLY:
final String defaultPermsString = ChatColor.GRAY + (permissions.getDefaultPermissionCommandSender(sender) ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
final String defaultPermsString = ChatColor.GRAY + (sender.isOp() ? ChatColor.ITALIC + " (Permission!)" : ChatColor.ITALIC + " (No Permission!)");
sender.sendMessage(ChatColor.GOLD + " Default: " + ChatColor.YELLOW + ChatColor.ITALIC + "OP's Only!" + defaultPermsString);
break;

View File

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

View File

@ -0,0 +1,16 @@
package fr.xephi.authme.permission;
/**
* The default permission for a command if there is no support for permission nodes.
*/
public enum DefaultPermission {
/** No one can execute the command. */
NOT_ALLOWED,
/** Only players with the OP status may execute the command. */
OP_ONLY,
/** The command can be executed by anyone. */
ALLOWED
}

View File

@ -5,7 +5,18 @@ package fr.xephi.authme.permission;
*/
public interface PermissionNode {
/** Return the node of the permission, e.g. "authme.unregister". */
/**
* Return the node of the permission, e.g. "authme.player.unregister".
*
* @return The name of the permission node
*/
String getNode();
/**
* Return the wildcard node that also grants the permission.
*
* @return The wildcard permission node (e.g. "authme.player.*")
*/
PermissionNode getWildcardNode();
}

View File

@ -5,11 +5,14 @@ import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.CalculableType;
import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.util.CollectionUtils;
import net.milkbowl.vault.permission.Permission;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
@ -38,7 +41,7 @@ import java.util.logging.Logger;
* @author Tim Visée, http://timvisee.com
* @version 0.2.1
*/
public class PermissionsManager {
public class PermissionsManager implements PermissionsService {
/**
* Vault instance.
@ -100,8 +103,8 @@ public class PermissionsManager {
*
* @return The name of the permissions system used.
*/
public String getUsedPermissionsSystemType() {
return this.permsType.getName();
public PermissionsSystemType getSystem() {
return permsType;
}
/**
@ -260,7 +263,6 @@ public class PermissionsManager {
*
* @param event Event instance.
*/
// TODO ljacqu 20151129: Misleading name since onPluginEnable is a typical event-based method name
public void onPluginEnable(PluginEnableEvent event) {
// Get the plugin and it's name
Plugin plugin = event.getPlugin();
@ -296,35 +298,7 @@ public class PermissionsManager {
}
}
/**
* Get the logger instance.
*
* @return Logger instance.
*/
public Logger getLogger() {
return this.log;
}
/**
* Set the logger instance.
*
* @param log Logger instance.
*/
public void setLogger(Logger log) {
this.log = log;
}
/**
* Check if the player has permission. If no permissions system is used, the player has to be OP.
*
* @param player The player.
* @param permsNode Permissions node.
*
* @return True if the player has permission.
*/
public boolean hasPermission(Player player, String permsNode) {
return hasPermission(player, permsNode, player.isOp());
}
/**
* Check if the player has permission for the given permissions node. If no permissions system is used,
@ -340,7 +314,41 @@ public class PermissionsManager {
}
public boolean hasPermission(Player player, PermissionNode permissionNode, boolean def) {
return hasPermission(player, permissionNode.getNode(), def);
return hasPermission(player, permissionNode.getNode(), def)
|| hasPermission(player, permissionNode.getWildcardNode().getNode(), def);
}
public boolean hasPermission(Player player, Iterable<PermissionNode> nodes, boolean def) {
for (PermissionNode node : nodes) {
if (!hasPermission(player, node, def)) {
return false;
}
}
return true;
}
public boolean hasPermission(Player player, CommandDescription command) {
if (CollectionUtils.isEmpty(command.getCommandPermissions().getPermissionNodes())) {
return true;
}
DefaultPermission defaultPermission = command.getCommandPermissions().getDefaultPermission();
boolean def = evaluateDefaultPermission(defaultPermission, player);
return hasPermission(player, command.getCommandPermissions().getPermissionNodes(), def);
}
public static boolean evaluateDefaultPermission(DefaultPermission defaultPermission, CommandSender sender) {
switch (defaultPermission) {
case ALLOWED:
return true;
case OP_ONLY:
return sender.isOp();
case NOT_ALLOWED:
default:
return false;
}
}
/**
@ -352,7 +360,7 @@ public class PermissionsManager {
*
* @return True if the player has permission.
*/
public boolean hasPermission(Player player, String permsNode, boolean def) {
private boolean hasPermission(Player player, String permsNode, boolean def) {
// If no permissions system is used, return the default value
if (!isEnabled())
return def;
@ -915,34 +923,5 @@ public class PermissionsManager {
return removeGroups(player, groupNames);
}
private enum PermissionsSystemType {
NONE("None"),
PERMISSIONS_EX("PermissionsEx"),
PERMISSIONS_BUKKIT("Permissions Bukkit"),
B_PERMISSIONS("bPermissions"),
ESSENTIALS_GROUP_MANAGER("Essentials Group Manager"),
Z_PERMISSIONS("zPermissions"),
VAULT("Vault"),
PERMISSIONS("Permissions");
public final String name;
/**
* Constructor for PermissionsSystemType.
*
* @param name String
*/
PermissionsSystemType(String name) {
this.name = name;
}
/**
* Method getName.
*
* @return String
*/
public String getName() {
return this.name;
}
}
}

View File

@ -0,0 +1,39 @@
package fr.xephi.authme.permission;
import fr.xephi.authme.command.CommandDescription;
import org.bukkit.entity.Player;
/**
* Interface for dealing with permissions.
*/
public interface PermissionsService {
/**
* Check if the player has the given permission.
*
* @param player The player
* @param permission The permission node to check
* @param def Default returned if no permissions system is used
*
* @return True if the player has permission
*/
boolean hasPermission(Player player, PermissionNode permission, boolean def);
/**
* Check if the player has the permissions for the given command.
*
* @param player The player
* @param command The command whose permissions should be checked
*
* @return True if the player may execute the command
*/
boolean hasPermission(Player player, CommandDescription command);
/**
* Return the permission system the service is working with.
*
* @return The permission system AuthMe is hooked into
*/
PermissionsSystemType getSystem();
}

View File

@ -0,0 +1,38 @@
package fr.xephi.authme.permission;
/**
* Enum representing the permissions systems AuthMe supports.
*/
public enum PermissionsSystemType {
NONE("None"),
PERMISSIONS_EX("PermissionsEx"),
PERMISSIONS_BUKKIT("Permissions Bukkit"),
B_PERMISSIONS("bPermissions"),
ESSENTIALS_GROUP_MANAGER("Essentials Group Manager"),
Z_PERMISSIONS("zPermissions"),
VAULT("Vault"),
PERMISSIONS("Permissions");
public final String name;
/**
* Constructor for PermissionsSystemType.
*
* @param name The name the permissions manager goes by
*/
PermissionsSystemType(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}

View File

@ -18,47 +18,47 @@ public enum PlayerPermission implements PermissionNode {
/**
* Command permission to login.
*/
LOGIN("authme.command.player.login"),
LOGIN("authme.player.login"),
/**
* Command permission to logout.
*/
LOGOUT("authme.command.player.logout"),
LOGOUT("authme.player.logout"),
/**
* Command permission to register.
*/
REGISTER("authme.command.player.register"),
REGISTER("authme.player.register"),
/**
* Command permission to unregister.
*/
UNREGISTER("authme.command.player.unregister"),
UNREGISTER("authme.player.unregister"),
/**
* Command permission to change the password.
*/
CHANGE_PASSWORD("authme.command.player.changepassword"),
CHANGE_PASSWORD("authme.player.changepassword"),
/**
* Command permission to add an email address.
*/
ADD_EMAIL("authme.command.player.email.add"),
ADD_EMAIL("authme.player.email.add"),
/**
* Command permission to change the email address.
*/
CHANGE_EMAIL("authme.command.player.email.change"),
CHANGE_EMAIL("authme.player.email.change"),
/**
* Command permission to recover an account using it's email address.
*/
RECOVER_EMAIL("authme.command.player.email.recover"),
RECOVER_EMAIL("authme.player.email.recover"),
/**
* Command permission to use captcha.
*/
CAPTCHA("authme.command.player.captcha"),
CAPTCHA("authme.player.captcha"),
/**
* Permission for users a login can be forced to.
@ -68,33 +68,28 @@ public enum PlayerPermission implements PermissionNode {
/**
* Permission for users to bypass force-survival mode.
*/
BYPASS_FORCE_SURVIVAL("authme.command.player.bypassforcesurvival"),
BYPASS_FORCE_SURVIVAL("authme.player.bypassforcesurvival"),
/**
* Permission for users to allow two accounts.
*/
ALLOW_MULTIPLE_ACCOUNTS("authme.command.player.allow2accounts"),
ALLOW_MULTIPLE_ACCOUNTS("authme.player.allow2accounts"),
/**
* Permission for user to see other accounts.
*/
SEE_OTHER_ACCOUNTS("authme.command.player.seeotheraccounts");
SEE_OTHER_ACCOUNTS("authme.player.seeotheraccounts"),
/**
* Permission node.
* Permission to use all player (non-admin) commands.
*/
PLAYER_ALL("authme.player.*");
/**
* The permission node.
*/
private String node;
/**
* Get the permission node.
*
* @return Permission node.
*/
@Override
public String getNode() {
return node;
}
/**
* Constructor.
*
@ -103,4 +98,14 @@ public enum PlayerPermission implements PermissionNode {
PlayerPermission(String node) {
this.node = node;
}
@Override
public String getNode() {
return node;
}
@Override
public PermissionNode getWildcardNode() {
return PLAYER_ALL;
}
}

View File

@ -135,6 +135,13 @@ public class AsynchronousLogin {
m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
return null;
}
if (Settings.preventOtherCase && !player.getName().equals(pAuth.getRealName()))
{
// TODO: Add a message like : MessageKey.INVALID_NAME_CASE
m.send(player, MessageKey.USERNAME_ALREADY_ONLINE_ERROR);
return null;
}
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.canLogin())

View File

@ -73,7 +73,7 @@ public final class Settings {
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
customAttributes, generateImage, isRemoveSpeedEnabled;
customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase;
public static String helpHeader, getNickRegex, getUnloggedinGroup, getMySQLHost,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword,
@ -294,6 +294,7 @@ public final class Settings {
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
customAttributes = configFile.getBoolean("Hooks.customAttributes");
generateImage = configFile.getBoolean("Email.generateImage", false);
preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false);
// Load the welcome message
getWelcomeMessage();
@ -713,6 +714,12 @@ public final class Settings {
changes = true;
}
if (!contains("settings.preventOtherCase"))
{
set("settings.preventOtherCase", false);
changes = true;
}
if (contains("Email.mailText"))
{
set("Email.mailText", null);

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -20,7 +21,7 @@ public final class CollectionUtils {
* @return The sublist consisting at most of {@code count} elements (less if the parameters
* exceed the size of the list)
*/
public static List<String> getRange(List<String> list, int start, int count) {
public static <T> List<T> getRange(List<T> list, int start, int count) {
if (start >= list.size() || count <= 0) {
return new ArrayList<>();
} else if (start < 0) {
@ -38,10 +39,14 @@ public final class CollectionUtils {
* @return The sublist of all elements from index {@code start} and on; empty list
* if the start index exceeds the list's size
*/
public static List<String> getRange(List<String> list, int start) {
public static <T> List<T> getRange(List<T> list, int start) {
if (start >= list.size()) {
return new ArrayList<>();
}
return getRange(list, start, list.size() - start);
}
public static <T> boolean isEmpty(Collection<T> coll) {
return coll == null || coll.isEmpty();
}
}

View File

@ -259,6 +259,9 @@ settings:
delayJoinLeaveMessages: true
# Do we need to add potion effect Blinding before login/register ?
applyBlindEffect: false
# Do we need to prevent people to login without another case ?
# Xephi is registered, also Xephi can login, but not XEPHI/xephi/XePhI
preventOtherCase: false
ExternalBoardOptions:
# MySQL column for the salt , needed for some forum/cms support
mySQLColumnSalt: ''

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.command;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.util.WrapperMock;
import org.bukkit.command.CommandSender;
@ -50,6 +51,7 @@ public class CommandHandlerTest {
}
@Test
@Ignore
public void shouldForwardCommandToExecutable() {
// given
CommandSender sender = Mockito.mock(CommandSender.class);
@ -89,7 +91,7 @@ public class CommandHandlerTest {
CommandDescription.CommandBuilder command = CommandDescription.builder()
.labels(labels)
.parent(parent)
.permissions(CommandPermissions.DefaultPermission.OP_ONLY, permission)
.permissions(DefaultPermission.OP_ONLY, permission)
.description("Test")
.detailedDescription("Test command")
.executableCommand(mock(ExecutableCommand.class));

View File

@ -7,10 +7,17 @@ import fr.xephi.authme.util.WrapperMock;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static fr.xephi.authme.command.CommandPermissions.DefaultPermission.OP_ONLY;
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

3
src/tools/README.md Normal file
View File

@ -0,0 +1,3 @@
# About src/tools
This _tools_ folder provides helpers and extended tests useful during the development of AuthMe.
This folder is not included during the build of AuthMe.

View File

@ -0,0 +1,21 @@
## Bat Helpers
Collection of .bat files to quickly perform some frequent development tasks.
They allow you to quickly build the project and to move the generated JAR to
the plugins folder of your test server.
### Setup
1. Copy the files into a new, convenient directory
2. Open setvars.bat with a text editor and add the correct directories
3. Open `cmd` and navigate to your _bathelpers_ folder (`cd C:\path\the\folder`)
4. Type `list_files.bat` (Hint: Type `l` and hit Tab) to see the available tasks
### Example use case
1. After writing changes, `build_project` to build project
2. `move_plugin` moves the JAR file to the plugin folder
3. `run_server` to start the server with the fresh JAR
4. Problem detected, stop the server
5. Make a small change, use `quick_build` and `move_plugin` to update
6. Verify the change again on the server: `run_server`
All files start with a different letter, so you can conveniently type the
first letter and then complete with Tab.

View File

@ -0,0 +1,6 @@
: Analyze the project with Sonar (requires you install SonarQube)
if "%jarfile%" == "" (
call setvars.bat
)
mvn clean verify sonar:sonar -f "%pomfile%"

View File

@ -0,0 +1,6 @@
: Build the project normally
if "%jarfile%" == "" (
call setvars.bat
)
mvn clean install -f "%pomfile%"

View File

@ -0,0 +1,2 @@
: List all bat files in the directory
dir /B *.bat

View File

@ -0,0 +1,11 @@
: Moves the AuthMe JAR file to the plugins folder of the test server
: You will have to hit 'Y' to really replace it if it already exists
if "%jarfile%" == "" (
call setvars.bat
)
if exist %jarfile% (
xcopy %jarfile% %plugins%
) else (
echo Target file not found: '%jarfile%'
)

View File

@ -0,0 +1,6 @@
: Build quickly without cleaning or testing
if "%jarfile%" == "" (
call setvars.bat
)
mvn install -f "%pomfile%" -Dmaven.test.skip

View File

@ -0,0 +1,9 @@
: Start the Minecraft server
if "%jarfile%" == "" (
call setvars.bat
)
cd "%server%"
call java -Xmx1024M -Xms1024M -jar spigot_server.jar
cd "%batdir%"
dir /B *.bat

View File

@ -0,0 +1,14 @@
: The folder in which these .bat files are located
SET batdir=C:\your\path\AUTHME_DEV\bathelpers\
: The location of the generated JAR file
SET jarfile=C:\Users\yourname\IdeaProjects\AuthMeReloaded\target\AuthMe-5.1-SNAPSHOT.jar
: The location of the pom.xml file of the project
SET pomfile=C:\Users\yourname\IdeaProjects\AuthMeReloaded\pom.xml
: The folder in which the server is located
SET server=C:\your\path\AUTHME_DEV\spigot-server\
: The location of the plugins folder of the Minecraft server
SET plugins=%server%\plugins

View File

@ -0,0 +1,43 @@
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
<!-- File auto-generated on Sat Dec 05 21:18:25 CET 2015. See permissions/permission_nodes.tpl.md -->
## AuthMe Permission Nodes
The following are the permission nodes that are currently supported by the latest dev builds.
- **authme.admin.*** Give access to all admin commands.
- **authme.admin.accounts** Administrator command to see all accounts associated with a user.
- **authme.admin.changemail** Administrator command to set or change the email address of a user.
- **authme.admin.changepassword** Administrator command to change the password of a user.
- **authme.admin.converter** Administrator command to convert old or other data to AuthMe data.
- **authme.admin.firstspawn** Administrator command to teleport to the first AuthMe spawn.
- **authme.admin.forcelogin** Administrator command to force-login an existing user.
- **authme.admin.getemail** Administrator command to get the email address of a user, if set.
- **authme.admin.getip** Administrator command to get the last known IP of a user.
- **authme.admin.lastlogin** Administrator command to see the last login date and time of a user.
- **authme.admin.purge** Administrator command to purge old user data.
- **authme.admin.purgebannedplayers** Administrator command to purge all data associated with banned players.
- **authme.admin.purgelastpos** Administrator command to purge the last position of a user.
- **authme.admin.register** Administrator command to register a new user.
- **authme.admin.reload** Administrator command to reload the plugin configuration.
- **authme.admin.setfirstspawn** Administrator command to set the first AuthMe spawn.
- **authme.admin.setspawn** Administrator command to set the AuthMe spawn.
- **authme.admin.spawn** Administrator command to teleport to the AuthMe spawn.
- **authme.admin.switchantibot** Administrator command to toggle the AntiBot protection status.
- **authme.admin.unregister** Administrator command to unregister an existing user.
- **authme.player.*** Permission to use all player (non-admin) commands.
- **authme.player.allow2accounts** Permission for users to allow two accounts.
- **authme.player.bypassantibot** Permission node to bypass AntiBot protection.
- **authme.player.bypassforcesurvival** Permission for users to bypass force-survival mode.
- **authme.player.canbeforced** Permission for users a login can be forced to.
- **authme.player.captcha** Command permission to use captcha.
- **authme.player.changepassword** Command permission to change the password.
- **authme.player.email.add** Command permission to add an email address.
- **authme.player.email.change** Command permission to change the email address.
- **authme.player.email.recover** Command permission to recover an account using it's email address.
- **authme.player.login** Command permission to login.
- **authme.player.logout** Command permission to logout.
- **authme.player.register** Command permission to register.
- **authme.player.seeotheraccounts** Permission for user to see other accounts.
- **authme.player.unregister** Command permission to unregister.
- **authme.player.vip** Permission node to identify VIP users.

View File

@ -0,0 +1,113 @@
package permissions;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.util.StringUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Gatherer to generate up-to-date lists of the AuthMe permission nodes.
*/
public class PermissionNodesGatherer {
/** The folder in which the implementations of {@link PermissionNode} reside. */
private static final String PERMISSION_NODE_SOURCE_FOLDER =
"src/main/java/fr/xephi/authme/permission/";
/**
* Regular expression that should match the JavaDoc comment above an enum, <i>including</i>
* the name of the enum value. The first group (i.e. {@code \\1}) should be the JavaDoc description;
* the second group should contain the enum value.
*/
private static final Pattern JAVADOC_WITH_ENUM_PATTERN = Pattern.compile(
"/\\*\\*\\s+\\*" // Match starting '/**' and the '*' on the next line
+ "(.*?)\\s+\\*/" // Capture everything until we encounter '*/'
+ "\\s+([A-Z_]+)\\("); // Match the enum name (e.g. 'LOGIN'), until before the first '('
/**
* Return a sorted collection of all permission nodes.
*
* @return AuthMe permission nodes sorted alphabetically
*/
public Set<String> gatherNodes() {
Set<String> nodes = new TreeSet<>();
for (PermissionNode perm : PlayerPermission.values()) {
nodes.add(perm.getNode());
}
for (PermissionNode perm : AdminPermission.values()) {
nodes.add(perm.getNode());
}
return nodes;
}
/**
* Return a sorted collection of all permission nodes, including its JavaDoc description.
*
* @return Ordered map whose keys are the permission nodes and the values the associated JavaDoc
*/
public Map<String, String> gatherNodesWithJavaDoc() {
Map<String, String> result = new TreeMap<>();
addDescriptionsForClass(PlayerPermission.class, result);
addDescriptionsForClass(AdminPermission.class, result);
return result;
}
private <T extends Enum<T> & PermissionNode> void addDescriptionsForClass(Class<T> clazz,
Map<String, String> descriptions) {
String classSource = getSourceForClass(clazz);
Map<String, String> sourceDescriptions = extractJavaDocFromSource(classSource);
for (T perm : EnumSet.allOf(clazz)) {
String description = sourceDescriptions.get(perm.name());
if (description == null) {
System.out.println("Note: Could not retrieve description for "
+ clazz.getSimpleName() + "#" + perm.name());
description = "";
}
descriptions.put(perm.getNode(), description.trim());
}
}
private static Map<String, String> extractJavaDocFromSource(String source) {
Map<String, String> allMatches = new HashMap<>();
Matcher matcher = JAVADOC_WITH_ENUM_PATTERN.matcher(source);
while (matcher.find()) {
String description = matcher.group(1);
String enumValue = matcher.group(2);
allMatches.put(enumValue, description);
}
return allMatches;
}
/**
* Return the Java source code for the given implementation of {@link PermissionNode}.
*
* @param clazz The clazz to the get the source for
* @param <T> The concrete class
* @return Source code of the file
*/
private static <T extends Enum<T> & PermissionNode> String getSourceForClass(Class<T> clazz) {
String classFile = PERMISSION_NODE_SOURCE_FOLDER + clazz.getSimpleName() + ".java";
Charset cs = Charset.forName("utf-8");
try {
return StringUtils.join("\n",
Files.readAllLines(Paths.get(classFile), cs));
} catch (IOException e) {
throw new RuntimeException("Failed to get the source for class '" + clazz.getSimpleName() + "'");
}
}
}

View File

@ -0,0 +1,86 @@
package permissions;
import utils.ANewMap;
import utils.GeneratedFileWriter;
import utils.TagReplacer;
import utils.ToolsConstants;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
/**
* Class responsible for formatting a permissions node list and
* for writing it to a file if desired.
*/
public class PermissionsListWriter {
private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md";
public static void main(String[] args) {
// Ask if result should be written to file
Scanner scanner = new Scanner(System.in);
System.out.println("Include description? [Enter 'n' for no]");
boolean includeDescription = !matches("n", scanner);
if (!includeDescription) {
outputSimpleList();
return;
}
System.out.println("Write to file? [Enter 'n' for console output]");
boolean writeToFile = !matches("n", scanner);
scanner.close();
if (writeToFile) {
generateAndWriteFile();
} else {
System.out.println(generatePermissionsList());
}
}
private static void generateAndWriteFile() {
final String permissionsTagValue = generatePermissionsList();
Map<String, Object> tags = ANewMap.<String, Object>with("permissions", permissionsTagValue).build();
GeneratedFileWriter.generateFileFromTemplate(
ToolsConstants.TOOLS_SOURCE_ROOT + "permissions/permission_nodes.tpl.md", PERMISSIONS_OUTPUT_FILE, tags);
System.out.println("Wrote to '" + PERMISSIONS_OUTPUT_FILE + "'");
System.out.println("Before committing, please verify the output!");
}
private static String generatePermissionsList() {
PermissionNodesGatherer gatherer = new PermissionNodesGatherer();
Map<String, String> permissions = gatherer.gatherNodesWithJavaDoc();
final String template = GeneratedFileWriter.readFromToolsFile("permissions/permission_node_entry.tpl.md");
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : permissions.entrySet()) {
Map<String, Object> tags = ANewMap.<String, Object>
with("node", entry.getKey())
.and("description", entry.getValue())
.build();
sb.append(TagReplacer.applyReplacements(template, tags));
}
return sb.toString();
}
private static void outputSimpleList() {
PermissionNodesGatherer gatherer = new PermissionNodesGatherer();
Set<String> nodes = gatherer.gatherNodes();
for (String node : nodes) {
System.out.println(node);
}
System.out.println();
System.out.println("Total: " + nodes.size());
}
private static boolean matches(String answer, Scanner sc) {
String userInput = sc.nextLine();
return answer.equalsIgnoreCase(userInput);
}
}

View File

@ -0,0 +1,2 @@
# About
Helper script to generate a page with an up-to-date list of permission nodes.

View File

@ -0,0 +1 @@
- **{node}** {description}

View File

@ -0,0 +1,7 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See permissions/permission_nodes.tpl.md -->
## AuthMe Permission Nodes
The following are the permission nodes that are currently supported by the latest dev builds.
{permissions}

View File

@ -0,0 +1,36 @@
package utils;
import java.util.HashMap;
import java.util.Map;
/**
* A map builder for the lazy.
* <p />
* Sample usage:
* <code>
* Map&lt;String, Integer> map = ANewMap
* .with("test", 123)
* .and("text", 938)
* .and("abc", 456)
* .build();
* </code>
*/
public class ANewMap<K, V> {
private Map<K, V> map = new HashMap<>();
public static <K, V> ANewMap<K, V> with(K key, V value) {
ANewMap<K, V> instance = new ANewMap<>();
return instance.and(key, value);
}
public ANewMap<K, V> and(K key, V value) {
map.put(key, value);
return this;
}
public Map<K, V> build() {
return map;
}
}

View File

@ -0,0 +1,47 @@
package utils;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
/**
* Utility class for writing a generated file with a timestamp.
*/
public final class GeneratedFileWriter {
private final static Charset CHARSET = Charset.forName("utf-8");
private GeneratedFileWriter() {
}
public static void generateFileFromTemplate(String templateFile, String destinationFile, Map<String, Object> tags) {
String template = readFromFile(templateFile);
String result = TagReplacer.applyReplacements(template, tags);
writeToFile(destinationFile, result);
}
private static void writeToFile(String outputFile, String contents) {
try {
Files.write(Paths.get(outputFile), contents.getBytes());
} catch (IOException e) {
throw new RuntimeException("Failed to write to file '" + outputFile + "'", e);
}
}
public static String readFromFile(String file) {
try {
return new String(Files.readAllBytes(Paths.get(file)), CHARSET);
} catch (IOException e) {
throw new RuntimeException("Could not read from file '" + file + "'", e);
}
}
public static String readFromToolsFile(String file) {
return readFromFile(ToolsConstants.TOOLS_SOURCE_ROOT + file);
}
}

View File

@ -0,0 +1,46 @@
package utils;
import java.util.Date;
import java.util.Map;
/**
* Class responsible for replacing template tags to actual content.
* For all files, the following tags are defined:
* <ul>
* <li>{gen_date} the generation date</li>
* <li>{gen_warning} - warning not to edit the generated file directly</li>
* </ul>
*/
public class TagReplacer {
/**
* Replace a template with default tags and custom ones supplied by a map.
*
* @param template The template to process
* @param tags Map with additional tags, e.g. a map entry with key "foo" and value "bar" will replace
* any occurrences of "{foo}" to "bar".
* @return The filled template
*/
public static String applyReplacements(String template, Map<String, Object> tags) {
String result = template;
for (Map.Entry<String, Object> tagRule : tags.entrySet()) {
result = result.replace("{" + tagRule.getKey() + "}", tagRule.getValue().toString());
}
return applyReplacements(result);
}
/**
* Apply the default tag replacements.
*
* @param template The template to process
* @return The filled template
*/
public static String applyReplacements(String template) {
return template
.replace("{gen_date}", new Date().toString())
.replace("{gen_warning}", "AUTO-GENERATED FILE! Do not edit this directly");
}
}

View File

@ -0,0 +1,17 @@
package utils;
/**
* Constants for the src/tools folder.
*/
public final class ToolsConstants {
private ToolsConstants() {
}
public static final String MAIN_SOURCE_ROOT = "src/main/java/";
public static final String TOOLS_SOURCE_ROOT = "src/tools/";
public static final String DOCS_FOLDER = TOOLS_SOURCE_ROOT + "docs/";
}