#963 Create tool task to generate plugin.yml

- Create task that generates commands/permissions section of plugin.yml
- Change CommandInitializer to return a List instead of Set (preserve insertion order)
- Merge CommandSyntaxHelper into CommandUtils
This commit is contained in:
ljacqu
2016-10-23 12:17:37 +02:00
parent 1867617dbb
commit d09964f1cb
18 changed files with 527 additions and 337 deletions
@@ -1,6 +1,6 @@
package fr.xephi.authme.command;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import fr.xephi.authme.command.executable.HelpCommand;
import fr.xephi.authme.command.executable.authme.AccountsCommand;
import fr.xephi.authme.command.executable.authme.AuthMeCommand;
@@ -41,14 +41,13 @@ import fr.xephi.authme.permission.PlayerPermission;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* Initializes all available AuthMe commands.
*/
public class CommandInitializer {
private Set<CommandDescription> commands;
private List<CommandDescription> commands;
public CommandInitializer() {
buildCommands();
@@ -59,7 +58,7 @@ public class CommandInitializer {
*
* @return the command descriptions
*/
public Set<CommandDescription> getCommands() {
public List<CommandDescription> getCommands() {
return commands;
}
@@ -67,7 +66,7 @@ public class CommandInitializer {
// Register the base AuthMe Reloaded command
final CommandDescription AUTHME_BASE = CommandDescription.builder()
.labels("authme")
.description("Main command")
.description("AuthMe op commands")
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
.executableCommand(AuthMeCommand.class)
.register();
@@ -324,7 +323,7 @@ public class CommandInitializer {
final CommandDescription REGISTER_BASE = CommandDescription.builder()
.parent(null)
.labels("register", "reg")
.description("Registration command")
.description("Register an account")
.detailedDescription("Command to register using AuthMeReloaded.")
.withArgument("password", "Password", true)
.withArgument("verifyPassword", "Verify password", true)
@@ -336,7 +335,7 @@ public class CommandInitializer {
CommandDescription UNREGISTER_BASE = CommandDescription.builder()
.parent(null)
.labels("unregister", "unreg")
.description("Unregistration Command")
.description("Unregister an account")
.detailedDescription("Command to unregister using AuthMeReloaded.")
.withArgument("password", "Password", false)
.permission(PlayerPermission.UNREGISTER)
@@ -347,10 +346,10 @@ public class CommandInitializer {
final CommandDescription CHANGE_PASSWORD_BASE = CommandDescription.builder()
.parent(null)
.labels("changepassword", "changepass", "cp")
.description("Change password Command")
.description("Change password of an account")
.detailedDescription("Command to change your password using AuthMeReloaded.")
.withArgument("oldPassword", "Old Password", false)
.withArgument("newPassword", "New Password.", false)
.withArgument("oldPassword", "Old password", false)
.withArgument("newPassword", "New password", false)
.permission(PlayerPermission.CHANGE_PASSWORD)
.executableCommand(ChangePasswordCommand.class)
.register();
@@ -359,8 +358,8 @@ public class CommandInitializer {
CommandDescription EMAIL_BASE = CommandDescription.builder()
.parent(null)
.labels("email")
.description("Email command")
.detailedDescription("The AuthMeReloaded Email command base.")
.description("Add email or recover password")
.detailedDescription("The AuthMeReloaded email command base.")
.executableCommand(EmailBaseCommand.class)
.register();
@@ -401,7 +400,7 @@ public class CommandInitializer {
CommandDescription.builder()
.parent(EMAIL_BASE)
.labels("recover", "recovery", "recoveremail", "recovermail")
.description("Recover password using Email")
.description("Recover password using email")
.detailedDescription("Recover your account using an Email address by sending a mail containing " +
"a new password.")
.withArgument("email", "Email address", false)
@@ -421,7 +420,7 @@ public class CommandInitializer {
.executableCommand(CaptchaCommand.class)
.register();
Set<CommandDescription> baseCommands = ImmutableSet.of(
List<CommandDescription> baseCommands = ImmutableList.of(
AUTHME_BASE,
LOGIN_BASE,
LOGOUT_BASE,
@@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -26,7 +27,7 @@ public class CommandMapper {
*/
private static final Class<? extends ExecutableCommand> HELP_COMMAND_CLASS = HelpCommand.class;
private final Set<CommandDescription> baseCommands;
private final Collection<CommandDescription> baseCommands;
private final PermissionsManager permissionsManager;
@Inject
@@ -1,9 +1,11 @@
package fr.xephi.authme.command;
import com.google.common.collect.Lists;
import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public final class CommandUtils {
@@ -34,6 +36,14 @@ public final class CommandUtils {
return sb.toString();
}
/**
* Constructs a hierarchical list of commands for the given command. The commands are in order:
* the parents of the given command precede the provided command. For example, given the command
* for {@code /authme register}, a list with {@code [{authme}, {authme register}]} is returned.
*
* @param command the command to build a parent list for
* @return the parent list
*/
public static List<CommandDescription> constructParentList(CommandDescription command) {
List<CommandDescription> commands = new ArrayList<>();
CommandDescription currentCommand = command;
@@ -43,4 +53,35 @@ public final class CommandUtils {
}
return Lists.reverse(commands);
}
public static String buildSyntax(CommandDescription command) {
String arguments = command.getArguments().stream()
.map(arg -> formatArgument(arg))
.collect(Collectors.joining(" "));
return (constructCommandPath(command) + " " + arguments).trim();
}
public static String buildSyntax(CommandDescription command, List<String> correctLabels) {
String commandSyntax = ChatColor.WHITE + "/" + correctLabels.get(0) + ChatColor.YELLOW;
for (int i = 1; i < correctLabels.size(); ++i) {
commandSyntax += " " + correctLabels.get(i);
}
for (CommandArgumentDescription argument : command.getArguments()) {
commandSyntax += " " + formatArgument(argument);
}
return commandSyntax;
}
/**
* Format a command argument with the proper type of brackets.
*
* @param argument the argument to format
* @return the formatted argument
*/
public static String formatArgument(CommandArgumentDescription argument) {
if (argument.isOptional()) {
return "[" + argument.getName() + "]";
}
return "<" + argument.getName() + ">";
}
}
@@ -1,36 +0,0 @@
package fr.xephi.authme.command.help;
import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription;
import org.bukkit.ChatColor;
import java.util.List;
/**
* Helper class for displaying the syntax of a command properly to a user.
*/
final class CommandSyntaxHelper {
private CommandSyntaxHelper() {
}
public static String getSyntax(CommandDescription command, List<String> correctLabels) {
String commandSyntax = ChatColor.WHITE + "/" + correctLabels.get(0) + ChatColor.YELLOW;
for (int i = 1; i < correctLabels.size(); ++i) {
commandSyntax += " " + correctLabels.get(i);
}
for (CommandArgumentDescription argument : command.getArguments()) {
commandSyntax += " " + formatArgument(argument);
}
return commandSyntax;
}
/** Format a command argument with the proper type of brackets. */
private static String formatArgument(CommandArgumentDescription argument) {
if (argument.isOptional()) {
return "[" + argument.getName() + "]";
}
return "<" + argument.getName() + ">";
}
}
@@ -80,7 +80,7 @@ public class HelpProvider implements Reloadable {
if (hasFlag(SHOW_COMMAND, options)) {
lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.COMMAND) + ": "
+ CommandSyntaxHelper.getSyntax(command, correctLabels));
+ CommandUtils.buildSyntax(command, correctLabels));
}
if (hasFlag(SHOW_DESCRIPTION, options)) {
lines.add(ChatColor.GOLD + helpMessagesService.getMessage(SHORT_DESCRIPTION) + ": "
@@ -194,7 +194,7 @@ public class HelpProvider implements Reloadable {
// Create a list of alternatives
for (String label : command.getLabels()) {
if (!label.equalsIgnoreCase(usedLabel)) {
lines.add(" " + CommandSyntaxHelper.getSyntax(command, commandLabelsFn.apply(label)));
lines.add(" " + CommandUtils.buildSyntax(command, commandLabelsFn.apply(label)));
}
}
}
+193 -187
View File
@@ -15,191 +15,197 @@ softdepend:
- EssentialsSpawn
- ProtocolLib
commands:
authme:
description: AuthMe op commands
usage: '/authme reload|register playername password|changepassword playername password|unregister playername|version|converter'
register:
description: Register an account
usage: /register <password> <confirmpassword>
aliases: [reg]
login:
description: Login command
usage: /login <password>
aliases: [l,log]
changepassword:
description: Change password of an account
usage: /changepassword <oldPassword> <newPassword>
aliases: [cp,changepass]
logout:
description: Logout
usage: /logout
unregister:
description: Unregister your account
usage: /unregister <password>
aliases: [unreg]
email:
description: Add Email or recover password
usage: '/email add your@email.com your@email.com|change oldEmail newEmail|recovery your@email.com'
captcha:
description: Captcha command
usage: /captcha <code>
authme:
description: AuthMe op commands
usage: /authme register|unregister|forcelogin|password|lastlogin|accounts|email|setemail|getip|spawn|setspawn|firstspawn|setfirstspawn|purge|resetpos|purgebannedplayers|switchantibot|reload|version|converter|messages
login:
description: Login command
usage: /login <password>
aliases:
- l
- log
logout:
description: Logout command
usage: /logout
register:
description: Register an account
usage: /register [password] [verifyPassword]
aliases:
- reg
unregister:
description: Unregister an account
usage: /unregister <password>
aliases:
- unreg
changepassword:
description: Change password of an account
usage: /changepassword <oldPassword> <newPassword>
aliases:
- changepass
- cp
email:
description: Add email or recover password
usage: /email show|add|change|recover
captcha:
description: Captcha Command
usage: /captcha <captcha>
permissions:
authme.admin.*:
description: Give access to all admin commands.
children:
authme.admin.accounts: true
authme.admin.antibotmessages: true
authme.admin.changemail: true
authme.admin.changepassword: true
authme.admin.converter: true
authme.admin.firstspawn: true
authme.admin.forcelogin: true
authme.admin.getemail: true
authme.admin.getip: true
authme.admin.lastlogin: true
authme.admin.purge: true
authme.admin.purgebannedplayers: true
authme.admin.purgelastpos: true
authme.admin.register: true
authme.admin.reload: true
authme.admin.setfirstspawn: true
authme.admin.setspawn: true
authme.admin.spawn: true
authme.admin.switchantibot: true
authme.admin.unregister: true
authme.admin.updatemessages: true
authme.admin.register:
description: Administrator command to register a new user.
default: op
authme.admin.unregister:
description: Administrator command to unregister an existing user.
default: op
authme.admin.forcelogin:
description: Administrator command to force-login an existing user.
default: op
authme.admin.changepassword:
description: Administrator command to change the password of a user.
default: op
authme.admin.lastlogin:
description: Administrator command to see the last login date and time of a user.
default: op
authme.admin.accounts:
description: Administrator command to see all accounts associated with a user.
default: op
authme.admin.getemail:
description: Administrator command to get the email address of a user, if set.
default: op
authme.admin.changemail:
description: Administrator command to set or change the email address of a user.
default: op
authme.admin.getip:
description: Administrator command to get the last known IP of a user.
default: op
authme.admin.spawn:
description: Administrator command to teleport to the AuthMe spawn.
default: op
authme.admin.setspawn:
description: Administrator command to set the AuthMe spawn.
default: op
authme.admin.firstspawn:
description: Administrator command to teleport to the first AuthMe spawn.
default: op
authme.admin.setfirstspawn:
description: Administrator command to set the first AuthMe spawn.
default: op
authme.admin.purge:
description: Administrator command to purge old user data.
default: op
authme.admin.purgelastpos:
description: Administrator command to purge the last position of a user.
default: op
authme.admin.purgebannedplayers:
description: Administrator command to purge all data associated with banned players.
default: op
authme.admin.seeotheraccounts:
description: Permission for user to see other accounts.
default: op
authme.admin.switchantibot:
description: Administrator command to toggle the AntiBot protection status.
default: op
authme.admin.converter:
description: Administrator command to convert old or other data to AuthMe data.
default: op
authme.admin.reload:
description: Administrator command to reload the plugin configuration.
default: op
authme.admin.antibotmessages:
description: Permission to see Antibot messages.
default: op
authme.admin.updatemessages:
description: Permission to use the update messages command.
default: op
authme.player.*:
description: Permission to use all player (non-admin) commands.
children:
authme.player.canbeforced: true
authme.player.captcha: true
authme.player.changepassword: true
authme.player.email.add: true
authme.player.email.change: true
authme.player.email.recover: true
authme.player.login: true
authme.player.logout: true
authme.player.register: true
authme.player.unregister: true
authme.player.seeownaccounts: true
authme.player.email:
description: Gives access to player email commands
default: false
children:
authme.player.email.add: true
authme.player.email.change: true
authme.player.email.recover: true
authme.player.login:
description: Command permission to login.
default: true
authme.player.logout:
description: Command permission to logout.
default: true
authme.player.register:
description: Command permission to register.
default: true
authme.player.unregister:
description: Command permission to unregister.
default: true
authme.player.changepassword:
description: Command permission to change the password.
default: true
authme.player.email.add:
description: Command permission to add an email address.
default: true
authme.player.email.change:
description: Command permission to change the email address.
default: true
authme.player.email.recover:
description: Command permission to recover an account using its email address.
default: true
authme.player.captcha:
description: Command permission to use captcha.
default: true
authme.player.canbeforced:
description: Permission for users a login can be forced to.
default: true
authme.player.seeownaccounts:
description: Permission to use to see own other accounts.
default: true
authme.vip:
description: Allow vip slot when the server is full
default: op
authme.bypassantibot:
description: Bypass the AntiBot check
default: op
authme.allowmultipleaccounts:
description: Allow more accounts for same ip
default: op
authme.bypassforcesurvival:
description: Bypass all ForceSurvival features
default: op
authme.bypasspurge:
description: Permission to bypass the purging process
default: false
authme.admin.*:
description: Gives access to all admin commands
children:
authme.admin.accounts: true
authme.admin.antibotmessages: true
authme.admin.changemail: true
authme.admin.changepassword: true
authme.admin.converter: true
authme.admin.firstspawn: true
authme.admin.forcelogin: true
authme.admin.getemail: true
authme.admin.getip: true
authme.admin.lastlogin: true
authme.admin.purge: true
authme.admin.purgebannedplayers: true
authme.admin.purgelastpos: true
authme.admin.register: true
authme.admin.reload: true
authme.admin.seeotheraccounts: true
authme.admin.setfirstspawn: true
authme.admin.setspawn: true
authme.admin.spawn: true
authme.admin.switchantibot: true
authme.admin.unregister: true
authme.admin.updatemessages: true
authme.admin.accounts:
description: Administrator command to see all accounts associated with a user.
default: op
authme.admin.antibotmessages:
description: Permission to see Antibot messages.
default: op
authme.admin.changemail:
description: Administrator command to set or change the email address of a user.
default: op
authme.admin.changepassword:
description: Administrator command to change the password of a user.
default: op
authme.admin.converter:
description: Administrator command to convert old or other data to AuthMe data.
default: op
authme.admin.firstspawn:
description: Administrator command to teleport to the first AuthMe spawn.
default: op
authme.admin.forcelogin:
description: Administrator command to force-login an existing user.
default: op
authme.admin.getemail:
description: Administrator command to get the email address of a user, if set.
default: op
authme.admin.getip:
description: Administrator command to get the last known IP of a user.
default: op
authme.admin.lastlogin:
description: Administrator command to see the last login date and time of a user.
default: op
authme.admin.purge:
description: Administrator command to purge old user data.
default: op
authme.admin.purgebannedplayers:
description: Administrator command to purge all data associated with banned players.
default: op
authme.admin.purgelastpos:
description: Administrator command to purge the last position of a user.
default: op
authme.admin.register:
description: Administrator command to register a new user.
default: op
authme.admin.reload:
description: Administrator command to reload the plugin configuration.
default: op
authme.admin.seeotheraccounts:
description: Permission to see the other accounts of the players that log in.
default: op
authme.admin.setfirstspawn:
description: Administrator command to set the first AuthMe spawn.
default: op
authme.admin.setspawn:
description: Administrator command to set the AuthMe spawn.
default: op
authme.admin.spawn:
description: Administrator command to teleport to the AuthMe spawn.
default: op
authme.admin.switchantibot:
description: Administrator command to toggle the AntiBot protection status.
default: op
authme.admin.unregister:
description: Administrator command to unregister an existing user.
default: op
authme.admin.updatemessages:
description: Permission to use the update messages command.
default: op
authme.allowmultipleaccounts:
description: Permission to be able to register multiple accounts.
default: op
authme.bypassantibot:
description: Permission node to bypass AntiBot protection.
default: op
authme.bypassforcesurvival:
description: Permission for users to bypass force-survival mode.
default: op
authme.bypasspurge:
description: Permission to bypass the purging process.
default: false
authme.player.*:
description: Gives access to all player commands
children:
authme.player.canbeforced: true
authme.player.captcha: true
authme.player.changepassword: true
authme.player.email.add: true
authme.player.email.change: true
authme.player.email.recover: true
authme.player.login: true
authme.player.logout: true
authme.player.register: true
authme.player.seeownaccounts: true
authme.player.unregister: true
authme.player.canbeforced:
description: Permission for users a login can be forced to.
default: true
authme.player.captcha:
description: Command permission to use captcha.
default: true
authme.player.changepassword:
description: Command permission to change the password.
default: true
authme.player.email:
description: Gives access to all email commands
children:
authme.player.email.add: true
authme.player.email.change: true
authme.player.email.recover: true
authme.player.email.add:
description: Command permission to add an email address.
default: true
authme.player.email.change:
description: Command permission to change the email address.
default: true
authme.player.email.recover:
description: Command permission to recover an account using its email address.
default: true
authme.player.login:
description: Command permission to login.
default: true
authme.player.logout:
description: Command permission to logout.
default: true
authme.player.register:
description: Command permission to register.
default: true
authme.player.seeownaccounts:
description: Permission to use to see own other accounts.
default: true
authme.player.unregister:
description: Command permission to unregister.
default: true
authme.vip:
description: Permission node to identify VIP users.
default: op